summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/test_hitregion_canvas.html
blob: 452cb33b631988b1ae1567c70d5ac34200b81ba9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE HTML>
<title>Canvas Tests</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<body>
<script>

SimpleTest.waitForExplicitFinish();
const Cc = SpecialPowers.Cc;
const Cr = SpecialPowers.Cr;
</script>

<p>Canvas test: hit regions</p>
<canvas id="c1" width="150" height="50">
  <a id="c1_a"></a>
</canvas>
<a id="c1_b"></a>

<script type="text/javascript">

function test_hitregions() {
  var c = document.getElementById("c1");
  var d = document.getElementById("c1_a");
  var e = document.getElementById("c1_b");

  var ctx = c.getContext("2d");
  var _thrown_outer = false;
  try {
    ctx.rect(10,10,100,100);
    ctx.addHitRegion({control: d});
    ctx.addHitRegion({control: e});
    ctx.addHitRegion({id: "a", control: d});
    ctx.addHitRegion({id: "a", control: d});

    ctx.removeHitRegion("a");
    ctx.removeHitRegion("a");
    ctx.removeHitRegion("b");

    ctx.clearHitRegions();
  } catch (e) {
      _thrown_outer = true;
  }
  ok(!_thrown_outer, ctx.canvas.id + ' should not throw exception');

  var _thrown_outer = false;
  try {
    ctx.rect(10,10,100,100);
    ctx.addHitRegion({control: d});
    ctx.addHitRegion({control: e});
    ctx.addHitRegion({id: "a", control: d});
    ctx.addHitRegion({id: "a", control: d});

    ctx.clearHitRegions();
  } catch (e) {
      _thrown_outer = true;
  }
  ok(!_thrown_outer, ctx.canvas.id + ' should not throw exception');

  var _thrown = undefined; try {
    ctx.beginPath();
    ctx.addHitRegion({control: d});
  } catch (ex) { _thrown = ex };

  ok(_thrown && _thrown.name == "NotSupportedError", "should throw NotSupportedError");

}
</script>

<script>
 
function runTests() {
 try {
  test_hitregions();
 } catch(e) {
  throw e;
  ok(false, "unexpected exception thrown in: test_hitregions");
 }
 SimpleTest.finish();
}

addLoadEvent(function() {
  SpecialPowers.pushPrefEnv({"set":[["canvas.hitregions.enabled", true]]}, runTests);
});
</script>