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

Side by Side Diff: components/viz/hittest/hittest_aggregator_unittest.cc

Issue 2908783002: WIP Hittest Component.
Patch Set: improvements from reviewer comments 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 "hittest_aggregator.h"
6 #include "cc/surfaces/frame_sink_id.h"
7 #include "cc/surfaces/local_surface_id.h"
8 #include "cc/surfaces/surface_id.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace viz {
rjkroege 2017/06/07 17:16:45 conceivably it could be in a child namespace like
gklassen 2017/06/07 20:04:44 Done.
12 namespace test {
13
14 namespace {
15
16 constexpr cc::FrameSinkId kDisplayFrameSink(2, 0);
17
18 cc::SurfaceId MakeSurfaceId(const cc::FrameSinkId& frame_sink_id,
19 uint32_t local_id) {
20 return cc::SurfaceId(
21 frame_sink_id,
22 cc::LocalSurfaceId(local_id, base::UnguessableToken::Deserialize(0, 1u)));
23 }
24
25 } // namespace
26
27 using namespace hittest::mojom;
28
29 class HittestAggregatorTest : public testing::Test {
30 public:
31 HittestAggregatorTest() {}
32 ~HittestAggregatorTest() override {}
33
34 void SetUp() override {}
35
36 void TearDown() override {}
37
38 HittestAggregator aggregator_;
39
40 int count() {
41 HittestAggregator::Element* end = aggregator_.current_regions_;
42 while (end->child_count_ != LAST_REGION) {
43 end++;
44 }
45 return end - aggregator_.current_regions_;
46 }
47
48 HittestRegion RegionAtIndex(int i) {
49 return aggregator_.current_regions_[i].region_;
50 }
51 };
52
53 TEST_F(HittestAggregatorTest, HittestAggregation) {
rjkroege 2017/06/07 17:16:45 not very useful.
gklassen 2017/06/07 20:04:44 Done.
54 EXPECT_TRUE(true);
55 }
56
57 TEST(HittestAggregatorTestNoFixture, HittestDataValidation) {
58 EXPECT_TRUE(false);
59 }
60
61 // tests brainstorm
62 // A. Validation
63 // - Rect is within the display
64 // - flags is one of available values?
65 // B. Aggregation
66 // - happy paths:
67 // - missing surface parent
68 // C. SurfaceFinding
69 // -
70
71 TEST_F(HittestAggregatorTest, SimplestHappyPath) {
72 // one hittest_data with no sub-regions gets all events
73
74 EXPECT_TRUE(count() == 0);
75
76 cc::SurfaceId display_surface_id = MakeSurfaceId(kDisplayFrameSink, 1);
77
78 auto hittest_data = HittestData::New();
79 hittest_data->surface_id_ = display_surface_id;
80 hittest_data->flags_ = hittest::mojom::HittestRegionFlags::HITTEST_NONE;
81 hittest_data->rect_.SetRect(0, 0, 1024, 768);
82
83 aggregator_.SubmitHittestData(std::move(hittest_data));
84
85 EXPECT_TRUE(count() == 0);
86
87 aggregator_.Aggregate(display_surface_id);
88
89 // there should now be only one region
90 EXPECT_TRUE(count() == 1);
91
92 HittestRegion region = RegionAtIndex(0);
93 EXPECT_TRUE(region.rect_ == gfx::Rect(0, 0, 1027, 768));
94 EXPECT_TRUE(region.flags_ == HittestRegionFlags::HITTEST_NONE);
95 }
96
97 TEST_F(HittestAggregatorTest, HittestDataValidation) {
98 auto hittest_data = hittest::mojom::HittestData::New();
99 hittest_data->surface_id_ = MakeSurfaceId(kDisplayFrameSink, 1);
100 hittest_data->flags_ = hittest::mojom::HittestRegionFlags::HITTEST_NONE;
101 hittest_data->rect_.SetRect(0, 0, 10, 10);
102
103 auto hittest_region = hittest::mojom::HittestRegion::New();
104 hittest_region->surface_id_ = MakeSurfaceId(kDisplayFrameSink, 2);
105 hittest_region->flags_ = hittest::mojom::HittestRegionFlags::HITTEST_ASK;
106 hittest_region->rect_.SetRect(0, 0, 10, 10);
107
108 // todo: confirm that transform inits to Identity
109 // DCHECK( hittest_region.transform_ )
110
111 hittest_data->regions_.push_back(std::move(hittest_region));
112
113 aggregator_.SubmitHittestData(std::move(hittest_data));
114 }
115
116 } // namespace test
117 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698