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