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

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

Issue 2248263003: Updates PointerEventRouter to handle switching move type (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: false- Created 4 years, 4 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
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/pointer_watcher_event_router.h" 5 #include "ui/views/mus/pointer_watcher_event_router.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 "services/ui/public/cpp/tests/window_tree_client_private.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/events/event.h" 12 #include "ui/events/event.h"
12 #include "ui/views/mus/window_manager_connection.h" 13 #include "ui/views/mus/window_manager_connection.h"
13 #include "ui/views/pointer_watcher.h" 14 #include "ui/views/pointer_watcher.h"
14 #include "ui/views/test/scoped_views_test_helper.h" 15 #include "ui/views/test/scoped_views_test_helper.h"
15 16
16 namespace views { 17 namespace views {
17 namespace { 18 namespace {
18 19
19 class TestPointerWatcher : public PointerWatcher { 20 class TestPointerWatcher : public PointerWatcher {
(...skipping 24 matching lines...) Expand all
44 public: 45 public:
45 PointerWatcherEventRouterTest() {} 46 PointerWatcherEventRouterTest() {}
46 ~PointerWatcherEventRouterTest() override {} 47 ~PointerWatcherEventRouterTest() override {}
47 48
48 void OnPointerEventObserved(const ui::PointerEvent& event) { 49 void OnPointerEventObserved(const ui::PointerEvent& event) {
49 WindowManagerConnection::Get() 50 WindowManagerConnection::Get()
50 ->pointer_watcher_event_router() 51 ->pointer_watcher_event_router()
51 ->OnPointerEventObserved(event, nullptr); 52 ->OnPointerEventObserved(event, nullptr);
52 } 53 }
53 54
55 PointerWatcherEventRouter::EventTypes event_types() const {
56 return WindowManagerConnection::Get()
57 ->pointer_watcher_event_router()
58 ->event_types_;
59 }
60
54 private: 61 private:
55 DISALLOW_COPY_AND_ASSIGN(PointerWatcherEventRouterTest); 62 DISALLOW_COPY_AND_ASSIGN(PointerWatcherEventRouterTest);
56 }; 63 };
57 64
65 TEST_F(PointerWatcherEventRouterTest, EventTypes) {
66 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI);
67 ScopedViewsTestHelper helper;
68 TestPointerWatcher pointer_watcher1, pointer_watcher2;
69 PointerWatcherEventRouter* pointer_watcher_event_router =
70 WindowManagerConnection::Get()->pointer_watcher_event_router();
71 ui::WindowTreeClientPrivate test_api(
72 WindowManagerConnection::Get()->client());
73 EXPECT_FALSE(test_api.HasPointerWatcher());
74
75 // Start with no moves.
76 pointer_watcher_event_router->AddPointerWatcher(&pointer_watcher1, false);
77 EXPECT_EQ(PointerWatcherEventRouter::EventTypes::NON_MOVE_EVENTS,
78 event_types());
79 EXPECT_TRUE(test_api.HasPointerWatcher());
80
81 // Add moves.
82 pointer_watcher_event_router->AddPointerWatcher(&pointer_watcher2, true);
83 EXPECT_EQ(PointerWatcherEventRouter::EventTypes::MOVE_EVENTS, event_types());
84 EXPECT_TRUE(test_api.HasPointerWatcher());
85
86 // Remove no-moves.
87 pointer_watcher_event_router->RemovePointerWatcher(&pointer_watcher1);
88 EXPECT_EQ(PointerWatcherEventRouter::EventTypes::MOVE_EVENTS, event_types());
89 EXPECT_TRUE(test_api.HasPointerWatcher());
90
91 // Remove moves.
msw 2016/08/18 22:45:23 optional nit: test the transition from MOVE_EVENTS
sky 2016/08/18 23:17:15 Done.
92 pointer_watcher_event_router->RemovePointerWatcher(&pointer_watcher2);
93 EXPECT_EQ(PointerWatcherEventRouter::EventTypes::NONE, event_types());
94 EXPECT_FALSE(test_api.HasPointerWatcher());
95 }
96
58 TEST_F(PointerWatcherEventRouterTest, PointerWatcherNoMove) { 97 TEST_F(PointerWatcherEventRouterTest, PointerWatcherNoMove) {
59 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); 98 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI);
60 ScopedViewsTestHelper helper; 99 ScopedViewsTestHelper helper;
61 ASSERT_TRUE(WindowManagerConnection::Get()); 100 ASSERT_TRUE(WindowManagerConnection::Get());
62 PointerWatcherEventRouter* pointer_watcher_event_router = 101 PointerWatcherEventRouter* pointer_watcher_event_router =
63 WindowManagerConnection::Get()->pointer_watcher_event_router(); 102 WindowManagerConnection::Get()->pointer_watcher_event_router();
64 ASSERT_TRUE(pointer_watcher_event_router); 103 ASSERT_TRUE(pointer_watcher_event_router);
65 104
66 ui::PointerEvent pointer_event_down( 105 ui::PointerEvent pointer_event_down(
67 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_NONE, 1, 106 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_NONE, 1,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 watcher2.Reset(); 194 watcher2.Reset();
156 195
157 // Removing the last PointerWatcher stops sending events to it. 196 // Removing the last PointerWatcher stops sending events to it.
158 pointer_watcher_event_router->RemovePointerWatcher(&watcher2); 197 pointer_watcher_event_router->RemovePointerWatcher(&watcher2);
159 OnPointerEventObserved(pointer_event_move); 198 OnPointerEventObserved(pointer_event_move);
160 EXPECT_FALSE(watcher1.last_event_observed()); 199 EXPECT_FALSE(watcher1.last_event_observed());
161 EXPECT_FALSE(watcher2.last_event_observed()); 200 EXPECT_FALSE(watcher2.last_event_observed());
162 } 201 }
163 202
164 } // namespace views 203 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698