diff options
Diffstat (limited to 'dom/canvas/test/test_hitregion_canvas.html')
-rw-r--r-- | dom/canvas/test/test_hitregion_canvas.html | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/dom/canvas/test/test_hitregion_canvas.html b/dom/canvas/test/test_hitregion_canvas.html new file mode 100644 index 000000000..452cb33b6 --- /dev/null +++ b/dom/canvas/test/test_hitregion_canvas.html @@ -0,0 +1,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> |