Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/canvas/canvas-lose-restore-max-int-size.html

Issue 2643193002: Deflake virtual/gpu/fast/canvas/canvas-lose-restore-max-int-size.html (Closed)
Patch Set: Remove test expectations Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> 1 <script src="../../resources/testharness.js"></script>
2 <html> 2 <script src="../../resources/testharnessreport.js"></script>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <script> 3 <script>
8 description("Tests to ensure correct behaviour of canvas loss and restoration wh en size is extremely large then, restored to a reasonable value."); 4 var canvas = document.createElement('canvas')
5 var ctx = canvas.getContext('2d');
9 6
10 if (window.testRunner) { 7 function verifyContextLost(shouldBeLost, message) {
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 // 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);
29 canvas.width = 100;
30 canvas.height = 100;
31 verifyContextLost(true); // Restoration is async.
32 // Restore a sane dimension
33
34 function verifyContextLost(shouldBeLost) {
35 // Verify context loss experimentally as well as isContextLost() 8 // Verify context loss experimentally as well as isContextLost()
36 ctx.fillStyle = '#0f0'; 9 ctx.fillStyle = '#0f0';
37 ctx.fillRect(0, 0, 1, 1); 10 ctx.fillRect(0, 0, 1, 1);
38 contextLostTest = ctx.getImageData(0, 0, 1, 1).data[1] == 0; 11 var contextLostTest = ctx.getImageData(0, 0, 1, 1).data[1] == 0;
39 if (shouldBeLost) { 12 assert_equals(contextLostTest, shouldBeLost, message + ': Ability to read a write to context');
40 shouldBeTrue('contextLostTest'); 13 assert_equals(ctx.isContextLost(), shouldBeLost, message + ': Context lost s tate');
41 shouldBeTrue('ctx.isContextLost()');
42 } else {
43 shouldBeFalse('contextLostTest');
44 shouldBeFalse('ctx.isContextLost()');
45 }
46 } 14 }
47 15
48 function contextLost() { 16 test(() => {
49 if (lostEventHasFired) { 17 verifyContextLost(false, 'initial state');
50 testFailed('Context lost event was dispatched more than once.'); 18 }, 'Context should initially not be lost');
51 } else {
52 testPassed('Graphics context lost event dispatched.');
53 }
54 lostEventHasFired = true;
55 verifyContextLost(true);
56 }
57 19
58 function contextRestored() { 20 test(() => {
59 if (lostEventHasFired) { 21 // WebIDL defines width and height as int. 2147483647 is int max.
60 testPassed('Context restored event dispatched after context lost.'); 22 var extremelyLargeNumber = 2147483647;
61 } else { 23 canvas.width = extremelyLargeNumber;
62 testFailed('Context restored event was dispatched before a context lost event.'); 24 canvas.height = extremelyLargeNumber;
63 } 25 verifyContextLost(true, 'extremely large height set');
64 verifyContextLost(false); 26 canvas.width = extremelyLargeNumber;
65 » if (window.testRunner) { 27 verifyContextLost(true, 'extremely large width set');
66 » testRunner.notifyDone(); 28 // Restore a sane dimension
67 } 29 canvas.width = 100;
68 } 30 canvas.height = 100;
31 // Restoration is async.
32 verifyContextLost(true, 'reasonable size set');
33 }, 'Context should be lost when size is set to an extremely large number and the n restored when set to a reasonable number');
34
35 var lostEventHasFired = false;
36 promise_test(() => {
37 return new Promise(resolve => {
38 canvas.addEventListener('contextlost', () => {
39 assert_false(lostEventHasFired, 'contextLost should only be fired on ce');
40 lostEventHasFired = true;
41 verifyContextLost(true);
42 resolve();
43 });
44 });
45 }, 'contextlost event should fire after size is set to extremely large number');
46
47 promise_test(() => {
48 return new Promise(resolve => {
49 canvas.addEventListener('contextrestored', () => {
50 assert_true(lostEventHasFired, 'Lost context event should fire befor e resorted context event');
51 verifyContextLost(false);
52 resolve();
53 });
54 });
55 }, 'contextrestored event should fire after size is restored to a reasonable num ber');
69 </script> 56 </script>
70 </body>
71 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698