OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/viz/host/hit_test/hit_test_query.h" | |
6 | |
7 #include "services/viz/hit_test/public/interfaces/hit_test_region_list.mojom.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 namespace viz { | |
11 namespace test { | |
12 | |
13 class HitTestQueryTest : public testing::Test { | |
14 public: | |
15 HitTestQueryTest() = default; | |
16 ~HitTestQueryTest() override = default; | |
17 | |
18 HitTestQuery hit_test_query_; | |
19 | |
20 private: | |
21 // testing::Test: | |
22 void SetUp() override {} | |
23 void TearDown() override {} | |
24 | |
25 DISALLOW_COPY_AND_ASSIGN(HitTestQueryTest); | |
26 }; | |
27 | |
28 // One surface. | |
29 // | |
30 // +e---------+ | |
31 // | | | |
32 // | | | |
33 // | | | |
34 // +----------+ | |
35 // | |
36 TEST_F(HitTestQueryTest, OneSurface) { | |
37 FrameSinkId e_id = FrameSinkId(1, 1); | |
38 gfx::Rect e_bounds = gfx::Rect(0, 0, 600, 600); | |
39 gfx::Transform transform_e_to_e; | |
40 AggregatedHitTestRegion aggregated_hit_test_region_list[1] = { | |
41 {e_id, mojom::kHitTestMine, e_bounds, transform_e_to_e, 0} // e | |
42 }; | |
43 hit_test_query_.set_aggregated_hit_test_region_list( | |
44 aggregated_hit_test_region_list, 1); | |
45 | |
46 // All points are in e's coordinate system when we reach this case. | |
47 gfx::Point point1(1, 1); | |
48 gfx::Point point2(600, 600); | |
49 gfx::Point point3(0, 0); | |
50 | |
51 Target target1 = hit_test_query_.FindTargetForLocation(point1); | |
52 EXPECT_EQ(e_id, target1.frame_sink_id); | |
53 EXPECT_EQ(point1, target1.location_in_target); | |
54 EXPECT_EQ(mojom::kHitTestMine, target1.flags); | |
55 | |
56 // point2 is on the bounds of e so no target found. | |
57 Target target2 = hit_test_query_.FindTargetForLocation(point2); | |
58 EXPECT_EQ(FrameSinkId(), target2.frame_sink_id); | |
59 EXPECT_EQ(gfx::Point(), target2.location_in_target); | |
60 EXPECT_FALSE(target2.flags); | |
61 | |
62 // There's a valid Target for point3, see Rect::Contains. | |
63 Target target3 = hit_test_query_.FindTargetForLocation(point3); | |
64 EXPECT_EQ(e_id, target3.frame_sink_id); | |
65 EXPECT_EQ(point3, target3.location_in_target); | |
66 EXPECT_EQ(mojom::kHitTestMine, target3.flags); | |
67 } | |
68 | |
69 // One embedder with two children. | |
70 // | |
71 // +e------------+ Point maps to | |
72 // | +c1-+ +c2---| ----- ------- | |
73 // |1| | | | 1 e | |
74 // | | 2 | | 3 | 4 2 c1 | |
75 // | +---+ | | 3 c2 | |
76 // +-------------+ 4 none | |
77 // | |
78 TEST_F(HitTestQueryTest, OneEmbedderTwoChildren) { | |
79 FrameSinkId e_id = FrameSinkId(1, 1); | |
80 FrameSinkId c1_id = FrameSinkId(2, 2); | |
81 FrameSinkId c2_id = FrameSinkId(3, 3); | |
82 gfx::Rect e_bounds_in_e = gfx::Rect(0, 0, 600, 600); | |
83 gfx::Rect c1_bounds_in_e = gfx::Rect(0, 0, 200, 200); | |
84 gfx::Rect c2_bounds_in_e = gfx::Rect(0, 0, 400, 400); | |
85 gfx::Transform transform_e_to_e, transform_e_to_c1, transform_e_to_c2; | |
86 transform_e_to_c1.Translate(-100, -100); | |
87 transform_e_to_c2.Translate(-300, -300); | |
88 AggregatedHitTestRegion aggregated_hit_test_region_list[3] = { | |
89 {e_id, mojom::kHitTestMine, e_bounds_in_e, transform_e_to_e, 2}, // e | |
90 {c1_id, mojom::kHitTestMine, c1_bounds_in_e, transform_e_to_c1, 0}, // c1 | |
91 {c2_id, mojom::kHitTestMine, c2_bounds_in_e, transform_e_to_c2, 0} // c2 | |
92 }; | |
93 hit_test_query_.set_aggregated_hit_test_region_list( | |
94 aggregated_hit_test_region_list, 3); | |
95 | |
96 // All points are in e's coordinate system when we reach this case. | |
97 gfx::Point point1(99, 200); | |
98 gfx::Point point2(150, 150); | |
99 gfx::Point point3(400, 400); | |
100 gfx::Point point4(650, 350); | |
101 | |
102 Target target1 = hit_test_query_.FindTargetForLocation(point1); | |
103 EXPECT_EQ(e_id, target1.frame_sink_id); | |
104 EXPECT_EQ(point1, target1.location_in_target); | |
105 EXPECT_EQ(mojom::kHitTestMine, target1.flags); | |
106 | |
107 Target target2 = hit_test_query_.FindTargetForLocation(point2); | |
108 EXPECT_EQ(c1_id, target2.frame_sink_id); | |
109 EXPECT_EQ(gfx::Point(50, 50), target2.location_in_target); | |
110 EXPECT_EQ(mojom::kHitTestMine, target2.flags); | |
111 | |
112 Target target3 = hit_test_query_.FindTargetForLocation(point3); | |
113 EXPECT_EQ(c2_id, target3.frame_sink_id); | |
114 EXPECT_EQ(gfx::Point(100, 100), target3.location_in_target); | |
115 EXPECT_EQ(mojom::kHitTestMine, target3.flags); | |
116 | |
117 Target target4 = hit_test_query_.FindTargetForLocation(point4); | |
118 EXPECT_EQ(FrameSinkId(), target4.frame_sink_id); | |
119 EXPECT_EQ(gfx::Point(), target4.location_in_target); | |
120 EXPECT_FALSE(target4.flags); | |
121 } | |
122 | |
123 // One embedder with a rotated child. | |
124 TEST_F(HitTestQueryTest, OneEmbedderRotatedChild) { | |
125 FrameSinkId e_id = FrameSinkId(1, 1); | |
126 FrameSinkId c_id = FrameSinkId(2, 2); | |
127 gfx::Rect e_bounds_in_e = gfx::Rect(0, 0, 600, 600); | |
128 gfx::Rect c_bounds_in_e = gfx::Rect(0, 0, 1000, 1000); | |
129 gfx::Transform transform_e_to_e, transform_e_to_c; | |
130 transform_e_to_c.Translate(-100, -100); | |
131 transform_e_to_c.Skew(2, 3); | |
132 transform_e_to_c.Scale(.5f, .7f); | |
133 | |
134 AggregatedHitTestRegion aggregated_hit_test_region_list[2] = { | |
135 {e_id, mojom::kHitTestMine, e_bounds_in_e, transform_e_to_e, 1}, // e | |
136 {c_id, mojom::kHitTestChildSurface | mojom::kHitTestMine, c_bounds_in_e, | |
137 transform_e_to_c, 0} // c | |
138 }; | |
139 hit_test_query_.set_aggregated_hit_test_region_list( | |
140 aggregated_hit_test_region_list, 2); | |
141 | |
142 // All points are in e's coordinate system when we reach this case. | |
143 gfx::Point point1(150, 120); // Point(-22, -12) after transform. | |
144 gfx::Point point2(550, 400); // Point(185, 194) after transform. | |
145 | |
146 Target target1 = hit_test_query_.FindTargetForLocation(point1); | |
147 EXPECT_EQ(e_id, target1.frame_sink_id); | |
148 EXPECT_EQ(point1, target1.location_in_target); | |
149 EXPECT_EQ(mojom::kHitTestMine, target1.flags); | |
150 | |
151 Target target2 = hit_test_query_.FindTargetForLocation(point2); | |
152 EXPECT_EQ(c_id, target2.frame_sink_id); | |
153 EXPECT_EQ(gfx::Point(185, 194), target2.location_in_target); | |
154 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target2.flags); | |
155 } | |
156 | |
157 // One embedder with a clipped child with a tab and transparent background. | |
158 // | |
159 // +e-------------+ | |
160 // | +c---------| Point maps to | |
161 // | 1 |+a--+ | ----- ------- | |
162 // | || 2 | 3 | 1 e | |
163 // | |+b--------| 2 a | |
164 // | || | 3 e ( transparent area in c ) | |
165 // | || 4 | 4 b | |
166 // +--------------+ | |
167 // | |
168 TEST_F(HitTestQueryTest, ClippedChildWithTabAndTransparentBackground) { | |
169 FrameSinkId e_id = FrameSinkId(1, 1); | |
170 FrameSinkId c_id = FrameSinkId(2, 2); | |
171 FrameSinkId a_id = FrameSinkId(3, 3); | |
172 FrameSinkId b_id = FrameSinkId(4, 4); | |
173 gfx::Rect e_bounds_in_e = gfx::Rect(0, 0, 600, 600); | |
174 gfx::Rect c_bounds_in_e = gfx::Rect(0, 0, 800, 800); | |
175 gfx::Rect a_bounds_in_c = gfx::Rect(0, 0, 200, 100); | |
176 gfx::Rect b_bounds_in_c = gfx::Rect(0, 0, 800, 600); | |
177 gfx::Transform transform_e_to_e, transform_e_to_c, transform_c_to_a, | |
178 transform_c_to_b; | |
179 transform_e_to_c.Translate(-200, -100); | |
180 transform_c_to_b.Translate(0, -100); | |
181 AggregatedHitTestRegion aggregated_hit_test_region_list[4] = { | |
182 {e_id, mojom::kHitTestMine, e_bounds_in_e, transform_e_to_e, 3}, // e | |
183 {c_id, mojom::kHitTestChildSurface | mojom::kHitTestIgnore, c_bounds_in_e, | |
184 transform_e_to_c, 2}, // c | |
185 {a_id, mojom::kHitTestChildSurface | mojom::kHitTestMine, a_bounds_in_c, | |
186 transform_c_to_a, 0}, // a | |
187 {b_id, mojom::kHitTestChildSurface | mojom::kHitTestMine, b_bounds_in_c, | |
188 transform_c_to_b, 0} // b | |
189 }; | |
190 hit_test_query_.set_aggregated_hit_test_region_list( | |
191 aggregated_hit_test_region_list, 4); | |
192 | |
193 // All points are in e's coordinate system when we reach this case. | |
194 gfx::Point point1(1, 1); | |
195 gfx::Point point2(202, 102); | |
196 gfx::Point point3(403, 103); | |
197 gfx::Point point4(202, 202); | |
198 | |
199 Target target1 = hit_test_query_.FindTargetForLocation(point1); | |
200 EXPECT_EQ(e_id, target1.frame_sink_id); | |
201 EXPECT_EQ(point1, target1.location_in_target); | |
202 EXPECT_EQ(mojom::kHitTestMine, target1.flags); | |
203 | |
204 Target target2 = hit_test_query_.FindTargetForLocation(point2); | |
205 EXPECT_EQ(a_id, target2.frame_sink_id); | |
206 EXPECT_EQ(gfx::Point(2, 2), target2.location_in_target); | |
207 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target2.flags); | |
208 | |
209 Target target3 = hit_test_query_.FindTargetForLocation(point3); | |
210 EXPECT_EQ(e_id, target3.frame_sink_id); | |
211 EXPECT_EQ(point3, target3.location_in_target); | |
212 EXPECT_EQ(mojom::kHitTestMine, target3.flags); | |
213 | |
214 Target target4 = hit_test_query_.FindTargetForLocation(point4); | |
215 EXPECT_EQ(b_id, target4.frame_sink_id); | |
216 EXPECT_EQ(gfx::Point(2, 2), target4.location_in_target); | |
217 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target4.flags); | |
218 } | |
219 | |
220 // One embedder with a clipped child with a tab and transparent background, and | |
221 // a child d under that. | |
222 // | |
223 // +e-------------+ | |
224 // | +d------| | |
225 // | +c-|-------| Point maps to | |
226 // | 1 |+a|-+ | ----- ------- | |
227 // | || 2 | 3 | 1 e | |
228 // | |+b|-------| 2 a | |
229 // | || | | 3 d | |
230 // | || | 4 | 4 b | |
231 // +--------------+ | |
232 // | |
233 TEST_F(HitTestQueryTest, ClippedChildWithChildUnderneath) { | |
234 FrameSinkId e_id = FrameSinkId(1, 1); | |
235 FrameSinkId c_id = FrameSinkId(2, 2); | |
236 FrameSinkId a_id = FrameSinkId(3, 3); | |
237 FrameSinkId b_id = FrameSinkId(4, 4); | |
238 FrameSinkId d_id = FrameSinkId(5, 5); | |
239 gfx::Rect e_bounds_in_e = gfx::Rect(0, 0, 600, 600); | |
240 gfx::Rect c_bounds_in_e = gfx::Rect(0, 0, 800, 800); | |
241 gfx::Rect a_bounds_in_c = gfx::Rect(0, 0, 200, 100); | |
242 gfx::Rect b_bounds_in_c = gfx::Rect(0, 0, 800, 600); | |
243 gfx::Rect d_bounds_in_e = gfx::Rect(0, 0, 800, 800); | |
244 gfx::Transform transform_e_to_e, transform_e_to_c, transform_c_to_a, | |
245 transform_c_to_b, transform_e_to_d; | |
246 transform_e_to_c.Translate(-200, -100); | |
247 transform_c_to_b.Translate(0, -100); | |
248 transform_e_to_d.Translate(-400, -50); | |
249 AggregatedHitTestRegion aggregated_hit_test_region_list[5] = { | |
250 {e_id, mojom::kHitTestMine, e_bounds_in_e, transform_e_to_e, 4}, // e | |
251 {c_id, mojom::kHitTestChildSurface | mojom::kHitTestIgnore, c_bounds_in_e, | |
252 transform_e_to_c, 2}, // c | |
253 {a_id, mojom::kHitTestChildSurface | mojom::kHitTestMine, a_bounds_in_c, | |
254 transform_c_to_a, 0}, // a | |
255 {b_id, mojom::kHitTestChildSurface | mojom::kHitTestMine, b_bounds_in_c, | |
256 transform_c_to_b, 0}, // b | |
257 {d_id, mojom::kHitTestChildSurface | mojom::kHitTestMine, d_bounds_in_e, | |
258 transform_e_to_d, 0} // d | |
259 }; | |
260 hit_test_query_.set_aggregated_hit_test_region_list( | |
261 aggregated_hit_test_region_list, 5); | |
262 | |
263 // All points are in e's coordinate system when we reach this case. | |
264 gfx::Point point1(1, 1); | |
265 gfx::Point point2(202, 102); | |
266 gfx::Point point3(450, 150); | |
267 gfx::Point point4(202, 202); | |
268 | |
269 Target target1 = hit_test_query_.FindTargetForLocation(point1); | |
270 EXPECT_EQ(e_id, target1.frame_sink_id); | |
271 EXPECT_EQ(point1, target1.location_in_target); | |
272 EXPECT_EQ(mojom::kHitTestMine, target1.flags); | |
273 | |
274 Target target2 = hit_test_query_.FindTargetForLocation(point2); | |
275 EXPECT_EQ(a_id, target2.frame_sink_id); | |
276 EXPECT_EQ(gfx::Point(2, 2), target2.location_in_target); | |
277 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target2.flags); | |
278 | |
279 Target target3 = hit_test_query_.FindTargetForLocation(point3); | |
280 EXPECT_EQ(d_id, target3.frame_sink_id); | |
281 EXPECT_EQ(gfx::Point(50, 100), target3.location_in_target); | |
282 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target3.flags); | |
283 | |
284 Target target4 = hit_test_query_.FindTargetForLocation(point4); | |
285 EXPECT_EQ(b_id, target4.frame_sink_id); | |
286 EXPECT_EQ(gfx::Point(2, 2), target4.location_in_target); | |
287 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target4.flags); | |
288 } | |
289 | |
290 // One embedder with two clipped children with a tab and transparent background. | |
291 // | |
292 // +e-------------+ | |
293 // | +c1--------| Point maps to | |
294 // | 1 |+a--+ | ----- ------- | |
295 // | || 2 | 3 | 1 e | |
296 // | |+b--------| 2 a | |
297 // | || | 3 e ( transparent area in c1 ) | |
298 // | || 4 | 4 b | |
299 // | +----------| 5 g | |
300 // | +c2--------| 6 e ( transparent area in c2 ) | |
301 // | |+g--+ | 7 h | |
302 // | || 5 | 6 | | |
303 // | |+h--------| | |
304 // | || | | |
305 // | || 7 | | |
306 // +--------------+ | |
307 // | |
308 TEST_F(HitTestQueryTest, ClippedChildrenWithTabAndTransparentBackground) { | |
309 FrameSinkId e_id = FrameSinkId(1, 1); | |
310 FrameSinkId c1_id = FrameSinkId(2, 2); | |
311 FrameSinkId a_id = FrameSinkId(3, 3); | |
312 FrameSinkId b_id = FrameSinkId(4, 4); | |
313 FrameSinkId c2_id = FrameSinkId(5, 5); | |
314 FrameSinkId g_id = FrameSinkId(6, 6); | |
315 FrameSinkId h_id = FrameSinkId(7, 7); | |
316 gfx::Rect e_bounds_in_e = gfx::Rect(0, 0, 600, 1200); | |
317 gfx::Rect c1_bounds_in_e = gfx::Rect(0, 0, 800, 500); | |
318 gfx::Rect a_bounds_in_c1 = gfx::Rect(0, 0, 200, 100); | |
319 gfx::Rect b_bounds_in_c1 = gfx::Rect(0, 0, 800, 400); | |
320 gfx::Rect c2_bounds_in_e = gfx::Rect(0, 0, 800, 500); | |
321 gfx::Rect g_bounds_in_c2 = gfx::Rect(0, 0, 200, 100); | |
322 gfx::Rect h_bounds_in_c2 = gfx::Rect(0, 0, 800, 800); | |
323 gfx::Transform transform_e_to_e, transform_e_to_c1, transform_c1_to_a, | |
324 transform_c1_to_b, transform_e_to_c2, transform_c2_to_g, | |
325 transform_c2_to_h; | |
326 transform_e_to_c1.Translate(-200, -100); | |
327 transform_c1_to_b.Translate(0, -100); | |
328 transform_e_to_c2.Translate(-200, -700); | |
329 transform_c2_to_h.Translate(0, -100); | |
330 AggregatedHitTestRegion aggregated_hit_test_region_list[7] = { | |
331 {e_id, mojom::kHitTestMine, e_bounds_in_e, transform_e_to_e, 6}, // e | |
332 {c1_id, mojom::kHitTestChildSurface | mojom::kHitTestIgnore, | |
333 c1_bounds_in_e, transform_e_to_c1, 2}, // c1 | |
334 {a_id, mojom::kHitTestChildSurface | mojom::kHitTestMine, a_bounds_in_c1, | |
335 transform_c1_to_a, 0}, // a | |
336 {b_id, mojom::kHitTestChildSurface | mojom::kHitTestMine, b_bounds_in_c1, | |
337 transform_c1_to_b, 0}, // b | |
338 {c2_id, mojom::kHitTestChildSurface | mojom::kHitTestIgnore, | |
339 c2_bounds_in_e, transform_e_to_c2, 2}, // c2 | |
340 {g_id, mojom::kHitTestChildSurface | mojom::kHitTestMine, g_bounds_in_c2, | |
341 transform_c2_to_g, 0}, // g | |
342 {h_id, mojom::kHitTestChildSurface | mojom::kHitTestMine, h_bounds_in_c2, | |
343 transform_c2_to_h, 0} // h | |
344 }; | |
345 hit_test_query_.set_aggregated_hit_test_region_list( | |
346 aggregated_hit_test_region_list, 7); | |
347 | |
348 // All points are in e's coordinate system when we reach this case. | |
349 gfx::Point point1(1, 1); | |
350 gfx::Point point2(202, 102); | |
351 gfx::Point point3(403, 103); | |
352 gfx::Point point4(202, 202); | |
353 gfx::Point point5(250, 750); | |
354 gfx::Point point6(450, 750); | |
355 gfx::Point point7(350, 1100); | |
356 | |
357 Target target1 = hit_test_query_.FindTargetForLocation(point1); | |
358 EXPECT_EQ(e_id, target1.frame_sink_id); | |
359 EXPECT_EQ(point1, target1.location_in_target); | |
360 EXPECT_EQ(mojom::kHitTestMine, target1.flags); | |
361 | |
362 Target target2 = hit_test_query_.FindTargetForLocation(point2); | |
363 EXPECT_EQ(a_id, target2.frame_sink_id); | |
364 EXPECT_EQ(gfx::Point(2, 2), target2.location_in_target); | |
365 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target2.flags); | |
366 | |
367 Target target3 = hit_test_query_.FindTargetForLocation(point3); | |
368 EXPECT_EQ(e_id, target3.frame_sink_id); | |
369 EXPECT_EQ(point3, target3.location_in_target); | |
370 EXPECT_EQ(mojom::kHitTestMine, target3.flags); | |
371 | |
372 Target target4 = hit_test_query_.FindTargetForLocation(point4); | |
373 EXPECT_EQ(b_id, target4.frame_sink_id); | |
374 EXPECT_EQ(gfx::Point(2, 2), target4.location_in_target); | |
375 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target4.flags); | |
376 | |
377 Target target5 = hit_test_query_.FindTargetForLocation(point5); | |
378 EXPECT_EQ(g_id, target5.frame_sink_id); | |
379 EXPECT_EQ(gfx::Point(50, 50), target5.location_in_target); | |
380 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target5.flags); | |
381 | |
382 Target target6 = hit_test_query_.FindTargetForLocation(point6); | |
383 EXPECT_EQ(e_id, target6.frame_sink_id); | |
384 EXPECT_EQ(point6, target6.location_in_target); | |
385 EXPECT_EQ(mojom::kHitTestMine, target6.flags); | |
386 | |
387 Target target7 = hit_test_query_.FindTargetForLocation(point7); | |
388 EXPECT_EQ(h_id, target7.frame_sink_id); | |
389 EXPECT_EQ(gfx::Point(150, 300), target7.location_in_target); | |
390 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target7.flags); | |
391 } | |
392 | |
393 // Children that are multiple layers deep. | |
394 // | |
395 // +e--------------------+ | |
396 // | +c2--------| Point maps to | |
397 // | +c1------|----+ | ----- ------- | |
398 // |1| +a-----|---+| | 1 e | |
399 // | | |+b----|--+|| | 2 g | |
400 // | | ||+g--+| ||| | 3 b | |
401 // | | ||| 2 || 3||| 4 | 4 c2 | |
402 // | | ||+---+| ||| | | |
403 // | | |+-----|--+|| | | |
404 // | | +------| --+| | | |
405 // | +--------|----+ | | |
406 // +---------------------+ | |
407 // | |
408 TEST_F(HitTestQueryTest, MultipleLayerChild) { | |
409 FrameSinkId e_id = FrameSinkId(1, 1); | |
410 FrameSinkId c1_id = FrameSinkId(2, 2); | |
411 FrameSinkId a_id = FrameSinkId(3, 3); | |
412 FrameSinkId b_id = FrameSinkId(4, 4); | |
413 FrameSinkId g_id = FrameSinkId(5, 5); | |
414 FrameSinkId c2_id = FrameSinkId(6, 6); | |
415 gfx::Rect e_bounds_in_e = gfx::Rect(0, 0, 1000, 1000); | |
416 gfx::Rect c1_bounds_in_e = gfx::Rect(0, 0, 800, 800); | |
417 gfx::Rect a_bounds_in_c1 = gfx::Rect(0, 0, 700, 700); | |
418 gfx::Rect b_bounds_in_a = gfx::Rect(0, 0, 600, 600); | |
419 gfx::Rect g_bounds_in_b = gfx::Rect(0, 0, 200, 200); | |
420 gfx::Rect c2_bounds_in_e = gfx::Rect(0, 0, 800, 800); | |
421 gfx::Transform transform_e_to_e, transform_e_to_c1, transform_c1_to_a, | |
422 transform_a_to_b, transform_b_to_g, transform_e_to_c2; | |
423 transform_e_to_c1.Translate(-100, -100); | |
424 transform_a_to_b.Translate(-50, -30); | |
425 transform_b_to_g.Translate(-150, -200); | |
426 transform_e_to_c2.Translate(-400, -50); | |
427 AggregatedHitTestRegion aggregated_hit_test_region_list[6] = { | |
428 {e_id, mojom::kHitTestMine, e_bounds_in_e, transform_e_to_e, 5}, // e | |
429 {c1_id, mojom::kHitTestChildSurface | mojom::kHitTestIgnore, | |
430 c1_bounds_in_e, transform_e_to_c1, 3}, // c1 | |
431 {a_id, mojom::kHitTestChildSurface | mojom::kHitTestMine, a_bounds_in_c1, | |
432 transform_c1_to_a, 2}, // a | |
433 {b_id, mojom::kHitTestChildSurface | mojom::kHitTestMine, b_bounds_in_a, | |
434 transform_a_to_b, 1}, // b | |
435 {g_id, mojom::kHitTestChildSurface | mojom::kHitTestMine, g_bounds_in_b, | |
436 transform_b_to_g, 0}, // g | |
437 {c2_id, mojom::kHitTestChildSurface | mojom::kHitTestMine, c2_bounds_in_e, | |
438 transform_e_to_c2, 0} // c2 | |
439 }; | |
440 hit_test_query_.set_aggregated_hit_test_region_list( | |
441 aggregated_hit_test_region_list, 6); | |
442 | |
443 // All points are in e's coordinate system when we reach this case. | |
444 gfx::Point point1(1, 1); | |
445 gfx::Point point2(300, 350); | |
446 gfx::Point point3(550, 350); | |
447 gfx::Point point4(900, 350); | |
448 | |
449 Target target1 = hit_test_query_.FindTargetForLocation(point1); | |
450 EXPECT_EQ(e_id, target1.frame_sink_id); | |
451 EXPECT_EQ(point1, target1.location_in_target); | |
452 EXPECT_EQ(mojom::kHitTestMine, target1.flags); | |
453 | |
454 Target target2 = hit_test_query_.FindTargetForLocation(point2); | |
455 EXPECT_EQ(g_id, target2.frame_sink_id); | |
456 EXPECT_EQ(gfx::Point(0, 20), target2.location_in_target); | |
457 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target2.flags); | |
458 | |
459 Target target3 = hit_test_query_.FindTargetForLocation(point3); | |
460 EXPECT_EQ(b_id, target3.frame_sink_id); | |
461 EXPECT_EQ(gfx::Point(400, 220), target3.location_in_target); | |
462 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target3.flags); | |
463 | |
464 Target target4 = hit_test_query_.FindTargetForLocation(point4); | |
465 EXPECT_EQ(c2_id, target4.frame_sink_id); | |
466 EXPECT_EQ(gfx::Point(500, 300), target4.location_in_target); | |
467 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target4.flags); | |
468 } | |
469 | |
470 // Multiple layers deep of transparent children. | |
471 // | |
472 // +e--------------------+ | |
473 // | +c2--------| Point maps to | |
474 // | +c1------|----+ | ----- ------- | |
475 // |1| +a-----|---+| | 1 e | |
476 // | | |+b----|--+|| | 2 e | |
477 // | | ||+g--+| ||| | 3 c2 | |
478 // | | ||| 2 || 3||| 4 | 4 c2 | |
479 // | | ||+---+| ||| | | |
480 // | | |+-----|--+|| | | |
481 // | | +------| --+| | | |
482 // | +--------|----+ | | |
483 // +---------------------+ | |
484 // | |
485 TEST_F(HitTestQueryTest, MultipleLayerTransparentChild) { | |
486 FrameSinkId e_id = FrameSinkId(1, 1); | |
487 FrameSinkId c1_id = FrameSinkId(2, 2); | |
488 FrameSinkId a_id = FrameSinkId(3, 3); | |
489 FrameSinkId b_id = FrameSinkId(4, 4); | |
490 FrameSinkId g_id = FrameSinkId(5, 5); | |
491 FrameSinkId c2_id = FrameSinkId(6, 6); | |
492 gfx::Rect e_bounds_in_e = gfx::Rect(0, 0, 1000, 1000); | |
493 gfx::Rect c1_bounds_in_e = gfx::Rect(0, 0, 800, 800); | |
494 gfx::Rect a_bounds_in_c1 = gfx::Rect(0, 0, 700, 700); | |
495 gfx::Rect b_bounds_in_a = gfx::Rect(0, 0, 600, 600); | |
496 gfx::Rect g_bounds_in_b = gfx::Rect(0, 0, 200, 200); | |
497 gfx::Rect c2_bounds_in_e = gfx::Rect(0, 0, 800, 800); | |
498 gfx::Transform transform_e_to_e, transform_e_to_c1, transform_c1_to_a, | |
499 transform_a_to_b, transform_b_to_g, transform_e_to_c2; | |
500 transform_e_to_c1.Translate(-100, -100); | |
501 transform_a_to_b.Translate(-50, -30); | |
502 transform_b_to_g.Translate(-150, -200); | |
503 transform_e_to_c2.Translate(-400, -50); | |
504 AggregatedHitTestRegion aggregated_hit_test_region_list[6] = { | |
505 {e_id, mojom::kHitTestMine, e_bounds_in_e, transform_e_to_e, 5}, // e | |
506 {c1_id, mojom::kHitTestChildSurface | mojom::kHitTestIgnore, | |
507 c1_bounds_in_e, transform_e_to_c1, 3}, // c1 | |
508 {a_id, mojom::kHitTestChildSurface | mojom::kHitTestIgnore, | |
509 a_bounds_in_c1, transform_c1_to_a, 2}, // a | |
510 {b_id, mojom::kHitTestChildSurface | mojom::kHitTestIgnore, b_bounds_in_a, | |
511 transform_a_to_b, 1}, // b | |
512 {g_id, mojom::kHitTestChildSurface | mojom::kHitTestIgnore, g_bounds_in_b, | |
513 transform_b_to_g, 0}, // g | |
514 {c2_id, mojom::kHitTestChildSurface | mojom::kHitTestMine, c2_bounds_in_e, | |
515 transform_e_to_c2, 0} // c2 | |
516 }; | |
517 hit_test_query_.set_aggregated_hit_test_region_list( | |
518 aggregated_hit_test_region_list, 6); | |
519 | |
520 // All points are in e's coordinate system when we reach this case. | |
521 gfx::Point point1(1, 1); | |
522 gfx::Point point2(300, 350); | |
523 gfx::Point point3(450, 350); | |
524 gfx::Point point4(900, 350); | |
525 | |
526 Target target1 = hit_test_query_.FindTargetForLocation(point1); | |
527 EXPECT_EQ(e_id, target1.frame_sink_id); | |
528 EXPECT_EQ(point1, target1.location_in_target); | |
529 EXPECT_TRUE(target1.flags); | |
530 | |
531 Target target2 = hit_test_query_.FindTargetForLocation(point2); | |
532 EXPECT_EQ(e_id, target2.frame_sink_id); | |
533 EXPECT_EQ(point2, target2.location_in_target); | |
534 EXPECT_TRUE(target2.flags); | |
535 | |
536 Target target3 = hit_test_query_.FindTargetForLocation(point3); | |
537 EXPECT_EQ(c2_id, target3.frame_sink_id); | |
538 EXPECT_EQ(gfx::Point(50, 300), target3.location_in_target); | |
539 EXPECT_TRUE(target3.flags); | |
540 | |
541 Target target4 = hit_test_query_.FindTargetForLocation(point4); | |
542 EXPECT_EQ(c2_id, target4.frame_sink_id); | |
543 EXPECT_EQ(gfx::Point(500, 300), target4.location_in_target); | |
544 EXPECT_TRUE(target4.flags); | |
545 } | |
546 | |
547 TEST_F(HitTestQueryTest, InvalidAggregatedHitTestRegionData) { | |
548 FrameSinkId e_id = FrameSinkId(1, 1); | |
549 FrameSinkId c_id = FrameSinkId(2, 2); | |
550 FrameSinkId a_id = FrameSinkId(3, 3); | |
551 FrameSinkId b_id = FrameSinkId(4, 4); | |
552 gfx::Rect e_bounds_in_e = gfx::Rect(0, 0, 600, 600); | |
553 gfx::Rect c_bounds_in_e = gfx::Rect(0, 0, 800, 800); | |
554 gfx::Rect a_bounds_in_c = gfx::Rect(0, 0, 200, 100); | |
555 gfx::Rect b_bounds_in_c = gfx::Rect(0, 0, 800, 600); | |
556 gfx::Transform transform_e_to_e, transform_e_to_c, transform_c_to_a, | |
557 transform_c_to_b; | |
558 transform_e_to_c.Translate(-200, -100); | |
559 transform_c_to_b.Translate(0, -100); | |
560 AggregatedHitTestRegion aggregated_hit_test_region_list[4] = { | |
561 {e_id, mojom::kHitTestMine, e_bounds_in_e, transform_e_to_e, 4}, // e | |
562 {c_id, mojom::kHitTestChildSurface | mojom::kHitTestIgnore, c_bounds_in_e, | |
563 transform_e_to_c, 2}, // c | |
564 {a_id, mojom::kHitTestChildSurface | mojom::kHitTestMine, a_bounds_in_c, | |
565 transform_c_to_a, 0}, // a | |
566 {b_id, mojom::kHitTestChildSurface | mojom::kHitTestMine, b_bounds_in_c, | |
567 transform_c_to_b, 0} // b | |
568 }; | |
569 hit_test_query_.set_aggregated_hit_test_region_list( | |
570 aggregated_hit_test_region_list, 4); | |
571 | |
572 // All points are in e's coordinate system when we reach this case. | |
573 gfx::Point point1(1, 1); | |
574 | |
575 // |child_count| is invalid, which is a security fault. For now, check to see | |
rjkroege
2017/07/19 18:01:26
which one is invalid? I was imagining a child cou
riajiang
2017/07/19 19:22:14
e's child_count is wrong since it only has three c
| |
576 // if the returned Target is invalid. | |
577 Target target1 = hit_test_query_.FindTargetForLocation(point1); | |
578 EXPECT_EQ(FrameSinkId(), target1.frame_sink_id); | |
579 EXPECT_EQ(gfx::Point(), target1.location_in_target); | |
580 EXPECT_FALSE(target1.flags); | |
581 } | |
582 | |
583 } // namespace test | |
584 } // namespace viz | |
OLD | NEW |