Bug 966591 - Part 7: Bounds + error handling tests. r=surkov
authorRik Cabanier <cabanier@adobe.com>
Tue, 25 Feb 2014 08:54:03 -0500
changeset 170712 675c6efa096fe08402126cf79513439c764353ed
parent 170711 fc089133d229dc28a1c8af60fa28597efe07973b
child 170713 ceac6a4674d23a4816e7d45faac9b27c7748c6e3
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewerssurkov
bugs966591
milestone30.0a1
Bug 966591 - Part 7: Bounds + error handling tests. r=surkov
accessible/tests/mochitest/elm/a11y.ini
accessible/tests/mochitest/elm/test_canvas.html
content/canvas/test/mochitest.ini
content/canvas/test/test_hitregion_canvas.html
--- a/accessible/tests/mochitest/elm/a11y.ini
+++ b/accessible/tests/mochitest/elm/a11y.ini
@@ -1,7 +1,8 @@
 [DEFAULT]
 
 [test_HTMLSpec.html]
 [test_figure.html]
 [test_listbox.xul]
 [test_nsApplicationAcc.html]
 [test_plugin.html]
+[test_canvas.html]
new file mode 100644
--- /dev/null
+++ b/accessible/tests/mochitest/elm/test_canvas.html
@@ -0,0 +1,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 type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript"
+          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">
+  SpecialPowers.setBoolPref("canvas.hitregions.enabled", true);
+
+    function doTest()
+    {
+      var canv = document.getElementById("c");
+      var context = canv.getContext('2d');
+      var element = document.getElementById("showA");
+      context.beginPath();
+      context.rect(10, 10, 150, 100);
+      context.addHitRegion({control: element});
+      var input = getAccessible("showA");
+      var input = getAccessible("showA");
+      var [cnvX, cnvY, cnvWidth, cnvHeight] = getBoundsForDOMElm(canv);
+      var [accX, accY, accWidth, accHeight] = getBounds(input);
+      is(accX, cnvX + 10, "accX should be 10 and not " + accX);
+      is(accY, cnvY + 10, "accY should be 10 and not " + accY);
+      is(accWidth, 150, "accWidth should be 150 and not " + accWidth);
+      is(accHeight, 100, "accHeight should be 100 and not " + accHeight);
+
+      SpecialPowers.setBoolPref("canvas.hitregions.enabled", false);
+      SimpleTest.finish();
+    }
+
+    SimpleTest.waitForExplicitFinish();
+    addA11yLoadEvent(doTest);
+  </script>
+</head>
+<body>
+
+  <canvas id="c">
+    <input id="showA" type="checkbox"><label for="showA"> Show As </label>
+  </canvas>
+
+</body>
+</html>
--- a/content/canvas/test/mochitest.ini
+++ b/content/canvas/test/mochitest.ini
@@ -185,16 +185,18 @@ disabled = bug 407107
 [test_bug753758.html]
 [test_bug764125.html]
 [test_bug856472.html]
 [test_bug866575.html]
 [test_bug902651.html]
 [test_canvas.html]
 [test_canvas_focusring.html]
 [test_canvas_font_setter.html]
+[test_hitregion_canvas.html]
+skip-if = os == "android" || appname == "b2g"
 [test_canvas_strokeStyle_getter.html]
 [test_drawImageIncomplete.html]
 [test_drawImage_document_domain.html]
 [test_drawImage_edge_cases.html]
 [test_ImageData_ctor.html]
 [test_isPointInStroke.html]
 [test_mozDashOffset.html]
 [test_mozGetAsFile.html]
new file mode 100644
--- /dev/null
+++ b/content/canvas/test/test_hitregion_canvas.html
@@ -0,0 +1,70 @@
+<!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;
+SpecialPowers.setBoolPref("canvas.hitregions.enabled", true);
+
+</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");
+  } 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();
+ SpecialPowers.setBoolPref("canvas.hitregions.enabled", false);
+}
+
+addLoadEvent(runTests);
+
+</script>