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

Side by Side Diff: components/viz/service/hit_test/hit_test_aggregator_unittest.cc

Issue 2933493003: Add viz-host HitTestQuery. (Closed)
Patch Set: don't combine uint and int; check for overflow Created 3 years, 5 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
« no previous file with comments | « components/viz/service/hit_test/DEPS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/viz/service/hit_test/hit_test_aggregator.h" 5 #include "components/viz/service/hit_test/hit_test_aggregator.h"
6 6
7 #include "components/viz/common/surfaces/frame_sink_id.h" 7 #include "components/viz/common/surfaces/frame_sink_id.h"
8 #include "components/viz/common/surfaces/local_surface_id.h" 8 #include "components/viz/common/surfaces/local_surface_id.h"
9 #include "components/viz/common/surfaces/surface_id.h" 9 #include "components/viz/common/surfaces/surface_id.h"
10 #include "components/viz/host/hit_test/hit_test_query.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 namespace viz { 13 namespace viz {
13 14
14 namespace { 15 namespace {
15 16
16 constexpr FrameSinkId kDisplayFrameSink(2, 0); 17 constexpr FrameSinkId kDisplayFrameSink(2, 0);
17 18
18 SurfaceId MakeSurfaceId(const FrameSinkId& frame_sink_id, uint32_t local_id) { 19 SurfaceId MakeSurfaceId(const FrameSinkId& frame_sink_id, uint32_t local_id) {
19 return SurfaceId( 20 return SurfaceId(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 69
69 class HitTestAggregatorTest : public testing::Test { 70 class HitTestAggregatorTest : public testing::Test {
70 public: 71 public:
71 HitTestAggregatorTest() = default; 72 HitTestAggregatorTest() = default;
72 ~HitTestAggregatorTest() override = default; 73 ~HitTestAggregatorTest() override = default;
73 74
74 // testing::Test: 75 // testing::Test:
75 void SetUp() override {} 76 void SetUp() override {}
76 void TearDown() override { aggregator_.Reset(); } 77 void TearDown() override { aggregator_.Reset(); }
77 78
78 TestHitTestAggregator aggregator_;
79
80 // Creates a hit test data element with 8 children recursively to 79 // Creates a hit test data element with 8 children recursively to
81 // the specified depth. SurfaceIds are generated in sequential order and 80 // the specified depth. SurfaceIds are generated in sequential order and
82 // the method returns the next unused id. 81 // the method returns the next unused id.
83 int CreateAndSubmitHitTestRegionListWith8Children(int id, int depth) { 82 int CreateAndSubmitHitTestRegionListWith8Children(int id, int depth) {
84 SurfaceId surface_id = MakeSurfaceId(kDisplayFrameSink, id); 83 SurfaceId surface_id = MakeSurfaceId(kDisplayFrameSink, id);
85 id++; 84 id++;
86 85
87 auto hit_test_region_list = mojom::HitTestRegionList::New(); 86 auto hit_test_region_list = mojom::HitTestRegionList::New();
88 hit_test_region_list->surface_id = surface_id; 87 hit_test_region_list->surface_id = surface_id;
89 hit_test_region_list->flags = mojom::kHitTestMine; 88 hit_test_region_list->flags = mojom::kHitTestMine;
90 hit_test_region_list->bounds.SetRect(0, 0, 1024, 768); 89 hit_test_region_list->bounds.SetRect(0, 0, 1024, 768);
91 90
92 for (int i = 0; i < 8; i++) { 91 for (int i = 0; i < 8; i++) {
93 auto hit_test_region = mojom::HitTestRegion::New(); 92 auto hit_test_region = mojom::HitTestRegion::New();
94 hit_test_region->rect.SetRect(100, 100, 100, 100); 93 hit_test_region->rect.SetRect(100, 100, 100, 100);
95 94
96 if (depth > 0) { 95 if (depth > 0) {
97 hit_test_region->flags = mojom::kHitTestChildSurface; 96 hit_test_region->flags = mojom::kHitTestChildSurface;
98 hit_test_region->surface_id = MakeSurfaceId(kDisplayFrameSink, id); 97 hit_test_region->surface_id = MakeSurfaceId(kDisplayFrameSink, id);
99 id = CreateAndSubmitHitTestRegionListWith8Children(id, depth - 1); 98 id = CreateAndSubmitHitTestRegionListWith8Children(id, depth - 1);
100 } else { 99 } else {
101 hit_test_region->flags = mojom::kHitTestMine; 100 hit_test_region->flags = mojom::kHitTestMine;
102 } 101 }
103 hit_test_region_list->regions.push_back(std::move(hit_test_region)); 102 hit_test_region_list->regions.push_back(std::move(hit_test_region));
104 } 103 }
105 104
106 aggregator_.SubmitHitTestRegionList(std::move(hit_test_region_list)); 105 aggregator_.SubmitHitTestRegionList(std::move(hit_test_region_list));
107 return id; 106 return id;
108 } 107 }
varkha 2017/07/22 04:31:45 I'd make the class data private with protected get
riajiang 2017/07/24 18:24:50 Done.
108
109 TestHitTestAggregator aggregator_;
110 HitTestQuery hit_test_query_;
109 }; 111 };
110 112
111 // TODO(gklassen): Add tests for 3D use cases as suggested by and with 113 // TODO(gklassen): Add tests for 3D use cases as suggested by and with
112 // input from rjkroege. 114 // input from rjkroege.
113 115
114 // One surface. 116 // One surface.
115 // 117 //
116 // +----------+ 118 // +----------+
117 // | | 119 // | |
118 // | | 120 // | |
(...skipping 29 matching lines...) Expand all
148 150
149 AggregatedHitTestRegion* regions = aggregator_.GetRegions(); 151 AggregatedHitTestRegion* regions = aggregator_.GetRegions();
150 152
151 AggregatedHitTestRegion* region = nullptr; 153 AggregatedHitTestRegion* region = nullptr;
152 154
153 region = &regions[0]; 155 region = &regions[0];
154 EXPECT_EQ(mojom::kHitTestMine, region->flags); 156 EXPECT_EQ(mojom::kHitTestMine, region->flags);
155 EXPECT_EQ(display_surface_id.frame_sink_id(), region->frame_sink_id); 157 EXPECT_EQ(display_surface_id.frame_sink_id(), region->frame_sink_id);
156 EXPECT_EQ(gfx::Rect(0, 0, 1024, 768), region->rect); 158 EXPECT_EQ(gfx::Rect(0, 0, 1024, 768), region->rect);
157 EXPECT_EQ(0, region->child_count); 159 EXPECT_EQ(0, region->child_count);
160
161 hit_test_query_.set_aggregated_hit_test_region_list(regions, 1);
162
163 // All points are in e's coordinate system when we reach this case.
164 gfx::Point point1(1, 1);
165 gfx::Point point2(1024, 768);
166 gfx::Point point3(0, 0);
167
168 Target target1 = hit_test_query_.FindTargetForLocation(point1);
169 EXPECT_EQ(display_surface_id.frame_sink_id(), target1.frame_sink_id);
varkha 2017/07/22 04:31:46 It looks like the order has changed. Would it be g
riajiang 2017/07/24 18:24:50 Done.
170 EXPECT_EQ(point1, target1.location_in_target);
171 EXPECT_EQ(mojom::kHitTestMine, target1.flags);
172
173 // point2 is on the bounds of e so no target found.
174 Target target2 = hit_test_query_.FindTargetForLocation(point2);
175 EXPECT_EQ(FrameSinkId(), target2.frame_sink_id);
176 EXPECT_EQ(gfx::Point(), target2.location_in_target);
177 EXPECT_FALSE(target2.flags);
178
179 // There's a valid Target for point3, see Rect::Contains.
180 Target target3 = hit_test_query_.FindTargetForLocation(point3);
181 EXPECT_EQ(display_surface_id.frame_sink_id(), target3.frame_sink_id);
182 EXPECT_EQ(point3, target3.location_in_target);
183 EXPECT_EQ(mojom::kHitTestMine, target3.flags);
158 } 184 }
159 185
160 // One opaque embedder with two regions. 186 // One opaque embedder with two regions.
161 // 187 //
162 // +e-------------+ 188 // +e-------------+
163 // | +r1-+ +r2--+ | 189 // | +r1-+ +r2--+ |
164 // | | | | | | 190 // | | | | | |
165 // | | | | | | 191 // | | | | | |
166 // | +---+ +----+ | 192 // | +---+ +----+ |
167 // +--------------+ 193 // +--------------+
168 // 194 //
169 TEST_F(HitTestAggregatorTest, OneEmbedderTwoRegions) { 195 TEST_F(HitTestAggregatorTest, OneEmbedderTwoRegions) {
170 EXPECT_EQ(0, aggregator_.Count()); 196 EXPECT_EQ(0, aggregator_.Count());
171 197
172 SurfaceId e_surface_id = MakeSurfaceId(kDisplayFrameSink, 1); 198 SurfaceId e_surface_id = MakeSurfaceId(kDisplayFrameSink, 1);
173 199
174 auto e_hit_test_data = mojom::HitTestRegionList::New(); 200 auto e_hit_test_data = mojom::HitTestRegionList::New();
175 e_hit_test_data->surface_id = e_surface_id; 201 e_hit_test_data->surface_id = e_surface_id;
176 e_hit_test_data->flags = mojom::kHitTestMine; 202 e_hit_test_data->flags = mojom::kHitTestMine;
177 e_hit_test_data->bounds.SetRect(0, 0, 1024, 768); 203 e_hit_test_data->bounds.SetRect(0, 0, 1024, 768);
178 204
179 auto e_hit_test_region_r1 = mojom::HitTestRegion::New(); 205 auto e_hit_test_region_r1 = mojom::HitTestRegion::New();
206 e_hit_test_region_r1->surface_id = e_surface_id;
180 e_hit_test_region_r1->flags = mojom::kHitTestMine; 207 e_hit_test_region_r1->flags = mojom::kHitTestMine;
181 e_hit_test_region_r1->rect.SetRect(100, 100, 200, 400); 208 e_hit_test_region_r1->rect.SetRect(100, 100, 200, 400);
182 209
183 auto e_hit_test_region_r2 = mojom::HitTestRegion::New(); 210 auto e_hit_test_region_r2 = mojom::HitTestRegion::New();
211 e_hit_test_region_r2->surface_id = e_surface_id;
184 e_hit_test_region_r2->flags = mojom::kHitTestMine; 212 e_hit_test_region_r2->flags = mojom::kHitTestMine;
185 e_hit_test_region_r2->rect.SetRect(400, 100, 300, 400); 213 e_hit_test_region_r2->rect.SetRect(400, 100, 300, 400);
186 214
187 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_r1)); 215 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_r1));
188 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_r2)); 216 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_r2));
189 217
190 // Submit mojom::HitTestRegionList. 218 // Submit mojom::HitTestRegionList.
191 219
192 EXPECT_EQ(0, aggregator_.GetPendingCount()); 220 EXPECT_EQ(0, aggregator_.GetPendingCount());
193 221
(...skipping 28 matching lines...) Expand all
222 250
223 region = &regions[1]; 251 region = &regions[1];
224 EXPECT_EQ(mojom::kHitTestMine, region->flags); 252 EXPECT_EQ(mojom::kHitTestMine, region->flags);
225 EXPECT_EQ(gfx::Rect(100, 100, 200, 400), region->rect); 253 EXPECT_EQ(gfx::Rect(100, 100, 200, 400), region->rect);
226 EXPECT_EQ(0, region->child_count); 254 EXPECT_EQ(0, region->child_count);
227 255
228 region = &regions[2]; 256 region = &regions[2];
229 EXPECT_EQ(mojom::kHitTestMine, region->flags); 257 EXPECT_EQ(mojom::kHitTestMine, region->flags);
230 EXPECT_EQ(gfx::Rect(400, 100, 300, 400), region->rect); 258 EXPECT_EQ(gfx::Rect(400, 100, 300, 400), region->rect);
231 EXPECT_EQ(0, region->child_count); 259 EXPECT_EQ(0, region->child_count);
260
261 hit_test_query_.set_aggregated_hit_test_region_list(regions, 3);
262
263 // All points are in e's coordinate system when we reach this case.
264 gfx::Point point1(99, 200);
265 gfx::Point point2(150, 150);
266 gfx::Point point3(400, 400);
267 gfx::Point point4(1200, 350);
268
269 Target target1 = hit_test_query_.FindTargetForLocation(point1);
270 EXPECT_EQ(e_surface_id.frame_sink_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(e_surface_id.frame_sink_id(), target2.frame_sink_id);
276 EXPECT_EQ(gfx::Point(50, 50), target2.location_in_target);
277 EXPECT_EQ(mojom::kHitTestMine, target2.flags);
278
279 Target target3 = hit_test_query_.FindTargetForLocation(point3);
280 EXPECT_EQ(e_surface_id.frame_sink_id(), target3.frame_sink_id);
281 EXPECT_EQ(gfx::Point(0, 300), target3.location_in_target);
282 EXPECT_EQ(mojom::kHitTestMine, target3.flags);
283
284 Target target4 = hit_test_query_.FindTargetForLocation(point4);
285 EXPECT_EQ(FrameSinkId(), target4.frame_sink_id);
286 EXPECT_EQ(gfx::Point(), target4.location_in_target);
287 EXPECT_FALSE(target4.flags);
232 } 288 }
233 289
234 // One embedder with two children. 290 // One embedder with two children.
235 // 291 //
236 // +e-------------+ 292 // +e-------------+
237 // | +c1-+ +c2--+ | 293 // | +c1-+ +c2--+ |
238 // | | | | | | 294 // | | | | | |
239 // | | | | | | 295 // | | | | | |
240 // | +---+ +----+ | 296 // | +---+ +----+ |
241 // +--------------+ 297 // +--------------+
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 EXPECT_EQ(mojom::kHitTestChildSurface, region->flags); 379 EXPECT_EQ(mojom::kHitTestChildSurface, region->flags);
324 EXPECT_EQ(c1_surface_id.frame_sink_id(), region->frame_sink_id); 380 EXPECT_EQ(c1_surface_id.frame_sink_id(), region->frame_sink_id);
325 EXPECT_EQ(gfx::Rect(100, 100, 200, 300), region->rect); 381 EXPECT_EQ(gfx::Rect(100, 100, 200, 300), region->rect);
326 EXPECT_EQ(0, region->child_count); 382 EXPECT_EQ(0, region->child_count);
327 383
328 region = &regions[2]; 384 region = &regions[2];
329 EXPECT_EQ(mojom::kHitTestChildSurface, region->flags); 385 EXPECT_EQ(mojom::kHitTestChildSurface, region->flags);
330 EXPECT_EQ(c2_surface_id.frame_sink_id(), region->frame_sink_id); 386 EXPECT_EQ(c2_surface_id.frame_sink_id(), region->frame_sink_id);
331 EXPECT_EQ(gfx::Rect(400, 100, 400, 300), region->rect); 387 EXPECT_EQ(gfx::Rect(400, 100, 400, 300), region->rect);
332 EXPECT_EQ(0, region->child_count); 388 EXPECT_EQ(0, region->child_count);
389
390 hit_test_query_.set_aggregated_hit_test_region_list(regions, 3);
391
392 // All points are in e's coordinate system when we reach this case.
393 // They all go to e since c1 and c2 cannot receive events.
394 gfx::Point point1(99, 200);
395 gfx::Point point2(150, 150);
396 gfx::Point point3(400, 400);
397 gfx::Point point4(1200, 350);
398
399 Target target1 = hit_test_query_.FindTargetForLocation(point1);
400 EXPECT_EQ(e_surface_id.frame_sink_id(), target1.frame_sink_id);
401 EXPECT_EQ(point1, target1.location_in_target);
402 EXPECT_EQ(mojom::kHitTestMine, target1.flags);
403
404 Target target2 = hit_test_query_.FindTargetForLocation(point2);
405 EXPECT_EQ(e_surface_id.frame_sink_id(), target2.frame_sink_id);
406 EXPECT_EQ(point2, target2.location_in_target);
407 EXPECT_EQ(mojom::kHitTestMine, target2.flags);
408
409 Target target3 = hit_test_query_.FindTargetForLocation(point3);
410 EXPECT_EQ(e_surface_id.frame_sink_id(), target3.frame_sink_id);
411 EXPECT_EQ(point3, target3.location_in_target);
412 EXPECT_EQ(mojom::kHitTestMine, target3.flags);
413
414 Target target4 = hit_test_query_.FindTargetForLocation(point4);
415 EXPECT_EQ(FrameSinkId(), target4.frame_sink_id);
416 EXPECT_EQ(gfx::Point(), target4.location_in_target);
417 EXPECT_FALSE(target4.flags);
333 } 418 }
334 419
335 // Occluded child frame (OOPIF). 420 // Occluded child frame (OOPIF).
336 // 421 //
337 // +e-----------+ 422 // +e-----------+
338 // | +c--+ | 423 // | +c--+ |
339 // | | +div-+ | 424 // | | +div-+ |
340 // | | | | | 425 // | | | | |
341 // | | +----+ | 426 // | | +----+ |
342 // | +---+ | 427 // | +---+ |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 EXPECT_EQ(mojom::kHitTestMine, region->flags); 502 EXPECT_EQ(mojom::kHitTestMine, region->flags);
418 EXPECT_EQ(e_surface_id.frame_sink_id(), region->frame_sink_id); 503 EXPECT_EQ(e_surface_id.frame_sink_id(), region->frame_sink_id);
419 EXPECT_EQ(gfx::Rect(200, 200, 300, 200), region->rect); 504 EXPECT_EQ(gfx::Rect(200, 200, 300, 200), region->rect);
420 EXPECT_EQ(0, region->child_count); 505 EXPECT_EQ(0, region->child_count);
421 506
422 region = &regions[2]; 507 region = &regions[2];
423 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine); 508 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine);
424 EXPECT_EQ(c_surface_id.frame_sink_id(), region->frame_sink_id); 509 EXPECT_EQ(c_surface_id.frame_sink_id(), region->frame_sink_id);
425 EXPECT_EQ(gfx::Rect(100, 100, 200, 500), region->rect); 510 EXPECT_EQ(gfx::Rect(100, 100, 200, 500), region->rect);
426 EXPECT_EQ(0, region->child_count); 511 EXPECT_EQ(0, region->child_count);
512
513 hit_test_query_.set_aggregated_hit_test_region_list(regions, 3);
514
515 // All points are in e's coordinate system when we reach this case.
516 gfx::Point point1(99, 200);
517 gfx::Point point2(150, 150);
518 gfx::Point point3(250, 250);
519
520 Target target1 = hit_test_query_.FindTargetForLocation(point1);
521 EXPECT_EQ(e_surface_id.frame_sink_id(), target1.frame_sink_id);
522 EXPECT_EQ(point1, target1.location_in_target);
523 EXPECT_EQ(mojom::kHitTestMine, target1.flags);
524
525 Target target2 = hit_test_query_.FindTargetForLocation(point2);
526 EXPECT_EQ(c_surface_id.frame_sink_id(), target2.frame_sink_id);
527 EXPECT_EQ(gfx::Point(50, 50), target2.location_in_target);
528 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target2.flags);
529
530 Target target3 = hit_test_query_.FindTargetForLocation(point3);
531 EXPECT_EQ(e_surface_id.frame_sink_id(), target3.frame_sink_id);
532 EXPECT_EQ(gfx::Point(50, 50), target3.location_in_target);
533 EXPECT_EQ(mojom::kHitTestMine, target3.flags);
427 } 534 }
428 535
429 // Foreground child frame (OOPIF). 536 // Foreground child frame (OOPIF).
430 // Same as the previous test except the child is foreground. 537 // Same as the previous test except the child is foreground.
431 // 538 //
432 // +e-----------+ 539 // +e-----------+
433 // | +c--+ | 540 // | +c--+ |
434 // | | |div-+ | 541 // | | |div-+ |
435 // | | | | | 542 // | | | | |
436 // | | |----+ | 543 // | | |----+ |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine); 619 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine);
513 EXPECT_EQ(c_surface_id.frame_sink_id(), region->frame_sink_id); 620 EXPECT_EQ(c_surface_id.frame_sink_id(), region->frame_sink_id);
514 EXPECT_EQ(gfx::Rect(100, 100, 200, 500), region->rect); 621 EXPECT_EQ(gfx::Rect(100, 100, 200, 500), region->rect);
515 EXPECT_EQ(0, region->child_count); 622 EXPECT_EQ(0, region->child_count);
516 623
517 region = &regions[2]; 624 region = &regions[2];
518 EXPECT_EQ(mojom::kHitTestMine, region->flags); 625 EXPECT_EQ(mojom::kHitTestMine, region->flags);
519 EXPECT_EQ(e_surface_id.frame_sink_id(), region->frame_sink_id); 626 EXPECT_EQ(e_surface_id.frame_sink_id(), region->frame_sink_id);
520 EXPECT_EQ(gfx::Rect(200, 200, 300, 200), region->rect); 627 EXPECT_EQ(gfx::Rect(200, 200, 300, 200), region->rect);
521 EXPECT_EQ(0, region->child_count); 628 EXPECT_EQ(0, region->child_count);
629
630 hit_test_query_.set_aggregated_hit_test_region_list(regions, 3);
631
632 // All points are in e's coordinate system when we reach this case.
633 gfx::Point point1(99, 200);
634 gfx::Point point2(150, 150);
635 gfx::Point point3(250, 250);
636 gfx::Point point4(350, 300);
637
638 Target target1 = hit_test_query_.FindTargetForLocation(point1);
639 EXPECT_EQ(e_surface_id.frame_sink_id(), target1.frame_sink_id);
640 EXPECT_EQ(point1, target1.location_in_target);
641 EXPECT_EQ(mojom::kHitTestMine, target1.flags);
642
643 Target target2 = hit_test_query_.FindTargetForLocation(point2);
644 EXPECT_EQ(c_surface_id.frame_sink_id(), target2.frame_sink_id);
645 EXPECT_EQ(gfx::Point(50, 50), target2.location_in_target);
646 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target2.flags);
647
648 Target target3 = hit_test_query_.FindTargetForLocation(point3);
649 EXPECT_EQ(c_surface_id.frame_sink_id(), target3.frame_sink_id);
650 EXPECT_EQ(gfx::Point(150, 150), target3.location_in_target);
651 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target3.flags);
652
653 Target target4 = hit_test_query_.FindTargetForLocation(point4);
654 EXPECT_EQ(e_surface_id.frame_sink_id(), target4.frame_sink_id);
655 EXPECT_EQ(gfx::Point(150, 100), target4.location_in_target);
656 EXPECT_EQ(mojom::kHitTestMine, target4.flags);
522 } 657 }
523 658
524 // One embedder with a clipped child with a tab and transparent background. 659 // One embedder with a clipped child with a tab and transparent background.
525 // 660 //
526 // +e-------------+ 661 // +e-------------+
527 // | +c---------| Point maps to 662 // | +c---------| Point maps to
528 // | 1 |+a--+ | ----- ------- 663 // | 1 |+a--+ | ----- -------
529 // | || 2 | 3 | 1 e 664 // | || 2 | 3 | 1 e
530 // | |+b--------| 2 a 665 // | |+b--------| 2 a
531 // | || | 3 e (transparent area in c) 666 // | || | 3 e (transparent area in c)
(...skipping 10 matching lines...) Expand all
542 SurfaceId b_surface_id = MakeSurfaceId(kDisplayFrameSink, 4); 677 SurfaceId b_surface_id = MakeSurfaceId(kDisplayFrameSink, 4);
543 678
544 auto e_hit_test_data = mojom::HitTestRegionList::New(); 679 auto e_hit_test_data = mojom::HitTestRegionList::New();
545 e_hit_test_data->surface_id = e_surface_id; 680 e_hit_test_data->surface_id = e_surface_id;
546 e_hit_test_data->flags = mojom::kHitTestMine; 681 e_hit_test_data->flags = mojom::kHitTestMine;
547 e_hit_test_data->bounds.SetRect(0, 0, 1024, 768); 682 e_hit_test_data->bounds.SetRect(0, 0, 1024, 768);
548 683
549 auto e_hit_test_region_c = mojom::HitTestRegion::New(); 684 auto e_hit_test_region_c = mojom::HitTestRegion::New();
550 e_hit_test_region_c->flags = mojom::kHitTestChildSurface; 685 e_hit_test_region_c->flags = mojom::kHitTestChildSurface;
551 e_hit_test_region_c->surface_id = c_surface_id; 686 e_hit_test_region_c->surface_id = c_surface_id;
552 e_hit_test_region_c->rect.SetRect(200, 100, 1600, 800); 687 e_hit_test_region_c->rect.SetRect(300, 100, 1600, 800);
553 e_hit_test_region_c->transform.Translate(200, 100); 688 e_hit_test_region_c->transform.Translate(200, 100);
554 689
555 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_c)); 690 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_c));
556 691
557 auto c_hit_test_data = mojom::HitTestRegionList::New(); 692 auto c_hit_test_data = mojom::HitTestRegionList::New();
558 c_hit_test_data->surface_id = c_surface_id; 693 c_hit_test_data->surface_id = c_surface_id;
559 c_hit_test_data->flags = mojom::kHitTestIgnore; 694 c_hit_test_data->flags = mojom::kHitTestIgnore;
560 c_hit_test_data->bounds.SetRect(0, 0, 1600, 800); 695 c_hit_test_data->bounds.SetRect(0, 0, 1600, 800);
561 696
562 auto c_hit_test_region_a = mojom::HitTestRegion::New(); 697 auto c_hit_test_region_a = mojom::HitTestRegion::New();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 766
632 region = &regions[0]; 767 region = &regions[0];
633 EXPECT_EQ(mojom::kHitTestMine, region->flags); 768 EXPECT_EQ(mojom::kHitTestMine, region->flags);
634 EXPECT_EQ(e_surface_id.frame_sink_id(), region->frame_sink_id); 769 EXPECT_EQ(e_surface_id.frame_sink_id(), region->frame_sink_id);
635 EXPECT_EQ(gfx::Rect(0, 0, 1024, 768), region->rect); 770 EXPECT_EQ(gfx::Rect(0, 0, 1024, 768), region->rect);
636 EXPECT_EQ(3, region->child_count); 771 EXPECT_EQ(3, region->child_count);
637 772
638 region = &regions[1]; 773 region = &regions[1];
639 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestIgnore); 774 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestIgnore);
640 EXPECT_EQ(c_surface_id.frame_sink_id(), region->frame_sink_id); 775 EXPECT_EQ(c_surface_id.frame_sink_id(), region->frame_sink_id);
641 EXPECT_EQ(gfx::Rect(200, 100, 1600, 800), region->rect); 776 EXPECT_EQ(gfx::Rect(300, 100, 1600, 800), region->rect);
642 EXPECT_EQ(2, region->child_count); 777 EXPECT_EQ(2, region->child_count);
643 778
644 gfx::Point point(300, 300); 779 gfx::Point point(300, 300);
645 region->transform.TransformPointReverse(&point); 780 region->transform.TransformPointReverse(&point);
646 EXPECT_TRUE(point == gfx::Point(100, 200)); 781 EXPECT_TRUE(point == gfx::Point(100, 200));
647 782
648 region = &regions[2]; 783 region = &regions[2];
649 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine); 784 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine);
650 EXPECT_EQ(a_surface_id.frame_sink_id(), region->frame_sink_id); 785 EXPECT_EQ(a_surface_id.frame_sink_id(), region->frame_sink_id);
651 EXPECT_EQ(gfx::Rect(0, 0, 200, 100), region->rect); 786 EXPECT_EQ(gfx::Rect(0, 0, 200, 100), region->rect);
652 EXPECT_EQ(0, region->child_count); 787 EXPECT_EQ(0, region->child_count);
653 788
654 region = &regions[3]; 789 region = &regions[3];
655 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine); 790 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine);
656 EXPECT_EQ(b_surface_id.frame_sink_id(), region->frame_sink_id); 791 EXPECT_EQ(b_surface_id.frame_sink_id(), region->frame_sink_id);
657 EXPECT_EQ(gfx::Rect(0, 100, 800, 600), region->rect); 792 EXPECT_EQ(gfx::Rect(0, 100, 800, 600), region->rect);
658 EXPECT_EQ(0, region->child_count); 793 EXPECT_EQ(0, region->child_count);
794
795 hit_test_query_.set_aggregated_hit_test_region_list(regions, 4);
796
797 // All points are in e's coordinate system when we reach this case.
798 gfx::Point point1(1, 1);
799 gfx::Point point2(100, 50);
800 gfx::Point point3(400, 70);
801 gfx::Point point4(200, 200);
802
803 Target target1 = hit_test_query_.FindTargetForLocation(point1);
804 EXPECT_EQ(e_surface_id.frame_sink_id(), target1.frame_sink_id);
805 EXPECT_EQ(point1, target1.location_in_target);
806 EXPECT_EQ(mojom::kHitTestMine, target1.flags);
807
808 Target target2 = hit_test_query_.FindTargetForLocation(point2);
809 EXPECT_EQ(a_surface_id.frame_sink_id(), target2.frame_sink_id);
810 EXPECT_EQ(gfx::Point(0, 50), target2.location_in_target);
811 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target2.flags);
812
813 Target target3 = hit_test_query_.FindTargetForLocation(point3);
814 EXPECT_EQ(e_surface_id.frame_sink_id(), target3.frame_sink_id);
815 EXPECT_EQ(point3, target3.location_in_target);
816 EXPECT_EQ(mojom::kHitTestMine, target3.flags);
817
818 Target target4 = hit_test_query_.FindTargetForLocation(point4);
819 EXPECT_EQ(b_surface_id.frame_sink_id(), target4.frame_sink_id);
820 EXPECT_EQ(gfx::Point(100, 100), target4.location_in_target);
821 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target4.flags);
659 } 822 }
660 823
661 // Three children deep. 824 // Three children deep.
662 // 825 //
663 // +e------------+ 826 // +e------------+
664 // | +c1-------+ | 827 // | +c1-------+ |
665 // | | +c2---+ | | 828 // | | +c2---+ | |
666 // | | | +c3-| | | 829 // | | | +c3-| | |
667 // | | | | | | | 830 // | | | | | | |
668 // | | | +---| | | 831 // | | | +---| | |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine); 946 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine);
784 EXPECT_EQ(c2_surface_id.frame_sink_id(), region->frame_sink_id); 947 EXPECT_EQ(c2_surface_id.frame_sink_id(), region->frame_sink_id);
785 EXPECT_EQ(gfx::Rect(100, 100, 500, 500), region->rect); 948 EXPECT_EQ(gfx::Rect(100, 100, 500, 500), region->rect);
786 EXPECT_EQ(1, region->child_count); 949 EXPECT_EQ(1, region->child_count);
787 950
788 region = &regions[3]; 951 region = &regions[3];
789 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine); 952 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine);
790 EXPECT_EQ(c3_surface_id.frame_sink_id(), region->frame_sink_id); 953 EXPECT_EQ(c3_surface_id.frame_sink_id(), region->frame_sink_id);
791 EXPECT_EQ(gfx::Rect(100, 100, 300, 300), region->rect); 954 EXPECT_EQ(gfx::Rect(100, 100, 300, 300), region->rect);
792 EXPECT_EQ(0, region->child_count); 955 EXPECT_EQ(0, region->child_count);
956
957 hit_test_query_.set_aggregated_hit_test_region_list(regions, 4);
958
959 // All points are in e's coordinate system when we reach this case.
960 gfx::Point point1(1, 1);
961 gfx::Point point2(100, 150);
962 gfx::Point point3(250, 450);
963 gfx::Point point4(450, 550);
964
965 Target target1 = hit_test_query_.FindTargetForLocation(point1);
966 EXPECT_EQ(e_surface_id.frame_sink_id(), target1.frame_sink_id);
967 EXPECT_EQ(point1, target1.location_in_target);
968 EXPECT_EQ(mojom::kHitTestMine, target1.flags);
969
970 Target target2 = hit_test_query_.FindTargetForLocation(point2);
971 EXPECT_EQ(c3_surface_id.frame_sink_id(), target2.frame_sink_id);
972 EXPECT_EQ(gfx::Point(0, 50), target2.location_in_target);
973 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target2.flags);
974
975 Target target3 = hit_test_query_.FindTargetForLocation(point3);
976 EXPECT_EQ(c2_surface_id.frame_sink_id(), target3.frame_sink_id);
977 EXPECT_EQ(gfx::Point(50, 250), target3.location_in_target);
978 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target3.flags);
979
980 Target target4 = hit_test_query_.FindTargetForLocation(point4);
981 EXPECT_EQ(c1_surface_id.frame_sink_id(), target4.frame_sink_id);
982 EXPECT_EQ(gfx::Point(150, 250), target4.location_in_target);
983 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target4.flags);
793 } 984 }
794 985
795 // Missing / late child. 986 // Missing / late child.
796 // 987 //
797 // +e-----------+ 988 // +e-----------+
798 // | +c--+ | 989 // | +c--+ |
799 // | | |div-+ | 990 // | | |div-+ |
800 // | | | | | 991 // | | | | |
801 // | | |----+ | 992 // | | |----+ |
802 // | +---+ | 993 // | +---+ |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 // Discard Surface and ensure active count goes down. 1199 // Discard Surface and ensure active count goes down.
1009 1200
1010 aggregator_.CallOnSurfaceDiscarded(c_surface_id); 1201 aggregator_.CallOnSurfaceDiscarded(c_surface_id);
1011 EXPECT_EQ(2, aggregator_.GetActiveRegionCount()); 1202 EXPECT_EQ(2, aggregator_.GetActiveRegionCount());
1012 1203
1013 aggregator_.CallOnSurfaceDiscarded(e_surface_id); 1204 aggregator_.CallOnSurfaceDiscarded(e_surface_id);
1014 EXPECT_EQ(0, aggregator_.GetActiveRegionCount()); 1205 EXPECT_EQ(0, aggregator_.GetActiveRegionCount());
1015 } 1206 }
1016 1207
1017 } // namespace viz 1208 } // namespace viz
OLDNEW
« no previous file with comments | « components/viz/service/hit_test/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698