| 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 967b5ad83d0f64a9593e3529092820ef1ca34cb9..9e18e0534c75ff172ef72096d3d9b1cf928bf2ee 100644
|
| --- a/ui/views/mus/window_manager_connection_unittest.cc
|
| +++ b/ui/views/mus/window_manager_connection_unittest.cc
|
| @@ -11,6 +11,7 @@
|
| #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 {
|
| @@ -49,6 +50,34 @@ class TestPointerWatcher : public PointerWatcher {
|
|
|
| } // 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,
|
| + const gfx::Point& location_in_screen,
|
| + Widget* target) override {
|
| + touch_observed_ = true;
|
| + }
|
| +
|
| + private:
|
| + bool touch_observed_ = false;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestTouchEventWatcher);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| class WindowManagerConnectionTest : public testing::Test {
|
| public:
|
| WindowManagerConnectionTest() {}
|
| @@ -115,4 +144,72 @@ TEST_F(WindowManagerConnectionTest, PointerWatcher) {
|
| EXPECT_FALSE(watcher1.touch_pressed());
|
| }
|
|
|
| +TEST_F(WindowManagerConnectionTest, TouchEventWatcher) {
|
| + 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
|
| + };
|
| +
|
| + TestTouchEventWatcher watcher1;
|
| + connection->AddTouchEventWatcher(&watcher1);
|
| +
|
| + // TouchEventWatchers do not trigger for mouse events.
|
| + for (size_t i = 0; i < arraysize(kMouseType); i++) {
|
| + ui::MouseEvent mouse_event(kMouseType[i], gfx::Point(0, 0),
|
| + gfx::Point(0, 0), 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());
|
| + watcher1.Reset();
|
| + }
|
| +
|
| + // TouchEventWatchers receive touch events.
|
| + for (size_t i = 0; i < arraysize(kTouchType); i++) {
|
| + ui::TouchEvent touch_event(kTouchType[i], gfx::Point(0, 0), 0,
|
| + base::TimeTicks());
|
| + ui::PointerEvent touch_pointer_event(touch_event);
|
| + EXPECT_TRUE(touch_pointer_event.IsTouchPointerEvent());
|
| + OnEventObserved(touch_pointer_event);
|
| + EXPECT_TRUE(watcher1.touch_observed());
|
| + watcher1.Reset();
|
| + }
|
| +
|
| + // Two TouchEventWatchers can both receive a single observed event.
|
| + TestTouchEventWatcher watcher2;
|
| + connection->AddTouchEventWatcher(&watcher2);
|
| + ui::TouchEvent touch_event(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 0,
|
| + base::TimeTicks());
|
| + ui::PointerEvent touch_pointer_event(touch_event);
|
| + OnEventObserved(touch_pointer_event);
|
| + EXPECT_TRUE(watcher1.touch_observed());
|
| + EXPECT_TRUE(watcher2.touch_observed());
|
| + watcher1.Reset();
|
| + watcher2.Reset();
|
| +
|
| + // Removing the first TouchEventWatcher stops sending events to it.
|
| + connection->RemoveTouchEventWatcher(&watcher1);
|
| + OnEventObserved(touch_pointer_event);
|
| + EXPECT_FALSE(watcher1.touch_observed());
|
| + EXPECT_TRUE(watcher2.touch_observed());
|
| + watcher1.Reset();
|
| + watcher2.Reset();
|
| +
|
| + // Removing the last TouchEventWatcher stops sending events to it.
|
| + connection->RemoveTouchEventWatcher(&watcher2);
|
| + OnEventObserved(touch_pointer_event);
|
| + EXPECT_FALSE(watcher1.touch_observed());
|
| + EXPECT_FALSE(watcher2.touch_observed());
|
| +}
|
| +
|
| } // namespace views
|
|
|