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

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

Issue 2799893002: Rewrite flaky canvas test to testharness.js to sidestep issue (Closed)
Patch Set: rebase Created 3 years, 8 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 <!doctype html>
2 <html> 2 <title>Canvas loss and restoration when size is extremely large and then restore d to a reasonable value</title>
3 <head> 3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/js-test.js"></script> 4 <script src="../../resources/testharnessreport.js"></script>
5 </head>
6 <body>
7 <script> 5 <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."); 6 async_test(t => {
7 var canvas = document.createElement('canvas')
8 canvas.addEventListener('contextlost', t.step_func(contextLost));
9 canvas.addEventListener('contextrestored', t.step_func(contextRestored));
10 var ctx = canvas.getContext('2d');
11 var lostEventHasFired = false;
12 verifyContextLost(false);
9 13
10 if (window.testRunner) { 14 var bigsize = 1000000000;
11 testRunner.dumpAsText(); 15 canvas.width = bigsize;
12 testRunner.waitUntilDone(); 16 canvas.height = bigsize;
13 } 17 verifyContextLost(true);
18 canvas.width = bigsize;
19 verifyContextLost(true);
20 // Restore a reasonable dimension
21 canvas.width = 100;
22 canvas.height = 100;
23 verifyContextLost(true); // Restoration is async.
14 24
15 var canvas = document.createElement('canvas') 25 function verifyContextLost(shouldBeLost) {
16 canvas.addEventListener('contextlost', contextLost); 26 // Verify context loss experimentally as well as isContextLost()
17 canvas.addEventListener('contextrestored', contextRestored); 27 ctx.fillStyle = '#0f0';
18 var ctx = canvas.getContext('2d'); 28 ctx.fillRect(0, 0, 1, 1);
19 var lostEventHasFired = false; 29 var contextLostTest = ctx.getImageData(0, 0, 1, 1).data[1] == 0;
20 verifyContextLost(false); 30 assert_equals(contextLostTest, shouldBeLost, 'image data is blank');
31 assert_equals(ctx.isContextLost(), shouldBeLost, 'context is lost');
32 }
21 33
22 var bigsize = 1000000000; 34 function contextLost() {
23 canvas.width = bigsize; 35 assert_false(lostEventHasFired, 'contextlost event has fired');
24 canvas.height = bigsize; 36 lostEventHasFired = true;
25 verifyContextLost(true); 37 verifyContextLost(true);
26 canvas.width = bigsize; 38 }
27 verifyContextLost(true);
28 canvas.width = 100;
29 canvas.height = 100;
30 verifyContextLost(true); // Restoration is async.
31 39
32 // Restore a sane dimension 40 function contextRestored() {
33 41 assert_true(lostEventHasFired, 'contextlost event has fired');
34 function verifyContextLost(shouldBeLost) { 42 verifyContextLost(false);
35 // Verify context loss experimentally as well as isContextLost() 43 t.done();
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 } 44 }
46 } 45 });
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> 46 </script>
70 </body>
71 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698