| 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/window_manager_connection.h" | 5 #include "ui/views/mus/window_manager_connection.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 "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/events/event.h" | 11 #include "ui/events/event.h" |
| 12 #include "ui/views/pointer_watcher.h" | 12 #include "ui/views/pointer_watcher.h" |
| 13 #include "ui/views/test/scoped_views_test_helper.h" | 13 #include "ui/views/test/scoped_views_test_helper.h" |
| 14 | 14 |
| 15 namespace views { | 15 namespace views { |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 class TestPointerWatcher : public PointerWatcher { | 18 class TestPointerWatcher : public PointerWatcher { |
| 19 public: | 19 public: |
| 20 TestPointerWatcher() {} | 20 TestPointerWatcher() {} |
| 21 ~TestPointerWatcher() override {} | 21 ~TestPointerWatcher() override {} |
| 22 | 22 |
| 23 ui::Event* last_event() { return last_event_.get(); } | 23 ui::Event* last_event() { return last_event_.get(); } |
| 24 | 24 |
| 25 void Reset() { last_event_.reset(); } | 25 void Reset() { last_event_.reset(); } |
| 26 | 26 |
| 27 // PointerWatcher: | 27 // PointerWatcher: |
| 28 void OnMousePressed(const ui::MouseEvent& event, | 28 void OnMousePressed(const ui::MouseEvent& event, |
| 29 const gfx::Point& location_in_screen) override { | 29 const gfx::Point& location_in_screen, |
| 30 Widget* target) override { |
| 30 last_event_ = ui::Event::Clone(event); | 31 last_event_ = ui::Event::Clone(event); |
| 31 } | 32 } |
| 32 void OnTouchPressed(const ui::TouchEvent& event, | 33 void OnTouchPressed(const ui::TouchEvent& event, |
| 33 const gfx::Point& location_in_screen) override { | 34 const gfx::Point& location_in_screen, |
| 35 Widget* target) override { |
| 34 last_event_ = ui::Event::Clone(event); | 36 last_event_ = ui::Event::Clone(event); |
| 35 } | 37 } |
| 36 | 38 |
| 37 private: | 39 private: |
| 38 std::unique_ptr<ui::Event> last_event_; | 40 std::unique_ptr<ui::Event> last_event_; |
| 39 | 41 |
| 40 DISALLOW_COPY_AND_ASSIGN(TestPointerWatcher); | 42 DISALLOW_COPY_AND_ASSIGN(TestPointerWatcher); |
| 41 }; | 43 }; |
| 42 | 44 |
| 43 } // namespace | 45 } // namespace |
| 44 | 46 |
| 45 class WindowManagerConnectionTest : public testing::Test { | 47 class WindowManagerConnectionTest : public testing::Test { |
| 46 public: | 48 public: |
| 47 WindowManagerConnectionTest() {} | 49 WindowManagerConnectionTest() {} |
| 48 ~WindowManagerConnectionTest() override {} | 50 ~WindowManagerConnectionTest() override {} |
| 49 | 51 |
| 50 void OnEventObserved(const ui::Event& event) { | 52 void OnEventObserved(const ui::Event& event) { |
| 51 WindowManagerConnection::Get()->OnEventObserved(event); | 53 WindowManagerConnection::Get()->OnEventObserved(event, nullptr); |
| 52 } | 54 } |
| 53 | 55 |
| 54 private: | 56 private: |
| 55 DISALLOW_COPY_AND_ASSIGN(WindowManagerConnectionTest); | 57 DISALLOW_COPY_AND_ASSIGN(WindowManagerConnectionTest); |
| 56 }; | 58 }; |
| 57 | 59 |
| 58 TEST_F(WindowManagerConnectionTest, PointerWatcher) { | 60 TEST_F(WindowManagerConnectionTest, PointerWatcher) { |
| 59 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); | 61 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); |
| 60 ScopedViewsTestHelper helper; | 62 ScopedViewsTestHelper helper; |
| 61 WindowManagerConnection* connection = WindowManagerConnection::Get(); | 63 WindowManagerConnection* connection = WindowManagerConnection::Get(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 watcher2.Reset(); | 103 watcher2.Reset(); |
| 102 | 104 |
| 103 // Removing the last PointerWatcher stops sending events to it. | 105 // Removing the last PointerWatcher stops sending events to it. |
| 104 connection->RemovePointerWatcher(&watcher2); | 106 connection->RemovePointerWatcher(&watcher2); |
| 105 OnEventObserved(mouse_pressed); | 107 OnEventObserved(mouse_pressed); |
| 106 EXPECT_FALSE(watcher1.last_event()); | 108 EXPECT_FALSE(watcher1.last_event()); |
| 107 EXPECT_FALSE(watcher2.last_event()); | 109 EXPECT_FALSE(watcher2.last_event()); |
| 108 } | 110 } |
| 109 | 111 |
| 110 } // namespace views | 112 } // namespace views |
| OLD | NEW |