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