[email protected] | f20d733 | 2011-03-08 21:11:53 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "build/build_config.h" |
| 6 | |
| 7 | #include "base/basictypes.h" |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 8 | #include "base/logging.h" |
| 9 | #include "base/message_loop.h" |
[email protected] | 1870d5cf | 2011-05-12 01:55:40 | [diff] [blame] | 10 | #include "base/stringprintf.h" |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 11 | #include "base/utf_string_conversions.h" |
| 12 | #include "base/values.h" |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 13 | #include "chrome/browser/dom_operation_notification_details.h" |
[email protected] | 2ad4a90 | 2010-11-17 06:05:13 | [diff] [blame] | 14 | #include "chrome/browser/ui/browser.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 15 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 16 | #include "chrome/common/chrome_paths.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 17 | #include "chrome/test/base/in_process_browser_test.h" |
| 18 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | 5de63471 | 2011-03-02 00:20:19 | [diff] [blame] | 19 | #include "content/browser/renderer_host/render_view_host.h" |
| 20 | #include "content/browser/renderer_host/render_widget_host_view.h" |
| 21 | #include "content/browser/tab_contents/tab_contents.h" |
| 22 | #include "content/browser/tab_contents/tab_contents_view.h" |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame^] | 23 | #include "content/public/browser/notification_registrar.h" |
[email protected] | f20d733 | 2011-03-08 21:11:53 | [diff] [blame] | 24 | #include "content/common/notification_service.h" |
[email protected] | 3985ba8 | 2010-07-29 21:44:12 | [diff] [blame] | 25 | #include "net/test/test_server.h" |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 26 | #include "ui/base/keycodes/keyboard_codes.h" |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 27 | |
| 28 | namespace { |
| 29 | |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 30 | const char kTestingPage[] = "files/keyevents_test.html"; |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 31 | const wchar_t kSuppressEventJS[] = |
| 32 | L"window.domAutomationController.send(setDefaultAction('%ls', %ls));"; |
| 33 | const wchar_t kGetResultJS[] = |
| 34 | L"window.domAutomationController.send(keyEventResult[%d]);"; |
| 35 | const wchar_t kGetResultLengthJS[] = |
| 36 | L"window.domAutomationController.send(keyEventResult.length);"; |
| 37 | const wchar_t kGetFocusedElementJS[] = |
| 38 | L"window.domAutomationController.send(focusedElement);"; |
| 39 | const wchar_t kSetFocusedElementJS[] = |
| 40 | L"window.domAutomationController.send(setFocusedElement('%ls'));"; |
| 41 | const wchar_t kGetTextBoxValueJS[] = |
| 42 | L"window.domAutomationController.send(" |
| 43 | L"document.getElementById('%ls').value);"; |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 44 | const wchar_t kSetTextBoxValueJS[] = |
| 45 | L"window.domAutomationController.send(" |
| 46 | L"document.getElementById('%ls').value = '%ls');"; |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 47 | const wchar_t kStartTestJS[] = |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 48 | L"window.domAutomationController.send(startTest(%d));"; |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 49 | |
| 50 | // Maximum lenght of the result array in KeyEventTestData structure. |
| 51 | const size_t kMaxResultLength = 10; |
| 52 | |
| 53 | // A structure holding test data of a keyboard event. |
| 54 | // Each keyboard event may generate multiple result strings representing |
| 55 | // the result of keydown, keypress, keyup and textInput events. |
| 56 | // For keydown, keypress and keyup events, the format of the result string is: |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 57 | // <type> <keyCode> <charCode> <ctrlKey> <shiftKey> <altKey> <commandKey> |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 58 | // where <type> may be 'D' (keydown), 'P' (keypress) or 'U' (keyup). |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 59 | // <ctrlKey>, <shiftKey> <altKey> and <commandKey> are boolean value indicating |
| 60 | // the state of corresponding modifier key. |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 61 | // For textInput event, the format is: T <text>, where <text> is the text to be |
| 62 | // input. |
| 63 | // Please refer to chrome/test/data/keyevents_test.html for details. |
| 64 | struct KeyEventTestData { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 65 | ui::KeyboardCode key; |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 66 | bool ctrl; |
| 67 | bool shift; |
| 68 | bool alt; |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 69 | bool command; |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 70 | |
| 71 | bool suppress_keydown; |
| 72 | bool suppress_keypress; |
| 73 | bool suppress_keyup; |
| 74 | bool suppress_textinput; |
| 75 | |
| 76 | int result_length; |
| 77 | const char* const result[kMaxResultLength]; |
| 78 | }; |
| 79 | |
| 80 | const wchar_t* GetBoolString(bool value) { |
| 81 | return value ? L"true" : L"false"; |
| 82 | } |
| 83 | |
| 84 | // A class to help wait for the finish of a key event test. |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame^] | 85 | class TestFinishObserver : public content::NotificationObserver { |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 86 | public: |
| 87 | explicit TestFinishObserver(RenderViewHost* render_view_host) |
| 88 | : finished_(false), waiting_(false) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 89 | registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame^] | 90 | content::Source<RenderViewHost>(render_view_host)); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | bool WaitForFinish() { |
| 94 | if (!finished_) { |
| 95 | waiting_ = true; |
| 96 | ui_test_utils::RunMessageLoop(); |
| 97 | waiting_ = false; |
| 98 | } |
| 99 | return finished_; |
| 100 | } |
| 101 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 102 | virtual void Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame^] | 103 | const content::NotificationSource& source, |
| 104 | const content::NotificationDetails& details) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 105 | DCHECK(type == chrome::NOTIFICATION_DOM_OPERATION_RESPONSE); |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame^] | 106 | content::Details<DomOperationNotificationDetails> dom_op_details(details); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 107 | // We might receive responses for other script execution, but we only |
| 108 | // care about the test finished message. |
| 109 | if (dom_op_details->json() == "\"FINISHED\"") { |
| 110 | finished_ = true; |
| 111 | if (waiting_) |
| 112 | MessageLoopForUI::current()->Quit(); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | private: |
| 117 | bool finished_; |
| 118 | bool waiting_; |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame^] | 119 | content::NotificationRegistrar registrar_; |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 120 | |
| 121 | DISALLOW_COPY_AND_ASSIGN(TestFinishObserver); |
| 122 | }; |
| 123 | |
| 124 | class BrowserKeyEventsTest : public InProcessBrowserTest { |
| 125 | public: |
| 126 | BrowserKeyEventsTest() { |
| 127 | set_show_window(true); |
| 128 | EnableDOMAutomation(); |
| 129 | } |
| 130 | |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 131 | bool IsViewFocused(ViewID vid) { |
| 132 | return ui_test_utils::IsViewFocused(browser(), vid); |
| 133 | } |
| 134 | |
| 135 | void ClickOnView(ViewID vid) { |
| 136 | ui_test_utils::ClickOnView(browser(), vid); |
| 137 | } |
| 138 | |
| 139 | // Set the suppress flag of an event specified by |type|. If |suppress| is |
| 140 | // true then the web page will suppress all events with |type|. Following |
| 141 | // event types are supported: keydown, keypress, keyup and textInput. |
| 142 | void SuppressEventByType(int tab_index, const wchar_t* type, bool suppress) { |
| 143 | ASSERT_LT(tab_index, browser()->tab_count()); |
| 144 | bool actual; |
| 145 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 146 | browser()->GetTabContentsAt(tab_index)->render_view_host(), |
| 147 | L"", |
[email protected] | 1870d5cf | 2011-05-12 01:55:40 | [diff] [blame] | 148 | base::StringPrintf(kSuppressEventJS, type, GetBoolString(!suppress)), |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 149 | &actual)); |
| 150 | ASSERT_EQ(!suppress, actual); |
| 151 | } |
| 152 | |
| 153 | void SuppressEvents(int tab_index, bool keydown, bool keypress, |
| 154 | bool keyup, bool textinput) { |
| 155 | ASSERT_NO_FATAL_FAILURE( |
| 156 | SuppressEventByType(tab_index, L"keydown", keydown)); |
| 157 | ASSERT_NO_FATAL_FAILURE( |
| 158 | SuppressEventByType(tab_index, L"keypress", keypress)); |
| 159 | ASSERT_NO_FATAL_FAILURE( |
| 160 | SuppressEventByType(tab_index, L"keyup", keyup)); |
| 161 | ASSERT_NO_FATAL_FAILURE( |
| 162 | SuppressEventByType(tab_index, L"textInput", textinput)); |
| 163 | } |
| 164 | |
| 165 | void SuppressAllEvents(int tab_index, bool suppress) { |
| 166 | SuppressEvents(tab_index, suppress, suppress, suppress, suppress); |
| 167 | } |
| 168 | |
| 169 | void GetResultLength(int tab_index, int* length) { |
| 170 | ASSERT_LT(tab_index, browser()->tab_count()); |
| 171 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt( |
| 172 | browser()->GetTabContentsAt(tab_index)->render_view_host(), |
| 173 | L"", kGetResultLengthJS, length)); |
| 174 | } |
| 175 | |
| 176 | void CheckResult(int tab_index, int length, const char* const result[]) { |
| 177 | ASSERT_LT(tab_index, browser()->tab_count()); |
| 178 | int actual_length; |
| 179 | ASSERT_NO_FATAL_FAILURE(GetResultLength(tab_index, &actual_length)); |
| 180 | ASSERT_GE(actual_length, length); |
| 181 | for (int i = 0; i < actual_length; ++i) { |
| 182 | std::string actual; |
| 183 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 184 | browser()->GetTabContentsAt(tab_index)->render_view_host(), |
[email protected] | 1870d5cf | 2011-05-12 01:55:40 | [diff] [blame] | 185 | L"", base::StringPrintf(kGetResultJS, i), &actual)); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 186 | |
| 187 | // If more events were received than expected, then the additional events |
| 188 | // must be keyup events. |
| 189 | if (i < length) |
| 190 | ASSERT_STREQ(result[i], actual.c_str()); |
| 191 | else |
| 192 | ASSERT_EQ('U', actual[0]); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | void CheckFocusedElement(int tab_index, const wchar_t* focused) { |
| 197 | ASSERT_LT(tab_index, browser()->tab_count()); |
| 198 | std::string actual; |
| 199 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 200 | browser()->GetTabContentsAt(tab_index)->render_view_host(), |
| 201 | L"", kGetFocusedElementJS, &actual)); |
| 202 | ASSERT_EQ(WideToUTF8(focused), actual); |
| 203 | } |
| 204 | |
| 205 | void SetFocusedElement(int tab_index, const wchar_t* focused) { |
| 206 | ASSERT_LT(tab_index, browser()->tab_count()); |
| 207 | bool actual; |
| 208 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 209 | browser()->GetTabContentsAt(tab_index)->render_view_host(), |
| 210 | L"", |
[email protected] | 1870d5cf | 2011-05-12 01:55:40 | [diff] [blame] | 211 | base::StringPrintf(kSetFocusedElementJS, focused), |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 212 | &actual)); |
| 213 | ASSERT_TRUE(actual); |
| 214 | } |
| 215 | |
| 216 | void CheckTextBoxValue(int tab_index, const wchar_t* id, |
| 217 | const wchar_t* value) { |
| 218 | ASSERT_LT(tab_index, browser()->tab_count()); |
| 219 | std::string actual; |
| 220 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 221 | browser()->GetTabContentsAt(tab_index)->render_view_host(), |
| 222 | L"", |
[email protected] | 1870d5cf | 2011-05-12 01:55:40 | [diff] [blame] | 223 | base::StringPrintf(kGetTextBoxValueJS, id), |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 224 | &actual)); |
| 225 | ASSERT_EQ(WideToUTF8(value), actual); |
| 226 | } |
| 227 | |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 228 | void SetTextBoxValue(int tab_index, const wchar_t* id, |
| 229 | const wchar_t* value) { |
| 230 | ASSERT_LT(tab_index, browser()->tab_count()); |
| 231 | std::string actual; |
| 232 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 233 | browser()->GetTabContentsAt(tab_index)->render_view_host(), |
| 234 | L"", |
[email protected] | 1870d5cf | 2011-05-12 01:55:40 | [diff] [blame] | 235 | base::StringPrintf(kSetTextBoxValueJS, id, value), |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 236 | &actual)); |
| 237 | ASSERT_EQ(WideToUTF8(value), actual); |
| 238 | } |
| 239 | |
| 240 | void StartTest(int tab_index, int result_length) { |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 241 | ASSERT_LT(tab_index, browser()->tab_count()); |
| 242 | bool actual; |
| 243 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 244 | browser()->GetTabContentsAt(tab_index)->render_view_host(), |
[email protected] | 1870d5cf | 2011-05-12 01:55:40 | [diff] [blame] | 245 | L"", base::StringPrintf(kStartTestJS, result_length), &actual)); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 246 | ASSERT_TRUE(actual); |
| 247 | } |
| 248 | |
| 249 | void TestKeyEvent(int tab_index, const KeyEventTestData& test) { |
| 250 | ASSERT_LT(tab_index, browser()->tab_count()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 251 | ASSERT_EQ(tab_index, browser()->active_index()); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 252 | |
| 253 | // Inform our testing web page that we are about to start testing a key |
| 254 | // event. |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 255 | ASSERT_NO_FATAL_FAILURE(StartTest(tab_index, test.result_length)); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 256 | ASSERT_NO_FATAL_FAILURE(SuppressEvents( |
| 257 | tab_index, test.suppress_keydown, test.suppress_keypress, |
| 258 | test.suppress_keyup, test.suppress_textinput)); |
| 259 | |
| 260 | // We need to create a finish observer before sending the key event, |
| 261 | // because the test finished message might be arrived before returning |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 262 | // from the SendKeyPressSync() method. |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 263 | TestFinishObserver finish_observer( |
| 264 | browser()->GetTabContentsAt(tab_index)->render_view_host()); |
| 265 | |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 266 | ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 267 | browser(), test.key, test.ctrl, test.shift, test.alt, test.command)); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 268 | ASSERT_TRUE(finish_observer.WaitForFinish()); |
| 269 | ASSERT_NO_FATAL_FAILURE(CheckResult( |
| 270 | tab_index, test.result_length, test.result)); |
| 271 | } |
| 272 | |
| 273 | std::string GetTestDataDescription(const KeyEventTestData& data) { |
[email protected] | 1870d5cf | 2011-05-12 01:55:40 | [diff] [blame] | 274 | std::string desc = base::StringPrintf( |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 275 | " VKEY:0x%02x, ctrl:%d, shift:%d, alt:%d, command:%d\n" |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 276 | " Suppress: keydown:%d, keypress:%d, keyup:%d, textInput:%d\n" |
| 277 | " Expected results(%d):\n", |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 278 | data.key, data.ctrl, data.shift, data.alt, data.command, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 279 | data.suppress_keydown, data.suppress_keypress, data.suppress_keyup, |
| 280 | data.suppress_textinput, data.result_length); |
| 281 | for (int i = 0; i < data.result_length; ++i) { |
| 282 | desc.append(" "); |
| 283 | desc.append(data.result[i]); |
| 284 | desc.append("\n"); |
| 285 | } |
| 286 | return desc; |
| 287 | } |
| 288 | }; |
| 289 | |
[email protected] | cb93193 | 2011-05-03 19:57:33 | [diff] [blame] | 290 | #if defined(OS_MACOSX) |
[email protected] | 92c0174 | 2011-05-04 23:35:21 | [diff] [blame] | 291 | // http://crbug.com/81451 |
| 292 | IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, DISABLED_NormalKeyEvents) { |
[email protected] | cb93193 | 2011-05-03 19:57:33 | [diff] [blame] | 293 | #else |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 294 | IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, NormalKeyEvents) { |
[email protected] | cb93193 | 2011-05-03 19:57:33 | [diff] [blame] | 295 | #endif |
| 296 | |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 297 | static const KeyEventTestData kTestNoInput[] = { |
| 298 | // a |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 299 | { ui::VKEY_A, false, false, false, false, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 300 | false, false, false, false, 3, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 301 | { "D 65 0 false false false false", |
| 302 | "P 97 97 false false false false", |
| 303 | "U 65 0 false false false false" } }, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 304 | // shift-a |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 305 | { ui::VKEY_A, false, true, false, false, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 306 | false, false, false, false, 5, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 307 | { "D 16 0 false true false false", |
| 308 | "D 65 0 false true false false", |
| 309 | "P 65 65 false true false false", |
| 310 | "U 65 0 false true false false", |
| 311 | "U 16 0 false true false false" } }, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 312 | // a, suppress keydown |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 313 | { ui::VKEY_A, false, false, false, false, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 314 | true, false, false, false, 2, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 315 | { "D 65 0 false false false false", |
| 316 | "U 65 0 false false false false" } }, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 317 | }; |
| 318 | |
| 319 | static const KeyEventTestData kTestWithInput[] = { |
| 320 | // a |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 321 | { ui::VKEY_A, false, false, false, false, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 322 | false, false, false, false, 4, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 323 | { "D 65 0 false false false false", |
| 324 | "P 97 97 false false false false", |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 325 | "T a", |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 326 | "U 65 0 false false false false" } }, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 327 | // shift-a |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 328 | { ui::VKEY_A, false, true, false, false, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 329 | false, false, false, false, 6, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 330 | { "D 16 0 false true false false", |
| 331 | "D 65 0 false true false false", |
| 332 | "P 65 65 false true false false", |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 333 | "T A", |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 334 | "U 65 0 false true false false", |
| 335 | "U 16 0 false true false false" } }, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 336 | // a, suppress keydown |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 337 | { ui::VKEY_A, false, false, false, false, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 338 | true, false, false, false, 2, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 339 | { "D 65 0 false false false false", |
| 340 | "U 65 0 false false false false" } }, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 341 | // a, suppress keypress |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 342 | { ui::VKEY_A, false, false, false, false, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 343 | false, true, false, false, 3, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 344 | { "D 65 0 false false false false", |
| 345 | "P 97 97 false false false false", |
| 346 | "U 65 0 false false false false" } }, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 347 | // a, suppress textInput |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 348 | { ui::VKEY_A, false, false, false, false, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 349 | false, false, false, true, 4, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 350 | { "D 65 0 false false false false", |
| 351 | "P 97 97 false false false false", |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 352 | "T a", |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 353 | "U 65 0 false false false false" } }, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 354 | }; |
| 355 | |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 356 | ASSERT_TRUE(test_server()->Start()); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 357 | |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 358 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 359 | GURL url = test_server()->GetURL(kTestingPage); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 360 | ui_test_utils::NavigateToURL(browser(), url); |
| 361 | |
| 362 | ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); |
| 363 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 364 | |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 365 | int tab_index = browser()->active_index(); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 366 | for (size_t i = 0; i < arraysize(kTestNoInput); ++i) { |
| 367 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestNoInput[i])) |
| 368 | << "kTestNoInput[" << i << "] failed:\n" |
| 369 | << GetTestDataDescription(kTestNoInput[i]); |
| 370 | } |
| 371 | |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 372 | // Input in normal text box. |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 373 | ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"A")); |
| 374 | for (size_t i = 0; i < arraysize(kTestWithInput); ++i) { |
| 375 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestWithInput[i])) |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 376 | << "kTestWithInput[" << i << "] in text box failed:\n" |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 377 | << GetTestDataDescription(kTestWithInput[i]); |
| 378 | } |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 379 | EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, L"A", L"aA")); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 380 | |
| 381 | // Input in password box. |
| 382 | ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"B")); |
| 383 | for (size_t i = 0; i < arraysize(kTestWithInput); ++i) { |
| 384 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestWithInput[i])) |
| 385 | << "kTestWithInput[" << i << "] in password box failed:\n" |
| 386 | << GetTestDataDescription(kTestWithInput[i]); |
| 387 | } |
| 388 | EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, L"B", L"aA")); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 389 | } |
| 390 | |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 391 | #if defined(OS_WIN) || defined(OS_LINUX) |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 392 | IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, CtrlKeyEvents) { |
| 393 | static const KeyEventTestData kTestCtrlF = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 394 | ui::VKEY_F, true, false, false, false, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 395 | false, false, false, false, 2, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 396 | { "D 17 0 true false false false", |
| 397 | "D 70 0 true false false false" } |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 398 | }; |
| 399 | |
| 400 | static const KeyEventTestData kTestCtrlFSuppressKeyDown = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 401 | ui::VKEY_F, true, false, false, false, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 402 | true, false, false, false, 4, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 403 | { "D 17 0 true false false false", |
| 404 | "D 70 0 true false false false", |
| 405 | "U 70 0 true false false false", |
| 406 | "U 17 0 true false false false" } |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 407 | }; |
| 408 | |
| 409 | // Ctrl+Z doesn't bind to any accelerators, which then should generate a |
| 410 | // keypress event with charCode=26. |
| 411 | static const KeyEventTestData kTestCtrlZ = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 412 | ui::VKEY_Z, true, false, false, false, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 413 | false, false, false, false, 5, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 414 | { "D 17 0 true false false false", |
| 415 | "D 90 0 true false false false", |
| 416 | "P 26 26 true false false false", |
| 417 | "U 90 0 true false false false", |
| 418 | "U 17 0 true false false false" } |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 419 | }; |
| 420 | |
| 421 | static const KeyEventTestData kTestCtrlZSuppressKeyDown = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 422 | ui::VKEY_Z, true, false, false, false, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 423 | true, false, false, false, 4, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 424 | { "D 17 0 true false false false", |
| 425 | "D 90 0 true false false false", |
| 426 | "U 90 0 true false false false", |
| 427 | "U 17 0 true false false false" } |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 428 | }; |
| 429 | |
| 430 | // Ctrl+Enter shall generate a keypress event with charCode=10 (LF). |
| 431 | static const KeyEventTestData kTestCtrlEnter = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 432 | ui::VKEY_RETURN, true, false, false, false, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 433 | false, false, false, false, 5, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 434 | { "D 17 0 true false false false", |
| 435 | "D 13 0 true false false false", |
| 436 | "P 10 10 true false false false", |
| 437 | "U 13 0 true false false false", |
| 438 | "U 17 0 true false false false" } |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 439 | }; |
| 440 | |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 441 | ASSERT_TRUE(test_server()->Start()); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 442 | |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 443 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 444 | GURL url = test_server()->GetURL(kTestingPage); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 445 | ui_test_utils::NavigateToURL(browser(), url); |
| 446 | |
| 447 | ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); |
| 448 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 449 | |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 450 | int tab_index = browser()->active_index(); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 451 | // Press Ctrl+F, which will make the Find box open and request focus. |
| 452 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlF)); |
| 453 | EXPECT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
| 454 | |
| 455 | // Press Escape to close the Find box and move the focus back to the web page. |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 456 | ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 457 | browser(), ui::VKEY_ESCAPE, false, false, false, false)); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 458 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 459 | |
| 460 | // Press Ctrl+F with keydown suppressed shall not open the find box. |
| 461 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlFSuppressKeyDown)); |
| 462 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 463 | |
| 464 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlZ)); |
| 465 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlZSuppressKeyDown)); |
| 466 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlEnter)); |
| 467 | } |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 468 | #elif defined(OS_MACOSX) |
[email protected] | cb93193 | 2011-05-03 19:57:33 | [diff] [blame] | 469 | // http://crbug.com/81451 |
| 470 | IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, FLAKY_CommandKeyEvents) { |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 471 | static const KeyEventTestData kTestCmdF = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 472 | ui::VKEY_F, false, false, false, true, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 473 | false, false, false, false, 2, |
| 474 | { "D 91 0 false false false true", |
| 475 | "D 70 0 false false false true" } |
| 476 | }; |
| 477 | |
| 478 | // On Mac we don't send key up events when command modifier is down. |
| 479 | static const KeyEventTestData kTestCmdFSuppressKeyDown = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 480 | ui::VKEY_F, false, false, false, true, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 481 | true, false, false, false, 3, |
| 482 | { "D 91 0 false false false true", |
| 483 | "D 70 0 false false false true", |
| 484 | "U 91 0 false false false true" } |
| 485 | }; |
| 486 | |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 487 | ASSERT_TRUE(test_server()->Start()); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 488 | |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 489 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 490 | GURL url = test_server()->GetURL(kTestingPage); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 491 | ui_test_utils::NavigateToURL(browser(), url); |
| 492 | |
| 493 | ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); |
| 494 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 495 | |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 496 | int tab_index = browser()->active_index(); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 497 | // Press Cmd+F, which will make the Find box open and request focus. |
| 498 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCmdF)); |
| 499 | EXPECT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
| 500 | |
| 501 | // Press Escape to close the Find box and move the focus back to the web page. |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 502 | ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 503 | browser(), ui::VKEY_ESCAPE, false, false, false, false)); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 504 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 505 | |
| 506 | // Press Cmd+F with keydown suppressed shall not open the find box. |
| 507 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCmdFSuppressKeyDown)); |
| 508 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 509 | } |
| 510 | #endif |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 511 | |
[email protected] | cb93193 | 2011-05-03 19:57:33 | [diff] [blame] | 512 | // http://crbug.com/81451 |
| 513 | #if defined(OS_MACOSX) |
[email protected] | ce09a71 | 2011-05-05 22:31:51 | [diff] [blame] | 514 | IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, DISABLED_AccessKeys) { |
[email protected] | cb93193 | 2011-05-03 19:57:33 | [diff] [blame] | 515 | #else |
[email protected] | ce09a71 | 2011-05-05 22:31:51 | [diff] [blame] | 516 | IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, AccessKeys) { |
[email protected] | cb93193 | 2011-05-03 19:57:33 | [diff] [blame] | 517 | #endif |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 518 | #if defined(OS_MACOSX) |
| 519 | // On Mac, access keys use ctrl+alt modifiers. |
| 520 | static const KeyEventTestData kTestAccessA = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 521 | ui::VKEY_A, true, false, true, false, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 522 | false, false, false, false, 6, |
| 523 | { "D 17 0 true false false false", |
| 524 | "D 18 0 true false true false", |
| 525 | "D 65 0 true false true false", |
| 526 | "U 65 0 true false true false", |
| 527 | "U 18 0 true false true false", |
| 528 | "U 17 0 true false false false" } |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 529 | }; |
| 530 | |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 531 | static const KeyEventTestData kTestAccessDSuppress = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 532 | ui::VKEY_D, true, false, true, false, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 533 | true, true, true, false, 6, |
| 534 | { "D 17 0 true false false false", |
| 535 | "D 18 0 true false true false", |
| 536 | "D 68 0 true false true false", |
| 537 | "U 68 0 true false true false", |
| 538 | "U 18 0 true false true false", |
| 539 | "U 17 0 true false false false" } |
| 540 | }; |
| 541 | |
| 542 | static const KeyEventTestData kTestAccess1 = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 543 | ui::VKEY_1, true, false, true, false, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 544 | false, false, false, false, 6, |
| 545 | { "D 17 0 true false false false", |
| 546 | "D 18 0 true false true false", |
| 547 | "D 49 0 true false true false", |
| 548 | "U 49 0 true false true false", |
| 549 | "U 18 0 true false true false", |
| 550 | "U 17 0 true false false false" } |
| 551 | }; |
| 552 | #else |
| 553 | static const KeyEventTestData kTestAccessA = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 554 | ui::VKEY_A, false, false, true, false, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 555 | false, false, false, false, 4, |
| 556 | { "D 18 0 false false true false", |
| 557 | "D 65 0 false false true false", |
| 558 | "U 65 0 false false true false", |
| 559 | "U 18 0 false false true false" } |
| 560 | }; |
| 561 | |
| 562 | static const KeyEventTestData kTestAccessD = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 563 | ui::VKEY_D, false, false, true, false, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 564 | false, false, false, false, 2, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 565 | { "D 18 0 false false true false", |
| 566 | "D 68 0 false false true false" } |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 567 | }; |
| 568 | |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 569 | static const KeyEventTestData kTestAccessDSuppress = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 570 | ui::VKEY_D, false, false, true, false, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 571 | true, true, true, false, 4, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 572 | { "D 18 0 false false true false", |
| 573 | "D 68 0 false false true false", |
| 574 | "U 68 0 false false true false", |
| 575 | "U 18 0 false false true false" } |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 576 | }; |
| 577 | |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 578 | static const KeyEventTestData kTestAccess1 = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 579 | ui::VKEY_1, false, false, true, false, |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 580 | false, false, false, false, 4, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 581 | { "D 18 0 false false true false", |
| 582 | "D 49 0 false false true false", |
| 583 | "U 49 0 false false true false", |
| 584 | "U 18 0 false false true false" } |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 585 | }; |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 586 | #endif |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 587 | |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 588 | ASSERT_TRUE(test_server()->Start()); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 589 | |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 590 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 591 | GURL url = test_server()->GetURL(kTestingPage); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 592 | ui_test_utils::NavigateToURL(browser(), url); |
| 593 | |
[email protected] | f07d7bf | 2010-04-06 08:02:42 | [diff] [blame] | 594 | ui_test_utils::RunAllPendingInMessageLoop(); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 595 | ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); |
| 596 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 597 | |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 598 | int tab_index = browser()->active_index(); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 599 | // Make sure no element is focused. |
| 600 | EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); |
| 601 | // Alt+A should focus the element with accesskey = "A". |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 602 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccessA)); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 603 | EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"A")); |
| 604 | |
| 605 | // Blur the focused element. |
| 606 | EXPECT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"")); |
| 607 | // Make sure no element is focused. |
| 608 | EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 609 | |
| 610 | #if !defined(OS_MACOSX) |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 611 | // Alt+D should move the focus to the location entry. |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 612 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccessD)); |
[email protected] | 095b55f6 | 2010-09-24 08:06:04 | [diff] [blame] | 613 | |
| 614 | // TODO(isherman): This is an experimental change to help diagnose |
| 615 | // http://crbug.com/55713 |
| 616 | ui_test_utils::RunAllPendingInMessageLoop(); |
| 617 | |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 618 | EXPECT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
| 619 | // No element should be focused, as Alt+D was handled by the browser. |
| 620 | EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); |
| 621 | |
| 622 | // Move the focus back to the web page. |
| 623 | ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); |
| 624 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 625 | |
| 626 | // Make sure no element is focused. |
| 627 | EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 628 | #endif |
| 629 | |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 630 | // If the keydown event is suppressed, then Alt+D should be handled as an |
| 631 | // accesskey rather than an accelerator key. Activation of an accesskey is not |
| 632 | // a part of the default action of the key event, so it should not be |
| 633 | // suppressed at all. |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 634 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccessDSuppress)); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 635 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 636 | EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"D")); |
| 637 | |
| 638 | // Blur the focused element. |
| 639 | EXPECT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"")); |
| 640 | // Make sure no element is focused. |
| 641 | EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 642 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccess1)); |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 643 | #if defined(TOOLKIT_GTK) |
| 644 | // On GTK, alt-0..9 are assigned as tab selection accelerators, so they can |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 645 | // not be used as accesskeys. |
| 646 | EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 647 | #else |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 648 | EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"1")); |
| 649 | #endif |
| 650 | } |
| 651 | |
[email protected] | 6db9896 | 2011-10-04 22:42:49 | [diff] [blame] | 652 | // Flaky, http://crbug.com/69475. |
| 653 | #if defined(OS_LINUX) |
| 654 | #define MAYBE_ReservedAccelerators FLAKY_ReservedAccelerators |
| 655 | #else |
| 656 | #define MAYBE_ReservedAccelerators ReservedAccelerators |
| 657 | #endif |
| 658 | IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, MAYBE_ReservedAccelerators) { |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 659 | ASSERT_TRUE(test_server()->Start()); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 660 | |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 661 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 662 | GURL url = test_server()->GetURL(kTestingPage); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 663 | ui_test_utils::NavigateToURL(browser(), url); |
| 664 | |
| 665 | ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); |
| 666 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 667 | |
[email protected] | 0f72a2dc | 2010-12-06 19:40:23 | [diff] [blame] | 668 | ASSERT_EQ(1, browser()->tab_count()); |
| 669 | |
[email protected] | e4292a23 | 2010-12-11 01:46:41 | [diff] [blame] | 670 | static const KeyEventTestData kTestCtrlOrCmdT = { |
[email protected] | 3ab6796d3 | 2010-12-21 23:56:07 | [diff] [blame] | 671 | #if defined(OS_MACOSX) |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 672 | ui::VKEY_T, false, false, false, true, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 673 | true, false, false, false, 1, |
| 674 | { "D 91 0 false false false true" } |
[email protected] | 3ab6796d3 | 2010-12-21 23:56:07 | [diff] [blame] | 675 | #else |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 676 | ui::VKEY_T, true, false, false, false, |
[email protected] | 3ab6796d3 | 2010-12-21 23:56:07 | [diff] [blame] | 677 | true, false, false, false, 1, |
| 678 | { "D 17 0 true false false false" } |
[email protected] | e4292a23 | 2010-12-11 01:46:41 | [diff] [blame] | 679 | #endif |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 680 | }; |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 681 | |
[email protected] | 0f72a2dc | 2010-12-06 19:40:23 | [diff] [blame] | 682 | ui_test_utils::WindowedNotificationObserver wait_for_new_tab( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 683 | content::NOTIFICATION_TAB_PARENTED, |
[email protected] | 0f72a2dc | 2010-12-06 19:40:23 | [diff] [blame] | 684 | NotificationService::AllSources()); |
| 685 | |
[email protected] | e4292a23 | 2010-12-11 01:46:41 | [diff] [blame] | 686 | // Press Ctrl/Cmd+T, which will open a new tab. It cannot be suppressed. |
| 687 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlOrCmdT)); |
[email protected] | ae67374 | 2011-08-24 19:48:37 | [diff] [blame] | 688 | wait_for_new_tab.Wait(); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 689 | |
| 690 | int result_length; |
| 691 | ASSERT_NO_FATAL_FAILURE(GetResultLength(0, &result_length)); |
| 692 | EXPECT_EQ(1, result_length); |
| 693 | |
[email protected] | 0f72a2dc | 2010-12-06 19:40:23 | [diff] [blame] | 694 | EXPECT_EQ(2, browser()->tab_count()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 695 | ASSERT_EQ(1, browser()->active_index()); |
[email protected] | 0f72a2dc | 2010-12-06 19:40:23 | [diff] [blame] | 696 | |
| 697 | // Because of issue http://crbug.com/65375, switching back to the first tab |
| 698 | // may cause the focus to be grabbed by omnibox. So instead, we load our |
| 699 | // testing page in the newly created tab and try Cmd-W here. |
| 700 | ui_test_utils::NavigateToURL(browser(), url); |
| 701 | |
| 702 | // Make sure the focus is in the testing page. |
| 703 | ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); |
| 704 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 705 | |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 706 | // Reserved accelerators can't be suppressed. |
[email protected] | 0f72a2dc | 2010-12-06 19:40:23 | [diff] [blame] | 707 | ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(1, true)); |
| 708 | |
[email protected] | e4292a23 | 2010-12-11 01:46:41 | [diff] [blame] | 709 | ui_test_utils::WindowedNotificationObserver wait_for_tab_closed( |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame^] | 710 | content::NOTIFICATION_TAB_CLOSED, content::Source<NavigationController>( |
[email protected] | e4292a23 | 2010-12-11 01:46:41 | [diff] [blame] | 711 | &browser()->GetTabContentsAt(1)->controller())); |
| 712 | |
| 713 | // Press Ctrl/Cmd+W, which will close the tab. |
[email protected] | 3ab6796d3 | 2010-12-21 23:56:07 | [diff] [blame] | 714 | #if defined(OS_MACOSX) |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 715 | ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 716 | browser(), ui::VKEY_W, false, false, false, true)); |
[email protected] | 3ab6796d3 | 2010-12-21 23:56:07 | [diff] [blame] | 717 | #else |
| 718 | ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 719 | browser(), ui::VKEY_W, true, false, false, false)); |
[email protected] | e4292a23 | 2010-12-11 01:46:41 | [diff] [blame] | 720 | #endif |
| 721 | |
| 722 | ASSERT_NO_FATAL_FAILURE(wait_for_tab_closed.Wait()); |
| 723 | |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 724 | EXPECT_EQ(1, browser()->tab_count()); |
[email protected] | 21abcc74 | 2009-10-23 02:52:06 | [diff] [blame] | 725 | } |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 726 | |
| 727 | #if defined(OS_MACOSX) |
| 728 | IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, EditorKeyBindings) { |
| 729 | static const KeyEventTestData kTestCtrlA = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 730 | ui::VKEY_A, true, false, false, false, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 731 | false, false, false, false, 4, |
| 732 | { "D 17 0 true false false false", |
| 733 | "D 65 0 true false false false", |
| 734 | "U 65 0 true false false false", |
| 735 | "U 17 0 true false false false" } |
| 736 | }; |
| 737 | |
| 738 | static const KeyEventTestData kTestCtrlF = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 739 | ui::VKEY_F, true, false, false, false, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 740 | false, false, false, false, 4, |
| 741 | { "D 17 0 true false false false", |
| 742 | "D 70 0 true false false false", |
| 743 | "U 70 0 true false false false", |
| 744 | "U 17 0 true false false false" } |
| 745 | }; |
| 746 | |
| 747 | static const KeyEventTestData kTestCtrlK = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 748 | ui::VKEY_K, true, false, false, false, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 749 | false, false, false, false, 4, |
| 750 | { "D 17 0 true false false false", |
| 751 | "D 75 0 true false false false", |
| 752 | "U 75 0 true false false false", |
| 753 | "U 17 0 true false false false" } |
| 754 | }; |
| 755 | |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 756 | ASSERT_TRUE(test_server()->Start()); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 757 | |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 758 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 759 | GURL url = test_server()->GetURL(kTestingPage); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 760 | ui_test_utils::NavigateToURL(browser(), url); |
| 761 | |
| 762 | ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); |
| 763 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 764 | |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 765 | int tab_index = browser()->active_index(); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 766 | ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"A")); |
| 767 | ASSERT_NO_FATAL_FAILURE(SetTextBoxValue(tab_index, L"A", L"Hello")); |
| 768 | // Move the caret to the beginning of the line. |
| 769 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlA)); |
| 770 | // Forward one character |
| 771 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlF)); |
| 772 | // Delete to the end of the line. |
| 773 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlK)); |
| 774 | EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, L"A", L"H")); |
| 775 | } |
| 776 | #endif |
| 777 | |
| 778 | IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, PageUpDownKeys) { |
| 779 | static const KeyEventTestData kTestPageUp = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 780 | ui::VKEY_PRIOR, false, false, false, false, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 781 | false, false, false, false, 2, |
| 782 | { "D 33 0 false false false false", |
| 783 | "U 33 0 false false false false" } |
| 784 | }; |
| 785 | |
| 786 | static const KeyEventTestData kTestPageDown = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 787 | ui::VKEY_NEXT, false, false, false, false, |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 788 | false, false, false, false, 2, |
| 789 | { "D 34 0 false false false false", |
| 790 | "U 34 0 false false false false" } |
| 791 | }; |
| 792 | |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 793 | ASSERT_TRUE(test_server()->Start()); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 794 | |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 795 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 796 | GURL url = test_server()->GetURL(kTestingPage); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 797 | ui_test_utils::NavigateToURL(browser(), url); |
| 798 | |
| 799 | ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); |
| 800 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 801 | |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 802 | int tab_index = browser()->active_index(); |
[email protected] | 853300a8 | 2010-07-27 21:17:57 | [diff] [blame] | 803 | ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"A")); |
| 804 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestPageUp)); |
| 805 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestPageDown)); |
| 806 | EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, L"A", L"")); |
| 807 | } |
[email protected] | 629e034 | 2010-07-27 23:30:13 | [diff] [blame] | 808 | |
[email protected] | ee19cb20 | 2010-08-04 19:48:19 | [diff] [blame] | 809 | #if defined(OS_WIN) || defined(TOOLKIT_VIEWS) |
| 810 | IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, FocusMenuBarByAltKey) { |
| 811 | static const KeyEventTestData kTestAltKey = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 812 | ui::VKEY_MENU, false, false, false, false, |
[email protected] | ee19cb20 | 2010-08-04 19:48:19 | [diff] [blame] | 813 | false, false, false, false, 2, |
| 814 | { "D 18 0 false false true false", |
| 815 | "U 18 0 false false true false" } |
| 816 | }; |
| 817 | |
| 818 | static const KeyEventTestData kTestAltKeySuppress = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 819 | ui::VKEY_MENU, false, false, false, false, |
[email protected] | ee19cb20 | 2010-08-04 19:48:19 | [diff] [blame] | 820 | true, false, false, false, 2, |
| 821 | { "D 18 0 false false true false", |
| 822 | "U 18 0 false false true false" } |
| 823 | }; |
| 824 | |
| 825 | static const KeyEventTestData kTestCtrlAltKey = { |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 826 | ui::VKEY_MENU, true, false, false, false, |
[email protected] | ee19cb20 | 2010-08-04 19:48:19 | [diff] [blame] | 827 | false, false, false, false, 4, |
| 828 | { "D 17 0 true false false false", |
| 829 | "D 18 0 true false true false", |
| 830 | "U 18 0 true false true false", |
| 831 | "U 17 0 true false false false" } |
| 832 | }; |
| 833 | |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 834 | ASSERT_TRUE(test_server()->Start()); |
[email protected] | ee19cb20 | 2010-08-04 19:48:19 | [diff] [blame] | 835 | |
[email protected] | a6e602f | 2010-09-28 22:28:30 | [diff] [blame] | 836 | ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 837 | GURL url = test_server()->GetURL(kTestingPage); |
[email protected] | ee19cb20 | 2010-08-04 19:48:19 | [diff] [blame] | 838 | ui_test_utils::NavigateToURL(browser(), url); |
| 839 | |
| 840 | ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); |
| 841 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 842 | |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 843 | int tab_index = browser()->active_index(); |
[email protected] | ee19cb20 | 2010-08-04 19:48:19 | [diff] [blame] | 844 | // Press and release Alt key to focus wrench menu button. |
| 845 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltKey)); |
| 846 | EXPECT_TRUE(IsViewFocused(VIEW_ID_APP_MENU)); |
| 847 | |
| 848 | ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); |
| 849 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 850 | |
| 851 | // Alt key can be suppressed. |
| 852 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltKeySuppress)); |
| 853 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 854 | |
| 855 | // Ctrl+Alt should have no effect. |
| 856 | EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlAltKey)); |
| 857 | ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 858 | } |
| 859 | #endif |
| 860 | |
[email protected] | 629e034 | 2010-07-27 23:30:13 | [diff] [blame] | 861 | } // namespace |