diff options
-rw-r--r-- | ash/accelerators/accelerator_controller_unittest.cc | 63 | ||||
-rw-r--r-- | ash/ash.gyp | 2 | ||||
-rw-r--r-- | ash/test/test_volume_control_delegate.cc | 40 | ||||
-rw-r--r-- | ash/test/test_volume_control_delegate.h | 56 | ||||
-rw-r--r-- | ash/wm/maximize_mode/maximize_mode_controller_unittest.cc | 30 | ||||
-rw-r--r-- | ash/wm/maximize_mode/maximize_mode_event_blocker.cc | 16 |
6 files changed, 150 insertions, 57 deletions
diff --git a/ash/accelerators/accelerator_controller_unittest.cc b/ash/accelerators/accelerator_controller_unittest.cc index 93277ea..dbdc9e1 100644 --- a/ash/accelerators/accelerator_controller_unittest.cc +++ b/ash/accelerators/accelerator_controller_unittest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "ash/accelerators/accelerator_controller.h" + #include "ash/accelerators/accelerator_table.h" #include "ash/accessibility_delegate.h" #include "ash/ash_switches.h" @@ -18,6 +19,7 @@ #include "ash/test/display_manager_test_api.h" #include "ash/test/test_screenshot_delegate.h" #include "ash/test/test_shell_delegate.h" +#include "ash/test/test_volume_control_delegate.h" #include "ash/volume_control_delegate.h" #include "ash/wm/window_state.h" #include "ash/wm/window_util.h" @@ -69,55 +71,6 @@ class ReleaseAccelerator : public ui::Accelerator { } }; -class DummyVolumeControlDelegate : public VolumeControlDelegate { - public: - explicit DummyVolumeControlDelegate(bool consume) - : consume_(consume), - handle_volume_mute_count_(0), - handle_volume_down_count_(0), - handle_volume_up_count_(0) { - } - virtual ~DummyVolumeControlDelegate() {} - - virtual bool HandleVolumeMute(const ui::Accelerator& accelerator) OVERRIDE { - ++handle_volume_mute_count_; - last_accelerator_ = accelerator; - return consume_; - } - virtual bool HandleVolumeDown(const ui::Accelerator& accelerator) OVERRIDE { - ++handle_volume_down_count_; - last_accelerator_ = accelerator; - return consume_; - } - virtual bool HandleVolumeUp(const ui::Accelerator& accelerator) OVERRIDE { - ++handle_volume_up_count_; - last_accelerator_ = accelerator; - return consume_; - } - - int handle_volume_mute_count() const { - return handle_volume_mute_count_; - } - int handle_volume_down_count() const { - return handle_volume_down_count_; - } - int handle_volume_up_count() const { - return handle_volume_up_count_; - } - const ui::Accelerator& last_accelerator() const { - return last_accelerator_; - } - - private: - const bool consume_; - int handle_volume_mute_count_; - int handle_volume_down_count_; - int handle_volume_up_count_; - ui::Accelerator last_accelerator_; - - DISALLOW_COPY_AND_ASSIGN(DummyVolumeControlDelegate); -}; - class DummyBrightnessControlDelegate : public BrightnessControlDelegate { public: explicit DummyBrightnessControlDelegate(bool consume) @@ -714,8 +667,8 @@ TEST_F(AcceleratorControllerTest, GlobalAccelerators) { const ui::Accelerator volume_down(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); const ui::Accelerator volume_up(ui::VKEY_VOLUME_UP, ui::EF_NONE); { - DummyVolumeControlDelegate* delegate = - new DummyVolumeControlDelegate(false); + TestVolumeControlDelegate* delegate = + new TestVolumeControlDelegate(false); ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate( scoped_ptr<VolumeControlDelegate>(delegate).Pass()); EXPECT_EQ(0, delegate->handle_volume_mute_count()); @@ -732,7 +685,7 @@ TEST_F(AcceleratorControllerTest, GlobalAccelerators) { EXPECT_EQ(volume_up, delegate->last_accelerator()); } { - DummyVolumeControlDelegate* delegate = new DummyVolumeControlDelegate(true); + TestVolumeControlDelegate* delegate = new TestVolumeControlDelegate(true); ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate( scoped_ptr<VolumeControlDelegate>(delegate).Pass()); EXPECT_EQ(0, delegate->handle_volume_mute_count()); @@ -1190,8 +1143,8 @@ TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) { EXPECT_TRUE(ProcessWithContext(volume_mute)); EXPECT_TRUE(ProcessWithContext(volume_down)); EXPECT_TRUE(ProcessWithContext(volume_up)); - DummyVolumeControlDelegate* delegate = - new DummyVolumeControlDelegate(false); + TestVolumeControlDelegate* delegate = + new TestVolumeControlDelegate(false); ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate( scoped_ptr<VolumeControlDelegate>(delegate).Pass()); EXPECT_EQ(0, delegate->handle_volume_mute_count()); @@ -1208,7 +1161,7 @@ TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) { EXPECT_EQ(volume_up, delegate->last_accelerator()); } { - DummyVolumeControlDelegate* delegate = new DummyVolumeControlDelegate(true); + TestVolumeControlDelegate* delegate = new TestVolumeControlDelegate(true); ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate( scoped_ptr<VolumeControlDelegate>(delegate).Pass()); EXPECT_EQ(0, delegate->handle_volume_mute_count()); diff --git a/ash/ash.gyp b/ash/ash.gyp index 1cd7748..321ed69 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -832,6 +832,8 @@ 'test/test_system_tray_delegate.h', 'test/test_user_wallpaper_delegate.cc', 'test/test_user_wallpaper_delegate.h', + 'test/test_volume_control_delegate.cc', + 'test/test_volume_control_delegate.h', 'test/ui_controls_factory_ash.cc', 'test/ui_controls_factory_ash.h', ], diff --git a/ash/test/test_volume_control_delegate.cc b/ash/test/test_volume_control_delegate.cc new file mode 100644 index 0000000..7c5cad0 --- /dev/null +++ b/ash/test/test_volume_control_delegate.cc @@ -0,0 +1,40 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/test/test_volume_control_delegate.h" + +namespace ash { + +TestVolumeControlDelegate::TestVolumeControlDelegate(bool consume) + : consume_(consume), + handle_volume_mute_count_(0), + handle_volume_down_count_(0), + handle_volume_up_count_(0) { +} + +TestVolumeControlDelegate::~TestVolumeControlDelegate() { +} + +bool TestVolumeControlDelegate::HandleVolumeMute( + const ui::Accelerator& accelerator) { + ++handle_volume_mute_count_; + last_accelerator_ = accelerator; + return consume_; +} + +bool TestVolumeControlDelegate::HandleVolumeDown( + const ui::Accelerator& accelerator) { + ++handle_volume_down_count_; + last_accelerator_ = accelerator; + return consume_; +} + +bool TestVolumeControlDelegate::HandleVolumeUp( + const ui::Accelerator& accelerator) { + ++handle_volume_up_count_; + last_accelerator_ = accelerator; + return consume_; +} + +} // namespace ash diff --git a/ash/test/test_volume_control_delegate.h b/ash/test/test_volume_control_delegate.h new file mode 100644 index 0000000..85b3e5d --- /dev/null +++ b/ash/test/test_volume_control_delegate.h @@ -0,0 +1,56 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ASH_TEST_TEST_VOLUME_CONTROL_DELEGATE_H_ +#define ASH_TEST_TEST_VOLUME_CONTROL_DELEGATE_H_ + +#include "ash/volume_control_delegate.h" +#include "ui/base/accelerators/accelerator.h" + +namespace ash { + +// A simple test double for a VolumeControlDelegate +// Will count the number of times the HandleVolumeMute, HandleVolumeDown and +// HandleVolumeUp methods are invoked. +class TestVolumeControlDelegate : public ash::VolumeControlDelegate { + public: + explicit TestVolumeControlDelegate(bool consume); + virtual ~TestVolumeControlDelegate(); + + int handle_volume_mute_count() const { + return handle_volume_mute_count_; + } + + int handle_volume_down_count() const { + return handle_volume_down_count_; + } + + int handle_volume_up_count() const { + return handle_volume_up_count_; + } + + const ui::Accelerator& last_accelerator() const { + return last_accelerator_; + } + + // ash::VolumeControlDelegate: + virtual bool HandleVolumeMute(const ui::Accelerator& accelerator) OVERRIDE; + virtual bool HandleVolumeDown(const ui::Accelerator& accelerator) OVERRIDE; + virtual bool HandleVolumeUp(const ui::Accelerator& accelerator) OVERRIDE; + + private: + // Keeps track of the return value that should be used for the methods + // inherited from VolumeControlDelegate + bool consume_; + int handle_volume_mute_count_; + int handle_volume_down_count_; + int handle_volume_up_count_; + ui::Accelerator last_accelerator_; + + DISALLOW_COPY_AND_ASSIGN(TestVolumeControlDelegate); +}; + +} // namespace ash + +#endif // ASH_TEST_TEST_VOLUME_CONTROL_DELEGATE_H_ diff --git a/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc b/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc index d619fd5..33b8988 100644 --- a/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc +++ b/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc @@ -7,8 +7,10 @@ #include "ash/accelerometer/accelerometer_controller.h" #include "ash/display/display_manager.h" #include "ash/shell.h" +#include "ash/system/tray/system_tray_delegate.h" #include "ash/test/ash_test_base.h" #include "ash/test/display_manager_test_api.h" +#include "ash/test/test_volume_control_delegate.h" #include "ui/aura/test/event_generator.h" #include "ui/events/event_handler.h" #include "ui/gfx/vector3d_f.h" @@ -327,6 +329,34 @@ TEST_F(MaximizeModeControllerTest, BlocksKeyboard) { counter.reset(); } +// Tests that maximize mode does not block Volume Up & Down events. +TEST_F(MaximizeModeControllerTest, AllowsVolumeControl) { + aura::Window* root = Shell::GetPrimaryRootWindow(); + aura::test::EventGenerator event_generator(root, root); + + TestVolumeControlDelegate* volume_delegate = + new TestVolumeControlDelegate(true); + ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate( + scoped_ptr<VolumeControlDelegate>(volume_delegate).Pass()); + + // Trigger maximize mode by opening to 270 to begin the test in maximize mode. + TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f), + gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); + ASSERT_TRUE(IsMaximizeModeStarted()); + + // Verify volume down button event is not blocked + ASSERT_EQ(0, volume_delegate->handle_volume_down_count()); + event_generator.PressKey(ui::VKEY_VOLUME_DOWN, 0); + event_generator.ReleaseKey(ui::VKEY_VOLUME_DOWN, 0); + EXPECT_EQ(1, volume_delegate->handle_volume_down_count()); + + // Verify volume up event is not blocked + ASSERT_EQ(0, volume_delegate->handle_volume_up_count()); + event_generator.PressKey(ui::VKEY_VOLUME_UP, 0); + event_generator.ReleaseKey(ui::VKEY_VOLUME_UP, 0); + EXPECT_EQ(1, volume_delegate->handle_volume_up_count()); +} + TEST_F(MaximizeModeControllerTest, LaptopTest) { // Feeds in sample accelerometer data and verifies that there are no // transitions into touchview / maximize mode while shaking the device around diff --git a/ash/wm/maximize_mode/maximize_mode_event_blocker.cc b/ash/wm/maximize_mode/maximize_mode_event_blocker.cc index e283149..dd9fcde 100644 --- a/ash/wm/maximize_mode/maximize_mode_event_blocker.cc +++ b/ash/wm/maximize_mode/maximize_mode_event_blocker.cc @@ -8,6 +8,7 @@ #include "base/memory/scoped_ptr.h" #include "ui/aura/client/cursor_client.h" #include "ui/events/event_targeter.h" +#include "ui/events/keycodes/keyboard_codes.h" namespace ash { @@ -54,8 +55,19 @@ void BlockKeyboardAndTouchpadTargeter::SetDefaultTargeter( ui::EventTarget* BlockKeyboardAndTouchpadTargeter::FindTargetForEvent( ui::EventTarget* root, ui::Event* event) { - if (event->HasNativeEvent() && (event->IsMouseEvent() || event->IsKeyEvent())) - return NULL; + if (event->HasNativeEvent()) { + if (event->IsMouseEvent()) + return NULL; + if (event->IsKeyEvent()) { + // TODO(bruthig): Fix this to block rewritten volume keys + // (i.e. F9 and F10) from the device's keyboard. https://crbug.com/368669 + ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(event); + if (key_event->key_code() != ui::VKEY_VOLUME_DOWN && + key_event->key_code() != ui::VKEY_VOLUME_UP) { + return NULL; + } + } + } return default_targeter_->FindTargetForEvent(root, event); } |