1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/test_hitregion_canvas.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,70 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<title>Canvas Tests</title> 1.6 +<script src="/tests/SimpleTest/SimpleTest.js"></script> 1.7 +<link rel="stylesheet" href="/tests/SimpleTest/test.css"> 1.8 +<body> 1.9 +<script> 1.10 + 1.11 +SimpleTest.waitForExplicitFinish(); 1.12 +const Cc = SpecialPowers.Cc; 1.13 +const Cr = SpecialPowers.Cr; 1.14 +SpecialPowers.setBoolPref("canvas.hitregions.enabled", true); 1.15 + 1.16 +</script> 1.17 + 1.18 +<p>Canvas test: hit regions</p> 1.19 +<canvas id="c1" width="150" height="50"> 1.20 + <a id="c1_a"></a> 1.21 +</canvas> 1.22 +<a id="c1_b"></a> 1.23 + 1.24 +<script type="text/javascript"> 1.25 + 1.26 +function test_hitregions() { 1.27 + var c = document.getElementById("c1"); 1.28 + var d = document.getElementById("c1_a"); 1.29 + var e = document.getElementById("c1_b"); 1.30 + 1.31 + var ctx = c.getContext("2d"); 1.32 + var _thrown_outer = false; 1.33 + try { 1.34 + ctx.rect(10,10,100,100); 1.35 + ctx.addHitRegion({control: d}); 1.36 + ctx.addHitRegion({control: e}); 1.37 + ctx.addHitRegion({id: "a", control: d}); 1.38 + ctx.addHitRegion({id: "a", control: d}); 1.39 + 1.40 + ctx.removeHitRegion("a"); 1.41 + ctx.removeHitRegion("a"); 1.42 + ctx.removeHitRegion("b"); 1.43 + } catch (e) { 1.44 + _thrown_outer = true; 1.45 + } 1.46 + ok(!_thrown_outer, ctx.canvas.id + ' should not throw exception'); 1.47 + 1.48 + var _thrown = undefined; try { 1.49 + ctx.beginPath(); 1.50 + ctx.addHitRegion({control: d}); 1.51 + } catch (ex) { _thrown = ex }; 1.52 + 1.53 + ok(_thrown && _thrown.name == "NotSupportedError", "should throw NotSupportedError"); 1.54 + 1.55 +} 1.56 +</script> 1.57 + 1.58 +<script> 1.59 + 1.60 +function runTests() { 1.61 + try { 1.62 + test_hitregions(); 1.63 + } catch(e) { 1.64 + throw e; 1.65 + ok(false, "unexpected exception thrown in: test_hitregions"); 1.66 + } 1.67 + SimpleTest.finish(); 1.68 + SpecialPowers.setBoolPref("canvas.hitregions.enabled", false); 1.69 +} 1.70 + 1.71 +addLoadEvent(runTests); 1.72 + 1.73 +</script>