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

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: Fix updating cursor on enter notify. 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 10 matching lines...) Expand all
415 286
416 // Holding volume down and pressing power takes a screenshot. 287 // Holding volume down and pressing power takes a screenshot.
417 event_generator.PressKey(ui::VKEY_VOLUME_DOWN, 0); 288 event_generator.PressKey(ui::VKEY_VOLUME_DOWN, 0);
418 event_generator.PressKey(ui::VKEY_POWER, 0); 289 event_generator.PressKey(ui::VKEY_POWER, 0);
419 event_generator.ReleaseKey(ui::VKEY_POWER, 0); 290 event_generator.ReleaseKey(ui::VKEY_POWER, 0);
420 EXPECT_EQ(1, delegate->handle_take_screenshot_count()); 291 EXPECT_EQ(1, delegate->handle_take_screenshot_count());
421 event_generator.ReleaseKey(ui::VKEY_VOLUME_DOWN, 0); 292 event_generator.ReleaseKey(ui::VKEY_VOLUME_DOWN, 0);
422 } 293 }
423 #endif // OS_CHROMEOS 294 #endif // OS_CHROMEOS
424 295
425 #if defined(USE_X11)
426 // Tests that maximize mode allows volume up/down events originating
427 // from dedicated buttons versus remapped keyboard buttons.
428 TEST_F(MaximizeModeControllerTest, AllowsVolumeControl) {
429 aura::Window* root = Shell::GetPrimaryRootWindow();
430 aura::test::EventGenerator event_generator(root, root);
431
432 TestVolumeControlDelegate* volume_delegate =
433 new TestVolumeControlDelegate(true);
434 ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate(
435 scoped_ptr<VolumeControlDelegate>(volume_delegate).Pass());
436
437 // Trigger maximize mode by opening to 270 to begin the test in maximize mode.
438 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
439 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
440 ASSERT_TRUE(IsMaximizeModeStarted());
441
442 ui::ScopedXI2Event xevent;
443
444 // Verify F9 button event is blocked
445 ASSERT_EQ(0, volume_delegate->handle_volume_down_count());
446 xevent.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_VOLUME_DOWN, ui::EF_NONE);
447 ui::KeyEvent press_f9(xevent, false /* is_char */);
448 press_f9.set_flags(ui::EF_FUNCTION_KEY);
449 event_generator.Dispatch(&press_f9);
450 EXPECT_EQ(0, volume_delegate->handle_volume_down_count());
451
452 // Verify F10 button event is blocked
453 ASSERT_EQ(0, volume_delegate->handle_volume_up_count());
454 xevent.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_VOLUME_UP, ui::EF_NONE);
455 ui::KeyEvent press_f10(xevent, false /* is_char */);
456 press_f10.set_flags(ui::EF_FUNCTION_KEY);
457 event_generator.Dispatch(&press_f10);
458 EXPECT_EQ(0, volume_delegate->handle_volume_up_count());
459
460 // Verify volume down button event is not blocked
461 ASSERT_EQ(0, volume_delegate->handle_volume_down_count());
462 xevent.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_VOLUME_DOWN, ui::EF_NONE);
463 ui::KeyEvent press_vol_down(xevent, false /* is_char */);
464 event_generator.Dispatch(&press_vol_down);
465 EXPECT_EQ(1, volume_delegate->handle_volume_down_count());
466
467 // Verify volume up event is not blocked
468 ASSERT_EQ(0, volume_delegate->handle_volume_up_count());
469 xevent.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_VOLUME_UP, ui::EF_NONE);
470 ui::KeyEvent press_vol_up(xevent, false /* is_char */);
471 event_generator.Dispatch(&press_vol_up);
472 EXPECT_EQ(1, volume_delegate->handle_volume_up_count());
473 }
474 #endif // defined(USE_X11)
475
476 TEST_F(MaximizeModeControllerTest, LaptopTest) { 296 TEST_F(MaximizeModeControllerTest, LaptopTest) {
477 // Feeds in sample accelerometer data and verifies that there are no 297 // Feeds in sample accelerometer data and verifies that there are no
478 // transitions into touchview / maximize mode while shaking the device around 298 // transitions into touchview / maximize mode while shaking the device around
479 // with the hinge at less than 180 degrees. 299 // with the hinge at less than 180 degrees.
480 ASSERT_EQ(0u, kAccelerometerLaptopModeTestDataLength % 6); 300 ASSERT_EQ(0u, kAccelerometerLaptopModeTestDataLength % 6);
481 for (size_t i = 0; i < kAccelerometerLaptopModeTestDataLength / 6; ++i) { 301 for (size_t i = 0; i < kAccelerometerLaptopModeTestDataLength / 6; ++i) {
482 gfx::Vector3dF base(kAccelerometerLaptopModeTestData[i * 6], 302 gfx::Vector3dF base(kAccelerometerLaptopModeTestData[i * 6],
483 kAccelerometerLaptopModeTestData[i * 6 + 1], 303 kAccelerometerLaptopModeTestData[i * 6 + 1],
484 kAccelerometerLaptopModeTestData[i * 6 + 2]); 304 kAccelerometerLaptopModeTestData[i * 6 + 2]);
485 gfx::Vector3dF lid(kAccelerometerLaptopModeTestData[i * 6 + 3], 305 gfx::Vector3dF lid(kAccelerometerLaptopModeTestData[i * 6 + 3],
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 // User sets rotation to the same rotation that the display was at when 490 // User sets rotation to the same rotation that the display was at when
671 // maximize mode was activated. 491 // maximize mode was activated.
672 SetInternalDisplayRotation(gfx::Display::ROTATE_0); 492 SetInternalDisplayRotation(gfx::Display::ROTATE_0);
673 // Exit maximize mode 493 // Exit maximize mode
674 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), 494 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
675 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 495 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
676 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 496 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
677 } 497 }
678 498
679 } // namespace ash 499 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/maximize_mode/maximize_mode_controller.cc ('k') | ash/wm/maximize_mode/maximize_mode_event_blocker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698