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

Side by Side Diff: ash/aura/pointer_watcher_adapter_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/aura/pointer_watcher_adapter.cc ('k') | ash/aura/wm_shell_aura.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/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 PointerWatcherDelegateAuraTest = 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 |pointer_event_count_| and
18 // calls to OnMouseCaptureChanged() to |capture_changed_count_|. 18 // calls to OnMouseCaptureChanged() to |capture_changed_count_|.
19 class TestPointerWatcher : public views::PointerWatcher { 19 class TestPointerWatcher : public views::PointerWatcher {
20 public: 20 public:
21 explicit TestPointerWatcher(bool wants_moves) { 21 explicit TestPointerWatcher(bool wants_moves) {
22 Shell::GetInstance()->AddPointerWatcher(this, wants_moves); 22 WmShell::Get()->AddPointerWatcher(this, wants_moves);
23 } 23 }
24 ~TestPointerWatcher() override { 24 ~TestPointerWatcher() override { WmShell::Get()->RemovePointerWatcher(this); }
25 Shell::GetInstance()->RemovePointerWatcher(this);
26 }
27 25
28 void ClearCounts() { pointer_event_count_ = capture_changed_count_ = 0; } 26 void ClearCounts() { pointer_event_count_ = capture_changed_count_ = 0; }
29 27
30 int pointer_event_count() const { return pointer_event_count_; } 28 int pointer_event_count() const { return pointer_event_count_; }
31 int capture_changed_count() const { return capture_changed_count_; } 29 int capture_changed_count() const { return capture_changed_count_; }
32 30
33 // views::PointerWatcher: 31 // views::PointerWatcher:
34 void OnPointerEventObserved(const ui::PointerEvent& event, 32 void OnPointerEventObserved(const ui::PointerEvent& event,
35 const gfx::Point& location_in_screen, 33 const gfx::Point& location_in_screen,
36 views::Widget* target) override { 34 views::Widget* target) override {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 move_watcher_.ClearCounts(); 66 move_watcher_.ClearCounts();
69 } 67 }
70 68
71 private: 69 private:
72 TestPointerWatcher non_move_watcher_; 70 TestPointerWatcher non_move_watcher_;
73 TestPointerWatcher move_watcher_; 71 TestPointerWatcher move_watcher_;
74 72
75 DISALLOW_COPY_AND_ASSIGN(TestHelper); 73 DISALLOW_COPY_AND_ASSIGN(TestHelper);
76 }; 74 };
77 75
78 TEST_F(PointerWatcherDelegateAuraTest, MouseEvents) { 76 TEST_F(PointerWatcherAdapterTest, MouseEvents) {
79 TestHelper helper; 77 TestHelper helper;
80 78
81 // Move: only the move PointerWatcher should get the event. 79 // Move: only the move PointerWatcher should get the event.
82 GetEventGenerator().MoveMouseTo(gfx::Point(10, 10)); 80 GetEventGenerator().MoveMouseTo(gfx::Point(10, 10));
83 helper.ExpectCallCount(0, 0, 1, 0); 81 helper.ExpectCallCount(0, 0, 1, 0);
84 82
85 // Press: both. 83 // Press: both.
86 GetEventGenerator().PressLeftButton(); 84 GetEventGenerator().PressLeftButton();
87 helper.ExpectCallCount(1, 0, 1, 0); 85 helper.ExpectCallCount(1, 0, 1, 0);
88 86
(...skipping 19 matching lines...) Expand all
108 GetEventGenerator().MoveMouseWheel(10, 11); 106 GetEventGenerator().MoveMouseWheel(10, 11);
109 helper.ExpectCallCount(0, 0, 0, 0); 107 helper.ExpectCallCount(0, 0, 0, 0);
110 108
111 // Capture: both. 109 // Capture: both.
112 ui::MouseEvent capture_event(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(), 110 ui::MouseEvent capture_event(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(),
113 gfx::Point(), ui::EventTimeForNow(), 0, 0); 111 gfx::Point(), ui::EventTimeForNow(), 0, 0);
114 GetEventGenerator().Dispatch(&capture_event); 112 GetEventGenerator().Dispatch(&capture_event);
115 helper.ExpectCallCount(0, 1, 0, 1); 113 helper.ExpectCallCount(0, 1, 0, 1);
116 } 114 }
117 115
118 TEST_F(PointerWatcherDelegateAuraTest, TouchEvents) { 116 TEST_F(PointerWatcherAdapterTest, TouchEvents) {
119 TestHelper helper; 117 TestHelper helper;
120 118
121 // Press: both. 119 // Press: both.
122 const int touch_id = 11; 120 const int touch_id = 11;
123 GetEventGenerator().PressTouchId(touch_id); 121 GetEventGenerator().PressTouchId(touch_id);
124 helper.ExpectCallCount(1, 0, 1, 0); 122 helper.ExpectCallCount(1, 0, 1, 0);
125 123
126 // Drag: none. 124 // Drag: none.
127 GetEventGenerator().MoveTouchId(gfx::Point(20, 30), touch_id); 125 GetEventGenerator().MoveTouchId(gfx::Point(20, 30), touch_id);
128 helper.ExpectCallCount(0, 0, 0, 0); 126 helper.ExpectCallCount(0, 0, 0, 0);
129 127
130 // Release: both (contrary to mouse above, touch does not implicitly generate 128 // Release: both (contrary to mouse above, touch does not implicitly generate
131 // capture). 129 // capture).
132 GetEventGenerator().ReleaseTouchId(touch_id); 130 GetEventGenerator().ReleaseTouchId(touch_id);
133 helper.ExpectCallCount(1, 0, 1, 0); 131 helper.ExpectCallCount(1, 0, 1, 0);
134 } 132 }
135 133
136 } // namespace ash 134 } // namespace ash
OLDNEW
« no previous file with comments | « ash/aura/pointer_watcher_adapter.cc ('k') | ash/aura/wm_shell_aura.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698