| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/keyboard_codes.h" | 5 #include "base/keyboard_codes.h" |
| 6 #include "chrome/test/automation/browser_proxy.h" | 6 #include "chrome/test/automation/browser_proxy.h" |
| 7 #include "chrome/test/automation/tab_proxy.h" | 7 #include "chrome/test/automation/tab_proxy.h" |
| 8 #include "chrome/test/automation/window_proxy.h" | 8 #include "chrome/test/automation/window_proxy.h" |
| 9 #include "chrome/test/ui/ui_test.h" | 9 #include "chrome/test/ui/ui_test.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 11 #include "views/event.h" |
| 11 | 12 |
| 12 // This functionality currently works on Windows and on Linux when | 13 // This functionality currently works on Windows and on Linux when |
| 13 // toolkit_views is defined (i.e. for Chrome OS). It's not needed | 14 // toolkit_views is defined (i.e. for Chrome OS). It's not needed |
| 14 // on the Mac, and it's not yet implemented on Linux. | 15 // on the Mac, and it's not yet implemented on Linux. |
| 15 #if defined(TOOLKIT_VIEWS) | 16 #if defined(TOOLKIT_VIEWS) |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 class KeyboardAccessTest : public UITest { | 20 class KeyboardAccessTest : public UITest { |
| 20 public: | 21 public: |
| 21 KeyboardAccessTest() { | 22 KeyboardAccessTest() { |
| 22 dom_automation_enabled_ = true; | 23 dom_automation_enabled_ = true; |
| 23 show_window_ = true; | 24 show_window_ = true; |
| 24 } | 25 } |
| 25 | 26 |
| 26 // Use the keyboard to select "New Tab" from the app menu. | 27 // Use the keyboard to select "New Tab" from the app menu. |
| 27 // This test depends on the fact that there are two menus and that | 28 // This test depends on the fact that there is one menu and that |
| 28 // New Tab is the first item in the app menu. If the menus change, | 29 // New Tab is the first item in the menu. If the menus change, |
| 29 // this test will need to be changed to reflect that. | 30 // this test will need to be changed to reflect that. |
| 30 // | 31 // |
| 31 // If alternate_key_sequence is true, use "Alt" instead of "F10" to | 32 // If alternate_key_sequence is true, use "Alt" instead of "F10" to |
| 32 // open the menu bar, and "Down" instead of "Enter" to open a menu. | 33 // open the menu bar, and "Down" instead of "Enter" to open a menu. |
| 33 void TestMenuKeyboardAccess(bool alternate_key_sequence); | 34 void TestMenuKeyboardAccess(bool alternate_key_sequence); |
| 34 | 35 |
| 35 DISALLOW_COPY_AND_ASSIGN(KeyboardAccessTest); | 36 DISALLOW_COPY_AND_ASSIGN(KeyboardAccessTest); |
| 36 }; | 37 }; |
| 37 | 38 |
| 38 void KeyboardAccessTest::TestMenuKeyboardAccess(bool alternate_key_sequence) { | 39 void KeyboardAccessTest::TestMenuKeyboardAccess(bool alternate_key_sequence) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 } | 95 } |
| 95 | 96 |
| 96 TEST_F(KeyboardAccessTest, TestMenuKeyboardAccess) { | 97 TEST_F(KeyboardAccessTest, TestMenuKeyboardAccess) { |
| 97 TestMenuKeyboardAccess(false); | 98 TestMenuKeyboardAccess(false); |
| 98 } | 99 } |
| 99 | 100 |
| 100 TEST_F(KeyboardAccessTest, TestAltMenuKeyboardAccess) { | 101 TEST_F(KeyboardAccessTest, TestAltMenuKeyboardAccess) { |
| 101 TestMenuKeyboardAccess(true); | 102 TestMenuKeyboardAccess(true); |
| 102 } | 103 } |
| 103 | 104 |
| 105 TEST_F(KeyboardAccessTest, ReserveKeyboardAccelerators) { |
| 106 const std::string kBadPage = |
| 107 "<html><script>" |
| 108 "document.onkeydown = function() {" |
| 109 " event.preventDefault();" |
| 110 " return false;" |
| 111 "}" |
| 112 "</script></html>"; |
| 113 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 114 ASSERT_TRUE(browser); |
| 115 browser->AppendTab(GURL("data:text/html," + kBadPage)); |
| 116 int tab_count = 0; |
| 117 ASSERT_TRUE(browser->GetTabCount(&tab_count)); |
| 118 ASSERT_EQ(tab_count, 2); |
| 119 |
| 120 int active_tab = 0; |
| 121 ASSERT_TRUE(browser->GetActiveTabIndex(&active_tab)); |
| 122 ASSERT_EQ(active_tab, 1); |
| 123 |
| 124 scoped_refptr<WindowProxy> window(browser->GetWindow()); |
| 125 ASSERT_TRUE(window); |
| 126 ASSERT_TRUE(window->SimulateOSKeyPress( |
| 127 base::VKEY_TAB, views::Event::EF_CONTROL_DOWN)); |
| 128 ASSERT_TRUE(browser->WaitForTabToBecomeActive(0, action_max_timeout_ms())); |
| 129 |
| 130 #if !defined(OS_MACOSX) // see BrowserWindowCocoa::GetCommandId |
| 131 ASSERT_TRUE(browser->ActivateTab(1)); |
| 132 ASSERT_TRUE(window->SimulateOSKeyPress( |
| 133 base::VKEY_F4, views::Event::EF_CONTROL_DOWN)); |
| 134 ASSERT_TRUE(browser->WaitForTabCountToBecome(1, action_max_timeout_ms())); |
| 135 #endif |
| 136 } |
| 137 |
| 104 } // namespace | 138 } // namespace |
| 105 | 139 |
| 106 #endif // defined(TOOLKIT_VIEWS) | 140 #endif // defined(TOOLKIT_VIEWS) |
| OLD | NEW |