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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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 "mojo/services/window_manager/view_target.h"
6
7 #include <set>
8
9 #include "mojo/services/public/cpp/view_manager/view.h"
10 #include "mojo/services/window_manager/window_manager_test_util.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/gfx/geometry/rect.h"
13
14 namespace mojo {
15
16 class ViewTargetTest : public testing::Test {
17 public:
18 ViewTargetTest() {}
19 ~ViewTargetTest() override {}
20
21 void TearDown() override {
22 view_collector_.Destroy();
23 testing::Test::TearDown();
24 }
25
26 protected:
27 ViewCollector view_collector_;
28
29 private:
30 DISALLOW_COPY_AND_ASSIGN(ViewTargetTest);
31 };
32
33 TEST_F(ViewTargetTest, AddChild) {
34 TestViewTarget* v1 =
35 new TestViewTarget(1, gfx::Rect(0, 0, 100, 100), &view_collector_);
36 TestViewTarget* v11 =
37 new TestViewTarget(2, gfx::Rect(10, 10, 80, 80), &view_collector_);
38
39 v1->AddChild(v11);
40
41 EXPECT_EQ(1U, v1->GetChildren().size());
42 EXPECT_EQ(v1, v11->GetParent());
43 }
44
45 // V1
46 // +-- V2
47 TEST_F(ViewTargetTest, ConvertPointToTarget_Simple) {
48 TestViewTarget* v1 =
49 new TestViewTarget(1, gfx::Rect(20, 20, 400, 400), &view_collector_);
50 TestViewTarget* v2 =
51 new TestViewTarget(2, gfx::Rect(10, 10, 350, 350), &view_collector_);
52 v1->AddChild(v2);
53
54 gfx::Point point1_in_v2_coords(5, 5);
55 ViewTarget::ConvertPointToTarget(v2, v1, &point1_in_v2_coords);
56 gfx::Point point1_in_v1_coords(15, 15);
57 EXPECT_EQ(point1_in_v1_coords, point1_in_v2_coords);
58
59 gfx::Point point2_in_v1_coords(5, 5);
60 ViewTarget::ConvertPointToTarget(v1, v2, &point2_in_v1_coords);
61 gfx::Point point2_in_v2_coords(-5, -5);
62 EXPECT_EQ(point2_in_v2_coords, point2_in_v1_coords);
63 }
64
65 // V1
66 // +-- V2
67 // +-- V3
68 TEST_F(ViewTargetTest, ConvertPointToTarget_Medium) {
69 TestViewTarget* v1 =
70 new TestViewTarget(1, gfx::Rect(20, 20, 400, 400), &view_collector_);
71 TestViewTarget* v2 =
72 new TestViewTarget(2, gfx::Rect(10, 10, 350, 350), &view_collector_);
73 TestViewTarget* v3 =
74 new TestViewTarget(3, gfx::Rect(10, 10, 100, 100), &view_collector_);
75 v1->AddChild(v2);
76 v2->AddChild(v3);
77
78 gfx::Point point1_in_v3_coords(5, 5);
79 ViewTarget::ConvertPointToTarget(v3, v1, &point1_in_v3_coords);
80 gfx::Point point1_in_v1_coords(25, 25);
81 EXPECT_EQ(point1_in_v1_coords, point1_in_v3_coords);
82
83 gfx::Point point2_in_v1_coords(5, 5);
84 ViewTarget::ConvertPointToTarget(v1, v3, &point2_in_v1_coords);
85 gfx::Point point2_in_v3_coords(-15, -15);
86 EXPECT_EQ(point2_in_v3_coords, point2_in_v1_coords);
87 }
88
89 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698