accessible/tests/mochitest/hittest/test_canvas_hitregion.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/tests/mochitest/hittest/test_canvas_hitregion.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,88 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>nsIAccessible::childAtPoint() for canvas from browser tests</title>
     1.8 +  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
     1.9 +
    1.10 +  <script type="application/javascript"
    1.11 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +
    1.13 +  <script type="application/javascript"
    1.14 +          src="../common.js"></script>
    1.15 +  <script type="application/javascript"
    1.16 +          src="../layout.js"></script>
    1.17 +
    1.18 +  <script type="application/javascript">
    1.19 +    SpecialPowers.setBoolPref("canvas.hitregions.enabled", true);
    1.20 +
    1.21 +    function redrawCheckbox(context, element, x, y)
    1.22 +    {
    1.23 +      context.save();
    1.24 +      context.font = '10px sans-serif';
    1.25 +      context.textAlign = 'left';
    1.26 +      context.textBaseline = 'middle';
    1.27 +      var metrics = context.measureText(element.parentNode.textContent);
    1.28 +      context.beginPath();
    1.29 +      context.strokeStyle = 'black';
    1.30 +      context.rect(x-5, y-5, 10, 10);
    1.31 +      context.stroke();
    1.32 +      if (element.checked) {
    1.33 +        context.fillStyle = 'black';
    1.34 +        context.fill();
    1.35 +      }
    1.36 +      context.fillText(element.parentNode.textContent, x+5, y);
    1.37 +
    1.38 +      context.beginPath();
    1.39 +      context.rect(x-7, y-7, 12 + metrics.width+2, 14);
    1.40 +
    1.41 +      if (document.activeElement == element)
    1.42 +        context.drawFocusIfNeeded(element);
    1.43 +      context.addHitRegion({control: element});
    1.44 +      context.restore();
    1.45 +    }
    1.46 +
    1.47 +    function doTest()
    1.48 +    {
    1.49 +      getNode("hitcanvas").scrollIntoView(true);
    1.50 +
    1.51 +      var context = document.getElementById("hitcanvas").getContext('2d');
    1.52 +      redrawCheckbox(context, document.getElementById('hitcheck'), 20, 40);
    1.53 +
    1.54 +      var hitcanvas = getAccessible("hitcanvas");
    1.55 +      var hitcheck = getAccessible("hitcheck");
    1.56 +
    1.57 +      var [hitX, hitY, hitWidth, hitHeight] = getBounds(hitcanvas);
    1.58 +
    1.59 +      var docAcc = getAccessible(document);
    1.60 +      var tgtX = hitX+25;
    1.61 +      var tgtY = hitY+45;
    1.62 +      hitAcc = docAcc.getDeepestChildAtPoint(tgtX, tgtY);
    1.63 +      // test if we hit the region associated with the shadow dom checkbox
    1.64 +      is(hitAcc, hitcheck, "Hit match at " + tgtX + "," + tgtY +
    1.65 +                          ". Found: " + prettyName(hitAcc));
    1.66 +
    1.67 +      tgtY = hitY+75;
    1.68 +      hitAcc = docAcc.getDeepestChildAtPoint(tgtX, tgtY);
    1.69 +      // test that we don't hit the region associated with the shadow dom checkbox
    1.70 +      is(hitAcc, hitcanvas, "Hit match at " + tgtX + "," + tgtY +
    1.71 +                          ". Found: " + prettyName(hitAcc));
    1.72 +
    1.73 +      SpecialPowers.setBoolPref("canvas.hitregions.enabled", false);
    1.74 +      SimpleTest.finish();
    1.75 +    }
    1.76 +
    1.77 +    SimpleTest.waitForExplicitFinish();
    1.78 +    addA11yLoadEvent(doTest);
    1.79 +  </script>
    1.80 +</head>
    1.81 +<body>
    1.82 +
    1.83 +  <a target="_blank"
    1.84 +     href="https://bugzilla.mozilla.org/show_bug.cgi?id=966591"
    1.85 +     title="nsIAccessible::childAtPoint() for canvas hit regions from browser tests">Mozilla Bug 966591</a>
    1.86 +
    1.87 +  <canvas id="hitcanvas">
    1.88 +    <input id="hitcheck" type="checkbox"><label for="showA"> Show A </label>
    1.89 +  </canvas>
    1.90 +</body>
    1.91 +</html>

mercurial