diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-15 03:21:06 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-15 03:21:06 +0000 |
commit | e4ea52364663acf64dc3a197660b78b38761a3fc (patch) | |
tree | 7ed815df5517e9c978359777cca0e860950af5ae /ash/accelerators/magnifier_key_scroller_unittest.cc | |
parent | 726127fdb3582f187eda5595fab13eb49de11fb2 (diff) | |
download | chromium_src-e4ea52364663acf64dc3a197660b78b38761a3fc.zip chromium_src-e4ea52364663acf64dc3a197660b78b38761a3fc.tar.gz chromium_src-e4ea52364663acf64dc3a197660b78b38761a3fc.tar.bz2 |
Long press menu (shift+f6) to toggle spoken feedback.
Factor out KeyHoldDetector.
BUG=343277
TEST=SpokenFeedbackTogglerTest
Review URL: https://codereview.chromium.org/164823005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251490 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/accelerators/magnifier_key_scroller_unittest.cc')
-rw-r--r-- | ash/accelerators/magnifier_key_scroller_unittest.cc | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/ash/accelerators/magnifier_key_scroller_unittest.cc b/ash/accelerators/magnifier_key_scroller_unittest.cc new file mode 100644 index 0000000..21eb2ab --- /dev/null +++ b/ash/accelerators/magnifier_key_scroller_unittest.cc @@ -0,0 +1,111 @@ +// 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/accelerators/magnifier_key_scroller.h" + +#include "ash/magnifier/magnification_controller.h" +#include "ash/shell.h" +#include "ash/test/ash_test_base.h" +#include "ash/wm/window_util.h" +#include "ui/aura/test/event_generator.h" +#include "ui/aura/test/test_window_delegate.h" + +namespace ash { +namespace { + +class KeyEventDelegate : public aura::test::TestWindowDelegate { + public: + KeyEventDelegate() {} + virtual ~KeyEventDelegate() {} + + // ui::EventHandler overrides: + virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE { + key_event.reset(new ui::KeyEvent( + event->type(), event->key_code(), event->flags(), false)); + } + + const ui::KeyEvent* event() const { return key_event.get(); } + void reset() { key_event.reset(); } + + private: + scoped_ptr<ui::KeyEvent> key_event; + + DISALLOW_COPY_AND_ASSIGN(KeyEventDelegate); +}; + +} // namespace + +typedef ash::test::AshTestBase MagnifierKeyScrollerTest; + +TEST_F(MagnifierKeyScrollerTest, Basic) { + KeyEventDelegate delegate; + scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( + &delegate, + 0, + gfx::Rect(10, 10, 100, 100))); + wm::ActivateWindow(window.get()); + + MagnifierKeyScroller::ScopedEnablerForTest scoped; + Shell* shell = Shell::GetInstance(); + MagnificationController* controller = shell->magnification_controller(); + controller->SetEnabled(true); + + EXPECT_EQ("200,150", controller->GetWindowPosition().ToString()); + aura::test::EventGenerator& generator = GetEventGenerator(); + + // Click and Release generates the press event upon release. + generator.PressKey(ui::VKEY_DOWN, ui::EF_SHIFT_DOWN); + EXPECT_EQ("200,150", controller->GetWindowPosition().ToString()); + EXPECT_FALSE(delegate.event()); + + generator.ReleaseKey(ui::VKEY_DOWN, 0); + EXPECT_EQ("200,150", controller->GetWindowPosition().ToString()); + RunAllPendingInMessageLoop(); + EXPECT_TRUE(delegate.event()); + EXPECT_EQ(ui::ET_KEY_PRESSED, delegate.event()->type()); + delegate.reset(); + + // Click and hold scrolls the magnifier screen. + generator.PressKey(ui::VKEY_DOWN, ui::EF_SHIFT_DOWN); + EXPECT_EQ("200,150", controller->GetWindowPosition().ToString()); + EXPECT_FALSE(delegate.event()); + + generator.PressKey(ui::VKEY_DOWN, ui::EF_SHIFT_DOWN); + EXPECT_EQ("200,300", controller->GetWindowPosition().ToString()); + EXPECT_FALSE(delegate.event()); + + generator.ReleaseKey(ui::VKEY_DOWN, 0); + EXPECT_EQ("200,300", controller->GetWindowPosition().ToString()); + EXPECT_FALSE(delegate.event()); + + // Events are passed normally when the magnifier is off. + controller->SetEnabled(false); + + generator.PressKey(ui::VKEY_DOWN, ui::EF_SHIFT_DOWN); + EXPECT_TRUE(delegate.event()); + EXPECT_EQ(ui::ET_KEY_PRESSED, delegate.event()->type()); + delegate.reset(); + + generator.ReleaseKey(ui::VKEY_DOWN, 0); + EXPECT_TRUE(delegate.event()); + EXPECT_EQ(ui::ET_KEY_RELEASED, delegate.event()->type()); + delegate.reset(); + + generator.PressKey(ui::VKEY_DOWN, ui::EF_SHIFT_DOWN); + EXPECT_TRUE(delegate.event()); + EXPECT_EQ(ui::ET_KEY_PRESSED, delegate.event()->type()); + delegate.reset(); + + generator.PressKey(ui::VKEY_DOWN, ui::EF_SHIFT_DOWN); + EXPECT_TRUE(delegate.event()); + EXPECT_EQ(ui::ET_KEY_PRESSED, delegate.event()->type()); + delegate.reset(); + + generator.ReleaseKey(ui::VKEY_DOWN, 0); + EXPECT_TRUE(delegate.event()); + EXPECT_EQ(ui::ET_KEY_RELEASED, delegate.event()->type()); + delegate.reset(); +} + +} // namespace ash |