| 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..6087302cdbaf5c9490387b2fd76b073c3021aa2b 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; }
|
|
|
| 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 OnPointerEventObserved(const ui::LocatedEvent& event,
|
| + const gfx::Point& location_in_screen,
|
| + Widget* target) override {
|
| + if (want_moves_) {
|
| + if (event.IsTouchPointerEvent() || event.IsTouchEvent())
|
| + touch_event_observed_ = true;
|
| + else if (event.IsMousePointerEvent() || event.IsMouseEvent())
|
| + mouse_event_observed_ = true;
|
| + } else {
|
| + if (event.type() == ui::ET_TOUCH_PRESSED)
|
| + touch_pressed_ = true;
|
| + else if (event.type() == ui::ET_MOUSE_PRESSED)
|
| + 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, PointerDownWatcher) {
|
| base::MessageLoop message_loop(base::MessageLoop::TYPE_UI);
|
| ScopedViewsTestHelper helper;
|
| WindowManagerConnection* connection = WindowManagerConnection::Get();
|
| @@ -101,14 +89,18 @@ TEST_F(WindowManagerConnectionTest, PointerWatcher) {
|
|
|
| // PointerWatchers receive mouse events.
|
| TestPointerWatcher watcher1;
|
| - connection->AddPointerWatcher(&watcher1);
|
| + watcher1.set_want_moves(false);
|
| + connection->AddPointerWatcher(&watcher1,
|
| + ui::EventPointerType::POINTER_TYPE_ANY, 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 +111,14 @@ 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,
|
| + ui::EventPointerType::POINTER_TYPE_ANY, 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();
|
|
|
| @@ -154,8 +150,10 @@ 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,
|
| + ui::EventPointerType::POINTER_TYPE_TOUCH, true);
|
|
|
| // TouchEventWatchers do not trigger for mouse events.
|
| for (size_t i = 0; i < arraysize(kMouseType); i++) {
|
| @@ -164,7 +162,7 @@ TEST_F(WindowManagerConnectionTest, TouchEventWatcher) {
|
| ui::PointerEvent mouse_pointer_event(mouse_event);
|
| EXPECT_TRUE(mouse_pointer_event.IsMousePointerEvent());
|
| OnEventObserved(mouse_pointer_event);
|
| - EXPECT_FALSE(watcher1.touch_observed());
|
| + EXPECT_FALSE(watcher1.touch_event_observed());
|
| watcher1.Reset();
|
| }
|
|
|
| @@ -174,41 +172,125 @@ TEST_F(WindowManagerConnectionTest, TouchEventWatcher) {
|
| base::TimeTicks());
|
| EXPECT_TRUE(touch_event.IsTouchEvent());
|
| OnEventObserved(touch_event);
|
| - EXPECT_TRUE(watcher1.touch_observed());
|
| + EXPECT_TRUE(watcher1.touch_event_observed());
|
| + EXPECT_FALSE(watcher1.touch_pressed());
|
| 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.touch_pressed());
|
| watcher1.Reset();
|
| }
|
|
|
| // Two TouchEventWatchers can both receive a single observed event.
|
| - TestTouchEventWatcher watcher2;
|
| - connection->AddTouchEventWatcher(&watcher2);
|
| + TestPointerWatcher watcher2;
|
| + watcher2.set_want_moves(true);
|
| + connection->AddPointerWatcher(&watcher2,
|
| + ui::EventPointerType::POINTER_TYPE_TOUCH, 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());
|
| +}
|
| +
|
| +TEST_F(WindowManagerConnectionTest, MouseEventWatcher) {
|
| + base::MessageLoop message_loop(base::MessageLoop::TYPE_UI);
|
| + ScopedViewsTestHelper helper;
|
| + WindowManagerConnection* connection = WindowManagerConnection::Get();
|
| + ASSERT_TRUE(connection);
|
| +
|
| + const ui::EventType kMouseType[] = {
|
| + ui::ET_MOUSE_PRESSED, ui::ET_MOUSE_DRAGGED, ui::ET_MOUSE_MOVED,
|
| + ui::ET_MOUSE_ENTERED, ui::ET_MOUSE_EXITED, ui::ET_MOUSE_RELEASED};
|
| + const ui::EventType kTouchType[] = {ui::ET_TOUCH_PRESSED, ui::ET_TOUCH_MOVED,
|
| + ui::ET_TOUCH_RELEASED,
|
| + ui::ET_TOUCH_CANCELLED};
|
| +
|
| + TestPointerWatcher watcher1;
|
| + watcher1.set_want_moves(true);
|
| + connection->AddPointerWatcher(&watcher1,
|
| + ui::EventPointerType::POINTER_TYPE_MOUSE, true);
|
| +
|
| + // MouseEventWatchers receive both MouseEvent and MousePointerEvent.
|
| + for (size_t i = 0; i < arraysize(kMouseType); i++) {
|
| + ui::MouseEvent mouse_event(kMouseType[i], gfx::Point(), gfx::Point(),
|
| + base::TimeTicks(), 0, 0);
|
| + EXPECT_TRUE(mouse_event.IsMouseEvent());
|
| + OnEventObserved(mouse_event);
|
| + EXPECT_TRUE(watcher1.mouse_event_observed());
|
| + EXPECT_FALSE(watcher1.mouse_pressed());
|
| + watcher1.Reset();
|
| +
|
| + ui::PointerEvent mouse_pointer_event(mouse_event);
|
| + EXPECT_TRUE(mouse_pointer_event.IsMousePointerEvent());
|
| + OnEventObserved(mouse_pointer_event);
|
| + EXPECT_TRUE(watcher1.mouse_event_observed());
|
| + EXPECT_FALSE(watcher1.mouse_pressed());
|
| + watcher1.Reset();
|
| + }
|
| +
|
| + // MouseEventWatchers do not trigger for touch events.
|
| + for (size_t i = 0; i < arraysize(kTouchType); i++) {
|
| + ui::TouchEvent touch_event(kTouchType[i], gfx::Point(), 0,
|
| + base::TimeTicks());
|
| + ui::PointerEvent touch_pointer_event(touch_event);
|
| + EXPECT_TRUE(touch_pointer_event.IsTouchPointerEvent());
|
| + OnEventObserved(touch_pointer_event);
|
| + EXPECT_FALSE(watcher1.touch_event_observed());
|
| + watcher1.Reset();
|
| + }
|
| +
|
| + // Two MouseEventWatchers can both receive a single observed event.
|
| + TestPointerWatcher watcher2;
|
| + watcher2.set_want_moves(true);
|
| + connection->AddPointerWatcher(&watcher2,
|
| + ui::EventPointerType::POINTER_TYPE_MOUSE, true);
|
| + ui::MouseEvent mouse_event(ui::ET_MOUSE_ENTERED, gfx::Point(), gfx::Point(),
|
| + base::TimeTicks(), 0, 0);
|
| + ui::PointerEvent mouse_pointer_event(mouse_event);
|
| + OnEventObserved(mouse_pointer_event);
|
| + EXPECT_TRUE(watcher1.mouse_event_observed());
|
| + EXPECT_TRUE(watcher2.mouse_event_observed());
|
| + EXPECT_FALSE(watcher1.mouse_pressed());
|
| + EXPECT_FALSE(watcher2.mouse_pressed());
|
| + watcher1.Reset();
|
| + watcher2.Reset();
|
| +
|
| + // Removing the first MouseEventWatcher stops sending events to it.
|
| + connection->RemovePointerWatcher(&watcher1);
|
| + OnEventObserved(mouse_pointer_event);
|
| + EXPECT_FALSE(watcher1.mouse_event_observed());
|
| + EXPECT_TRUE(watcher2.mouse_event_observed());
|
| + watcher1.Reset();
|
| + watcher2.Reset();
|
| +
|
| + // Removing the last MouseEventWatcher stops sending events to it.
|
| + connection->RemovePointerWatcher(&watcher2);
|
| + OnEventObserved(mouse_pointer_event);
|
| + EXPECT_FALSE(watcher1.mouse_event_observed());
|
| + EXPECT_FALSE(watcher2.mouse_event_observed());
|
| }
|
|
|
| } // namespace views
|
|
|