Index: components/viz/hittest/hittest_aggregator_unittest.cc |
diff --git a/components/viz/hittest/hittest_aggregator_unittest.cc b/components/viz/hittest/hittest_aggregator_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f493eb25f881e628218512b0726ee07e71bc8b09 |
--- /dev/null |
+++ b/components/viz/hittest/hittest_aggregator_unittest.cc |
@@ -0,0 +1,117 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "hittest_aggregator.h" |
+#include "cc/surfaces/frame_sink_id.h" |
+#include "cc/surfaces/local_surface_id.h" |
+#include "cc/surfaces/surface_id.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+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.
|
+namespace test { |
+ |
+namespace { |
+ |
+constexpr cc::FrameSinkId kDisplayFrameSink(2, 0); |
+ |
+cc::SurfaceId MakeSurfaceId(const cc::FrameSinkId& frame_sink_id, |
+ uint32_t local_id) { |
+ return cc::SurfaceId( |
+ frame_sink_id, |
+ cc::LocalSurfaceId(local_id, base::UnguessableToken::Deserialize(0, 1u))); |
+} |
+ |
+} // namespace |
+ |
+using namespace hittest::mojom; |
+ |
+class HittestAggregatorTest : public testing::Test { |
+ public: |
+ HittestAggregatorTest() {} |
+ ~HittestAggregatorTest() override {} |
+ |
+ void SetUp() override {} |
+ |
+ void TearDown() override {} |
+ |
+ HittestAggregator aggregator_; |
+ |
+ int count() { |
+ HittestAggregator::Element* end = aggregator_.current_regions_; |
+ while (end->child_count_ != LAST_REGION) { |
+ end++; |
+ } |
+ return end - aggregator_.current_regions_; |
+ } |
+ |
+ HittestRegion RegionAtIndex(int i) { |
+ return aggregator_.current_regions_[i].region_; |
+ } |
+}; |
+ |
+TEST_F(HittestAggregatorTest, HittestAggregation) { |
rjkroege
2017/06/07 17:16:45
not very useful.
gklassen
2017/06/07 20:04:44
Done.
|
+ EXPECT_TRUE(true); |
+} |
+ |
+TEST(HittestAggregatorTestNoFixture, HittestDataValidation) { |
+ EXPECT_TRUE(false); |
+} |
+ |
+// tests brainstorm |
+// A. Validation |
+// - Rect is within the display |
+// - flags is one of available values? |
+// B. Aggregation |
+// - happy paths: |
+// - missing surface parent |
+// C. SurfaceFinding |
+// - |
+ |
+TEST_F(HittestAggregatorTest, SimplestHappyPath) { |
+ // one hittest_data with no sub-regions gets all events |
+ |
+ EXPECT_TRUE(count() == 0); |
+ |
+ cc::SurfaceId display_surface_id = MakeSurfaceId(kDisplayFrameSink, 1); |
+ |
+ auto hittest_data = HittestData::New(); |
+ hittest_data->surface_id_ = display_surface_id; |
+ hittest_data->flags_ = hittest::mojom::HittestRegionFlags::HITTEST_NONE; |
+ hittest_data->rect_.SetRect(0, 0, 1024, 768); |
+ |
+ aggregator_.SubmitHittestData(std::move(hittest_data)); |
+ |
+ EXPECT_TRUE(count() == 0); |
+ |
+ aggregator_.Aggregate(display_surface_id); |
+ |
+ // there should now be only one region |
+ EXPECT_TRUE(count() == 1); |
+ |
+ HittestRegion region = RegionAtIndex(0); |
+ EXPECT_TRUE(region.rect_ == gfx::Rect(0, 0, 1027, 768)); |
+ EXPECT_TRUE(region.flags_ == HittestRegionFlags::HITTEST_NONE); |
+} |
+ |
+TEST_F(HittestAggregatorTest, HittestDataValidation) { |
+ auto hittest_data = hittest::mojom::HittestData::New(); |
+ hittest_data->surface_id_ = MakeSurfaceId(kDisplayFrameSink, 1); |
+ hittest_data->flags_ = hittest::mojom::HittestRegionFlags::HITTEST_NONE; |
+ hittest_data->rect_.SetRect(0, 0, 10, 10); |
+ |
+ auto hittest_region = hittest::mojom::HittestRegion::New(); |
+ hittest_region->surface_id_ = MakeSurfaceId(kDisplayFrameSink, 2); |
+ hittest_region->flags_ = hittest::mojom::HittestRegionFlags::HITTEST_ASK; |
+ hittest_region->rect_.SetRect(0, 0, 10, 10); |
+ |
+ // todo: confirm that transform inits to Identity |
+ // DCHECK( hittest_region.transform_ ) |
+ |
+ hittest_data->regions_.push_back(std::move(hittest_region)); |
+ |
+ aggregator_.SubmitHittestData(std::move(hittest_data)); |
+} |
+ |
+} // namespace test |
+} // namespace cc |