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

Side by Side Diff: components/viz/host/hit_test/hit_test_query_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698