summaryrefslogtreecommitdiffstats
path: root/accessible/tests/mochitest/elm/test_canvas.html
blob: 65d6d4bca48767f89700d76f84ef4be2c151a725 (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
<!DOCTYPE html>
<html>
<head>
  <title>Accessible boundaries for hit regions</title>
  <link rel="stylesheet" type="text/css"
        href="chrome://mochikit/content/tests/SimpleTest/test.css" />

  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>

  <script type="application/javascript"
          src="../common.js"></script>
  <script type="application/javascript"
          src="../role.js"></script>
  <script type="application/javascript"
          src="../layout.js"></script>

  <script type="application/javascript">
    var kX = 10, kY = 10, kWidth = 150, kHeight = 100;
    function doTest() {
      var canv = document.getElementById("c");
      var context = canv.getContext("2d");
      var element = document.getElementById("showA");
      context.beginPath();
      context.rect(kX, kY, kWidth, kHeight);
      context.addHitRegion({control: element});

      var input = getAccessible("showA");
      var [cnvX, cnvY, /* cnvWidth */, /* cnvHeight */] = getBoundsForDOMElm(canv);
      var [accX, accY, accWidth, accHeight] = getBounds(input);

      var [x, y, w, h] = CSSToDevicePixels(window, kX, kY, kWidth, kHeight);
      is(accX, cnvX + x, "wrong accX");
      is(accY, cnvY + y, "wrong accY");
      is(accWidth, w, "wrong accWidth");
      is(accHeight, h, "wrong accHeight");

      SimpleTest.finish();
    }

    SimpleTest.waitForExplicitFinish();
    addA11yLoadEvent(function() {
      SpecialPowers.pushPrefEnv({"set": [["canvas.hitregions.enabled", true]]}, doTest);
    });

    </script>
</head>
<body>

  <canvas id="c">
    <input id="showA" type="checkbox"><label for="showA"> Show As </label>
  </canvas>

</body>
</html>