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