Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Unified Diff: third_party/WebKit/LayoutTests/fast/canvas/canvas-hit-regions-clip-test.html

Issue 1630683002: Canvas2d: addHitRegion() should take clipping region into account. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/fast/canvas/canvas-hit-regions-clip-test.html
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-hit-regions-clip-test.html b/third_party/WebKit/LayoutTests/fast/canvas/canvas-hit-regions-clip-test.html
new file mode 100644
index 0000000000000000000000000000000000000000..6d6f7520fef07b5566af4687a939efb5096c2f07
--- /dev/null
+++ b/third_party/WebKit/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";
Stephen White 2016/01/25 15:37:35 Other tests seem to call debug() in this case. Is
zino 2016/01/27 17:10:30 Sorry, I just copied and pasted old codes.
+
+ 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>

Powered by Google App Engine
This is Rietveld 408576698