Chromium Code Reviews| Index: ui/views/mus/window_manager_connection_unittest.cc |
| diff --git a/ui/views/mus/window_manager_connection_unittest.cc b/ui/views/mus/window_manager_connection_unittest.cc |
| index e84d9eae989e423a3e863176a68396372911944f..e284377e4e73e381f196f506dd3a85784b8a497c 100644 |
| --- a/ui/views/mus/window_manager_connection_unittest.cc |
| +++ b/ui/views/mus/window_manager_connection_unittest.cc |
| @@ -11,7 +11,6 @@ |
| #include "ui/events/event.h" |
| #include "ui/views/pointer_watcher.h" |
| #include "ui/views/test/scoped_views_test_helper.h" |
| -#include "ui/views/touch_event_watcher.h" |
| namespace views { |
| namespace { |
| @@ -23,58 +22,47 @@ class TestPointerWatcher : public PointerWatcher { |
| bool mouse_pressed() const { return mouse_pressed_; } |
| bool touch_pressed() const { return touch_pressed_; } |
| + bool mouse_event_observed() const { return mouse_event_observed_; } |
| + bool touch_event_observed() const { return touch_event_observed_; } |
| + |
| + void set_want_moves(bool want_moves) { want_moves_ = want_moves; } |
|
James Cook
2016/07/27 01:54:02
I wouldn't explicitly set_want_moves(), just rely
riajiang
2016/07/27 22:39:16
Done.
|
| void Reset() { |
| mouse_pressed_ = false; |
| touch_pressed_ = false; |
| + mouse_event_observed_ = false; |
| + touch_event_observed_ = false; |
| } |
| // PointerWatcher: |
| - void OnMousePressed(const ui::MouseEvent& event, |
| - const gfx::Point& location_in_screen, |
| - Widget* target) override { |
| - mouse_pressed_ = true; |
| - } |
| - void OnTouchPressed(const ui::TouchEvent& event, |
| - const gfx::Point& location_in_screen, |
| - Widget* target) override { |
| - touch_pressed_ = true; |
| + void OnPointerWatcherEvent(const ui::PointerEvent& event, |
|
James Cook
2016/07/27 01:54:01
The tests might be easier to reason about if this
riajiang
2016/07/27 22:39:16
Done.
|
| + const gfx::Point& location_in_screen, |
| + Widget* target) override { |
| + if (event.IsTouchPointerEvent()) { |
| + if (want_moves_) |
| + touch_event_observed_ = true; |
| + else if (event.type() == ui::ET_POINTER_DOWN) |
| + touch_pressed_ = true; |
| + } else if (event.IsMousePointerEvent()) { |
| + if (want_moves_) |
| + mouse_event_observed_ = true; |
| + else if (event.type() == ui::ET_POINTER_DOWN) |
| + mouse_pressed_ = true; |
| + } |
| } |
| private: |
| bool mouse_pressed_ = false; |
| bool touch_pressed_ = false; |
| + bool mouse_event_observed_ = false; |
| + bool touch_event_observed_ = false; |
| + bool want_moves_ = false; |
| DISALLOW_COPY_AND_ASSIGN(TestPointerWatcher); |
| }; |
| } // namespace |
| -namespace { |
| - |
| -class TestTouchEventWatcher : public TouchEventWatcher { |
| - public: |
| - TestTouchEventWatcher() {} |
| - ~TestTouchEventWatcher() override {} |
| - |
| - bool touch_observed() const { return touch_observed_; } |
| - |
| - void Reset() { touch_observed_ = false; } |
| - |
| - // TouchEventWatcher: |
| - void OnTouchEventObserved(const ui::LocatedEvent& event, |
| - Widget* target) override { |
| - touch_observed_ = true; |
| - } |
| - |
| - private: |
| - bool touch_observed_ = false; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(TestTouchEventWatcher); |
| -}; |
| - |
| -} // namespace |
| - |
| class WindowManagerConnectionTest : public testing::Test { |
| public: |
| WindowManagerConnectionTest() {} |
| @@ -88,7 +76,7 @@ class WindowManagerConnectionTest : public testing::Test { |
| DISALLOW_COPY_AND_ASSIGN(WindowManagerConnectionTest); |
| }; |
| -TEST_F(WindowManagerConnectionTest, PointerWatcher) { |
| +TEST_F(WindowManagerConnectionTest, PointerWatcherNoMove) { |
| base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); |
| ScopedViewsTestHelper helper; |
| WindowManagerConnection* connection = WindowManagerConnection::Get(); |
| @@ -101,14 +89,17 @@ TEST_F(WindowManagerConnectionTest, PointerWatcher) { |
| // PointerWatchers receive mouse events. |
| TestPointerWatcher watcher1; |
| - connection->AddPointerWatcher(&watcher1); |
| + watcher1.set_want_moves(false); |
| + connection->AddPointerWatcher(&watcher1, false); |
| OnEventObserved(mouse_pressed); |
| EXPECT_TRUE(watcher1.mouse_pressed()); |
| + EXPECT_FALSE(watcher1.mouse_event_observed()); |
| watcher1.Reset(); |
| // PointerWatchers receive touch events. |
| OnEventObserved(touch_pressed); |
| EXPECT_TRUE(watcher1.touch_pressed()); |
| + EXPECT_FALSE(watcher1.touch_event_observed()); |
| watcher1.Reset(); |
| // PointerWatchers do not trigger for key events. |
| @@ -119,10 +110,13 @@ TEST_F(WindowManagerConnectionTest, PointerWatcher) { |
| // Two PointerWatchers can both receive a single observed event. |
| TestPointerWatcher watcher2; |
| - connection->AddPointerWatcher(&watcher2); |
| + watcher2.set_want_moves(false); |
| + connection->AddPointerWatcher(&watcher2, false); |
| OnEventObserved(mouse_pressed); |
| EXPECT_TRUE(watcher1.mouse_pressed()); |
| EXPECT_TRUE(watcher2.mouse_pressed()); |
| + EXPECT_FALSE(watcher1.mouse_event_observed()); |
| + EXPECT_FALSE(watcher2.mouse_event_observed()); |
| watcher1.Reset(); |
| watcher2.Reset(); |
| @@ -141,7 +135,7 @@ TEST_F(WindowManagerConnectionTest, PointerWatcher) { |
| EXPECT_FALSE(watcher1.touch_pressed()); |
| } |
| -TEST_F(WindowManagerConnectionTest, TouchEventWatcher) { |
| +TEST_F(WindowManagerConnectionTest, PointerWatcherMove) { |
|
James Cook
2016/07/27 01:54:01
This test could probably be simplified to just che
riajiang
2016/07/27 22:39:16
Done.
|
| base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); |
| ScopedViewsTestHelper helper; |
| WindowManagerConnection* connection = WindowManagerConnection::Get(); |
| @@ -154,61 +148,60 @@ TEST_F(WindowManagerConnectionTest, TouchEventWatcher) { |
| ui::ET_TOUCH_RELEASED, |
| ui::ET_TOUCH_CANCELLED}; |
| - TestTouchEventWatcher watcher1; |
| - connection->AddTouchEventWatcher(&watcher1); |
| + TestPointerWatcher watcher1; |
| + watcher1.set_want_moves(true); |
| + connection->AddPointerWatcher(&watcher1, true); |
| - // TouchEventWatchers do not trigger for mouse events. |
| for (size_t i = 0; i < arraysize(kMouseType); i++) { |
| ui::MouseEvent mouse_event(kMouseType[i], gfx::Point(), gfx::Point(), |
| base::TimeTicks(), 0, 0); |
| ui::PointerEvent mouse_pointer_event(mouse_event); |
| EXPECT_TRUE(mouse_pointer_event.IsMousePointerEvent()); |
| OnEventObserved(mouse_pointer_event); |
| - EXPECT_FALSE(watcher1.touch_observed()); |
| + EXPECT_TRUE(watcher1.mouse_event_observed()); |
| + EXPECT_FALSE(watcher1.touch_event_observed()); |
| watcher1.Reset(); |
| } |
| - // TouchEventWatchers receive both TouchEvent and TouchPointerEvent. |
| for (size_t i = 0; i < arraysize(kTouchType); i++) { |
| ui::TouchEvent touch_event(kTouchType[i], gfx::Point(), 0, |
| base::TimeTicks()); |
| - EXPECT_TRUE(touch_event.IsTouchEvent()); |
| - OnEventObserved(touch_event); |
| - EXPECT_TRUE(watcher1.touch_observed()); |
| - watcher1.Reset(); |
| - |
| ui::PointerEvent touch_pointer_event(touch_event); |
| EXPECT_TRUE(touch_pointer_event.IsTouchPointerEvent()); |
| OnEventObserved(touch_pointer_event); |
| - EXPECT_TRUE(watcher1.touch_observed()); |
| + EXPECT_TRUE(watcher1.touch_event_observed()); |
| + EXPECT_FALSE(watcher1.mouse_event_observed()); |
| watcher1.Reset(); |
| } |
| - // Two TouchEventWatchers can both receive a single observed event. |
| - TestTouchEventWatcher watcher2; |
| - connection->AddTouchEventWatcher(&watcher2); |
| + // Two PointerWatchers can both receive a single observed event. |
| + TestPointerWatcher watcher2; |
| + watcher2.set_want_moves(true); |
| + connection->AddPointerWatcher(&watcher2, true); |
| ui::TouchEvent touch_event(ui::ET_TOUCH_PRESSED, gfx::Point(), 0, |
| base::TimeTicks()); |
| ui::PointerEvent touch_pointer_event(touch_event); |
| OnEventObserved(touch_pointer_event); |
| - EXPECT_TRUE(watcher1.touch_observed()); |
| - EXPECT_TRUE(watcher2.touch_observed()); |
| + EXPECT_TRUE(watcher1.touch_event_observed()); |
| + EXPECT_TRUE(watcher2.touch_event_observed()); |
| + EXPECT_FALSE(watcher1.touch_pressed()); |
| + EXPECT_FALSE(watcher2.touch_pressed()); |
| watcher1.Reset(); |
| watcher2.Reset(); |
| // Removing the first TouchEventWatcher stops sending events to it. |
| - connection->RemoveTouchEventWatcher(&watcher1); |
| + connection->RemovePointerWatcher(&watcher1); |
| OnEventObserved(touch_pointer_event); |
| - EXPECT_FALSE(watcher1.touch_observed()); |
| - EXPECT_TRUE(watcher2.touch_observed()); |
| + EXPECT_FALSE(watcher1.touch_event_observed()); |
| + EXPECT_TRUE(watcher2.touch_event_observed()); |
| watcher1.Reset(); |
| watcher2.Reset(); |
| // Removing the last TouchEventWatcher stops sending events to it. |
| - connection->RemoveTouchEventWatcher(&watcher2); |
| + connection->RemovePointerWatcher(&watcher2); |
| OnEventObserved(touch_pointer_event); |
| - EXPECT_FALSE(watcher1.touch_observed()); |
| - EXPECT_FALSE(watcher2.touch_observed()); |
| + EXPECT_FALSE(watcher1.touch_event_observed()); |
| + EXPECT_FALSE(watcher2.touch_event_observed()); |
| } |
| } // namespace views |