OLD | NEW |
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 Loading... |
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. |
| 92 pointer_watcher_event_router->RemovePointerWatcher(&pointer_watcher2); |
| 93 EXPECT_EQ(PointerWatcherEventRouter::EventTypes::NONE, event_types()); |
| 94 EXPECT_FALSE(test_api.HasPointerWatcher()); |
| 95 |
| 96 // Add moves. |
| 97 pointer_watcher_event_router->AddPointerWatcher(&pointer_watcher2, true); |
| 98 EXPECT_EQ(PointerWatcherEventRouter::EventTypes::MOVE_EVENTS, event_types()); |
| 99 EXPECT_TRUE(test_api.HasPointerWatcher()); |
| 100 |
| 101 // Add no moves. |
| 102 pointer_watcher_event_router->AddPointerWatcher(&pointer_watcher1, false); |
| 103 EXPECT_EQ(PointerWatcherEventRouter::EventTypes::MOVE_EVENTS, event_types()); |
| 104 EXPECT_TRUE(test_api.HasPointerWatcher()); |
| 105 |
| 106 // Remove moves. |
| 107 pointer_watcher_event_router->RemovePointerWatcher(&pointer_watcher2); |
| 108 EXPECT_EQ(PointerWatcherEventRouter::EventTypes::NON_MOVE_EVENTS, |
| 109 event_types()); |
| 110 EXPECT_TRUE(test_api.HasPointerWatcher()); |
| 111 |
| 112 // Remove no-moves. |
| 113 pointer_watcher_event_router->RemovePointerWatcher(&pointer_watcher1); |
| 114 EXPECT_EQ(PointerWatcherEventRouter::EventTypes::NONE, event_types()); |
| 115 EXPECT_FALSE(test_api.HasPointerWatcher()); |
| 116 } |
| 117 |
58 TEST_F(PointerWatcherEventRouterTest, PointerWatcherNoMove) { | 118 TEST_F(PointerWatcherEventRouterTest, PointerWatcherNoMove) { |
59 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); | 119 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); |
60 ScopedViewsTestHelper helper; | 120 ScopedViewsTestHelper helper; |
61 ASSERT_TRUE(WindowManagerConnection::Get()); | 121 ASSERT_TRUE(WindowManagerConnection::Get()); |
62 PointerWatcherEventRouter* pointer_watcher_event_router = | 122 PointerWatcherEventRouter* pointer_watcher_event_router = |
63 WindowManagerConnection::Get()->pointer_watcher_event_router(); | 123 WindowManagerConnection::Get()->pointer_watcher_event_router(); |
64 ASSERT_TRUE(pointer_watcher_event_router); | 124 ASSERT_TRUE(pointer_watcher_event_router); |
65 | 125 |
66 ui::PointerEvent pointer_event_down( | 126 ui::PointerEvent pointer_event_down( |
67 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_NONE, 1, | 127 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_NONE, 1, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 watcher2.Reset(); | 215 watcher2.Reset(); |
156 | 216 |
157 // Removing the last PointerWatcher stops sending events to it. | 217 // Removing the last PointerWatcher stops sending events to it. |
158 pointer_watcher_event_router->RemovePointerWatcher(&watcher2); | 218 pointer_watcher_event_router->RemovePointerWatcher(&watcher2); |
159 OnPointerEventObserved(pointer_event_move); | 219 OnPointerEventObserved(pointer_event_move); |
160 EXPECT_FALSE(watcher1.last_event_observed()); | 220 EXPECT_FALSE(watcher1.last_event_observed()); |
161 EXPECT_FALSE(watcher2.last_event_observed()); | 221 EXPECT_FALSE(watcher2.last_event_observed()); |
162 } | 222 } |
163 | 223 |
164 } // namespace views | 224 } // namespace views |
OLD | NEW |