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

Unified Diff: ui/views/mus/window_manager_connection_unittest.cc

Issue 2125663002: mus: Add watcher for all touch events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a comment 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/mus/window_manager_connection.cc ('k') | ui/views/pointer_watcher.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..e84d9eae989e423a3e863176a68396372911944f 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,31 @@ 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,
+ 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 +141,74 @@ 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(), 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());
+ 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());
+ 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,
+ 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
« no previous file with comments | « ui/views/mus/window_manager_connection.cc ('k') | ui/views/pointer_watcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698