| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <script src="../../resources/testharness.js"></script> |
| 2 <html> | 2 <script src="../../resources/testharnessreport.js"></script> |
| 3 <head> | |
| 4 <title>Canvas Hit Regions: transform test</title> | |
| 5 <script src="../../resources/js-test.js"></script> | |
| 6 </head> | |
| 7 <body> | 3 <body> |
| 8 <canvas id="canvas" width="400" height="400"></canvas> | 4 <canvas id="canvas" width="400" height="400"></canvas> |
| 9 <script src="./resources/canvas-hit-region-event.js"></script> | 5 <script src="./resources/canvas-hit-region-event.js"></script> |
| 10 <script> | 6 <script> |
| 7 test(function(t) { |
| 11 | 8 |
| 12 var canvas = document.getElementById("canvas"); | 9 var canvas = document.getElementById("canvas"); |
| 13 var context = canvas.getContext("2d"); | 10 var context = canvas.getContext("2d"); |
| 14 var testSet = []; | 11 var testSet = []; |
| 15 | 12 |
| 16 function clickTests(message, tests) | 13 function clickTests(message, tests) |
| 17 { | 14 { |
| 18 testSet.push({ | |
| 19 type : "debug", | |
| 20 message : message | |
| 21 }); | |
| 22 | |
| 23 for (var i = 0; i < tests.length; i++) | 15 for (var i = 0; i < tests.length; i++) |
| 24 testSet.push({ | 16 testSet.push({ |
| 25 type : "shouldBe", | |
| 26 actual : clickCanvas(tests[i].x, tests[i].y), | 17 actual : clickCanvas(tests[i].x, tests[i].y), |
| 27 expected : tests[i].expected | 18 expected : tests[i].expected |
| 28 }); | 19 }); |
| 29 | |
| 30 testSet.push({ | |
| 31 type : "debug", | |
| 32 message : "" | |
| 33 }); | |
| 34 } | 20 } |
| 35 | 21 |
| 36 function createHitRegion(pathMethod) | 22 function createHitRegion(pathMethod) |
| 37 { | 23 { |
| 38 context.removeHitRegion("hit"); | 24 context.removeHitRegion("hit"); |
| 39 context.beginPath(); | 25 context.beginPath(); |
| 40 context.save(); | 26 context.save(); |
| 41 pathMethod(); | 27 pathMethod(); |
| 42 context.restore(); | 28 context.restore(); |
| 43 context.addHitRegion({ | 29 context.addHitRegion({ |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 { x : 36, y : 12, expected : null }, | 135 { x : 36, y : 12, expected : null }, |
| 150 { x : 40, y : 33, expected : null }, | 136 { x : 40, y : 33, expected : null }, |
| 151 { x : 9, y : 31, expected : null }, | 137 { x : 9, y : 31, expected : null }, |
| 152 { x : 18, y : 41, expected : "hit" }, | 138 { x : 18, y : 41, expected : "hit" }, |
| 153 { x : 12, y : 25, expected : "hit" }, | 139 { x : 12, y : 25, expected : "hit" }, |
| 154 { x : 25, y : 42, expected : null }, | 140 { x : 25, y : 42, expected : null }, |
| 155 ]); | 141 ]); |
| 156 | 142 |
| 157 for (var i = 0; i < testSet.length; i++) { | 143 for (var i = 0; i < testSet.length; i++) { |
| 158 var test = testSet[i]; | 144 var test = testSet[i]; |
| 159 | 145 window.region = test.expected; |
| 160 if (test.type == "debug") { | 146 assert_equals(region, test.actual); |
| 161 debug(test.message); | |
| 162 } | |
| 163 else if (test.type == "shouldBe") { | |
| 164 window.region = test.expected; | |
| 165 if (test.expected == null) | |
| 166 shouldBe("region", String(test.actual)); | |
| 167 else | |
| 168 shouldBe("region", "'" + test.actual + "'"); | |
| 169 } | |
| 170 } | 147 } |
| 171 | 148 |
| 149 }, 'Canvas Hit Regions: transform test'); |
| 172 </script> | 150 </script> |
| 173 </body> | 151 </body> |
| 174 </html> | |
| OLD | NEW |