Bug 979692 - Add simple hit testing for canvas hit regions. r=roc
authorRik Cabanier <cabanier@adobe.com>
Sun, 18 May 2014 19:44:00 -0400
changeset 184554 a5377c80a3a58b6c9bad99a664682da60cc97b78
parent 184553 2fb4209eb06ab065db838c3bd92967a8131563e7
child 184555 fab2921f6306e1a462dc32b869d2f6650cfac8ae
push id26826
push usercbook@mozilla.com
push dateFri, 23 May 2014 13:41:49 +0000
treeherdermozilla-central@e3d39ffacb5e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs979692
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 979692 - Add simple hit testing for canvas hit regions. r=roc
content/canvas/test/mochitest.ini
content/canvas/test/test_hitregion_event.html
--- a/content/canvas/test/mochitest.ini
+++ b/content/canvas/test/mochitest.ini
@@ -189,16 +189,17 @@ disabled = bug 407107
 [test_bug902651.html]
 [test_canvas.html]
 skip-if = (toolkit == 'gonk' && debug) #debug-only crash; bug 933541
 [test_canvas_focusring.html]
 skip-if = (toolkit == 'gonk' && !debug) #specialpowers.wrap
 [test_canvas_font_setter.html]
 [test_canvas_path.html]
 [test_hitregion_canvas.html]
+[test_hitregion_event.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_drawWindow.html]
 support-files = file_drawWindow_source.html file_drawWindow_common.js
 skip-if = (buildapp == 'b2g' && toolkit != 'gonk')
new file mode 100644
--- /dev/null
+++ b/content/canvas/test/test_hitregion_event.html
@@ -0,0 +1,77 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test click events on canvas hit regions</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<p id="display">
+<canvas id="input">
+</canvas>
+</p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script type="application/javascript">
+SpecialPowers.pushPrefEnv({"set": [["canvas.hitregions.enabled", true]]}, function() {
+
+  var input = document.getElementById("input");
+  var regionId = "";
+  input.addEventListener('mousedown', function(evt){
+    regionId = evt.region;
+  })
+
+  function runTests()
+  {
+    try {
+      var ctx = input.getContext("2d");
+      ctx.beginPath();
+      ctx.rect(20, 20, 100, 75);
+      ctx.fill();
+      ctx.addHitRegion({id: "a"});
+      ctx.beginPath();
+      ctx.fillStyle = "red";
+      ctx.rect(60, 40, 100, 75);
+      ctx.fill();
+      ctx.addHitRegion({id: "b"});
+      ctx.beginPath();
+      ctx.fillStyle = "yellow";
+      ctx.rect(80, 60, 10, 10);
+      ctx.fill();
+      ctx.addHitRegion({id: "c"});
+
+      synthesizeMouse(input, 25,25, {type: "mousedown"});
+      is(regionId, "a", "Hit region a", ". Found: " + regionId);
+
+      synthesizeMouse(input, 5,5, {type: "mousedown", button: 1});
+      is(regionId, "", "Hit region null", ". Found: " + regionId);
+
+      synthesizeMouse(input, 65,45, {type: "mousedown"});
+      is(regionId, "b", "Hit region b", ". Found: " + regionId);
+
+      synthesizeMouse(input, 85,65, {type: "mousedown"});
+      is(regionId, "c", "Hit region c", ". Found: " + regionId);
+
+      ctx.removeHitRegion("c");
+      synthesizeMouse(input, 85,65, {type: "mousedown"});
+      is(regionId, "b", "Hit region b", ". Found: " + regionId);
+    } catch (e) {
+      ok(false, "unexpected exception thrown: " + e);
+    }
+
+    SimpleTest.finish();
+  }
+ 
+  runTests();
+});
+
+SimpleTest.waitForExplicitFinish();
+
+
+</script>
+</pre>
+</body>
+</html>