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

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

Issue 1921673005: mus: Add PointerWatcher for passively observing mouse and touch events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 7 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
« no previous file with comments | « ui/views/mus/window_manager_connection.cc ('k') | ui/views/pointer_watcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/views/mus/window_manager_connection.h"
6
7 #include <memory>
8
9 #include "base/message_loop/message_loop.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/events/event.h"
12 #include "ui/views/pointer_watcher.h"
13 #include "ui/views/test/scoped_views_test_helper.h"
14
15 namespace views {
16 namespace {
17
18 class TestPointerWatcher : public PointerWatcher {
19 public:
20 TestPointerWatcher() {}
21 ~TestPointerWatcher() override {}
22
23 ui::Event* last_event() { return last_event_.get(); }
24
25 void Reset() { last_event_.reset(); }
26
27 // PointerWatcher:
28 void OnMousePressed(const ui::MouseEvent& event) override {
29 last_event_ = ui::Event::Clone(event);
30 }
31 void OnTouchPressed(const ui::TouchEvent& event) override {
32 last_event_ = ui::Event::Clone(event);
33 }
34
35 private:
36 std::unique_ptr<ui::Event> last_event_;
37
38 DISALLOW_COPY_AND_ASSIGN(TestPointerWatcher);
39 };
40
41 } // namespace
42
43 class WindowManagerConnectionTest : public testing::Test {
44 public:
45 WindowManagerConnectionTest() {}
46 ~WindowManagerConnectionTest() override {}
47
48 void OnEventObserved(const ui::Event& event) {
49 WindowManagerConnection::Get()->OnEventObserved(event);
50 }
51
52 private:
53 DISALLOW_COPY_AND_ASSIGN(WindowManagerConnectionTest);
54 };
55
56 TEST_F(WindowManagerConnectionTest, PointerWatcher) {
57 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI);
58 ScopedViewsTestHelper helper;
59 WindowManagerConnection* connection = WindowManagerConnection::Get();
60 ASSERT_TRUE(connection);
61 ui::MouseEvent mouse_pressed(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
62 base::TimeDelta(), ui::EF_NONE, 0);
63 ui::TouchEvent touch_pressed(ui::ET_TOUCH_PRESSED, gfx::Point(), 1,
64 base::TimeDelta());
65 ui::KeyEvent key_pressed(ui::ET_KEY_PRESSED, ui::VKEY_A, 0);
66
67 // PointerWatchers receive mouse events.
68 TestPointerWatcher watcher1;
69 connection->AddPointerWatcher(&watcher1);
70 OnEventObserved(mouse_pressed);
71 EXPECT_EQ(ui::ET_MOUSE_PRESSED, watcher1.last_event()->type());
72 watcher1.Reset();
73
74 // PointerWatchers receive touch events.
75 OnEventObserved(touch_pressed);
76 EXPECT_EQ(ui::ET_TOUCH_PRESSED, watcher1.last_event()->type());
77 watcher1.Reset();
78
79 // PointerWatchers do not receive key events.
80 OnEventObserved(key_pressed);
81 EXPECT_FALSE(watcher1.last_event());
82 watcher1.Reset();
83
84 // Two PointerWatchers can both receive a single observed event.
85 TestPointerWatcher watcher2;
86 connection->AddPointerWatcher(&watcher2);
87 OnEventObserved(mouse_pressed);
88 EXPECT_EQ(ui::ET_MOUSE_PRESSED, watcher1.last_event()->type());
89 EXPECT_EQ(ui::ET_MOUSE_PRESSED, watcher2.last_event()->type());
90 watcher1.Reset();
91 watcher2.Reset();
92
93 // Removing the first PointerWatcher stops sending events to it.
94 connection->RemovePointerWatcher(&watcher1);
95 OnEventObserved(mouse_pressed);
96 EXPECT_FALSE(watcher1.last_event());
97 EXPECT_EQ(ui::ET_MOUSE_PRESSED, watcher2.last_event()->type());
98 watcher1.Reset();
99 watcher2.Reset();
100
101 // Removing the last PointerWatcher stops sending events to it.
102 connection->RemovePointerWatcher(&watcher2);
103 OnEventObserved(mouse_pressed);
104 EXPECT_FALSE(watcher1.last_event());
105 EXPECT_FALSE(watcher2.last_event());
106 }
107
108 } // namespace views
OLDNEW
« 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