diff options
author | mazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-20 20:21:11 +0000 |
---|---|---|
committer | mazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-20 20:21:11 +0000 |
commit | e7146cef7148efeaa5b22404e1e3f94aec14749f (patch) | |
tree | 3241a5ebcb2b378a98d7bd5919ee4579a4162616 /ash/keyboard_overlay | |
parent | 114ade48063f3e979ea39df06d33ab4554ea4611 (diff) | |
download | chromium_src-e7146cef7148efeaa5b22404e1e3f94aec14749f.zip chromium_src-e7146cef7148efeaa5b22404e1e3f94aec14749f.tar.gz chromium_src-e7146cef7148efeaa5b22404e1e3f94aec14749f.tar.bz2 |
Make VKEY_F14 and VKEY_HELP close keyboard overlay.
Also add tests to verify that the shortcuts that open the keyboard overlay close it.
BUG=chrome-os-partner:16067
Review URL: https://chromiumcodereview.appspot.com/11636037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@174220 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/keyboard_overlay')
-rw-r--r-- | ash/keyboard_overlay/keyboard_overlay_view.cc | 18 | ||||
-rw-r--r-- | ash/keyboard_overlay/keyboard_overlay_view.h | 14 | ||||
-rw-r--r-- | ash/keyboard_overlay/keyboard_overlay_view_unittest.cc | 76 |
3 files changed, 103 insertions, 5 deletions
diff --git a/ash/keyboard_overlay/keyboard_overlay_view.cc b/ash/keyboard_overlay/keyboard_overlay_view.cc index a52ace1..82c8091 100644 --- a/ash/keyboard_overlay/keyboard_overlay_view.cc +++ b/ash/keyboard_overlay/keyboard_overlay_view.cc @@ -19,14 +19,13 @@ using ui::WebDialogDelegate; namespace { -// Keys to invoke Cancel (Escape, Ctrl+Alt+/, or Shift+Ctrl+Alt+/). -const struct KeyEventData { - ui::KeyboardCode key_code; - int flags; -} kCancelKeys[] = { +// Keys to invoke Cancel (Escape, Ctrl+Alt+/, or Shift+Ctrl+Alt+/, Help, F14). +const ash::KeyboardOverlayView::KeyEventData kCancelKeys[] = { { ui::VKEY_ESCAPE, ui::EF_NONE}, { ui::VKEY_OEM_2, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN }, { ui::VKEY_OEM_2, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN }, + { ui::VKEY_HELP, ui::EF_NONE }, + { ui::VKEY_F14, ui::EF_NONE }, }; } @@ -84,4 +83,13 @@ void KeyboardOverlayView::WindowClosing() { Cancel(); } +// static +void KeyboardOverlayView::GetCancelingKeysForTesting( + std::vector<KeyboardOverlayView::KeyEventData>* canceling_keys) { + CHECK(canceling_keys); + canceling_keys->clear(); + for (size_t i = 0; i < arraysize(kCancelKeys); ++i) + canceling_keys->push_back(kCancelKeys[i]); +} + } // namespace ash diff --git a/ash/keyboard_overlay/keyboard_overlay_view.h b/ash/keyboard_overlay/keyboard_overlay_view.h index d83cb13..3e352ae 100644 --- a/ash/keyboard_overlay/keyboard_overlay_view.h +++ b/ash/keyboard_overlay/keyboard_overlay_view.h @@ -5,9 +5,12 @@ #ifndef ASH_KEYBOARD_OVERLAY_KEYBOARD_OVERLAY_VIEW_H_ #define ASH_KEYBOARD_OVERLAY_KEYBOARD_OVERLAY_VIEW_H_ +#include <vector> + #include "ash/ash_export.h" #include "ash/wm/overlay_event_filter.h" #include "base/compiler_specific.h" +#include "base/gtest_prod_util.h" #include "ui/views/controls/webview/web_dialog_view.h" class GURL; @@ -27,6 +30,11 @@ class ASH_EXPORT KeyboardOverlayView : public views::WebDialogView, public ash::internal::OverlayEventFilter::Delegate { public: + struct KeyEventData { + ui::KeyboardCode key_code; + int flags; + }; + KeyboardOverlayView(content::BrowserContext* context, ui::WebDialogDelegate* delegate, WebContentsHandler* handler); @@ -43,9 +51,15 @@ class ASH_EXPORT KeyboardOverlayView const GURL& url); private: + FRIEND_TEST_ALL_PREFIXES(KeyboardOverlayViewTest, OpenAcceleratorsClose); + FRIEND_TEST_ALL_PREFIXES(KeyboardOverlayViewTest, NoRedundantCancelingKeys); + // Overridden from views::WidgetDelegate: virtual void WindowClosing() OVERRIDE; + static void GetCancelingKeysForTesting( + std::vector<KeyEventData>* canceling_keys); + DISALLOW_COPY_AND_ASSIGN(KeyboardOverlayView); }; diff --git a/ash/keyboard_overlay/keyboard_overlay_view_unittest.cc b/ash/keyboard_overlay/keyboard_overlay_view_unittest.cc new file mode 100644 index 0000000..fcb82ce --- /dev/null +++ b/ash/keyboard_overlay/keyboard_overlay_view_unittest.cc @@ -0,0 +1,76 @@ +// Copyright (c) 2012 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/keyboard_overlay/keyboard_overlay_view.h" + +#include <algorithm> + +#include "ash/accelerators/accelerator_table.h" +#include "ash/keyboard_overlay/keyboard_overlay_delegate.h" +#include "ash/shell.h" +#include "ash/test/ash_test_base.h" +#include "ui/web_dialogs/test/test_web_contents_handler.h" +#include "ui/web_dialogs/test/test_web_dialog_delegate.h" + +namespace ash { + +typedef test::AshTestBase KeyboardOverlayViewTest; + +bool operator==(const KeyboardOverlayView::KeyEventData& lhs, + const KeyboardOverlayView::KeyEventData& rhs) { + return (lhs.key_code == rhs.key_code) && (lhs.flags == rhs.flags); +} + +// Verifies that the accelerators that open the keyboard overlay close it. +TEST_F(KeyboardOverlayViewTest, OpenAcceleratorsClose) { + KeyboardOverlayView* view = new KeyboardOverlayView( + Shell::GetInstance()->browser_context(), + new ui::test::TestWebDialogDelegate(GURL("chrome://keyboardoverlay")), + new ui::test::TestWebContentsHandler); + for (size_t i = 0; i < kAcceleratorDataLength; ++i) { + if (kAcceleratorData[i].action != SHOW_KEYBOARD_OVERLAY) + continue; + const AcceleratorData& open_key_data = kAcceleratorData[i]; + ui::KeyEvent open_key(open_key_data.trigger_on_press ? + ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED, + open_key_data.keycode, + open_key_data.modifiers, + false); + EXPECT_TRUE(view->IsCancelingKeyEvent(&open_key)); + } +} + +// Verifies that there are no redunduant keys in the canceling keys. +TEST_F(KeyboardOverlayViewTest, NoRedundantCancelingKeys) { + std::vector<KeyboardOverlayView::KeyEventData> open_keys; + for (size_t i = 0; i < kAcceleratorDataLength; ++i) { + if (kAcceleratorData[i].action != SHOW_KEYBOARD_OVERLAY) + continue; + // Escape is used just for canceling. + KeyboardOverlayView::KeyEventData open_key = { + kAcceleratorData[i].keycode, + kAcceleratorData[i].modifiers, + }; + open_keys.push_back(open_key); + } + + std::vector<KeyboardOverlayView::KeyEventData> canceling_keys; + KeyboardOverlayView::GetCancelingKeysForTesting(&canceling_keys); + + // Escape is used just for canceling, so exclude it from the comparison with + // open keys. + KeyboardOverlayView::KeyEventData escape = { ui::VKEY_ESCAPE, ui::EF_NONE }; + std::vector<KeyboardOverlayView::KeyEventData>::iterator escape_itr = + std::find(canceling_keys.begin(), canceling_keys.end(), escape); + canceling_keys.erase(escape_itr); + + // Other canceling keys should be same as opening keys. + EXPECT_EQ(open_keys.size(), canceling_keys.size()); + for (size_t i = 0; i < canceling_keys.size(); ++i) { + EXPECT_NE(std::find(open_keys.begin(), open_keys.end(), canceling_keys[i]), + open_keys.end()); + } +} + +} // namespace ash |