OLD | NEW |
1 <!DOCTYPE HTML> | 1 <script src="../../resources/testharness.js"></script> |
2 <head> | 2 <script src="../../resources/testharnessreport.js"></script> |
3 <title>Canvas test: drawFocusIfNeeded with Path2D</title> | 3 |
4 <script src="../../resources/js-test.js"></script> | |
5 </head> | |
6 <body style="padding: 0; margin: 0"> | |
7 <canvas id="canvas" class="output" width="300" height="350"> | 4 <canvas id="canvas" class="output" width="300" height="350"> |
8 <button id="button1"></button> | 5 <button id="button1"></button> |
9 <button id="button2"></button> | 6 <button id="button2"></button> |
10 </canvas> | 7 </canvas> |
| 8 |
11 <script> | 9 <script> |
12 if (window.testRunner) | 10 test(function(t) { |
13 testRunner.dumpAsText(); | |
14 | 11 |
15 document.getElementById("button1").focus(); | 12 document.getElementById("button1").focus(); |
16 | 13 |
17 var canvas = document.getElementById("canvas").getContext("2d"); | 14 var canvas = document.getElementById("canvas").getContext("2d"); |
18 | 15 |
19 shouldThrow('canvas.drawFocusIfNeeded(undefined);'); | 16 assert_throws(null, function(){canvas.drawFocusIfNeeded(undefined);}); |
20 shouldThrow('canvas.drawFocusIfNeeded(undefined, undefined);'); | 17 assert_throws(null, function(){canvas.drawFocusIfNeeded(undefined, undefined
);}); |
21 shouldThrow('canvas.drawFocusIfNeeded(null);'); | 18 assert_throws(null, function(){canvas.drawFocusIfNeeded(null);}); |
22 shouldThrow('canvas.drawFocusIfNeeded(null, null);'); | 19 assert_throws(null, function(){canvas.drawFocusIfNeeded(null, null);}); |
23 shouldThrow('canvas.drawFocusIfNeeded();'); | 20 assert_throws(null, function(){canvas.drawFocusIfNeeded();}); |
24 | 21 |
25 var path = new Path2D(); | 22 var path = new Path2D(); |
26 path.rect(50, 50, 200, 100); | 23 path.rect(50, 50, 200, 100); |
27 canvas.fillStyle = "#ccf"; | 24 canvas.fillStyle = "#ccf"; |
28 canvas.fill(path); | 25 canvas.fill(path); |
29 // re-test null case after having defined a path (regression test for crbug.com/
353248) | 26 // re-test null case after having defined a path (regression test for crbug.
com/353248) |
30 shouldThrow('canvas.drawFocusIfNeeded(null);'); | 27 assert_throws(null, function(){canvas.drawFocusIfNeeded(null);}); |
31 shouldThrow('canvas.drawFocusIfNeeded(null, null);'); | 28 assert_throws(null, function(){canvas.drawFocusIfNeeded(null, null);}); |
32 canvas.drawFocusIfNeeded(path, document.getElementById("button1")); | 29 canvas.drawFocusIfNeeded(path, document.getElementById("button1")); |
33 | 30 |
34 path = new Path2D(); | 31 path = new Path2D(); |
35 path.rect(50, 200, 200, 100); | 32 path.rect(50, 200, 200, 100); |
36 canvas.fillStyle = "#cfc"; | 33 canvas.fillStyle = "#cfc"; |
37 canvas.fill(path); | 34 canvas.fill(path); |
38 canvas.drawFocusIfNeeded(path, document.getElementById("button2")); | 35 canvas.drawFocusIfNeeded(path, document.getElementById("button2")); |
39 | 36 |
40 // The top rect"s focus ring is tied to button1, which is focused. | 37 // The top rect"s focus ring is tied to button1, which is focused. |
41 // It should have an outline in some color other than the background color. | 38 // It should have an outline in some color other than the background color. |
42 var imageData = canvas.getImageData(49, 50, 1, 1); | 39 var imageData = canvas.getImageData(49, 50, 1, 1); |
43 var data = imageData.data; | 40 var data = imageData.data; |
44 shouldBe("data[0] != 0 || data[1] != 0 || data[2] != 0", "true"); | 41 assert_true(data[0] != 0 || data[1] != 0 || data[2] != 0); |
45 | 42 |
46 // The bottom rect"s focus ring is tied to button2, which is not focused. | 43 // The bottom rect"s focus ring is tied to button2, which is not focused. |
47 imageData = canvas.getImageData(49, 200, 1, 1); | 44 imageData = canvas.getImageData(49, 200, 1, 1); |
48 data = imageData.data; | 45 data = imageData.data; |
49 shouldBe("data[0] == 0 && data[1] == 0 && data[2] == 0", "true"); | 46 assert_true(data[0] == 0 && data[1] == 0 && data[2] == 0); |
| 47 |
| 48 }, 'Canvas test: drawFocusIfNeeded with Path2D'); |
50 </script> | 49 </script> |
51 </body> | 50 </body> |
OLD | NEW |