Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE HTML> | |
| 2 <head> | 1 <head> |
| 3 <title>Canvas Hit Regions: accessibility test</title> | 2 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/js-test.js"></script> | 3 <script src="../../resources/testharnessreport.js"></script> |
| 5 </head> | |
| 6 <body> | 4 <body> |
| 7 <canvas id="canvas"> | 5 <canvas id="canvas"> |
| 8 <button id="button1"></button> | 6 <button id="button1"></button> |
| 9 <div id="container1"> | 7 <div id="container1"> |
| 10 <button id="button2"></button> | 8 <button id="button2"></button> |
| 11 <button id="button3"></button> | 9 <button id="button3"></button> |
| 12 </div> | 10 </div> |
| 13 <div id="container2"> | 11 <div id="container2"> |
| 14 <div id="container3"> | 12 <div id="container3"> |
| 15 <button id="button4"></button> | 13 <button id="button4"></button> |
| 16 <button id="button5"></button> | 14 <button id="button5"></button> |
| 17 </div> | 15 </div> |
| 18 <button id="button6"></button> | 16 <button id="button6"></button> |
| 19 </div> | 17 </div> |
| 20 </canvas> | 18 </canvas> |
| 21 <div id="console"></div> | 19 <div id="console"></div> |
| 22 <script> | 20 <script> |
| 23 | 21 |
| 24 var canvas = document.getElementById("canvas"); | 22 var canvas = document.getElementById("canvas"); |
| 25 var context = canvas.getContext("2d"); | 23 var context = canvas.getContext("2d"); |
| 26 | 24 |
| 27 function drawRectAndAddHitRegion(control, x, y, width, height) { | 25 function drawRectAndAddHitRegion(control, x, y, width, height) { |
| 28 if (window.accessibilityController) | 26 if (window.accessibilityController) |
| 29 window["ax" + control] = accessibilityController.accessibleElementById(con trol); | 27 window["ax" + control] = accessibilityController.accessibleElementById(contr ol); |
| 30 | 28 |
| 31 context.beginPath(); | 29 context.beginPath(); |
| 32 context.rect(x, y, width, height); | 30 context.rect(x, y, width, height); |
| 33 context.fill(); | 31 context.fill(); |
| 34 context.addHitRegion({ | 32 context.addHitRegion({ |
| 35 id : control, | 33 id : control, |
| 36 control : document.getElementById(control) | 34 control : document.getElementById(control) |
| 37 }); | 35 }); |
| 38 } | 36 } |
| 39 | 37 |
| 40 function testAccessibilityRect(control, x, y, width, height) { | 38 function testAccessibilityRect(control, x, y, width, height) { |
| 41 | 39 |
| 42 if (window.accessibilityController && !window["ax" + control]) | 40 if (window.accessibilityController && !window["ax" + control]) |
| 43 window["ax" + control] = accessibilityController.accessibleElementById(con trol); | 41 window["ax" + control] = accessibilityController.accessibleElementById(contr ol); |
| 44 | 42 |
| 45 shouldBe("ax" + control + ".x", x.toString()); | 43 assert_equals(eval("ax" + control + ".x"), x); |
| 46 shouldBe("ax" + control + ".y", y.toString()); | 44 assert_equals(eval("ax" + control + ".y"), y); |
| 47 shouldBe("ax" + control + ".width", width.toString()); | 45 assert_equals(eval("ax" + control + ".width"), width); |
| 48 shouldBe("ax" + control + ".height", height.toString()); | 46 assert_equals(eval("ax" + control + ".height"), height); |
| 49 } | 47 } |
| 50 | 48 |
| 49 test(function(t) { | |
|
Justin Novosad
2017/02/09 20:37:19
should use generate_tests here
zakerinasab
2017/02/13 17:06:10
Done.
| |
| 51 drawRectAndAddHitRegion("button1", 0, 0, 200, 200); | 50 drawRectAndAddHitRegion("button1", 0, 0, 200, 200); |
| 52 drawRectAndAddHitRegion("button2", 0, 0, 100, 50); | 51 drawRectAndAddHitRegion("button2", 0, 0, 100, 50); |
| 53 drawRectAndAddHitRegion("button3", 40, 20, 50, 70); | 52 drawRectAndAddHitRegion("button3", 40, 20, 50, 70); |
| 54 drawRectAndAddHitRegion("button4", 0, 0, 100, 50); | 53 drawRectAndAddHitRegion("button4", 0, 0, 100, 50); |
| 55 drawRectAndAddHitRegion("button5", 40, 20, 50, 70); | 54 drawRectAndAddHitRegion("button5", 40, 20, 50, 70); |
| 56 drawRectAndAddHitRegion("button6", 20, 10, 140, 30); | 55 drawRectAndAddHitRegion("button6", 20, 10, 140, 30); |
| 57 drawRectAndAddHitRegion("button7", 0, 0, 200, 200); | 56 drawRectAndAddHitRegion("button7", 0, 0, 200, 200); |
| 58 | 57 |
| 59 debug("Just one button tests."); | 58 // Just one button tests. |
| 60 testAccessibilityRect("button1", 8, 8, 200, 200); | 59 testAccessibilityRect("button1", 8, 8, 200, 200); |
| 61 debug(""); | 60 |
| 62 | 61 // The container1 has two buttons. |
| 63 debug("The container1 has two buttons."); | |
| 64 testAccessibilityRect("button2", 8, 8, 100, 50); | 62 testAccessibilityRect("button2", 8, 8, 100, 50); |
| 65 testAccessibilityRect("button3", 48, 28, 50, 70); | 63 testAccessibilityRect("button3", 48, 28, 50, 70); |
| 66 testAccessibilityRect("container1", 8, 8, 100, 90); | 64 testAccessibilityRect("container1", 8, 8, 100, 90); |
| 67 debug(""); | 65 |
| 68 | 66 // Remove the button2 from the container1. |
| 69 debug("Remove the button2 from the container1."); | |
| 70 document.getElementById("container1").removeChild(document.getElementById("but ton2")); | 67 document.getElementById("container1").removeChild(document.getElementById("but ton2")); |
| 71 testAccessibilityRect("container1", 48, 28, 50, 70); | 68 testAccessibilityRect("container1", 48, 28, 50, 70); |
| 72 debug(""); | 69 |
| 73 | 70 // Depth-two container tests. |
| 74 debug("Depth-two container tests."); | |
| 75 testAccessibilityRect("button4", 8, 8, 100, 50); | 71 testAccessibilityRect("button4", 8, 8, 100, 50); |
| 76 testAccessibilityRect("button5", 48, 28, 50, 70); | 72 testAccessibilityRect("button5", 48, 28, 50, 70); |
| 77 testAccessibilityRect("button6", 28, 18, 140, 30); | 73 testAccessibilityRect("button6", 28, 18, 140, 30); |
| 78 testAccessibilityRect("container2", 8, 8, 160, 90); | 74 testAccessibilityRect("container2", 8, 8, 160, 90); |
| 79 testAccessibilityRect("container3", 8, 8, 100, 90); | 75 testAccessibilityRect("container3", 8, 8, 100, 90); |
| 80 debug(""); | 76 }, 'Test canvas hit regions (accessibility test).'); |
| 81 | |
| 82 </script> | 77 </script> |
| 83 </body> | 78 </body> |
| 84 </html> | |
| OLD | NEW |