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

Side by Side Diff: ash/autoclick/autoclick_unittest.cc

Issue 2095193002: clang-format all of //ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/autoclick/autoclick_controller.cc ('k') | ash/cast_config_delegate.cc » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/autoclick/autoclick_controller.h" 5 #include "ash/autoclick/autoclick_controller.h"
6 #include "ash/shell.h" 6 #include "ash/shell.h"
7 #include "ash/test/ash_test_base.h" 7 #include "ash/test/ash_test_base.h"
8 #include "ui/aura/test/test_window_delegate.h" 8 #include "ui/aura/test/test_window_delegate.h"
9 #include "ui/aura/window.h" 9 #include "ui/aura/window.h"
10 #include "ui/aura/window_event_dispatcher.h" 10 #include "ui/aura/window_event_dispatcher.h"
11 #include "ui/events/event.h" 11 #include "ui/events/event.h"
12 #include "ui/events/event_constants.h" 12 #include "ui/events/event_constants.h"
13 #include "ui/events/event_handler.h" 13 #include "ui/events/event_handler.h"
14 #include "ui/events/event_utils.h" 14 #include "ui/events/event_utils.h"
15 #include "ui/events/keycodes/keyboard_codes.h" 15 #include "ui/events/keycodes/keyboard_codes.h"
16 #include "ui/events/test/event_generator.h" 16 #include "ui/events/test/event_generator.h"
17 17
18 namespace ash { 18 namespace ash {
19 19
20 class MouseEventCapturer : public ui::EventHandler { 20 class MouseEventCapturer : public ui::EventHandler {
21 public: 21 public:
22 MouseEventCapturer() { Reset(); } 22 MouseEventCapturer() { Reset(); }
23 ~MouseEventCapturer() override {} 23 ~MouseEventCapturer() override {}
24 24
25 void Reset() { 25 void Reset() { events_.clear(); }
26 events_.clear();
27 }
28 26
29 void OnMouseEvent(ui::MouseEvent* event) override { 27 void OnMouseEvent(ui::MouseEvent* event) override {
30 if (!(event->flags() & ui::EF_LEFT_MOUSE_BUTTON)) 28 if (!(event->flags() & ui::EF_LEFT_MOUSE_BUTTON))
31 return; 29 return;
32 // Filter out extraneous mouse events like mouse entered, exited, 30 // Filter out extraneous mouse events like mouse entered, exited,
33 // capture changed, etc. 31 // capture changed, etc.
34 ui::EventType type = event->type(); 32 ui::EventType type = event->type();
35 if (type == ui::ET_MOUSE_MOVED || type == ui::ET_MOUSE_PRESSED || 33 if (type == ui::ET_MOUSE_MOVED || type == ui::ET_MOUSE_PRESSED ||
36 type == ui::ET_MOUSE_RELEASED) { 34 type == ui::ET_MOUSE_RELEASED) {
37 events_.push_back(ui::MouseEvent(event->type(), event->location(), 35 events_.push_back(ui::MouseEvent(event->type(), event->location(),
38 event->root_location(), 36 event->root_location(),
39 ui::EventTimeForNow(), event->flags(), 37 ui::EventTimeForNow(), event->flags(),
40 event->changed_button_flags())); 38 event->changed_button_flags()));
41 // Stop event propagation so we don't click on random stuff that 39 // Stop event propagation so we don't click on random stuff that
42 // might break test assumptions. 40 // might break test assumptions.
43 event->StopPropagation(); 41 event->StopPropagation();
44 } 42 }
45 43
46 // If there is a possibility that we're in an infinite loop, we should 44 // If there is a possibility that we're in an infinite loop, we should
47 // exit early with a sensible error rather than letting the test time out. 45 // exit early with a sensible error rather than letting the test time out.
48 ASSERT_LT(events_.size(), 100u); 46 ASSERT_LT(events_.size(), 100u);
49 } 47 }
50 48
51 const std::vector<ui::MouseEvent>& captured_events() const { 49 const std::vector<ui::MouseEvent>& captured_events() const { return events_; }
52 return events_;
53 }
54 50
55 private: 51 private:
56 std::vector<ui::MouseEvent> events_; 52 std::vector<ui::MouseEvent> events_;
57 53
58 DISALLOW_COPY_AND_ASSIGN(MouseEventCapturer); 54 DISALLOW_COPY_AND_ASSIGN(MouseEventCapturer);
59 }; 55 };
60 56
61 class AutoclickTest : public test::AshTestBase { 57 class AutoclickTest : public test::AshTestBase {
62 public: 58 public:
63 AutoclickTest() {} 59 AutoclickTest() {}
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 203 }
208 204
209 TEST_F(AutoclickTest, KeyModifiersReleased) { 205 TEST_F(AutoclickTest, KeyModifiersReleased) {
210 GetAutoclickController()->SetEnabled(true); 206 GetAutoclickController()->SetEnabled(true);
211 207
212 ui::EventFlags modifier_flags = static_cast<ui::EventFlags>( 208 ui::EventFlags modifier_flags = static_cast<ui::EventFlags>(
213 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN); 209 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN);
214 MoveMouseWithFlagsTo(12, 12, modifier_flags); 210 MoveMouseWithFlagsTo(12, 12, modifier_flags);
215 211
216 // Simulate releasing key modifiers by sending key released events. 212 // Simulate releasing key modifiers by sending key released events.
217 GetEventGenerator().ReleaseKey(ui::VKEY_CONTROL, 213 GetEventGenerator().ReleaseKey(
214 ui::VKEY_CONTROL,
218 static_cast<ui::EventFlags>(ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN)); 215 static_cast<ui::EventFlags>(ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN));
219 GetEventGenerator().ReleaseKey(ui::VKEY_SHIFT, ui::EF_ALT_DOWN); 216 GetEventGenerator().ReleaseKey(ui::VKEY_SHIFT, ui::EF_ALT_DOWN);
220 217
221 std::vector<ui::MouseEvent> events; 218 std::vector<ui::MouseEvent> events;
222 events = WaitForMouseEvents(); 219 events = WaitForMouseEvents();
223 EXPECT_EQ(2u, events.size()); 220 EXPECT_EQ(2u, events.size());
224 EXPECT_EQ(0, events[0].flags() & ui::EF_CONTROL_DOWN); 221 EXPECT_EQ(0, events[0].flags() & ui::EF_CONTROL_DOWN);
225 EXPECT_EQ(0, events[0].flags() & ui::EF_SHIFT_DOWN); 222 EXPECT_EQ(0, events[0].flags() & ui::EF_SHIFT_DOWN);
226 EXPECT_EQ(ui::EF_ALT_DOWN, events[0].flags() & ui::EF_ALT_DOWN); 223 EXPECT_EQ(ui::EF_ALT_DOWN, events[0].flags() & ui::EF_ALT_DOWN);
227 } 224 }
(...skipping 18 matching lines...) Expand all
246 243
247 // Performing a gesture should cancel the autoclick. 244 // Performing a gesture should cancel the autoclick.
248 GetEventGenerator().MoveMouseTo(200, 200); 245 GetEventGenerator().MoveMouseTo(200, 200);
249 GetEventGenerator().GestureTapDownAndUp(gfx::Point(100, 100)); 246 GetEventGenerator().GestureTapDownAndUp(gfx::Point(100, 100));
250 events = WaitForMouseEvents(); 247 events = WaitForMouseEvents();
251 EXPECT_EQ(0u, events.size()); 248 EXPECT_EQ(0u, events.size());
252 249
253 // Test another gesture. 250 // Test another gesture.
254 GetEventGenerator().MoveMouseTo(100, 100); 251 GetEventGenerator().MoveMouseTo(100, 100);
255 GetEventGenerator().GestureScrollSequence( 252 GetEventGenerator().GestureScrollSequence(
256 gfx::Point(100, 100), 253 gfx::Point(100, 100), gfx::Point(200, 200),
257 gfx::Point(200, 200), 254 base::TimeDelta::FromMilliseconds(200), 3);
258 base::TimeDelta::FromMilliseconds(200),
259 3);
260 events = WaitForMouseEvents(); 255 events = WaitForMouseEvents();
261 EXPECT_EQ(0u, events.size()); 256 EXPECT_EQ(0u, events.size());
262 257
263 // Test scroll events. 258 // Test scroll events.
264 GetEventGenerator().MoveMouseTo(200, 200); 259 GetEventGenerator().MoveMouseTo(200, 200);
265 GetEventGenerator().ScrollSequence( 260 GetEventGenerator().ScrollSequence(gfx::Point(100, 100),
266 gfx::Point(100, 100), base::TimeDelta::FromMilliseconds(200), 261 base::TimeDelta::FromMilliseconds(200), 0,
267 0, 100, 3, 2); 262 100, 3, 2);
268 events = WaitForMouseEvents(); 263 events = WaitForMouseEvents();
269 EXPECT_EQ(0u, events.size()); 264 EXPECT_EQ(0u, events.size());
270 } 265 }
271 266
272 TEST_F(AutoclickTest, SynthesizedMouseMovesIgnored) { 267 TEST_F(AutoclickTest, SynthesizedMouseMovesIgnored) {
273 GetAutoclickController()->SetEnabled(true); 268 GetAutoclickController()->SetEnabled(true);
274 std::vector<ui::MouseEvent> events; 269 std::vector<ui::MouseEvent> events;
275 GetEventGenerator().MoveMouseTo(100, 100); 270 GetEventGenerator().MoveMouseTo(100, 100);
276 events = WaitForMouseEvents(); 271 events = WaitForMouseEvents();
277 EXPECT_EQ(2u, events.size()); 272 EXPECT_EQ(2u, events.size());
278 273
279 // Show a window and make sure the new window is under the cursor. As a 274 // Show a window and make sure the new window is under the cursor. As a
280 // result, synthesized mouse events will be dispatched to the window, but it 275 // result, synthesized mouse events will be dispatched to the window, but it
281 // should not trigger an autoclick. 276 // should not trigger an autoclick.
282 aura::test::EventCountDelegate delegate; 277 aura::test::EventCountDelegate delegate;
283 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( 278 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
284 &delegate, 123, gfx::Rect(50, 50, 100, 100))); 279 &delegate, 123, gfx::Rect(50, 50, 100, 100)));
285 window->Show(); 280 window->Show();
286 events = WaitForMouseEvents(); 281 events = WaitForMouseEvents();
287 EXPECT_EQ(0u, events.size()); 282 EXPECT_EQ(0u, events.size());
288 EXPECT_EQ("1 1 0", delegate.GetMouseMotionCountsAndReset()); 283 EXPECT_EQ("1 1 0", delegate.GetMouseMotionCountsAndReset());
289 } 284 }
290 285
291 } // namespace ash 286 } // namespace ash
OLDNEW
« no previous file with comments | « ash/autoclick/autoclick_controller.cc ('k') | ash/cast_config_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698