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

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

Issue 286103004: Blocked volume up/down events that originated from remapped function keys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge of 'master' branch 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
« no previous file with comments | « no previous file | ash/wm/maximize_mode/maximize_mode_event_blocker.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 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" 17 #include "ash/wm/maximize_mode/internal_input_device_list.h"
18 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h" 18 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h"
19 #include "ui/aura/test/event_generator.h" 19 #include "ui/aura/test/event_generator.h"
20 #include "ui/events/event_handler.h" 20 #include "ui/events/event_handler.h"
21 #include "ui/gfx/vector3d_f.h" 21 #include "ui/gfx/vector3d_f.h"
22 #include "ui/message_center/message_center.h" 22 #include "ui/message_center/message_center.h"
23 23
24 #if defined(USE_X11)
25 #include "ui/events/test/events_test_utils_x11.h"
26 #endif
27
24 namespace ash { 28 namespace ash {
25 29
26 namespace { 30 namespace {
27 31
28 const float kDegreesToRadians = 3.14159265f / 180.0f; 32 const float kDegreesToRadians = 3.14159265f / 180.0f;
29 33
30 // Filter to count the number of events seen. 34 // Filter to count the number of events seen.
31 class EventCounter : public ui::EventHandler { 35 class EventCounter : public ui::EventHandler {
32 public: 36 public:
33 EventCounter(); 37 EventCounter();
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 415
412 // Holding volume down and pressing power takes a screenshot. 416 // Holding volume down and pressing power takes a screenshot.
413 event_generator.PressKey(ui::VKEY_VOLUME_DOWN, 0); 417 event_generator.PressKey(ui::VKEY_VOLUME_DOWN, 0);
414 event_generator.PressKey(ui::VKEY_POWER, 0); 418 event_generator.PressKey(ui::VKEY_POWER, 0);
415 event_generator.ReleaseKey(ui::VKEY_POWER, 0); 419 event_generator.ReleaseKey(ui::VKEY_POWER, 0);
416 EXPECT_EQ(1, delegate->handle_take_screenshot_count()); 420 EXPECT_EQ(1, delegate->handle_take_screenshot_count());
417 event_generator.ReleaseKey(ui::VKEY_VOLUME_DOWN, 0); 421 event_generator.ReleaseKey(ui::VKEY_VOLUME_DOWN, 0);
418 } 422 }
419 #endif // OS_CHROMEOS 423 #endif // OS_CHROMEOS
420 424
421 // Tests that maximize mode does not block Volume Up & Down events. 425 #if defined(USE_X11)
426 // Tests that maximize mode allows volume up/down events originating
427 // from dedicated buttons versus remapped keyboard buttons.
422 TEST_F(MaximizeModeControllerTest, AllowsVolumeControl) { 428 TEST_F(MaximizeModeControllerTest, AllowsVolumeControl) {
423 aura::Window* root = Shell::GetPrimaryRootWindow(); 429 aura::Window* root = Shell::GetPrimaryRootWindow();
424 aura::test::EventGenerator event_generator(root, root); 430 aura::test::EventGenerator event_generator(root, root);
425 431
426 TestVolumeControlDelegate* volume_delegate = 432 TestVolumeControlDelegate* volume_delegate =
427 new TestVolumeControlDelegate(true); 433 new TestVolumeControlDelegate(true);
428 ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate( 434 ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate(
429 scoped_ptr<VolumeControlDelegate>(volume_delegate).Pass()); 435 scoped_ptr<VolumeControlDelegate>(volume_delegate).Pass());
430 436
431 // Trigger maximize mode by opening to 270 to begin the test in maximize mode. 437 // Trigger maximize mode by opening to 270 to begin the test in maximize mode.
432 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f), 438 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
433 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 439 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
434 ASSERT_TRUE(IsMaximizeModeStarted()); 440 ASSERT_TRUE(IsMaximizeModeStarted());
435 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
436 // Verify volume down button event is not blocked 460 // Verify volume down button event is not blocked
437 ASSERT_EQ(0, volume_delegate->handle_volume_down_count()); 461 ASSERT_EQ(0, volume_delegate->handle_volume_down_count());
438 event_generator.PressKey(ui::VKEY_VOLUME_DOWN, 0); 462 xevent.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_VOLUME_DOWN, ui::EF_NONE);
439 event_generator.ReleaseKey(ui::VKEY_VOLUME_DOWN, 0); 463 ui::KeyEvent press_vol_down(xevent, false /* is_char */);
464 event_generator.Dispatch(&press_vol_down);
440 EXPECT_EQ(1, volume_delegate->handle_volume_down_count()); 465 EXPECT_EQ(1, volume_delegate->handle_volume_down_count());
441 466
442 // Verify volume up event is not blocked 467 // Verify volume up event is not blocked
443 ASSERT_EQ(0, volume_delegate->handle_volume_up_count()); 468 ASSERT_EQ(0, volume_delegate->handle_volume_up_count());
444 event_generator.PressKey(ui::VKEY_VOLUME_UP, 0); 469 xevent.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_VOLUME_UP, ui::EF_NONE);
445 event_generator.ReleaseKey(ui::VKEY_VOLUME_UP, 0); 470 ui::KeyEvent press_vol_up(xevent, false /* is_char */);
471 event_generator.Dispatch(&press_vol_up);
446 EXPECT_EQ(1, volume_delegate->handle_volume_up_count()); 472 EXPECT_EQ(1, volume_delegate->handle_volume_up_count());
447 } 473 }
474 #endif // defined(USE_X11)
448 475
449 TEST_F(MaximizeModeControllerTest, LaptopTest) { 476 TEST_F(MaximizeModeControllerTest, LaptopTest) {
450 // Feeds in sample accelerometer data and verifies that there are no 477 // Feeds in sample accelerometer data and verifies that there are no
451 // transitions into touchview / maximize mode while shaking the device around 478 // transitions into touchview / maximize mode while shaking the device around
452 // with the hinge at less than 180 degrees. 479 // with the hinge at less than 180 degrees.
453 ASSERT_EQ(0u, kAccelerometerLaptopModeTestDataLength % 6); 480 ASSERT_EQ(0u, kAccelerometerLaptopModeTestDataLength % 6);
454 for (size_t i = 0; i < kAccelerometerLaptopModeTestDataLength / 6; ++i) { 481 for (size_t i = 0; i < kAccelerometerLaptopModeTestDataLength / 6; ++i) {
455 gfx::Vector3dF base(kAccelerometerLaptopModeTestData[i * 6], 482 gfx::Vector3dF base(kAccelerometerLaptopModeTestData[i * 6],
456 kAccelerometerLaptopModeTestData[i * 6 + 1], 483 kAccelerometerLaptopModeTestData[i * 6 + 1],
457 kAccelerometerLaptopModeTestData[i * 6 + 2]); 484 kAccelerometerLaptopModeTestData[i * 6 + 2]);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); 640 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
614 641
615 // Exit maximize mode 642 // Exit maximize mode
616 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), 643 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
617 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 644 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
618 EXPECT_FALSE(IsMaximizeModeStarted()); 645 EXPECT_FALSE(IsMaximizeModeStarted());
619 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 646 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
620 } 647 }
621 648
622 } // namespace ash 649 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/wm/maximize_mode/maximize_mode_event_blocker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698