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

Side by Side Diff: ui/views/mus/window_manager_connection_unittest.cc

Issue 2167643005: Revert of mus: Rename .*PointerWatcher.* to .*PointerDownWatcher.*. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: resolve conflicts Created 4 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 | « ui/views/mus/window_manager_connection.cc ('k') | ui/views/pointer_down_watcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ui/views/mus/window_manager_connection.h" 5 #include "ui/views/mus/window_manager_connection.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/events/event.h" 11 #include "ui/events/event.h"
12 #include "ui/views/pointer_down_watcher.h" 12 #include "ui/views/pointer_watcher.h"
13 #include "ui/views/test/scoped_views_test_helper.h" 13 #include "ui/views/test/scoped_views_test_helper.h"
14 #include "ui/views/touch_event_watcher.h" 14 #include "ui/views/touch_event_watcher.h"
15 15
16 namespace views { 16 namespace views {
17 namespace { 17 namespace {
18 18
19 class TestPointerDownWatcher : public PointerDownWatcher { 19 class TestPointerWatcher : public PointerWatcher {
20 public: 20 public:
21 TestPointerDownWatcher() {} 21 TestPointerWatcher() {}
22 ~TestPointerDownWatcher() override {} 22 ~TestPointerWatcher() override {}
23 23
24 bool mouse_pressed() const { return mouse_pressed_; } 24 bool mouse_pressed() const { return mouse_pressed_; }
25 bool touch_pressed() const { return touch_pressed_; } 25 bool touch_pressed() const { return touch_pressed_; }
26 26
27 void Reset() { 27 void Reset() {
28 mouse_pressed_ = false; 28 mouse_pressed_ = false;
29 touch_pressed_ = false; 29 touch_pressed_ = false;
30 } 30 }
31 31
32 // PointerDownWatcher: 32 // PointerWatcher:
33 void OnMousePressed(const ui::MouseEvent& event, 33 void OnMousePressed(const ui::MouseEvent& event,
34 const gfx::Point& location_in_screen, 34 const gfx::Point& location_in_screen,
35 Widget* target) override { 35 Widget* target) override {
36 mouse_pressed_ = true; 36 mouse_pressed_ = true;
37 } 37 }
38 void OnTouchPressed(const ui::TouchEvent& event, 38 void OnTouchPressed(const ui::TouchEvent& event,
39 const gfx::Point& location_in_screen, 39 const gfx::Point& location_in_screen,
40 Widget* target) override { 40 Widget* target) override {
41 touch_pressed_ = true; 41 touch_pressed_ = true;
42 } 42 }
43 43
44 private: 44 private:
45 bool mouse_pressed_ = false; 45 bool mouse_pressed_ = false;
46 bool touch_pressed_ = false; 46 bool touch_pressed_ = false;
47 47
48 DISALLOW_COPY_AND_ASSIGN(TestPointerDownWatcher); 48 DISALLOW_COPY_AND_ASSIGN(TestPointerWatcher);
49 }; 49 };
50 50
51 } // namespace 51 } // namespace
52 52
53 namespace { 53 namespace {
54 54
55 class TestTouchEventWatcher : public TouchEventWatcher { 55 class TestTouchEventWatcher : public TouchEventWatcher {
56 public: 56 public:
57 TestTouchEventWatcher() {} 57 TestTouchEventWatcher() {}
58 ~TestTouchEventWatcher() override {} 58 ~TestTouchEventWatcher() override {}
(...skipping 22 matching lines...) Expand all
81 ~WindowManagerConnectionTest() override {} 81 ~WindowManagerConnectionTest() override {}
82 82
83 void OnEventObserved(const ui::Event& event) { 83 void OnEventObserved(const ui::Event& event) {
84 WindowManagerConnection::Get()->OnEventObserved(event, nullptr); 84 WindowManagerConnection::Get()->OnEventObserved(event, nullptr);
85 } 85 }
86 86
87 private: 87 private:
88 DISALLOW_COPY_AND_ASSIGN(WindowManagerConnectionTest); 88 DISALLOW_COPY_AND_ASSIGN(WindowManagerConnectionTest);
89 }; 89 };
90 90
91 TEST_F(WindowManagerConnectionTest, PointerDownWatcher) { 91 TEST_F(WindowManagerConnectionTest, PointerWatcher) {
92 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); 92 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI);
93 ScopedViewsTestHelper helper; 93 ScopedViewsTestHelper helper;
94 WindowManagerConnection* connection = WindowManagerConnection::Get(); 94 WindowManagerConnection* connection = WindowManagerConnection::Get();
95 ASSERT_TRUE(connection); 95 ASSERT_TRUE(connection);
96 ui::MouseEvent mouse_pressed(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 96 ui::MouseEvent mouse_pressed(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
97 base::TimeTicks(), ui::EF_NONE, 0); 97 base::TimeTicks(), ui::EF_NONE, 0);
98 ui::TouchEvent touch_pressed(ui::ET_TOUCH_PRESSED, gfx::Point(), 1, 98 ui::TouchEvent touch_pressed(ui::ET_TOUCH_PRESSED, gfx::Point(), 1,
99 base::TimeTicks()); 99 base::TimeTicks());
100 ui::KeyEvent key_pressed(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); 100 ui::KeyEvent key_pressed(ui::ET_KEY_PRESSED, ui::VKEY_A, 0);
101 101
102 // PointerDownWatchers receive mouse events. 102 // PointerWatchers receive mouse events.
103 TestPointerDownWatcher watcher1; 103 TestPointerWatcher watcher1;
104 connection->AddPointerDownWatcher(&watcher1); 104 connection->AddPointerWatcher(&watcher1);
105 OnEventObserved(mouse_pressed); 105 OnEventObserved(mouse_pressed);
106 EXPECT_TRUE(watcher1.mouse_pressed()); 106 EXPECT_TRUE(watcher1.mouse_pressed());
107 watcher1.Reset(); 107 watcher1.Reset();
108 108
109 // PointerDownWatchers receive touch events. 109 // PointerWatchers receive touch events.
110 OnEventObserved(touch_pressed); 110 OnEventObserved(touch_pressed);
111 EXPECT_TRUE(watcher1.touch_pressed()); 111 EXPECT_TRUE(watcher1.touch_pressed());
112 watcher1.Reset(); 112 watcher1.Reset();
113 113
114 // PointerDownWatchers do not trigger for key events. 114 // PointerWatchers do not trigger for key events.
115 OnEventObserved(key_pressed); 115 OnEventObserved(key_pressed);
116 EXPECT_FALSE(watcher1.mouse_pressed()); 116 EXPECT_FALSE(watcher1.mouse_pressed());
117 EXPECT_FALSE(watcher1.touch_pressed()); 117 EXPECT_FALSE(watcher1.touch_pressed());
118 watcher1.Reset(); 118 watcher1.Reset();
119 119
120 // Two PointerDownWatchers can both receive a single observed event. 120 // Two PointerWatchers can both receive a single observed event.
121 TestPointerDownWatcher watcher2; 121 TestPointerWatcher watcher2;
122 connection->AddPointerDownWatcher(&watcher2); 122 connection->AddPointerWatcher(&watcher2);
123 OnEventObserved(mouse_pressed); 123 OnEventObserved(mouse_pressed);
124 EXPECT_TRUE(watcher1.mouse_pressed()); 124 EXPECT_TRUE(watcher1.mouse_pressed());
125 EXPECT_TRUE(watcher2.mouse_pressed()); 125 EXPECT_TRUE(watcher2.mouse_pressed());
126 watcher1.Reset(); 126 watcher1.Reset();
127 watcher2.Reset(); 127 watcher2.Reset();
128 128
129 // Removing the first PointerDownWatcher stops sending events to it. 129 // Removing the first PointerWatcher stops sending events to it.
130 connection->RemovePointerDownWatcher(&watcher1); 130 connection->RemovePointerWatcher(&watcher1);
131 OnEventObserved(mouse_pressed); 131 OnEventObserved(mouse_pressed);
132 EXPECT_FALSE(watcher1.mouse_pressed()); 132 EXPECT_FALSE(watcher1.mouse_pressed());
133 EXPECT_TRUE(watcher2.mouse_pressed()); 133 EXPECT_TRUE(watcher2.mouse_pressed());
134 watcher1.Reset(); 134 watcher1.Reset();
135 watcher2.Reset(); 135 watcher2.Reset();
136 136
137 // Removing the last PointerDownWatcher stops sending events to it. 137 // Removing the last PointerWatcher stops sending events to it.
138 connection->RemovePointerDownWatcher(&watcher2); 138 connection->RemovePointerWatcher(&watcher2);
139 OnEventObserved(mouse_pressed); 139 OnEventObserved(mouse_pressed);
140 EXPECT_FALSE(watcher1.mouse_pressed()); 140 EXPECT_FALSE(watcher1.mouse_pressed());
141 EXPECT_FALSE(watcher1.touch_pressed()); 141 EXPECT_FALSE(watcher1.touch_pressed());
142 } 142 }
143 143
144 TEST_F(WindowManagerConnectionTest, TouchEventWatcher) { 144 TEST_F(WindowManagerConnectionTest, TouchEventWatcher) {
145 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); 145 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI);
146 ScopedViewsTestHelper helper; 146 ScopedViewsTestHelper helper;
147 WindowManagerConnection* connection = WindowManagerConnection::Get(); 147 WindowManagerConnection* connection = WindowManagerConnection::Get();
148 ASSERT_TRUE(connection); 148 ASSERT_TRUE(connection);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 watcher2.Reset(); 205 watcher2.Reset();
206 206
207 // Removing the last TouchEventWatcher stops sending events to it. 207 // Removing the last TouchEventWatcher stops sending events to it.
208 connection->RemoveTouchEventWatcher(&watcher2); 208 connection->RemoveTouchEventWatcher(&watcher2);
209 OnEventObserved(touch_pointer_event); 209 OnEventObserved(touch_pointer_event);
210 EXPECT_FALSE(watcher1.touch_observed()); 210 EXPECT_FALSE(watcher1.touch_observed());
211 EXPECT_FALSE(watcher2.touch_observed()); 211 EXPECT_FALSE(watcher2.touch_observed());
212 } 212 }
213 213
214 } // namespace views 214 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/window_manager_connection.cc ('k') | ui/views/pointer_down_watcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698