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

Side by Side Diff: ash/wm/maximize_mode/maximize_mode_controller_unittest.cc

Issue 313913004: Block internal PlatformEvents before they are dispatched in touchview. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Block events from disabled devices through DeviceDataManager. Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/wm/maximize_mode/maximize_mode_controller.h" 5 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
6 6
7 #include "ash/accelerometer/accelerometer_controller.h" 7 #include "ash/accelerometer/accelerometer_controller.h"
8 #include "ash/display/display_manager.h" 8 #include "ash/display/display_manager.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/system/tray/system_tray_delegate.h" 10 #include "ash/system/tray/system_tray_delegate.h"
11 #include "ash/test/ash_test_base.h" 11 #include "ash/test/ash_test_base.h"
12 #include "ash/test/display_manager_test_api.h" 12 #include "ash/test/display_manager_test_api.h"
13 #include "ash/test/test_lock_state_controller_delegate.h" 13 #include "ash/test/test_lock_state_controller_delegate.h"
14 #include "ash/test/test_screenshot_delegate.h" 14 #include "ash/test/test_screenshot_delegate.h"
15 #include "ash/test/test_system_tray_delegate.h" 15 #include "ash/test/test_system_tray_delegate.h"
16 #include "ash/test/test_volume_control_delegate.h" 16 #include "ash/test/test_volume_control_delegate.h"
17 #include "ash/wm/maximize_mode/internal_input_device_list.h"
18 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h"
19 #include "ui/aura/test/event_generator.h" 17 #include "ui/aura/test/event_generator.h"
20 #include "ui/events/event_handler.h" 18 #include "ui/events/event_handler.h"
21 #include "ui/gfx/vector3d_f.h" 19 #include "ui/gfx/vector3d_f.h"
22 #include "ui/message_center/message_center.h" 20 #include "ui/message_center/message_center.h"
23 21
24 #if defined(USE_X11) 22 #if defined(USE_X11)
25 #include "ui/events/test/events_test_utils_x11.h" 23 #include "ui/events/test/events_test_utils_x11.h"
26 #endif 24 #endif
27 25
28 namespace ash { 26 namespace ash {
29 27
30 namespace { 28 namespace {
31 29
32 const float kDegreesToRadians = 3.14159265f / 180.0f; 30 const float kDegreesToRadians = 3.14159265f / 180.0f;
33 31
34 // Filter to count the number of events seen.
35 class EventCounter : public ui::EventHandler {
36 public:
37 EventCounter();
38 virtual ~EventCounter();
39
40 // Overridden from ui::EventHandler:
41 virtual void OnEvent(ui::Event* event) OVERRIDE;
42
43 void reset() {
44 event_count_ = 0;
45 }
46
47 size_t event_count() const { return event_count_; }
48
49 private:
50 size_t event_count_;
51
52 DISALLOW_COPY_AND_ASSIGN(EventCounter);
53 };
54
55 EventCounter::EventCounter() : event_count_(0) {
56 Shell::GetInstance()->AddPreTargetHandler(this);
57 }
58
59 EventCounter::~EventCounter() {
60 Shell::GetInstance()->RemovePreTargetHandler(this);
61 }
62
63 void EventCounter::OnEvent(ui::Event* event) {
64 event_count_++;
65 }
66
67 // A test internal input device list which pretends that all events are from
68 // internal devices to allow verifying that the event blocking works.
69 class TestInternalInputDeviceList : public InternalInputDeviceList {
70 public:
71 TestInternalInputDeviceList() {}
72 virtual ~TestInternalInputDeviceList() {}
73
74 virtual bool IsEventFromInternalDevice(const ui::Event* event) OVERRIDE {
75 return true;
76 }
77
78 private:
79 DISALLOW_COPY_AND_ASSIGN(TestInternalInputDeviceList);
80 };
81
82 } // namespace 32 } // namespace
83 33
84 // Test accelerometer data taken with the lid at less than 180 degrees while 34 // Test accelerometer data taken with the lid at less than 180 degrees while
85 // shaking the device around. The data is to be interpreted in groups of 6 where 35 // shaking the device around. The data is to be interpreted in groups of 6 where
86 // each 6 values corresponds to the X, Y, and Z readings from the base and lid 36 // each 6 values corresponds to the X, Y, and Z readings from the base and lid
87 // accelerometers in this order. 37 // accelerometers in this order.
88 extern const float kAccelerometerLaptopModeTestData[]; 38 extern const float kAccelerometerLaptopModeTestData[];
89 extern const size_t kAccelerometerLaptopModeTestDataLength; 39 extern const size_t kAccelerometerLaptopModeTestDataLength;
90 40
91 // Test accelerometer data taken with the lid open 360 degrees while 41 // Test accelerometer data taken with the lid open 360 degrees while
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 73
124 void TriggerAccelerometerUpdate(const gfx::Vector3dF& base, 74 void TriggerAccelerometerUpdate(const gfx::Vector3dF& base,
125 const gfx::Vector3dF& lid) { 75 const gfx::Vector3dF& lid) {
126 maximize_mode_controller()->OnAccelerometerUpdated(base, lid); 76 maximize_mode_controller()->OnAccelerometerUpdated(base, lid);
127 } 77 }
128 78
129 bool IsMaximizeModeStarted() { 79 bool IsMaximizeModeStarted() {
130 return maximize_mode_controller()->IsMaximizeModeWindowManagerEnabled(); 80 return maximize_mode_controller()->IsMaximizeModeWindowManagerEnabled();
131 } 81 }
132 82
133 // Overrides the internal input device list for the current event targeters
134 // with one which always returns true.
135 void InstallTestInternalDeviceList() {
136 maximize_mode_controller()->event_blocker_->internal_devices_.reset(
137 new TestInternalInputDeviceList);
138 }
139
140 gfx::Display::Rotation GetInternalDisplayRotation() const { 83 gfx::Display::Rotation GetInternalDisplayRotation() const {
141 return Shell::GetInstance()->display_manager()->GetDisplayInfo( 84 return Shell::GetInstance()->display_manager()->GetDisplayInfo(
142 gfx::Display::InternalDisplayId()).rotation(); 85 gfx::Display::InternalDisplayId()).rotation();
143 } 86 }
144 87
145 void SetInternalDisplayRotation(gfx::Display::Rotation rotation) const { 88 void SetInternalDisplayRotation(gfx::Display::Rotation rotation) const {
146 Shell::GetInstance()->display_manager()-> 89 Shell::GetInstance()->display_manager()->
147 SetDisplayRotation(gfx::Display::InternalDisplayId(), rotation); 90 SetDisplayRotation(gfx::Display::InternalDisplayId(), rotation);
148 } 91 }
149 92
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 ASSERT_TRUE(IsMaximizeModeStarted()); 256 ASSERT_TRUE(IsMaximizeModeStarted());
314 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 257 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
315 258
316 // Close lid back to 90, screen should rotate back. 259 // Close lid back to 90, screen should rotate back.
317 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.95f, 0.35f), 260 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.95f, 0.35f),
318 gfx::Vector3dF(-0.35f, 0.95f, 0.0f)); 261 gfx::Vector3dF(-0.35f, 0.95f, 0.0f));
319 ASSERT_FALSE(IsMaximizeModeStarted()); 262 ASSERT_FALSE(IsMaximizeModeStarted());
320 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 263 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
321 } 264 }
322 265
323 // Tests that maximize mode blocks keyboard and mouse events but not touch
324 // events.
325 TEST_F(MaximizeModeControllerTest, BlocksKeyboardAndMouse) {
326 aura::Window* root = Shell::GetPrimaryRootWindow();
327 aura::test::EventGenerator event_generator(root, root);
328 EventCounter counter;
329
330 event_generator.PressKey(ui::VKEY_ESCAPE, 0);
331 event_generator.ReleaseKey(ui::VKEY_ESCAPE, 0);
332 EXPECT_GT(counter.event_count(), 0u);
333 counter.reset();
334
335 event_generator.ClickLeftButton();
336 EXPECT_GT(counter.event_count(), 0u);
337 counter.reset();
338
339 event_generator.ScrollSequence(
340 gfx::Point(), base::TimeDelta::FromMilliseconds(5), 0, 100, 5, 2);
341 EXPECT_GT(counter.event_count(), 0u);
342 counter.reset();
343
344 event_generator.MoveMouseWheel(0, 10);
345 EXPECT_GT(counter.event_count(), 0u);
346 counter.reset();
347
348 event_generator.PressTouch();
349 event_generator.ReleaseTouch();
350 EXPECT_GT(counter.event_count(), 0u);
351 counter.reset();
352
353 // Open up 270 degrees.
354 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
355 gfx::Vector3dF(1.0f, 0.0f, 0.0f));
356 ASSERT_TRUE(IsMaximizeModeStarted());
357 InstallTestInternalDeviceList();
358
359 event_generator.PressKey(ui::VKEY_ESCAPE, 0);
360 event_generator.ReleaseKey(ui::VKEY_ESCAPE, 0);
361 EXPECT_EQ(0u, counter.event_count());
362 counter.reset();
363
364 event_generator.ClickLeftButton();
365 EXPECT_EQ(0u, counter.event_count());
366 counter.reset();
367
368 event_generator.ScrollSequence(
369 gfx::Point(), base::TimeDelta::FromMilliseconds(5), 0, 100, 5, 2);
370 EXPECT_EQ(0u, counter.event_count());
371 counter.reset();
372
373 event_generator.MoveMouseWheel(0, 10);
374 EXPECT_EQ(0u, counter.event_count());
375 counter.reset();
376
377 // Touch should not be blocked.
378 event_generator.PressTouch();
379 event_generator.ReleaseTouch();
380 EXPECT_GT(counter.event_count(), 0u);
381 counter.reset();
382
383 gfx::Vector3dF base;
384
385 // Lid open 90 degrees.
386 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
387 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
388
389 event_generator.PressKey(ui::VKEY_ESCAPE, 0);
390 event_generator.ReleaseKey(ui::VKEY_ESCAPE, 0);
391 EXPECT_GT(counter.event_count(), 0u);
392 counter.reset();
393 }
394
395 #if defined(OS_CHROMEOS) 266 #if defined(OS_CHROMEOS)
396 // Tests that a screenshot can be taken in maximize mode by holding volume down 267 // Tests that a screenshot can be taken in maximize mode by holding volume down
397 // and pressing power. 268 // and pressing power.
398 TEST_F(MaximizeModeControllerTest, Screenshot) { 269 TEST_F(MaximizeModeControllerTest, Screenshot) {
399 Shell::GetInstance()->lock_state_controller()->SetDelegate( 270 Shell::GetInstance()->lock_state_controller()->SetDelegate(
400 new test::TestLockStateControllerDelegate); 271 new test::TestLockStateControllerDelegate);
401 aura::Window* root = Shell::GetPrimaryRootWindow(); 272 aura::Window* root = Shell::GetPrimaryRootWindow();
402 aura::test::EventGenerator event_generator(root, root); 273 aura::test::EventGenerator event_generator(root, root);
403 test::TestScreenshotDelegate* delegate = GetScreenshotDelegate(); 274 test::TestScreenshotDelegate* delegate = GetScreenshotDelegate();
404 delegate->set_can_take_screenshot(true); 275 delegate->set_can_take_screenshot(true);
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); 511 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
641 512
642 // Exit maximize mode 513 // Exit maximize mode
643 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), 514 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
644 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 515 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
645 EXPECT_FALSE(IsMaximizeModeStarted()); 516 EXPECT_FALSE(IsMaximizeModeStarted());
646 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 517 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
647 } 518 }
648 519
649 } // namespace ash 520 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698