1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
4 <script src=
"../../resources/js-test.js"></script>
8 description("Tests to ensure correct behaviour of canvas loss and restoration when size is extremely large then, restored to a reasonable value.");
10 if (window
.testRunner
) {
11 testRunner
.dumpAsText();
12 testRunner
.waitUntilDone();
15 var canvas
= document
.createElement('canvas')
16 canvas
.addEventListener('contextlost', contextLost
);
17 canvas
.addEventListener('contextrestored', contextRestored
);
18 var ctx
= canvas
.getContext('2d');
19 var lostEventHasFired
= false;
20 verifyContextLost(false);
22 // WebIDL defines width and height as int. 2147483647 is int max.
23 var extremelyLargeNumber
= 2147483647;
24 canvas
.width
= extremelyLargeNumber
;
25 canvas
.height
= extremelyLargeNumber
;
26 verifyContextLost(true);
27 canvas
.width
= extremelyLargeNumber
;
28 verifyContextLost(true);
31 verifyContextLost(true); // Restoration is async.
32 // Restore a sane dimension
34 function verifyContextLost(shouldBeLost
) {
35 // Verify context loss experimentally as well as isContextLost()
36 ctx
.fillStyle
= '#0f0';
37 ctx
.fillRect(0, 0, 1, 1);
38 contextLostTest
= ctx
.getImageData(0, 0, 1, 1).data
[1] == 0;
40 shouldBeTrue('contextLostTest');
41 shouldBeTrue('ctx.isContextLost()');
43 shouldBeFalse('contextLostTest');
44 shouldBeFalse('ctx.isContextLost()');
48 function contextLost() {
49 if (lostEventHasFired
) {
50 testFailed('Context lost event was dispatched more than once.');
52 testPassed('Graphics context lost event dispatched.');
54 lostEventHasFired
= true;
55 verifyContextLost(true);
58 function contextRestored() {
59 if (lostEventHasFired
) {
60 testPassed('Context restored event dispatched after context lost.');
62 testFailed('Context restored event was dispatched before a context lost event.');
64 verifyContextLost(false);
65 if (window
.testRunner
) {
66 testRunner
.notifyDone();