|
1 <!DOCTYPE HTML> |
|
2 <title>Canvas Tests</title> |
|
3 <script src="/tests/SimpleTest/SimpleTest.js"></script> |
|
4 <link rel="stylesheet" href="/tests/SimpleTest/test.css"> |
|
5 <body> |
|
6 <script> |
|
7 |
|
8 SimpleTest.waitForExplicitFinish(); |
|
9 const Cc = SpecialPowers.Cc; |
|
10 const Cr = SpecialPowers.Cr; |
|
11 SpecialPowers.setBoolPref("canvas.hitregions.enabled", true); |
|
12 |
|
13 </script> |
|
14 |
|
15 <p>Canvas test: hit regions</p> |
|
16 <canvas id="c1" width="150" height="50"> |
|
17 <a id="c1_a"></a> |
|
18 </canvas> |
|
19 <a id="c1_b"></a> |
|
20 |
|
21 <script type="text/javascript"> |
|
22 |
|
23 function test_hitregions() { |
|
24 var c = document.getElementById("c1"); |
|
25 var d = document.getElementById("c1_a"); |
|
26 var e = document.getElementById("c1_b"); |
|
27 |
|
28 var ctx = c.getContext("2d"); |
|
29 var _thrown_outer = false; |
|
30 try { |
|
31 ctx.rect(10,10,100,100); |
|
32 ctx.addHitRegion({control: d}); |
|
33 ctx.addHitRegion({control: e}); |
|
34 ctx.addHitRegion({id: "a", control: d}); |
|
35 ctx.addHitRegion({id: "a", control: d}); |
|
36 |
|
37 ctx.removeHitRegion("a"); |
|
38 ctx.removeHitRegion("a"); |
|
39 ctx.removeHitRegion("b"); |
|
40 } catch (e) { |
|
41 _thrown_outer = true; |
|
42 } |
|
43 ok(!_thrown_outer, ctx.canvas.id + ' should not throw exception'); |
|
44 |
|
45 var _thrown = undefined; try { |
|
46 ctx.beginPath(); |
|
47 ctx.addHitRegion({control: d}); |
|
48 } catch (ex) { _thrown = ex }; |
|
49 |
|
50 ok(_thrown && _thrown.name == "NotSupportedError", "should throw NotSupportedError"); |
|
51 |
|
52 } |
|
53 </script> |
|
54 |
|
55 <script> |
|
56 |
|
57 function runTests() { |
|
58 try { |
|
59 test_hitregions(); |
|
60 } catch(e) { |
|
61 throw e; |
|
62 ok(false, "unexpected exception thrown in: test_hitregions"); |
|
63 } |
|
64 SimpleTest.finish(); |
|
65 SpecialPowers.setBoolPref("canvas.hitregions.enabled", false); |
|
66 } |
|
67 |
|
68 addLoadEvent(runTests); |
|
69 |
|
70 </script> |