summaryrefslogtreecommitdiffstats
path: root/chrome/test/automated_ui_tests
diff options
context:
space:
mode:
authordmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-22 15:29:20 +0000
committerdmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-22 15:29:20 +0000
commited256c7bd9828576ce865926e898a6c592b14037 (patch)
tree598f0023ad717aa23953cd4bcb666fc2df1410f6 /chrome/test/automated_ui_tests
parentb4fe9eb3acfd443091ebecbbbd1f87247cce9e1d (diff)
downloadchromium_src-ed256c7bd9828576ce865926e898a6c592b14037.zip
chromium_src-ed256c7bd9828576ce865926e898a6c592b14037.tar.gz
chromium_src-ed256c7bd9828576ce865926e898a6c592b14037.tar.bz2
Keyboard accessibility for the page and app menus.
Works on Windows, and on Linux with toolkit_views. The goal is to make Chrome behave more like a standard Windows application, for users who rely on the keyboard and expect standard keyboard accelerators to work. Pressing F10, or pressing and releasing Alt, will set focus to the Page menu, as if it was the first item in a menu bar. Pressing enter, space, up arrow, or down arrow will open the focused menu. Once a menu is opened, pressing left and right arrows will switch between the two menus. Pressing escape will return focus to the title of the previously open menu. A new UI test attempts to select something from the menus using only the keyboard. It works on Linux (with toolkit_views) and on Windows. BUG=none TEST=New keyboard accessibility ui test. Review URL: http://codereview.chromium.org/660323 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42217 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/automated_ui_tests')
-rw-r--r--chrome/test/automated_ui_tests/keyboard_access_uitest.cc100
1 files changed, 100 insertions, 0 deletions
diff --git a/chrome/test/automated_ui_tests/keyboard_access_uitest.cc b/chrome/test/automated_ui_tests/keyboard_access_uitest.cc
new file mode 100644
index 0000000..2ae5171
--- /dev/null
+++ b/chrome/test/automated_ui_tests/keyboard_access_uitest.cc
@@ -0,0 +1,100 @@
+// Copyright (c) 2010 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 "base/keyboard_codes.h"
+#include "chrome/test/automated_ui_tests/automated_ui_test_base.h"
+#include "chrome/test/automation/browser_proxy.h"
+#include "chrome/test/automation/tab_proxy.h"
+#include "chrome/test/automation/window_proxy.h"
+#include "googleurl/src/gurl.h"
+
+// This functionality currently works on Windows and on Linux when
+// toolkit_views is defined (i.e. for Chrome OS). It's not needed
+// on the Mac, and it's not yet implemented on Linux.
+#if !defined(TOOLKIT_VIEWS)
+#define MAYBE_TestMenuKeyboardAccess DISABLED_TestMenuKeyboardAccess
+#define MAYBE_TestAltMenuKeyboardAccess DISABLED_TestAltMenuKeyboardAccess
+#endif
+
+namespace {
+
+class KeyboardAccessTest : public AutomatedUITestBase {
+ public:
+ KeyboardAccessTest() {
+ dom_automation_enabled_ = true;
+ show_window_ = true;
+ }
+
+ // Use the keyboard to select "New Tab" from the app menu.
+ // This test depends on the fact that there are two menus and that
+ // New Tab is the first item in the app menu. If the menus change,
+ // this test will need to be changed to reflect that.
+ //
+ // If alternate_key_sequence is true, use "Alt" instead of "F10" to
+ // open the menu bar, and "Down" instead of "Enter" to open a menu.
+ void TestMenuKeyboardAccess(bool alternate_key_sequence);
+
+ DISALLOW_COPY_AND_ASSIGN(KeyboardAccessTest);
+};
+
+void KeyboardAccessTest::TestMenuKeyboardAccess(bool alternate_key_sequence) {
+ scoped_refptr<BrowserProxy> browser = automation()->GetBrowserWindow(0);
+ scoped_refptr<WindowProxy> window = browser->GetWindow();
+
+ // Navigate to a page in the first tab, which makes sure that focus is
+ // set to the browser window.
+ scoped_refptr<TabProxy> tab(GetActiveTab());
+ ASSERT_TRUE(tab.get());
+ ASSERT_TRUE(tab->NavigateToURL(GURL("about:")));
+
+ // The initial tab index should be 0.
+ int tab_index = -1;
+ ASSERT_TRUE(browser->GetActiveTabIndex(&tab_index));
+ ASSERT_EQ(0, tab_index);
+
+ // Get the focused view ID, then press a key to activate the
+ // page menu, then wait until the focused view changes.
+ int original_view_id = -1;
+ ASSERT_TRUE(window->GetFocusedViewID(&original_view_id));
+
+ if (alternate_key_sequence)
+ ASSERT_TRUE(window->SimulateOSKeyPress(base::VKEY_MENU, 0));
+ else
+ ASSERT_TRUE(window->SimulateOSKeyPress(base::VKEY_F10, 0));
+
+ int new_view_id = -1;
+ ASSERT_TRUE(window->WaitForFocusedViewIDToChange(
+ original_view_id, &new_view_id));
+
+ // Press RIGHT to focus the app menu, then RETURN or DOWN to open it.
+ ASSERT_TRUE(window->SimulateOSKeyPress(base::VKEY_RIGHT, 0));
+ if (alternate_key_sequence)
+ ASSERT_TRUE(window->SimulateOSKeyPress(base::VKEY_DOWN, 0));
+ else
+ ASSERT_TRUE(window->SimulateOSKeyPress(base::VKEY_RETURN, 0));
+
+ // Wait until the popup menu actually opens.
+ ASSERT_TRUE(window->WaitForPopupMenuOpen(sleep_timeout_ms()));
+
+ // Press DOWN to select the first item, then RETURN to select it.
+ ASSERT_TRUE(window->SimulateOSKeyPress(base::VKEY_DOWN, 0));
+ ASSERT_TRUE(window->SimulateOSKeyPress(base::VKEY_RETURN, 0));
+
+ // Wait for the new tab to appear.
+ ASSERT_TRUE(browser->WaitForTabCountToBecome(2, sleep_timeout_ms()));
+
+ // Make sure that the new tab index is 1.
+ ASSERT_TRUE(browser->GetActiveTabIndex(&tab_index));
+ ASSERT_EQ(1, tab_index);
+}
+
+TEST_F(KeyboardAccessTest, MAYBE_TestMenuKeyboardAccess) {
+ TestMenuKeyboardAccess(false);
+}
+
+TEST_F(KeyboardAccessTest, MAYBE_TestAltMenuKeyboardAccess) {
+ TestMenuKeyboardAccess(true);
+}
+
+} // namespace