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

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: Fixed patch set 2 errors. 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 TestPointerEvents {
18 NO_POINTER = 0x01,
19 BASIC_POINTER = 0x02,
20 MOVE_POINTER = 0x04,
21 DRAG_POINTER = 0x08
22 };
23
24 enum TestCaptureEvents {
25 NO_CAPTURE = 0x01,
26 BASIC_CAPTURE = 0x02,
27 MOVE_CAPTURE = 0x04,
28 DRAG_CAPTURE = 0x08
29 };
30
17 // Records calls to OnPointerEventObserved() in |pointer_event_count_| and 31 // Records calls to OnPointerEventObserved() in |pointer_event_count_| and
18 // calls to OnMouseCaptureChanged() to |capture_changed_count_|. 32 // calls to OnMouseCaptureChanged() to |capture_changed_count_|.
19 class TestPointerWatcher : public views::PointerWatcher { 33 class TestPointerWatcher : public views::PointerWatcher {
20 public: 34 public:
21 explicit TestPointerWatcher(bool wants_moves) { 35 explicit TestPointerWatcher(views::PointerWatcherEventTypes events) {
22 WmShell::Get()->AddPointerWatcher(this, wants_moves); 36 WmShell::Get()->AddPointerWatcher(this, events);
23 } 37 }
24 ~TestPointerWatcher() override { WmShell::Get()->RemovePointerWatcher(this); } 38 ~TestPointerWatcher() override { WmShell::Get()->RemovePointerWatcher(this); }
25 39
26 void ClearCounts() { pointer_event_count_ = capture_changed_count_ = 0; } 40 void ClearCounts() { pointer_event_count_ = capture_changed_count_ = 0; }
27 41
28 int pointer_event_count() const { return pointer_event_count_; } 42 int pointer_event_count() const { return pointer_event_count_; }
29 int capture_changed_count() const { return capture_changed_count_; } 43 int capture_changed_count() const { return capture_changed_count_; }
30 44
31 // views::PointerWatcher: 45 // views::PointerWatcher:
32 void OnPointerEventObserved(const ui::PointerEvent& event, 46 void OnPointerEventObserved(const ui::PointerEvent& event,
33 const gfx::Point& location_in_screen, 47 const gfx::Point& location_in_screen,
34 views::Widget* target) override { 48 views::Widget* target) override {
35 pointer_event_count_++; 49 pointer_event_count_++;
36 } 50 }
37 void OnMouseCaptureChanged() override { capture_changed_count_++; } 51 void OnMouseCaptureChanged() override { capture_changed_count_++; }
38 52
39 private: 53 private:
40 int pointer_event_count_ = 0; 54 int pointer_event_count_ = 0;
41 int capture_changed_count_ = 0; 55 int capture_changed_count_ = 0;
42 56
43 DISALLOW_COPY_AND_ASSIGN(TestPointerWatcher); 57 DISALLOW_COPY_AND_ASSIGN(TestPointerWatcher);
44 }; 58 };
45 59
46 // Creates two TestPointerWatchers, one that wants moves and one that doesn't. 60 // Creates three TestPointerWatchers, one that wants moves and one that wants
61 // drags, and one that does not want either.
47 class TestHelper { 62 class TestHelper {
48 public: 63 public:
49 TestHelper() : non_move_watcher_(false), move_watcher_(true) {} 64 TestHelper()
65 : non_move_watcher_(views::PointerWatcherEventTypes::BASIC),
66 move_watcher_(views::PointerWatcherEventTypes::MOVES),
67 drag_watcher_(views::PointerWatcherEventTypes::DRAGS) {}
50 ~TestHelper() {} 68 ~TestHelper() {}
51 69
52 // Used to verify call counts. 70 // Used to verify call counts. One ExpectCallCount call should be made after
53 void ExpectCallCount(int non_move_pointer_event_count, 71 // each generated mouse events.
54 int non_move_capture_changed_count, 72 void ExpectCallCount(int pointer, int capture) {
sky 2016/08/26 19:58:57 Can't you combine them all into a single bitmask?
sammiequon 2016/08/26 21:48:04 Done.
55 int move_pointer_event_count, 73 EXPECT_EQ(pointer & (1 << 1) ? 1 : 0,
56 int move_capture_changed_count) {
57 EXPECT_EQ(non_move_pointer_event_count,
58 non_move_watcher_.pointer_event_count()); 74 non_move_watcher_.pointer_event_count());
59 EXPECT_EQ(non_move_capture_changed_count, 75 EXPECT_EQ(capture & (1 << 1) ? 1 : 0,
60 non_move_watcher_.capture_changed_count()); 76 non_move_watcher_.capture_changed_count());
61 EXPECT_EQ(move_pointer_event_count, move_watcher_.pointer_event_count()); 77 EXPECT_EQ(pointer & (1 << 2) ? 1 : 0, move_watcher_.pointer_event_count());
62 EXPECT_EQ(move_capture_changed_count, 78 EXPECT_EQ(capture & (1 << 2) ? 1 : 0,
63 move_watcher_.capture_changed_count()); 79 move_watcher_.capture_changed_count());
80 EXPECT_EQ(pointer & (1 << 3) ? 1 : 0, drag_watcher_.pointer_event_count());
81 EXPECT_EQ(capture & (1 << 3) ? 1 : 0,
82 drag_watcher_.capture_changed_count());
64 83
65 non_move_watcher_.ClearCounts(); 84 non_move_watcher_.ClearCounts();
66 move_watcher_.ClearCounts(); 85 move_watcher_.ClearCounts();
86 drag_watcher_.ClearCounts();
67 } 87 }
68 88
69 private: 89 private:
70 TestPointerWatcher non_move_watcher_; 90 TestPointerWatcher non_move_watcher_;
71 TestPointerWatcher move_watcher_; 91 TestPointerWatcher move_watcher_;
92 TestPointerWatcher drag_watcher_;
72 93
73 DISALLOW_COPY_AND_ASSIGN(TestHelper); 94 DISALLOW_COPY_AND_ASSIGN(TestHelper);
74 }; 95 };
75 96
76 TEST_F(PointerWatcherAdapterTest, MouseEvents) { 97 TEST_F(PointerWatcherAdapterTest, MouseEvents) {
77 TestHelper helper; 98 TestHelper helper;
78 99
79 // Move: only the move PointerWatcher should get the event. 100 // Move: only the move and drag PointerWatcher should get the event.
80 GetEventGenerator().MoveMouseTo(gfx::Point(10, 10)); 101 GetEventGenerator().MoveMouseTo(gfx::Point(10, 10));
81 helper.ExpectCallCount(0, 0, 1, 0); 102 helper.ExpectCallCount(MOVE_POINTER | DRAG_POINTER, NO_CAPTURE);
82 103
83 // Press: both. 104 // Press: all.
84 GetEventGenerator().PressLeftButton(); 105 GetEventGenerator().PressLeftButton();
85 helper.ExpectCallCount(1, 0, 1, 0); 106 helper.ExpectCallCount(BASIC_POINTER | MOVE_POINTER | DRAG_POINTER,
107 NO_CAPTURE);
86 108
87 // Drag: none. 109 // Drag: only drag PointerWatcher should get the event.
88 GetEventGenerator().MoveMouseTo(gfx::Point(20, 30)); 110 // GetEventGenerator().MoveMouseTo(gfx::Point(20, 30));
89 helper.ExpectCallCount(0, 0, 0, 0); 111 // helper.ExpectCallCount2(int{TestPointerEvents::DRAG_POINTER},
112 // int{TestCaptureEvents::NO_CAPTURE});
90 113
91 // Release: both (aura generates a capture event here). 114 // Release: all (aura generates a capture event here).
92 GetEventGenerator().ReleaseLeftButton(); 115 GetEventGenerator().ReleaseLeftButton();
93 helper.ExpectCallCount(1, 1, 1, 1); 116 helper.ExpectCallCount(BASIC_POINTER | MOVE_POINTER | DRAG_POINTER,
117 BASIC_CAPTURE | MOVE_CAPTURE | DRAG_CAPTURE);
94 118
95 // Exit: none. 119 // Exit: none.
96 GetEventGenerator().SendMouseExit(); 120 GetEventGenerator().SendMouseExit();
97 helper.ExpectCallCount(0, 0, 0, 0); 121 helper.ExpectCallCount(NO_POINTER, NO_CAPTURE);
98 122
99 // Enter: none. 123 // Enter: none.
100 ui::MouseEvent enter_event(ui::ET_MOUSE_ENTERED, gfx::Point(), gfx::Point(), 124 ui::MouseEvent enter_event(ui::ET_MOUSE_ENTERED, gfx::Point(), gfx::Point(),
101 ui::EventTimeForNow(), 0, 0); 125 ui::EventTimeForNow(), 0, 0);
102 GetEventGenerator().Dispatch(&enter_event); 126 GetEventGenerator().Dispatch(&enter_event);
103 helper.ExpectCallCount(0, 0, 0, 0); 127 helper.ExpectCallCount(NO_POINTER, NO_CAPTURE);
104 128
105 // Wheel: none 129 // Wheel: none
106 GetEventGenerator().MoveMouseWheel(10, 11); 130 GetEventGenerator().MoveMouseWheel(10, 11);
107 helper.ExpectCallCount(0, 0, 0, 0); 131 helper.ExpectCallCount(NO_POINTER, NO_CAPTURE);
108 132
109 // Capture: both. 133 // Capture: all.
110 ui::MouseEvent capture_event(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(), 134 ui::MouseEvent capture_event(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(),
111 gfx::Point(), ui::EventTimeForNow(), 0, 0); 135 gfx::Point(), ui::EventTimeForNow(), 0, 0);
112 GetEventGenerator().Dispatch(&capture_event); 136 GetEventGenerator().Dispatch(&capture_event);
113 helper.ExpectCallCount(0, 1, 0, 1); 137 helper.ExpectCallCount(NO_POINTER,
138 BASIC_CAPTURE | MOVE_CAPTURE | DRAG_CAPTURE);
114 } 139 }
115 140
116 TEST_F(PointerWatcherAdapterTest, TouchEvents) { 141 TEST_F(PointerWatcherAdapterTest, TouchEvents) {
117 TestHelper helper; 142 TestHelper helper;
118 143
119 // Press: both. 144 // Press: both.
120 const int touch_id = 11; 145 const int touch_id = 11;
121 GetEventGenerator().PressTouchId(touch_id); 146 GetEventGenerator().PressTouchId(touch_id);
122 helper.ExpectCallCount(1, 0, 1, 0); 147 helper.ExpectCallCount(BASIC_POINTER | MOVE_POINTER | DRAG_POINTER,
148 NO_CAPTURE);
123 149
124 // Drag: none. 150 // Drag: only drag.
125 GetEventGenerator().MoveTouchId(gfx::Point(20, 30), touch_id); 151 GetEventGenerator().MoveTouchId(gfx::Point(20, 30), touch_id);
126 helper.ExpectCallCount(0, 0, 0, 0); 152 helper.ExpectCallCount(DRAG_POINTER, NO_CAPTURE);
127 153
128 // Release: both (contrary to mouse above, touch does not implicitly generate 154 // Release: both (contrary to mouse above, touch does not implicitly generate
129 // capture). 155 // capture).
130 GetEventGenerator().ReleaseTouchId(touch_id); 156 GetEventGenerator().ReleaseTouchId(touch_id);
131 helper.ExpectCallCount(1, 0, 1, 0); 157 helper.ExpectCallCount(BASIC_POINTER | MOVE_POINTER | DRAG_POINTER,
158 NO_CAPTURE);
132 } 159 }
133 160
134 } // namespace ash 161 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698