Index: LayoutTests/fast/canvas/canvas-hit-regions-clip-test.html |
diff --git a/LayoutTests/fast/canvas/canvas-hit-regions-clip-test.html b/LayoutTests/fast/canvas/canvas-hit-regions-clip-test.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6d6f7520fef07b5566af4687a939efb5096c2f07 |
--- /dev/null |
+++ b/LayoutTests/fast/canvas/canvas-hit-regions-clip-test.html |
@@ -0,0 +1,110 @@ |
+<!DOCTYPE html> |
+<html> |
+<head> |
+ <title>Canvas Hit Regions: clip test</title> |
+ <script src="../../resources/js-test.js"></script> |
+</head> |
+<body> |
+<canvas id="canvas" width="400" height="400"></canvas> |
+<script> |
+ |
+ var canvas = document.getElementById("canvas"); |
+ var context = canvas.getContext("2d"); |
+ |
+ function clickCanvas(x, y) |
+ { |
+ if (!window.eventSender) |
+ return "This test requires eventSender"; |
+ |
+ var result = null; |
+ function listener(event) |
+ { |
+ result = event.region; |
+ } |
+ |
+ var rect = canvas.getBoundingClientRect(); |
+ canvas.addEventListener("click", listener, false); |
+ eventSender.mouseMoveTo(rect.left + x, rect.top + y); |
+ eventSender.mouseDown(); |
+ eventSender.mouseUp(); |
+ canvas.removeEventListener("click", listener, false); |
+ |
+ return result; |
+ } |
+ |
+ debug("Simple rect clip tests."); |
+ context.save(); |
+ context.beginPath(); |
+ context.rect(0, 0, 100, 100); |
+ context.clip(); |
+ context.beginPath(); |
+ context.rect(50, 50, 100, 100); |
+ context.addHitRegion({ id : "clip" }); |
+ context.restore(); |
+ shouldBe("clickCanvas(10, 10)", "null"); |
+ shouldBe("clickCanvas(60, 60)", "'clip'"); |
+ debug(""); |
+ |
+ debug("Non rect clip tests."); |
+ context.save(); |
+ context.beginPath(); |
+ context.arc(50, 50, 50, 0, Math.PI * 2); |
+ context.clip(); |
+ context.beginPath(); |
+ context.rect(0, 0, 100, 100); |
+ context.addHitRegion({ id : "clip" }); |
+ context.restore(); |
+ shouldBe("clickCanvas(0, 0)", "null"); |
+ shouldBe("clickCanvas(100, 0)", "null"); |
+ shouldBe("clickCanvas(100, 100)", "null"); |
+ shouldBe("clickCanvas(0, 100)", "null"); |
+ shouldBe("clickCanvas(50, 50)", "'clip'"); |
+ debug(""); |
+ |
+ debug("Multiple clip tests."); |
+ context.save(); |
+ context.beginPath(); |
+ context.rect(0, 0, 100, 100); |
+ context.clip(); |
+ context.beginPath(); |
+ context.arc(100, 50, 50, 0, Math.PI * 2); |
+ context.clip(); |
+ context.beginPath(); |
+ context.rect(0, 0, 150, 50); |
+ context.addHitRegion({ id : "clip" }); |
+ context.restore(); |
+ shouldBe("clickCanvas(0, 0)", "null"); |
+ shouldBe("clickCanvas(100, 0)", "'clip'"); |
+ shouldBe("clickCanvas(100, 100)", "null"); |
+ shouldBe("clickCanvas(0, 100)", "null"); |
+ shouldBe("clickCanvas(50, 0)", "null"); |
+ shouldBe("clickCanvas(150, 0)", "null"); |
+ shouldBe("clickCanvas(150, 100)", "null"); |
+ shouldBe("clickCanvas(50, 100)", "null"); |
+ shouldBe("clickCanvas(50, 50)", "'clip'"); |
+ shouldBe("clickCanvas(100, 50)", "'clip'"); |
+ debug(""); |
+ |
+ debug("No pixels tests."); |
+ context.save(); |
+ context.beginPath(); |
+ context.rect(0, 0, 100, 100); |
+ context.clip(); |
+ context.beginPath(); |
+ context.rect(100, 100, 100, 100); |
+ shouldThrow("context.addHitRegion({ id : 'clip' })"); |
+ context.restore(); |
+ context.save(); |
+ context.beginPath(); |
+ context.rect(0, 0, 50, 50); |
+ context.rect(100, 0, 50, 50); |
+ context.clip(); |
+ context.beginPath(); |
+ context.arc(75, 75, 30, 0, Math.PI * 2); |
+ shouldThrow("context.addHitRegion({ id : 'clip' })"); |
+ context.restore(); |
+ debug(""); |
+ |
+</script> |
+</body> |
+</html> |