Skip to content

Commit

Permalink
Revert 268181 "Enabled volume buttons when TouchView is active"
Browse files Browse the repository at this point in the history
> Enabled volume buttons when TouchView is active
> 
> BUG=364584
> TEST=MaximizeModeControllerTest.AllowsVolumeControl
> 
> Review URL: https://codereview.chromium.org/251193005

TBR=bruthig@chromium.org

Review URL: https://codereview.chromium.org/266223003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268198 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
abodenha@google.com committed May 5, 2014
1 parent e33b3ef commit 680db87
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 152 deletions.
63 changes: 55 additions & 8 deletions ash/accelerators/accelerator_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// 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"
Expand All @@ -19,7 +18,6 @@
#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"
Expand Down Expand Up @@ -71,6 +69,55 @@ 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)
Expand Down Expand Up @@ -667,8 +714,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);
{
TestVolumeControlDelegate* delegate =
new TestVolumeControlDelegate(false);
DummyVolumeControlDelegate* delegate =
new DummyVolumeControlDelegate(false);
ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate(
scoped_ptr<VolumeControlDelegate>(delegate).Pass());
EXPECT_EQ(0, delegate->handle_volume_mute_count());
Expand All @@ -685,7 +732,7 @@ TEST_F(AcceleratorControllerTest, GlobalAccelerators) {
EXPECT_EQ(volume_up, delegate->last_accelerator());
}
{
TestVolumeControlDelegate* delegate = new TestVolumeControlDelegate(true);
DummyVolumeControlDelegate* delegate = new DummyVolumeControlDelegate(true);
ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate(
scoped_ptr<VolumeControlDelegate>(delegate).Pass());
EXPECT_EQ(0, delegate->handle_volume_mute_count());
Expand Down Expand Up @@ -1143,8 +1190,8 @@ TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) {
EXPECT_TRUE(ProcessWithContext(volume_mute));
EXPECT_TRUE(ProcessWithContext(volume_down));
EXPECT_TRUE(ProcessWithContext(volume_up));
TestVolumeControlDelegate* delegate =
new TestVolumeControlDelegate(false);
DummyVolumeControlDelegate* delegate =
new DummyVolumeControlDelegate(false);
ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate(
scoped_ptr<VolumeControlDelegate>(delegate).Pass());
EXPECT_EQ(0, delegate->handle_volume_mute_count());
Expand All @@ -1161,7 +1208,7 @@ TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) {
EXPECT_EQ(volume_up, delegate->last_accelerator());
}
{
TestVolumeControlDelegate* delegate = new TestVolumeControlDelegate(true);
DummyVolumeControlDelegate* delegate = new DummyVolumeControlDelegate(true);
ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate(
scoped_ptr<VolumeControlDelegate>(delegate).Pass());
EXPECT_EQ(0, delegate->handle_volume_mute_count());
Expand Down
2 changes: 0 additions & 2 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,6 @@
'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',
],
Expand Down
40 changes: 0 additions & 40 deletions ash/test/test_volume_control_delegate.cc

This file was deleted.

56 changes: 0 additions & 56 deletions ash/test/test_volume_control_delegate.h

This file was deleted.

34 changes: 2 additions & 32 deletions ash/wm/maximize_mode/maximize_mode_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
#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"
Expand Down Expand Up @@ -150,7 +148,7 @@ TEST_F(MaximizeModeControllerTest, EnterExitThresholds) {
// Tests that when the hinge is nearly vertically aligned, the current state
// persists as the computed angle is highly inaccurate in this orientation.
TEST_F(MaximizeModeControllerTest, HingeAligned) {
// Laptop in normal orientation lid open 90 degrees.
// Laptop in normal orientation lid open 90 degrees.
TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
EXPECT_FALSE(IsMaximizeModeStarted());
Expand Down Expand Up @@ -311,7 +309,7 @@ TEST_F(MaximizeModeControllerTest, BlocksKeyboard) {
EXPECT_EQ(0u, counter.event_count());
counter.reset();

// Touch should not be blocked.
// Touch should not be blocked.
event_generator.PressTouch();
event_generator.ReleaseTouch();
EXPECT_GT(counter.event_count(), 0u);
Expand All @@ -329,34 +327,6 @@ 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(false);
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
Expand Down
16 changes: 2 additions & 14 deletions ash/wm/maximize_mode/maximize_mode_event_blocker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#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 {

Expand Down Expand Up @@ -55,19 +54,8 @@ void BlockKeyboardAndTouchpadTargeter::SetDefaultTargeter(
ui::EventTarget* BlockKeyboardAndTouchpadTargeter::FindTargetForEvent(
ui::EventTarget* root,
ui::Event* event) {
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;
}
}
}
if (event->HasNativeEvent() && (event->IsMouseEvent() || event->IsKeyEvent()))
return NULL;
return default_targeter_->FindTargetForEvent(root, event);
}

Expand Down

0 comments on commit 680db87

Please sign in to comment.