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

Unified Diff: mojo/services/window_manager/view_target_unittest.cc

Issue 724973003: Get event targetting working for mouse events. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Patch beautification. Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: mojo/services/window_manager/view_target_unittest.cc
diff --git a/mojo/services/window_manager/view_target_unittest.cc b/mojo/services/window_manager/view_target_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b656653194ee00309bd8a233b5db8491be73f462
--- /dev/null
+++ b/mojo/services/window_manager/view_target_unittest.cc
@@ -0,0 +1,89 @@
+// Copyright 2014 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 "mojo/services/window_manager/view_target.h"
+
+#include <set>
+
+#include "mojo/services/public/cpp/view_manager/view.h"
+#include "mojo/services/window_manager/window_manager_test_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gfx/geometry/rect.h"
+
+namespace mojo {
+
+class ViewTargetTest : public testing::Test {
+ public:
+ ViewTargetTest() {}
+ ~ViewTargetTest() override {}
+
+ void TearDown() override {
+ view_collector_.Destroy();
+ testing::Test::TearDown();
+ }
+
+ protected:
+ ViewCollector view_collector_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ViewTargetTest);
+};
+
+TEST_F(ViewTargetTest, AddChild) {
+ TestViewTarget* v1 =
+ new TestViewTarget(1, gfx::Rect(0, 0, 100, 100), &view_collector_);
+ TestViewTarget* v11 =
+ new TestViewTarget(2, gfx::Rect(10, 10, 80, 80), &view_collector_);
+
+ v1->AddChild(v11);
+
+ EXPECT_EQ(1U, v1->GetChildren().size());
+ EXPECT_EQ(v1, v11->GetParent());
+}
+
+// V1
+// +-- V2
+TEST_F(ViewTargetTest, ConvertPointToTarget_Simple) {
+ TestViewTarget* v1 =
+ new TestViewTarget(1, gfx::Rect(20, 20, 400, 400), &view_collector_);
+ TestViewTarget* v2 =
+ new TestViewTarget(2, gfx::Rect(10, 10, 350, 350), &view_collector_);
+ v1->AddChild(v2);
+
+ gfx::Point point1_in_v2_coords(5, 5);
+ ViewTarget::ConvertPointToTarget(v2, v1, &point1_in_v2_coords);
+ gfx::Point point1_in_v1_coords(15, 15);
+ EXPECT_EQ(point1_in_v1_coords, point1_in_v2_coords);
+
+ gfx::Point point2_in_v1_coords(5, 5);
+ ViewTarget::ConvertPointToTarget(v1, v2, &point2_in_v1_coords);
+ gfx::Point point2_in_v2_coords(-5, -5);
+ EXPECT_EQ(point2_in_v2_coords, point2_in_v1_coords);
+}
+
+// V1
+// +-- V2
+// +-- V3
+TEST_F(ViewTargetTest, ConvertPointToTarget_Medium) {
+ TestViewTarget* v1 =
+ new TestViewTarget(1, gfx::Rect(20, 20, 400, 400), &view_collector_);
+ TestViewTarget* v2 =
+ new TestViewTarget(2, gfx::Rect(10, 10, 350, 350), &view_collector_);
+ TestViewTarget* v3 =
+ new TestViewTarget(3, gfx::Rect(10, 10, 100, 100), &view_collector_);
+ v1->AddChild(v2);
+ v2->AddChild(v3);
+
+ gfx::Point point1_in_v3_coords(5, 5);
+ ViewTarget::ConvertPointToTarget(v3, v1, &point1_in_v3_coords);
+ gfx::Point point1_in_v1_coords(25, 25);
+ EXPECT_EQ(point1_in_v1_coords, point1_in_v3_coords);
+
+ gfx::Point point2_in_v1_coords(5, 5);
+ ViewTarget::ConvertPointToTarget(v1, v3, &point2_in_v1_coords);
+ gfx::Point point2_in_v3_coords(-15, -15);
+ EXPECT_EQ(point2_in_v3_coords, point2_in_v1_coords);
+}
+
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698