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

Side by Side Diff: ash/pointer_watcher_delegate_aura_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698