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

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

Issue 2933493003: Add viz-host HitTestQuery. (Closed)
Patch Set: update 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.
rjkroege 2017/06/15 19:58:36 this is coming very well.
riajiang 2017/06/16 02:56:54 :)
29 //
30 // +e---------+
31 // | |
32 // | |
33 // | |
34 // +----------+
35 //
36 TEST_F(HitTestQueryTest, OneSurface) {
37 cc::FrameSinkId e_id = cc::FrameSinkId(1, 1);
38 std::vector<DisplayHitTestData> display_hit_test_data_list = {
39 {e_id, gfx::Rect(0, 0, 600, 600), gfx::Transform(), 1 /* HIT_TEST_MINE */,
rjkroege 2017/06/15 19:58:36 I would find it easier to read if you made this on
riajiang 2017/06/16 02:56:55 Done.
40 0} // e
41 };
42 hit_test_query_.set_display_hit_test_data_list(display_hit_test_data_list);
43
44 // All points are in e's coordinate system when we reach this case.
rjkroege 2017/06/15 19:58:36 is 0,0 in the region?
riajiang 2017/06/16 02:56:55 Ha I thought it's like 600,600 but it is in the re
45 gfx::Point point1(1, 1);
46 gfx::Point point2(600, 600);
47
48 Target target1 = hit_test_query_.FindTargetForLocation(point1);
49 EXPECT_EQ(e_id.ToString(), target1.id.ToString());
50 EXPECT_EQ(point1.ToString(), target1.location_in_target.ToString());
rjkroege 2017/06/15 19:58:36 Doesn't Point's == operator mean that you don't ne
riajiang 2017/06/16 02:56:55 Yes! And it's not needed for FrameSinkId as well s
51 EXPECT_TRUE(target1.flags);
52
53 // point2 is on the bounds of e so no target found.
54 Target target2 = hit_test_query_.FindTargetForLocation(point2);
55 EXPECT_EQ(cc::FrameSinkId().ToString(), target2.id.ToString());
56 EXPECT_EQ(gfx::Point().ToString(), target2.location_in_target.ToString());
57 EXPECT_FALSE(target2.flags);
58 }
59
60 // One embedder with two children.
61 //
62 // +e------------+ Point maps to
63 // | +c1-+ +c2---| ----- -------
64 // |1| | | | 1 e
65 // | | 2 | | 3 | 4 2 c1
66 // | +---+ | | 3 c2
67 // +-------------+ 4 none
68 //
69 TEST_F(HitTestQueryTest, OneEmbedderTwoChildren) {
70 cc::FrameSinkId e_id = cc::FrameSinkId(1, 1);
71 cc::FrameSinkId c1_id = cc::FrameSinkId(2, 2);
72 cc::FrameSinkId c2_id = cc::FrameSinkId(3, 3);
73 gfx::Rect e_bounds_in_e = gfx::Rect(0, 0, 600, 600);
74 gfx::Rect c1_bounds_in_e = gfx::Rect(0, 0, 200, 200);
75 gfx::Rect c2_bounds_in_e = gfx::Rect(0, 0, 400, 400);
76 gfx::Transform transform_e_to_e, transform_e_to_c1, transform_e_to_c2;
77 transform_e_to_c1.Translate(-100, -100);
78 transform_e_to_c2.Translate(-300, -300);
79 std::vector<DisplayHitTestData> display_hit_test_data_list = {
80 {e_id, e_bounds_in_e, transform_e_to_e, 1 /* HIT_TEST_MINE */, 2}, // e
81 {c1_id, c1_bounds_in_e, transform_e_to_c1, 1 /* HIT_TEST_MINE */,
82 0}, // c1
83 {c2_id, c2_bounds_in_e, transform_e_to_c2, 1 /* HIT_TEST_MINE */,
84 0} // c2
85 };
86 hit_test_query_.set_display_hit_test_data_list(display_hit_test_data_list);
87
88 // All points are in e's coordinate system when we reach this case.
89 gfx::Point point1(99, 200);
90 gfx::Point point2(150, 150);
91 gfx::Point point3(400, 400);
92 gfx::Point point4(650, 350);
93
94 Target target1 = hit_test_query_.FindTargetForLocation(point1);
95 EXPECT_EQ(e_id.ToString(), target1.id.ToString());
96 EXPECT_EQ(point1.ToString(), target1.location_in_target.ToString());
97 EXPECT_TRUE(target1.flags);
98
99 Target target2 = hit_test_query_.FindTargetForLocation(point2);
100 EXPECT_EQ(c1_id.ToString(), target2.id.ToString());
101 EXPECT_EQ(gfx::Point(50, 50).ToString(),
102 target2.location_in_target.ToString());
103 EXPECT_TRUE(target2.flags);
104
105 Target target3 = hit_test_query_.FindTargetForLocation(point3);
106 EXPECT_EQ(c2_id.ToString(), target3.id.ToString());
107 EXPECT_EQ(gfx::Point(100, 100).ToString(),
108 target3.location_in_target.ToString());
109 EXPECT_TRUE(target3.flags);
110
111 Target target4 = hit_test_query_.FindTargetForLocation(point4);
112 EXPECT_EQ(cc::FrameSinkId().ToString(), target4.id.ToString());
113 EXPECT_EQ(gfx::Point().ToString(), target4.location_in_target.ToString());
114 EXPECT_FALSE(target4.flags);
115 }
116
117 // One embedder with a rotated child.
118 TEST_F(HitTestQueryTest, OneEmbedderRotatedChild) {
119 cc::FrameSinkId e_id = cc::FrameSinkId(1, 1);
120 cc::FrameSinkId c_id = cc::FrameSinkId(2, 2);
121 gfx::Rect e_bounds_in_e = gfx::Rect(0, 0, 600, 600);
122 gfx::Rect c_bounds_in_e = gfx::Rect(0, 0, 1000, 1000);
123 gfx::Transform transform_e_to_e, transform_e_to_c;
124 transform_e_to_c.Translate(-100, -100);
125 transform_e_to_c.Skew(2, 3);
126 transform_e_to_c.Scale(.5f, .7f);
127
128 std::vector<DisplayHitTestData> display_hit_test_data_list = {
129 {e_id, e_bounds_in_e, transform_e_to_e, 1 /* HIT_TEST_MINE */, 1}, // e
130 {c_id, c_bounds_in_e, transform_e_to_c, 1 /* HIT_TEST_MINE */, 0} // c
131 };
132 hit_test_query_.set_display_hit_test_data_list(display_hit_test_data_list);
133
134 // All points are in e's coordinate system when we reach this case.
135 gfx::Point point1(150, 120); // Point(-22, -12) after transform.
136 gfx::Point point2(550, 400); // Point(185, 194) after transform.
137
138 Target target1 = hit_test_query_.FindTargetForLocation(point1);
139 EXPECT_EQ(e_id.ToString(), target1.id.ToString());
140 EXPECT_EQ(point1.ToString(), target1.location_in_target.ToString());
141 EXPECT_TRUE(target1.flags);
142
143 Target target2 = hit_test_query_.FindTargetForLocation(point2);
144 EXPECT_EQ(c_id.ToString(), target2.id.ToString());
145 EXPECT_EQ(gfx::Point(185, 194).ToString(),
146 target2.location_in_target.ToString());
147 EXPECT_TRUE(target2.flags);
148 }
149
150 // Children that are multiple layers deep.
151 //
152 // +e--------------------+ Point maps to
153 // | +c1---------+ +c2---| ----- -------
154 // |1| +a-------+| | | 1 e
155 // | | |+b-----+|| | | 2 g
156 // | | ||+g--+ ||| | | 3 c2
157 // | | ||| 2 | ||| | 3 |
158 // | | ||+---+ ||| | |
159 // | | |+------+|| | |
160 // | | +--------+| | |
161 // | +-----------+ | |
162 // +---------------------+
163 //
164 TEST_F(HitTestQueryTest, MultipleLayerChild) {
165 cc::FrameSinkId e_id = cc::FrameSinkId(1, 1);
166 cc::FrameSinkId a_id = cc::FrameSinkId(2, 2);
167 cc::FrameSinkId b_id = cc::FrameSinkId(3, 3);
168 cc::FrameSinkId g_id = cc::FrameSinkId(4, 4);
169 cc::FrameSinkId c2_id = cc::FrameSinkId(5, 5);
170 gfx::Rect e_bounds_in_e = gfx::Rect(0, 0, 1000, 1000);
171 gfx::Rect c1_bounds_in_e = gfx::Rect(0, 0, 600, 600);
172 gfx::Rect a_bounds_in_c1 = gfx::Rect(0, 0, 500, 500);
173 gfx::Rect b_bounds_in_c1 = gfx::Rect(0, 0, 400, 400);
174 gfx::Rect g_bounds_in_c1 = gfx::Rect(0, 0, 200, 200);
175 gfx::Rect c2_bounds_in_e = gfx::Rect(0, 0, 800, 800);
176 gfx::Transform transform_e_to_e, transform_e_to_c1, transform_c1_to_a,
177 transform_c1_to_b, transform_c1_to_g, transform_e_to_c2;
178 transform_e_to_c1.Translate(-100, -100);
rjkroege 2017/06/15 19:58:36 we need unit tests that handle 3space transformati
179 transform_c1_to_b.Translate(-50, -30);
180 transform_c1_to_g.Translate(-150, -200);
181 transform_e_to_c2.Translate(-800, -100);
182 std::vector<DisplayHitTestData> display_hit_test_data_list = {
183 {e_id, e_bounds_in_e, transform_e_to_e, 1 /* HIT_TEST_MINE */, 5}, // e
184 {e_id, c1_bounds_in_e, transform_e_to_c1, 0 /* HIT_TEST_BOUND */,
185 3}, // c1
186 {a_id, a_bounds_in_c1, transform_c1_to_a, 1 /* HIT_TEST_MINE */, 2}, // a
187 {b_id, b_bounds_in_c1, transform_c1_to_b, 1 /* HIT_TEST_MINE */, 1}, // b
188 {g_id, g_bounds_in_c1, transform_c1_to_g, 1 /* HIT_TEST_MINE */, 0}, // g
189 {c2_id, c2_bounds_in_e, transform_e_to_c2, 1 /* HIT_TEST_MINE */,
190 0} // c2
191 };
192 hit_test_query_.set_display_hit_test_data_list(display_hit_test_data_list);
193
194 // All points are in e's coordinate system when we reach this case.
195 gfx::Point point1(1, 1);
196 gfx::Point point2(300, 350);
197 gfx::Point point3(900, 350);
198
199 Target target1 = hit_test_query_.FindTargetForLocation(point1);
200 EXPECT_EQ(e_id.ToString(), target1.id.ToString());
201 EXPECT_EQ(point1.ToString(), target1.location_in_target.ToString());
202 EXPECT_TRUE(target1.flags);
203
204 Target target2 = hit_test_query_.FindTargetForLocation(point2);
205 EXPECT_EQ(g_id.ToString(), target2.id.ToString());
206 EXPECT_EQ(gfx::Point(0, 20).ToString(),
207 target2.location_in_target.ToString());
208 EXPECT_TRUE(target2.flags);
209
210 Target target3 = hit_test_query_.FindTargetForLocation(point3);
211 EXPECT_EQ(c2_id.ToString(), target3.id.ToString());
212 EXPECT_EQ(gfx::Point(100, 250).ToString(),
213 target3.location_in_target.ToString());
214 EXPECT_TRUE(target3.flags);
215 }
216
217 // One embedder with a clipped child with a tab and transparent background.
218 //
219 // +e-------------+
220 // | +c---------| Point maps to
rjkroege 2017/06/15 19:58:36 so... say we have a a d region inside area "3". b
riajiang 2017/06/16 02:56:55 If it's back-to-front (what I'm assuming for now),
221 // | 1 |+a--+ | ----- -------
222 // | || 2 | 3 | 1 e
223 // | |+b--------| 2 a
224 // | || | 3 e ( transparent area in c )
225 // | || 4 | 4 b
226 // +--------------+
227 //
228 TEST_F(HitTestQueryTest, ClippedChildWithTabAndTransparentBackground) {
229 cc::FrameSinkId e_id = cc::FrameSinkId(1, 1);
230 cc::FrameSinkId a_id = cc::FrameSinkId(2, 2);
231 cc::FrameSinkId b_id = cc::FrameSinkId(3, 3);
232 gfx::Rect e_bounds_in_e = gfx::Rect(0, 0, 600, 600);
233 gfx::Rect c_bounds_in_e = gfx::Rect(0, 0, 800, 800);
234 gfx::Rect a_bounds_in_c = gfx::Rect(0, 0, 200, 100);
235 gfx::Rect b_bounds_in_c = gfx::Rect(0, 0, 800, 600);
236 gfx::Transform transform_e_to_e, transform_e_to_c, transform_c_to_a,
237 transform_c_to_b;
238 transform_e_to_c.Translate(-200, -100);
239 transform_c_to_b.Translate(0, -100);
240 std::vector<DisplayHitTestData> display_hit_test_data_list = {
241 {e_id, e_bounds_in_e, transform_e_to_e, 1 /* HIT_TEST_MINE */, 3}, // e
242 {e_id, c_bounds_in_e, transform_e_to_c, 0 /* HIT_TEST_BOUND */, 2}, // c
243 {a_id, a_bounds_in_c, transform_c_to_a, 1 /* HIT_TEST_MINE */, 0}, // a
244 {b_id, b_bounds_in_c, transform_c_to_b, 1 /* HIT_TEST_MINE */, 0} // b
245 };
246 hit_test_query_.set_display_hit_test_data_list(display_hit_test_data_list);
247
248 // All points are in e's coordinate system when we reach this case.
249 gfx::Point point1(1, 1);
250 gfx::Point point2(202, 102);
251 gfx::Point point3(403, 103);
252 gfx::Point point4(202, 202);
253
254 Target target1 = hit_test_query_.FindTargetForLocation(point1);
255 EXPECT_EQ(e_id.ToString(), target1.id.ToString());
256 EXPECT_EQ(point1.ToString(), target1.location_in_target.ToString());
257 EXPECT_TRUE(target1.flags);
258
259 Target target2 = hit_test_query_.FindTargetForLocation(point2);
260 EXPECT_EQ(a_id.ToString(), target2.id.ToString());
261 EXPECT_EQ(gfx::Point(2, 2).ToString(), target2.location_in_target.ToString());
262 EXPECT_TRUE(target2.flags);
263
264 Target target3 = hit_test_query_.FindTargetForLocation(point3);
265 EXPECT_EQ(e_id.ToString(), target3.id.ToString());
266 EXPECT_EQ(point3.ToString(), target3.location_in_target.ToString());
267 EXPECT_TRUE(target3.flags);
268
269 Target target4 = hit_test_query_.FindTargetForLocation(point4);
270 EXPECT_EQ(b_id.ToString(), target4.id.ToString());
271 EXPECT_EQ(gfx::Point(2, 2).ToString(), target4.location_in_target.ToString());
272 EXPECT_TRUE(target4.flags);
273 }
274
275 // One embedder with two clipped children with a tab and transparent background.
276 //
277 // +e-------------+
278 // | +c1--------| Point maps to
279 // | 1 |+a--+ | ----- -------
280 // | || 2 | 3 | 1 e
281 // | |+b--------| 2 a
282 // | || | 3 e ( transparent area in c1 )
283 // | || 4 | 4 b
284 // | +----------| 5 g
285 // | +c2--------| 6 e ( transparent area in c2 )
286 // | |+g--+ | 7 h
287 // | || 5 | 6 |
288 // | |+h--------|
289 // | || |
290 // | || 7 |
291 // +--------------+
292 //
293 TEST_F(HitTestQueryTest, ClippedChildrenWithTabAndTransparentBackground) {
294 cc::FrameSinkId e_id = cc::FrameSinkId(1, 1);
295 cc::FrameSinkId a_id = cc::FrameSinkId(2, 2);
296 cc::FrameSinkId b_id = cc::FrameSinkId(3, 3);
297 cc::FrameSinkId g_id = cc::FrameSinkId(4, 4);
298 cc::FrameSinkId h_id = cc::FrameSinkId(5, 5);
299 gfx::Rect e_bounds_in_e = gfx::Rect(0, 0, 600, 1200);
300 gfx::Rect c1_bounds_in_e = gfx::Rect(0, 0, 800, 500);
301 gfx::Rect a_bounds_in_c1 = gfx::Rect(0, 0, 200, 100);
302 gfx::Rect b_bounds_in_c1 = gfx::Rect(0, 0, 800, 400);
303 gfx::Rect c2_bounds_in_e = gfx::Rect(0, 0, 800, 500);
304 gfx::Rect g_bounds_in_c2 = gfx::Rect(0, 0, 200, 100);
305 gfx::Rect h_bounds_in_c2 = gfx::Rect(0, 0, 800, 800);
306 gfx::Transform transform_e_to_e, transform_e_to_c1, transform_c1_to_a,
307 transform_c1_to_b, transform_e_to_c2, transform_c2_to_g,
308 transform_c2_to_h;
309 transform_e_to_c1.Translate(-200, -100);
310 transform_c1_to_b.Translate(0, -100);
311 transform_e_to_c2.Translate(-200, -700);
312 transform_c2_to_h.Translate(0, -100);
313 std::vector<DisplayHitTestData> display_hit_test_data_list = {
314 {e_id, e_bounds_in_e, transform_e_to_e, 1 /* HIT_TEST_MINE */, 6}, // e
315 {e_id, c1_bounds_in_e, transform_e_to_c1, 0 /* HIT_TEST_BOUND */,
316 2}, // c1
317 {a_id, a_bounds_in_c1, transform_c1_to_a, 1 /* HIT_TEST_MINE */, 0}, // a
318 {b_id, b_bounds_in_c1, transform_c1_to_b, 1 /* HIT_TEST_MINE */, 0}, // b
319 {e_id, c2_bounds_in_e, transform_e_to_c2, 0 /* HIT_TEST_BOUND */,
320 2}, // c2
321 {g_id, g_bounds_in_c2, transform_c2_to_g, 1 /* HIT_TEST_MINE */, 0}, // g
322 {h_id, h_bounds_in_c2, transform_c2_to_h, 1 /* HIT_TEST_MINE */, 0} // h
323 };
324 hit_test_query_.set_display_hit_test_data_list(display_hit_test_data_list);
325
326 // All points are in e's coordinate system when we reach this case.
327 gfx::Point point1(1, 1);
328 gfx::Point point2(202, 102);
329 gfx::Point point3(403, 103);
330 gfx::Point point4(202, 202);
331 gfx::Point point5(250, 750);
332 gfx::Point point6(450, 750);
333 gfx::Point point7(350, 1100);
334
335 Target target1 = hit_test_query_.FindTargetForLocation(point1);
336 EXPECT_EQ(e_id.ToString(), target1.id.ToString());
337 EXPECT_EQ(point1.ToString(), target1.location_in_target.ToString());
338 EXPECT_TRUE(target1.flags);
339
340 Target target2 = hit_test_query_.FindTargetForLocation(point2);
341 EXPECT_EQ(a_id.ToString(), target2.id.ToString());
342 EXPECT_EQ(gfx::Point(2, 2).ToString(), target2.location_in_target.ToString());
343 EXPECT_TRUE(target2.flags);
344
345 Target target3 = hit_test_query_.FindTargetForLocation(point3);
346 EXPECT_EQ(e_id.ToString(), target3.id.ToString());
347 EXPECT_EQ(point3.ToString(), target3.location_in_target.ToString());
348 EXPECT_TRUE(target3.flags);
349
350 Target target4 = hit_test_query_.FindTargetForLocation(point4);
351 EXPECT_EQ(b_id.ToString(), target4.id.ToString());
352 EXPECT_EQ(gfx::Point(2, 2).ToString(), target4.location_in_target.ToString());
353 EXPECT_TRUE(target4.flags);
354
355 Target target5 = hit_test_query_.FindTargetForLocation(point5);
356 EXPECT_EQ(g_id.ToString(), target5.id.ToString());
357 EXPECT_EQ(gfx::Point(50, 50).ToString(),
358 target5.location_in_target.ToString());
359 EXPECT_TRUE(target5.flags);
360
361 Target target6 = hit_test_query_.FindTargetForLocation(point6);
362 EXPECT_EQ(e_id.ToString(), target6.id.ToString());
363 EXPECT_EQ(point6.ToString(), target6.location_in_target.ToString());
364 EXPECT_TRUE(target6.flags);
365
366 Target target7 = hit_test_query_.FindTargetForLocation(point7);
367 EXPECT_EQ(h_id.ToString(), target7.id.ToString());
368 EXPECT_EQ(gfx::Point(150, 300).ToString(),
369 target7.location_in_target.ToString());
370 EXPECT_TRUE(target7.flags);
371 }
372
373 } // namespace test
374 } // namespace hit_test
375 } // namespace viz
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698