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

Side by Side Diff: LayoutTests/svg/hittest/update-rect.html

Issue 745383007: Fix an issue where hit detection could fail on rect and ellipse shapes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Address test failures Created 6 years 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 <body onload="onPageLoad()">
4 Regression test for <a href="http://crbug.com/436214">http://crbug.com/436214</a >. This tests updating SVG &lt;rect&gt; elements having various stroke styles. I f this test passes, you will see "PASS" below.
5 <p id="result">WAITING - click within each of the rectangular areas for results< /p>
6 <svg id="svg" width="820" height="500" version="1.1">
7 <rect fill="none" stroke="black" x="0.5" y="0.5" width="819" height="499"/>
8
9
10
11 <rect pointer-events="none" stroke-width="10px" stroke="#aaa" stroke-opacity ="0.2" fill="none" x="360" y="80" width="40" height="40"/>
12 <rect pointer-events="none" stroke-width="20px" stroke="#f0a000" stroke-dash array="30, 10" stroke-opacity="0.2" fill="none" x="60" y="60" width="200" height ="50"/>
13 <rect pointer-events="none" stroke-width="40px" stroke="#d000d0" stroke-line join="bevel" stroke-opacity="0.2" fill="none" x="80" y="350" width="140" height= "100"/>
14 <rect pointer-events="none" stroke-width="20px" stroke="#d00000" stroke-opac ity="0.2" fill="none" x="400" y="340" width="80" height="140"/>
15 <rect pointer-events="none" stroke-width="20px" stroke="#f39" stroke-opacity ="0.2" stroke-miterlimit="0" fill="none" x="130" y="180" width="130" height="50" />
16
17 <rect id="rect0" cursor="move" stroke-width="10px" stroke="#aaa" stroke-line cap="square" fill="none" x="360" y="80" width="40" height="40"/>
18 <rect id="rect1" cursor="move" stroke-width="20px" stroke="#f0a000" stroke-d asharray="30, 10" fill="none" x="60" y="60" width="200" height="50"/>
19 <rect id="rect2" cursor="move" stroke-width="40px" stroke="#d000d0" stroke-l inejoin="bevel" fill="none" x="80" y="350" width="140" height="100"/>
20 <rect id="rect3" cursor="move" stroke-width="20px" stroke="#d00000" stroke-l inecap="round" fill="none" x="400" y="340" width="80" height="140"/>
21 <rect id="rect4" cursor="move" stroke-width="20px" stroke="#f39" stroke-mite rlimit="0" fill="none" x="130" y="180" width="130" height="50"/>
22
23
24
25 <rect pointer-events="none" stroke-width="20px" stroke="#0c0" stroke-opacity ="0.2" fill="none" x="545" y="70" width="160" height="60"/>
26 <rect pointer-events="none" stroke-width="20px" stroke="#090" stroke-opacity ="0.2" fill="none" x="545" y="170" width="160" height="60"/>
27 <rect pointer-events="none" stroke-width="20px" stroke="#060" stroke-opacity ="0.2" fill="none" x="545" y="270" width="160" height="60"/>
28 <rect pointer-events="none" stroke-width="20px" stroke="#030" stroke-opacity ="0.2" fill="none" x="545" y="370" width="160" height="60"/>
29
30 <rect id="rect10" cursor="move" stroke-width="20px" stroke="#0c0" fill="none " x="545" y="70" width="160" height="60"/>
31 <rect id="rect11" cursor="move" stroke-width="20px" stroke="#090" fill="none " x="545" y="170" width="160" height="60"/>
32 <rect id="rect12" cursor="move" stroke-width="20px" stroke="#060" fill="none " x="545" y="270" width="160" height="60"/>
33 <rect id="rect13" cursor="move" stroke-width="20px" stroke="#030" fill="none " x="545" y="370" width="160" height="60"/>
34 </svg>
35 <script type="text/javascript">
36 if (window.testRunner) {
37 testRunner.dumpAsText();
38 testRunner.waitUntilDone();
39 }
40
41 var result = document.getElementById("result"),
42 svg = document.getElementById("svg"),
43 rect0 = document.getElementById("rect0"),
44 rect1 = document.getElementById("rect1"),
45 rect2 = document.getElementById("rect2"),
46 rect3 = document.getElementById("rect3"),
47 rect4 = document.getElementById("rect4"),
48 rect10 = document.getElementById("rect10"),
49 rect11 = document.getElementById("rect11"),
50 rect12 = document.getElementById("rect12"),
51 rect13 = document.getElementById("rect13");
52 function onPageLoad() {
53 var activeAreas = [{
54 rect: rect0,
55 click: function () {
56 this.rect.setAttribute("width", "100");
57 this.rect.setAttribute("height", "100");
58 }
59 }, {
60 rect: rect1,
61 click: function () {
62 this.rect.setAttribute("x", "100");
63 }
64 }, {
65 rect: rect2,
66 click: function () {
67 this.rect.setAttribute("y", "300");
68 }
69 }, {
70 rect: rect3,
71 click: function () {
72 this.rect.setAttribute("x", "350");
73 this.rect.setAttribute("y", "270");
74 }
75 }, {
76 rect: rect4,
77 click: function () {
78 this.rect.setAttribute("width", "170");
79 this.rect.setAttribute("height", "80");
80 }
81 }, {
82 rect: rect10,
83 click: function () {
84 this.rect.setAttribute("stroke-dasharray", "30, 10");
85 }
86 }, {
87 rect: rect11,
88 click: function () {
89 this.rect.setAttribute("stroke-miterlimit", "0");
90 }
91 }, {
92 rect: rect12,
93 click: function () {
94 this.rect.setAttribute("stroke-linejoin", "bevel");
95 }
96 }, {
97 rect: rect13,
98 click: function () {
99 this.rect.setAttribute("x", "575");
100 this.rect.setAttribute("y", "400");
101 this.rect.setAttribute("stroke-linecap", "square");
102 }
103 }];
104
105 for (var i = 0; i < activeAreas.length; ++i) {
106 var aa = activeAreas[i];
107 aa.x1 = +aa.rect.getAttribute("x");
108 aa.y1 = +aa.rect.getAttribute("y");
109 aa.x2 = aa.x1 + (+aa.rect.getAttribute("width"));
110 aa.y2 = aa.y1 + (+aa.rect.getAttribute("height"));
111 }
112
113 var bcr = svg.getBoundingClientRect(),
114 x0 = bcr.left << 0,
115 y0 = bcr.top << 0;
116
117 requestAnimationFrame(function () {
118 document.addEventListener("mousedown", function onMouseDown(event) {
119 var x = event.clientX - x0,
120 y = event.clientY - y0;
121 for (var i = 0; i < activeAreas.length; ++i) {
122 var aa = activeAreas[i];
123 if (aa.x1 <= x && x <= aa.x2
124 && aa.y1 <= y && y <= aa.y2) {
125 aa.click();
126 activeAreas.splice(i, 1);
127 break;
128 }
129 }
130
131 if (activeAreas.length == 0) {
132 document.removeEventListener("mousedown", onMouseDown, false);
133
134 result.textContent = "Running tests...";
135
136 var tests = [
137 { x: 400, y: 118, expectedElem: svg },
138 { x: 460, y: 180, expectedElem: rect0 },
139
140 { x: 263, y: 83, expectedElem: svg },
141 { x: 200, y: 62, expectedElem: rect1 },
142
143 { x: 235, y: 112, expectedElem: svg },
144 { x: 160, y: 350, expectedElem: svg },
145 { x: 233, y: 413, expectedElem: svg },
146 { x: 160, y: 300, expectedElem: rect2 },
147
148 { x: 400, y: 350, expectedElem: svg },
149 { x: 350, y: 370, expectedElem: rect3 },
150
151 { x: 200, y: 230, expectedElem: svg },
152 { x: 267, y: 236, expectedElem: svg },
153 { x: 304, y: 218, expectedElem: rect4 },
154 { x: 307, y: 266, expectedElem: svg },
155
156 { x: 707, y: 65, expectedElem: svg },
157 { x: 710, y: 130, expectedElem: rect10 },
158
159 { x: 712, y: 164, expectedElem: svg },
160 { x: 712, y: 216, expectedElem: rect11 },
161
162 { x: 712, y: 264, expectedElem: svg },
163 { x: 712, y: 316, expectedElem: rect12 },
164
165 { x: 610, y: 425, expectedElem: svg },
166 { x: 739, y: 394, expectedElem: rect13 }
167 ];
168
169 for (var i = 0; i < tests.length; ++i) {
170 var test = tests[i],
171 elem = document.elementFromPoint(x0 + test.x, y0 + test. y),
172 success;
173 if (elem !== test.expectedElem) {
174 success = false;
175 result.textContent = "FAIL - unexpected element at (" + test.x + ", " + test.y + ")";
176 } else {
177 success = true;
178 }
179
180 // Draw a dot and a label at the test point (helps with iden tification).
181 var dot = document.createElementNS("http://www.w3.org/2000/s vg", "circle");
182 dot.setAttribute("pointer-events", "none");
183 dot.setAttribute("cx", test.x);
184 dot.setAttribute("cy", test.y);
185 dot.setAttribute("r", "2");
186 if (!success) dot.setAttribute("fill", "red");
187 svg.appendChild(dot);
188 var label = document.createElementNS("http://www.w3.org/2000 /svg", "text");
189 label.setAttribute("pointer-events", "none");
190 label.setAttribute("x", test.x + 4);
191 label.setAttribute("y", test.y);
192 label.textContent = "(" + test.x + ", " + test.y + ")";
193 if (!success) label.setAttribute("fill", "red");
194 svg.appendChild(label);
195 }
196
197 if (result.textContent == "Running tests...")
198 result.textContent = "PASS";
199
200 if (window.testRunner)
201 testRunner.notifyDone();
202 }
203 }, false);
204
205 if (window.eventSender) {
206 // The bug would only occur if the shape attributes were modified
207 // within a mouse event handler when the mouse cursor was within
208 // the shape.
209 activeAreas.slice(0).map(function (aa, i, activeAreas) {
210 eventSender.mouseMoveTo((x0 + aa.x1 + (aa.x2 - aa.x1) / 2) << 0, (y0 + aa.y1 + (aa.y2 - aa.y1) / 2) << 0);
211 eventSender.mouseDown();
212 eventSender.mouseUp();
213 });
214 }
215 });
216 }
217 </script>
218 </body>
219 </html>
OLDNEW
« no previous file with comments | « LayoutTests/svg/hittest/update-ellipse-expected.txt ('k') | LayoutTests/svg/hittest/update-rect-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698