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

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

Issue 2271393002: Wires up drags to pointer watcher adapter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Rebased. 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
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 enum TestPointerCaptureEvents {
18 NONE = 0x01,
19 BASIC = 0x02,
20 MOVE = 0x04,
21 DRAG = 0x08
22 };
23
17 // Records calls to OnPointerEventObserved() in |mouse_wheel_event_count| for a 24 // Records calls to OnPointerEventObserved() in |mouse_wheel_event_count| for a
18 // mouse wheel event, in |capture_changed_count_| for a mouse capture change 25 // mouse wheel event, in |capture_changed_count_| for a mouse capture change
19 // event and in |pointer_event_count_| for all other pointer events. 26 // event and in |pointer_event_count_| for all other pointer events.
20 class TestPointerWatcher : public views::PointerWatcher { 27 class TestPointerWatcher : public views::PointerWatcher {
21 public: 28 public:
22 explicit TestPointerWatcher(bool wants_moves) { 29 explicit TestPointerWatcher(views::PointerWatcherEventTypes events) {
23 WmShell::Get()->AddPointerWatcher(this, wants_moves); 30 WmShell::Get()->AddPointerWatcher(this, events);
24 } 31 }
25 ~TestPointerWatcher() override { WmShell::Get()->RemovePointerWatcher(this); } 32 ~TestPointerWatcher() override { WmShell::Get()->RemovePointerWatcher(this); }
26 33
27 void ClearCounts() { 34 void ClearCounts() {
28 pointer_event_count_ = capture_changed_count_ = mouse_wheel_event_count_ = 35 pointer_event_count_ = capture_changed_count_ = mouse_wheel_event_count_ =
29 0; 36 0;
30 } 37 }
31 38
32 int pointer_event_count() const { return pointer_event_count_; } 39 int pointer_event_count() const { return pointer_event_count_; }
33 int capture_changed_count() const { return capture_changed_count_; } 40 int capture_changed_count() const { return capture_changed_count_; }
(...skipping 12 matching lines...) Expand all
46 } 53 }
47 54
48 private: 55 private:
49 int pointer_event_count_ = 0; 56 int pointer_event_count_ = 0;
50 int capture_changed_count_ = 0; 57 int capture_changed_count_ = 0;
51 int mouse_wheel_event_count_ = 0; 58 int mouse_wheel_event_count_ = 0;
52 59
53 DISALLOW_COPY_AND_ASSIGN(TestPointerWatcher); 60 DISALLOW_COPY_AND_ASSIGN(TestPointerWatcher);
54 }; 61 };
55 62
56 // Creates two TestPointerWatchers, one that wants moves and one that doesn't. 63 // Creates three TestPointerWatchers, one that wants moves and one that wants
64 // drags, and one that does not want either.
57 class TestHelper { 65 class TestHelper {
58 public: 66 public:
59 TestHelper() : non_move_watcher_(false), move_watcher_(true) {} 67 TestHelper()
68 : non_move_watcher_(views::PointerWatcherEventTypes::BASIC),
sky 2016/08/31 23:27:39 These names are now confusing. It should be basic_
sammiequon 2016/09/01 00:49:24 Done.
69 move_watcher_(views::PointerWatcherEventTypes::MOVES),
70 drag_watcher_(views::PointerWatcherEventTypes::DRAGS) {}
60 ~TestHelper() {} 71 ~TestHelper() {}
61 72
62 // Used to verify call counts. 73 // Used to verify call counts. One ExpectCallCount call should be made after
63 void ExpectCallCount(int non_move_pointer_event_count, 74 // each generated mouse events. |pointer_bitmask| defines which events are
64 int non_move_capture_changed_count, 75 // expected to have happened and |capture_bitmask| defines which captures are
65 int non_move_mouse_wheel_event_count, 76 // expected to have happened and |wheel_bitmask| defines which wheel movements
66 int move_pointer_event_count, 77 // are expected to have happened.
67 int move_capture_changed_count, 78 void ExpectCallCount(int pointer_bitmask,
sky 2016/08/31 23:27:39 I'm confused by what you have here. I would expect
sammiequon 2016/09/01 00:49:24 Done.
68 int move_mouse_wheel_event_count) { 79 int capture_bitmask,
69 EXPECT_EQ(non_move_pointer_event_count, 80 int wheel_bitmask) {
81 // Check if the first bit is set. If set that means a basic event for the
82 // non move watcher is expected to have happened.
83 EXPECT_EQ(pointer_bitmask & BASIC ? 1 : 0,
70 non_move_watcher_.pointer_event_count()); 84 non_move_watcher_.pointer_event_count());
71 EXPECT_EQ(non_move_capture_changed_count, 85 EXPECT_EQ(capture_bitmask & BASIC ? 1 : 0,
72 non_move_watcher_.capture_changed_count()); 86 non_move_watcher_.capture_changed_count());
73 EXPECT_EQ(non_move_mouse_wheel_event_count, 87 EXPECT_EQ(wheel_bitmask & BASIC ? 1 : 0,
74 non_move_watcher_.mouse_wheel_event_count()); 88 non_move_watcher_.mouse_wheel_event_count());
75 EXPECT_EQ(move_pointer_event_count, move_watcher_.pointer_event_count()); 89 // Check if the second bit is set. If set that means a move event for the
76 EXPECT_EQ(move_capture_changed_count, 90 // move watcher is expected to have happened.
91 EXPECT_EQ(pointer_bitmask & MOVE ? 1 : 0,
92 move_watcher_.pointer_event_count());
93 EXPECT_EQ(capture_bitmask & MOVE ? 1 : 0,
77 move_watcher_.capture_changed_count()); 94 move_watcher_.capture_changed_count());
78 EXPECT_EQ(move_mouse_wheel_event_count, 95 EXPECT_EQ(wheel_bitmask & MOVE ? 1 : 0,
79 move_watcher_.mouse_wheel_event_count()); 96 move_watcher_.mouse_wheel_event_count());
97 // Check if the third bit is set. If set that means a drag event for the
98 // drag watcher is expected to have happened.
99 EXPECT_EQ(pointer_bitmask & DRAG ? 1 : 0,
100 drag_watcher_.pointer_event_count());
101 EXPECT_EQ(capture_bitmask & DRAG ? 1 : 0,
102 drag_watcher_.capture_changed_count());
103 EXPECT_EQ(wheel_bitmask & DRAG ? 1 : 0,
104 drag_watcher_.mouse_wheel_event_count());
80 105
81 non_move_watcher_.ClearCounts(); 106 non_move_watcher_.ClearCounts();
82 move_watcher_.ClearCounts(); 107 move_watcher_.ClearCounts();
108 drag_watcher_.ClearCounts();
83 } 109 }
84 110
85 private: 111 private:
86 TestPointerWatcher non_move_watcher_; 112 TestPointerWatcher non_move_watcher_;
87 TestPointerWatcher move_watcher_; 113 TestPointerWatcher move_watcher_;
114 TestPointerWatcher drag_watcher_;
88 115
89 DISALLOW_COPY_AND_ASSIGN(TestHelper); 116 DISALLOW_COPY_AND_ASSIGN(TestHelper);
90 }; 117 };
91 118
92 TEST_F(PointerWatcherAdapterTest, MouseEvents) { 119 TEST_F(PointerWatcherAdapterTest, MouseEvents) {
93 TestHelper helper; 120 TestHelper helper;
94 121
95 // Move: only the move PointerWatcher should get the event. 122 // Move: only the move and drag PointerWatcher should get the event.
96 GetEventGenerator().MoveMouseTo(gfx::Point(10, 10)); 123 GetEventGenerator().MoveMouseTo(gfx::Point(10, 10));
97 helper.ExpectCallCount(0, 0, 0, 1, 0, 0); 124 helper.ExpectCallCount(MOVE | DRAG, NONE, NONE);
98 125
99 // Press: both. 126 // Press: all.
100 GetEventGenerator().PressLeftButton(); 127 GetEventGenerator().PressLeftButton();
101 helper.ExpectCallCount(1, 0, 0, 1, 0, 0); 128 helper.ExpectCallCount(BASIC | MOVE | DRAG, NONE, NONE);
102 129
103 // Drag: none. 130 // Drag: only drag PointerWatcher should get the event.
104 GetEventGenerator().MoveMouseTo(gfx::Point(20, 30)); 131 GetEventGenerator().MoveMouseTo(gfx::Point(20, 30));
105 helper.ExpectCallCount(0, 0, 0, 0, 0, 0); 132 helper.ExpectCallCount(DRAG, NONE, NONE);
106 133
107 // Release: both (aura generates a capture event here). 134 // Release: all (aura generates a capture event here).
108 GetEventGenerator().ReleaseLeftButton(); 135 GetEventGenerator().ReleaseLeftButton();
109 helper.ExpectCallCount(1, 1, 0, 1, 1, 0); 136 helper.ExpectCallCount(BASIC | MOVE | DRAG, BASIC | MOVE | DRAG, NONE);
110 137
111 // Exit: none. 138 // Exit: none.
112 GetEventGenerator().SendMouseExit(); 139 GetEventGenerator().SendMouseExit();
113 helper.ExpectCallCount(0, 0, 0, 0, 0, 0); 140 helper.ExpectCallCount(NONE, NONE, NONE);
114 141
115 // Enter: none. 142 // Enter: none.
116 ui::MouseEvent enter_event(ui::ET_MOUSE_ENTERED, gfx::Point(), gfx::Point(), 143 ui::MouseEvent enter_event(ui::ET_MOUSE_ENTERED, gfx::Point(), gfx::Point(),
117 ui::EventTimeForNow(), 0, 0); 144 ui::EventTimeForNow(), 0, 0);
118 GetEventGenerator().Dispatch(&enter_event); 145 GetEventGenerator().Dispatch(&enter_event);
119 helper.ExpectCallCount(0, 0, 0, 0, 0, 0); 146 helper.ExpectCallCount(NONE, NONE, NONE);
120 147
121 // Wheel: both 148 // Wheel: both
122 GetEventGenerator().MoveMouseWheel(10, 11); 149 GetEventGenerator().MoveMouseWheel(10, 11);
123 helper.ExpectCallCount(0, 0, 1, 0, 0, 1); 150 helper.ExpectCallCount(NONE, NONE, BASIC | MOVE | DRAG);
124 151
125 // Capture: both. 152 // Capture: all.
126 ui::MouseEvent capture_event(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(), 153 ui::MouseEvent capture_event(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(),
127 gfx::Point(), ui::EventTimeForNow(), 0, 0); 154 gfx::Point(), ui::EventTimeForNow(), 0, 0);
128 GetEventGenerator().Dispatch(&capture_event); 155 GetEventGenerator().Dispatch(&capture_event);
129 helper.ExpectCallCount(0, 1, 0, 0, 1, 0); 156 helper.ExpectCallCount(NONE, BASIC | MOVE | DRAG, NONE);
130 } 157 }
131 158
132 TEST_F(PointerWatcherAdapterTest, TouchEvents) { 159 TEST_F(PointerWatcherAdapterTest, TouchEvents) {
133 TestHelper helper; 160 TestHelper helper;
134 161
135 // Press: both. 162 // Press: both.
136 const int touch_id = 11; 163 const int touch_id = 11;
137 GetEventGenerator().PressTouchId(touch_id); 164 GetEventGenerator().PressTouchId(touch_id);
138 helper.ExpectCallCount(1, 0, 0, 1, 0, 0); 165 helper.ExpectCallCount(BASIC | MOVE | DRAG, NONE, NONE);
139 166
140 // Drag: none. 167 // Drag: only drag.
141 GetEventGenerator().MoveTouchId(gfx::Point(20, 30), touch_id); 168 GetEventGenerator().MoveTouchId(gfx::Point(20, 30), touch_id);
142 helper.ExpectCallCount(0, 0, 0, 0, 0, 0); 169 helper.ExpectCallCount(DRAG, NONE, NONE);
143 170
144 // Release: both (contrary to mouse above, touch does not implicitly generate 171 // Release: both (contrary to mouse above, touch does not implicitly generate
145 // capture). 172 // capture).
146 GetEventGenerator().ReleaseTouchId(touch_id); 173 GetEventGenerator().ReleaseTouchId(touch_id);
147 helper.ExpectCallCount(1, 0, 0, 1, 0, 0); 174 helper.ExpectCallCount(BASIC | MOVE | DRAG, NONE, NONE);
148 } 175 }
149 176
150 } // namespace ash 177 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698