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

Side by Side 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, 10 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Canvas Hit Regions: clip test</title>
5 <script src="../../resources/js-test.js"></script>
6 </head>
7 <body>
8 <canvas id="canvas" width="400" height="400"></canvas>
9 <script>
10
11 var canvas = document.getElementById("canvas");
12 var context = canvas.getContext("2d");
13
14 function clickCanvas(x, y)
15 {
16 if (!window.eventSender)
17 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.
18
19 var result = null;
20 function listener(event)
21 {
22 result = event.region;
23 }
24
25 var rect = canvas.getBoundingClientRect();
26 canvas.addEventListener("click", listener, false);
27 eventSender.mouseMoveTo(rect.left + x, rect.top + y);
28 eventSender.mouseDown();
29 eventSender.mouseUp();
30 canvas.removeEventListener("click", listener, false);
31
32 return result;
33 }
34
35 debug("Simple rect clip tests.");
36 context.save();
37 context.beginPath();
38 context.rect(0, 0, 100, 100);
39 context.clip();
40 context.beginPath();
41 context.rect(50, 50, 100, 100);
42 context.addHitRegion({ id : "clip" });
43 context.restore();
44 shouldBe("clickCanvas(10, 10)", "null");
45 shouldBe("clickCanvas(60, 60)", "'clip'");
46 debug("");
47
48 debug("Non rect clip tests.");
49 context.save();
50 context.beginPath();
51 context.arc(50, 50, 50, 0, Math.PI * 2);
52 context.clip();
53 context.beginPath();
54 context.rect(0, 0, 100, 100);
55 context.addHitRegion({ id : "clip" });
56 context.restore();
57 shouldBe("clickCanvas(0, 0)", "null");
58 shouldBe("clickCanvas(100, 0)", "null");
59 shouldBe("clickCanvas(100, 100)", "null");
60 shouldBe("clickCanvas(0, 100)", "null");
61 shouldBe("clickCanvas(50, 50)", "'clip'");
62 debug("");
63
64 debug("Multiple clip tests.");
65 context.save();
66 context.beginPath();
67 context.rect(0, 0, 100, 100);
68 context.clip();
69 context.beginPath();
70 context.arc(100, 50, 50, 0, Math.PI * 2);
71 context.clip();
72 context.beginPath();
73 context.rect(0, 0, 150, 50);
74 context.addHitRegion({ id : "clip" });
75 context.restore();
76 shouldBe("clickCanvas(0, 0)", "null");
77 shouldBe("clickCanvas(100, 0)", "'clip'");
78 shouldBe("clickCanvas(100, 100)", "null");
79 shouldBe("clickCanvas(0, 100)", "null");
80 shouldBe("clickCanvas(50, 0)", "null");
81 shouldBe("clickCanvas(150, 0)", "null");
82 shouldBe("clickCanvas(150, 100)", "null");
83 shouldBe("clickCanvas(50, 100)", "null");
84 shouldBe("clickCanvas(50, 50)", "'clip'");
85 shouldBe("clickCanvas(100, 50)", "'clip'");
86 debug("");
87
88 debug("No pixels tests.");
89 context.save();
90 context.beginPath();
91 context.rect(0, 0, 100, 100);
92 context.clip();
93 context.beginPath();
94 context.rect(100, 100, 100, 100);
95 shouldThrow("context.addHitRegion({ id : 'clip' })");
96 context.restore();
97 context.save();
98 context.beginPath();
99 context.rect(0, 0, 50, 50);
100 context.rect(100, 0, 50, 50);
101 context.clip();
102 context.beginPath();
103 context.arc(75, 75, 30, 0, Math.PI * 2);
104 shouldThrow("context.addHitRegion({ id : 'clip' })");
105 context.restore();
106 debug("");
107
108 </script>
109 </body>
110 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698