Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / canvas / canvas-lose-restore-googol-size.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <script>
8 description("Tests to ensure correct behaviour of canvas loss and restoration when size is extremely large then, restored to a reasonable value.");
9
10 if (window.testRunner) {
11     testRunner.dumpAsText();
12     testRunner.waitUntilDone();
13 }
14
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);
21
22 var googol = Math.pow(10,100);
23 canvas.width = googol;
24 canvas.height = googol;
25 verifyContextLost(true);
26 canvas.width = googol;
27 verifyContextLost(true);
28 canvas.width = 100;
29 canvas.height = 100;
30 verifyContextLost(true); // Restoration is async.
31
32 // Restore a sane dimension
33
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;
39     if (shouldBeLost) {
40         shouldBeTrue('contextLostTest');
41         shouldBeTrue('ctx.isContextLost()');
42     } else {
43         shouldBeFalse('contextLostTest');
44         shouldBeFalse('ctx.isContextLost()');
45     }
46 }
47
48 function contextLost() {
49     if (lostEventHasFired) {
50         testFailed('Context lost event was dispatched more than once.');
51     } else {
52         testPassed('Graphics context lost event dispatched.');
53     }
54     lostEventHasFired = true;
55     verifyContextLost(true);
56 }
57
58 function contextRestored() {
59     if (lostEventHasFired) {
60         testPassed('Context restored event dispatched after context lost.');
61     } else {
62         testFailed('Context restored event was dispatched before a context lost event.');
63     }
64     verifyContextLost(false);
65         if (window.testRunner) {
66         testRunner.notifyDone(); 
67     }
68 }
69 </script>
70 </body>
71 </html>