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

Side by Side Diff: ash/aura/pointer_watcher_adapter_unittest.cc

Issue 2256343003: Update ui::PointerEvent to support mouse wheel and capture change events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 3 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 | « ash/aura/pointer_watcher_adapter.cc ('k') | ash/shared/immersive_fullscreen_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ash/common/wm_shell.h" 5 #include "ash/common/wm_shell.h"
6 #include "ash/test/ash_test_base.h" 6 #include "ash/test/ash_test_base.h"
7 #include "ui/events/base_event_utils.h" 7 #include "ui/events/base_event_utils.h"
8 #include "ui/events/event.h" 8 #include "ui/events/event.h"
9 #include "ui/events/test/event_generator.h" 9 #include "ui/events/test/event_generator.h"
10 #include "ui/views/pointer_watcher.h" 10 #include "ui/views/pointer_watcher.h"
11 #include "ui/views/widget/widget.h" 11 #include "ui/views/widget/widget.h"
12 12
13 namespace ash { 13 namespace ash {
14 14
15 using PointerWatcherAdapterTest = test::AshTestBase; 15 using PointerWatcherAdapterTest = test::AshTestBase;
16 16
17 // Records calls to OnPointerEventObserved() in |pointer_event_count_| and 17 // Records calls to OnPointerEventObserved() in |mouse_wheel_event_count| for a
18 // calls to OnMouseCaptureChanged() to |capture_changed_count_|. 18 // mouse wheel event, in |capture_changed_count_| for a mouse capture change
19 // event and in |pointer_event_count_| for all other pointer events.
19 class TestPointerWatcher : public views::PointerWatcher { 20 class TestPointerWatcher : public views::PointerWatcher {
20 public: 21 public:
21 explicit TestPointerWatcher(bool wants_moves) { 22 explicit TestPointerWatcher(bool wants_moves) {
22 WmShell::Get()->AddPointerWatcher(this, wants_moves); 23 WmShell::Get()->AddPointerWatcher(this, wants_moves);
23 } 24 }
24 ~TestPointerWatcher() override { WmShell::Get()->RemovePointerWatcher(this); } 25 ~TestPointerWatcher() override { WmShell::Get()->RemovePointerWatcher(this); }
25 26
26 void ClearCounts() { pointer_event_count_ = capture_changed_count_ = 0; } 27 void ClearCounts() {
28 pointer_event_count_ = capture_changed_count_ = mouse_wheel_event_count_ =
29 0;
30 }
27 31
28 int pointer_event_count() const { return pointer_event_count_; } 32 int pointer_event_count() const { return pointer_event_count_; }
29 int capture_changed_count() const { return capture_changed_count_; } 33 int capture_changed_count() const { return capture_changed_count_; }
34 int mouse_wheel_event_count() const { return mouse_wheel_event_count_; }
30 35
31 // views::PointerWatcher: 36 // views::PointerWatcher:
32 void OnPointerEventObserved(const ui::PointerEvent& event, 37 void OnPointerEventObserved(const ui::PointerEvent& event,
33 const gfx::Point& location_in_screen, 38 const gfx::Point& location_in_screen,
34 views::Widget* target) override { 39 views::Widget* target) override {
35 pointer_event_count_++; 40 if (event.type() == ui::ET_POINTER_WHEEL_CHANGED)
41 mouse_wheel_event_count_++;
42 else if (event.type() == ui::ET_POINTER_CAPTURE_CHANGED)
43 capture_changed_count_++;
44 else
45 pointer_event_count_++;
36 } 46 }
37 void OnMouseCaptureChanged() override { capture_changed_count_++; }
38 47
39 private: 48 private:
40 int pointer_event_count_ = 0; 49 int pointer_event_count_ = 0;
41 int capture_changed_count_ = 0; 50 int capture_changed_count_ = 0;
51 int mouse_wheel_event_count_ = 0;
42 52
43 DISALLOW_COPY_AND_ASSIGN(TestPointerWatcher); 53 DISALLOW_COPY_AND_ASSIGN(TestPointerWatcher);
44 }; 54 };
45 55
46 // Creates two TestPointerWatchers, one that wants moves and one that doesn't. 56 // Creates two TestPointerWatchers, one that wants moves and one that doesn't.
47 class TestHelper { 57 class TestHelper {
48 public: 58 public:
49 TestHelper() : non_move_watcher_(false), move_watcher_(true) {} 59 TestHelper() : non_move_watcher_(false), move_watcher_(true) {}
50 ~TestHelper() {} 60 ~TestHelper() {}
51 61
52 // Used to verify call counts. 62 // Used to verify call counts.
53 void ExpectCallCount(int non_move_pointer_event_count, 63 void ExpectCallCount(int non_move_pointer_event_count,
54 int non_move_capture_changed_count, 64 int non_move_capture_changed_count,
65 int non_move_mouse_wheel_event_count,
55 int move_pointer_event_count, 66 int move_pointer_event_count,
56 int move_capture_changed_count) { 67 int move_capture_changed_count,
68 int move_mouse_wheel_event_count) {
57 EXPECT_EQ(non_move_pointer_event_count, 69 EXPECT_EQ(non_move_pointer_event_count,
58 non_move_watcher_.pointer_event_count()); 70 non_move_watcher_.pointer_event_count());
59 EXPECT_EQ(non_move_capture_changed_count, 71 EXPECT_EQ(non_move_capture_changed_count,
60 non_move_watcher_.capture_changed_count()); 72 non_move_watcher_.capture_changed_count());
73 EXPECT_EQ(non_move_mouse_wheel_event_count,
74 non_move_watcher_.mouse_wheel_event_count());
61 EXPECT_EQ(move_pointer_event_count, move_watcher_.pointer_event_count()); 75 EXPECT_EQ(move_pointer_event_count, move_watcher_.pointer_event_count());
62 EXPECT_EQ(move_capture_changed_count, 76 EXPECT_EQ(move_capture_changed_count,
63 move_watcher_.capture_changed_count()); 77 move_watcher_.capture_changed_count());
78 EXPECT_EQ(move_mouse_wheel_event_count,
79 move_watcher_.mouse_wheel_event_count());
64 80
65 non_move_watcher_.ClearCounts(); 81 non_move_watcher_.ClearCounts();
66 move_watcher_.ClearCounts(); 82 move_watcher_.ClearCounts();
67 } 83 }
68 84
69 private: 85 private:
70 TestPointerWatcher non_move_watcher_; 86 TestPointerWatcher non_move_watcher_;
71 TestPointerWatcher move_watcher_; 87 TestPointerWatcher move_watcher_;
72 88
73 DISALLOW_COPY_AND_ASSIGN(TestHelper); 89 DISALLOW_COPY_AND_ASSIGN(TestHelper);
74 }; 90 };
75 91
76 TEST_F(PointerWatcherAdapterTest, MouseEvents) { 92 TEST_F(PointerWatcherAdapterTest, MouseEvents) {
77 TestHelper helper; 93 TestHelper helper;
78 94
79 // Move: only the move PointerWatcher should get the event. 95 // Move: only the move PointerWatcher should get the event.
80 GetEventGenerator().MoveMouseTo(gfx::Point(10, 10)); 96 GetEventGenerator().MoveMouseTo(gfx::Point(10, 10));
81 helper.ExpectCallCount(0, 0, 1, 0); 97 helper.ExpectCallCount(0, 0, 0, 1, 0, 0);
82 98
83 // Press: both. 99 // Press: both.
84 GetEventGenerator().PressLeftButton(); 100 GetEventGenerator().PressLeftButton();
85 helper.ExpectCallCount(1, 0, 1, 0); 101 helper.ExpectCallCount(1, 0, 0, 1, 0, 0);
86 102
87 // Drag: none. 103 // Drag: none.
88 GetEventGenerator().MoveMouseTo(gfx::Point(20, 30)); 104 GetEventGenerator().MoveMouseTo(gfx::Point(20, 30));
89 helper.ExpectCallCount(0, 0, 0, 0); 105 helper.ExpectCallCount(0, 0, 0, 0, 0, 0);
90 106
91 // Release: both (aura generates a capture event here). 107 // Release: both (aura generates a capture event here).
92 GetEventGenerator().ReleaseLeftButton(); 108 GetEventGenerator().ReleaseLeftButton();
93 helper.ExpectCallCount(1, 1, 1, 1); 109 helper.ExpectCallCount(1, 1, 0, 1, 1, 0);
94 110
95 // Exit: none. 111 // Exit: none.
96 GetEventGenerator().SendMouseExit(); 112 GetEventGenerator().SendMouseExit();
97 helper.ExpectCallCount(0, 0, 0, 0); 113 helper.ExpectCallCount(0, 0, 0, 0, 0, 0);
98 114
99 // Enter: none. 115 // Enter: none.
100 ui::MouseEvent enter_event(ui::ET_MOUSE_ENTERED, gfx::Point(), gfx::Point(), 116 ui::MouseEvent enter_event(ui::ET_MOUSE_ENTERED, gfx::Point(), gfx::Point(),
101 ui::EventTimeForNow(), 0, 0); 117 ui::EventTimeForNow(), 0, 0);
102 GetEventGenerator().Dispatch(&enter_event); 118 GetEventGenerator().Dispatch(&enter_event);
103 helper.ExpectCallCount(0, 0, 0, 0); 119 helper.ExpectCallCount(0, 0, 0, 0, 0, 0);
104 120
105 // Wheel: none 121 // Wheel: both
106 GetEventGenerator().MoveMouseWheel(10, 11); 122 GetEventGenerator().MoveMouseWheel(10, 11);
107 helper.ExpectCallCount(0, 0, 0, 0); 123 helper.ExpectCallCount(0, 0, 1, 0, 0, 1);
108 124
109 // Capture: both. 125 // Capture: both.
110 ui::MouseEvent capture_event(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(), 126 ui::MouseEvent capture_event(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(),
111 gfx::Point(), ui::EventTimeForNow(), 0, 0); 127 gfx::Point(), ui::EventTimeForNow(), 0, 0);
112 GetEventGenerator().Dispatch(&capture_event); 128 GetEventGenerator().Dispatch(&capture_event);
113 helper.ExpectCallCount(0, 1, 0, 1); 129 helper.ExpectCallCount(0, 1, 0, 0, 1, 0);
114 } 130 }
115 131
116 TEST_F(PointerWatcherAdapterTest, TouchEvents) { 132 TEST_F(PointerWatcherAdapterTest, TouchEvents) {
117 TestHelper helper; 133 TestHelper helper;
118 134
119 // Press: both. 135 // Press: both.
120 const int touch_id = 11; 136 const int touch_id = 11;
121 GetEventGenerator().PressTouchId(touch_id); 137 GetEventGenerator().PressTouchId(touch_id);
122 helper.ExpectCallCount(1, 0, 1, 0); 138 helper.ExpectCallCount(1, 0, 0, 1, 0, 0);
123 139
124 // Drag: none. 140 // Drag: none.
125 GetEventGenerator().MoveTouchId(gfx::Point(20, 30), touch_id); 141 GetEventGenerator().MoveTouchId(gfx::Point(20, 30), touch_id);
126 helper.ExpectCallCount(0, 0, 0, 0); 142 helper.ExpectCallCount(0, 0, 0, 0, 0, 0);
127 143
128 // Release: both (contrary to mouse above, touch does not implicitly generate 144 // Release: both (contrary to mouse above, touch does not implicitly generate
129 // capture). 145 // capture).
130 GetEventGenerator().ReleaseTouchId(touch_id); 146 GetEventGenerator().ReleaseTouchId(touch_id);
131 helper.ExpectCallCount(1, 0, 1, 0); 147 helper.ExpectCallCount(1, 0, 0, 1, 0, 0);
132 } 148 }
133 149
134 } // namespace ash 150 } // namespace ash
OLDNEW
« no previous file with comments | « ash/aura/pointer_watcher_adapter.cc ('k') | ash/shared/immersive_fullscreen_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698