OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "net/test/test_server.h" | 25 #include "net/test/test_server.h" |
26 #include "ui/base/keycodes/keyboard_codes.h" | 26 #include "ui/base/keycodes/keyboard_codes.h" |
27 | 27 |
28 using content::DomOperationNotificationDetails; | 28 using content::DomOperationNotificationDetails; |
29 using content::NavigationController; | 29 using content::NavigationController; |
30 using content::RenderViewHost; | 30 using content::RenderViewHost; |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 const char kTestingPage[] = "files/keyevents_test.html"; | 34 const char kTestingPage[] = "files/keyevents_test.html"; |
35 const wchar_t kSuppressEventJS[] = | 35 const char kSuppressEventJS[] = |
36 L"window.domAutomationController.send(setDefaultAction('%ls', %ls));"; | 36 "window.domAutomationController.send(setDefaultAction('%s', %s));"; |
37 const wchar_t kGetResultJS[] = | 37 const char kGetResultJS[] = |
38 L"window.domAutomationController.send(keyEventResult[%d]);"; | 38 "window.domAutomationController.send(keyEventResult[%d]);"; |
39 const wchar_t kGetResultLengthJS[] = | 39 const wchar_t kGetResultLengthJS[] = |
40 L"window.domAutomationController.send(keyEventResult.length);"; | 40 L"window.domAutomationController.send(keyEventResult.length);"; |
41 const wchar_t kGetFocusedElementJS[] = | 41 const wchar_t kGetFocusedElementJS[] = |
42 L"window.domAutomationController.send(focusedElement);"; | 42 L"window.domAutomationController.send(focusedElement);"; |
43 const wchar_t kSetFocusedElementJS[] = | 43 const char kSetFocusedElementJS[] = |
44 L"window.domAutomationController.send(setFocusedElement('%ls'));"; | 44 "window.domAutomationController.send(setFocusedElement('%s'));"; |
45 const wchar_t kGetTextBoxValueJS[] = | 45 const char kGetTextBoxValueJS[] = |
46 L"window.domAutomationController.send(" | 46 "window.domAutomationController.send(" |
47 L"document.getElementById('%ls').value);"; | 47 "document.getElementById('%s').value);"; |
48 const wchar_t kSetTextBoxValueJS[] = | 48 const char kSetTextBoxValueJS[] = |
49 L"window.domAutomationController.send(" | 49 "window.domAutomationController.send(" |
50 L"document.getElementById('%ls').value = '%ls');"; | 50 "document.getElementById('%s').value = '%s');"; |
51 const wchar_t kStartTestJS[] = | 51 const char kStartTestJS[] = |
52 L"window.domAutomationController.send(startTest(%d));"; | 52 "window.domAutomationController.send(startTest(%d));"; |
53 | 53 |
54 // Maximum lenght of the result array in KeyEventTestData structure. | 54 // Maximum lenght of the result array in KeyEventTestData structure. |
55 const size_t kMaxResultLength = 10; | 55 const size_t kMaxResultLength = 10; |
56 | 56 |
57 // A structure holding test data of a keyboard event. | 57 // A structure holding test data of a keyboard event. |
58 // Each keyboard event may generate multiple result strings representing | 58 // Each keyboard event may generate multiple result strings representing |
59 // the result of keydown, keypress, keyup and textInput events. | 59 // the result of keydown, keypress, keyup and textInput events. |
60 // For keydown, keypress and keyup events, the format of the result string is: | 60 // For keydown, keypress and keyup events, the format of the result string is: |
61 // <type> <keyCode> <charCode> <ctrlKey> <shiftKey> <altKey> <commandKey> | 61 // <type> <keyCode> <charCode> <ctrlKey> <shiftKey> <altKey> <commandKey> |
62 // where <type> may be 'D' (keydown), 'P' (keypress) or 'U' (keyup). | 62 // where <type> may be 'D' (keydown), 'P' (keypress) or 'U' (keyup). |
(...skipping 11 matching lines...) Expand all Loading... |
74 | 74 |
75 bool suppress_keydown; | 75 bool suppress_keydown; |
76 bool suppress_keypress; | 76 bool suppress_keypress; |
77 bool suppress_keyup; | 77 bool suppress_keyup; |
78 bool suppress_textinput; | 78 bool suppress_textinput; |
79 | 79 |
80 int result_length; | 80 int result_length; |
81 const char* const result[kMaxResultLength]; | 81 const char* const result[kMaxResultLength]; |
82 }; | 82 }; |
83 | 83 |
84 const wchar_t* GetBoolString(bool value) { | 84 const char* GetBoolString(bool value) { |
85 return value ? L"true" : L"false"; | 85 return value ? "true" : "false"; |
86 } | 86 } |
87 | 87 |
88 // A class to help wait for the finish of a key event test. | 88 // A class to help wait for the finish of a key event test. |
89 class TestFinishObserver : public content::NotificationObserver { | 89 class TestFinishObserver : public content::NotificationObserver { |
90 public: | 90 public: |
91 explicit TestFinishObserver(RenderViewHost* render_view_host) | 91 explicit TestFinishObserver(RenderViewHost* render_view_host) |
92 : finished_(false), waiting_(false) { | 92 : finished_(false), waiting_(false) { |
93 registrar_.Add(this, content::NOTIFICATION_DOM_OPERATION_RESPONSE, | 93 registrar_.Add(this, content::NOTIFICATION_DOM_OPERATION_RESPONSE, |
94 content::Source<RenderViewHost>(render_view_host)); | 94 content::Source<RenderViewHost>(render_view_host)); |
95 } | 95 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 return ui_test_utils::IsViewFocused(browser(), vid); | 135 return ui_test_utils::IsViewFocused(browser(), vid); |
136 } | 136 } |
137 | 137 |
138 void ClickOnView(ViewID vid) { | 138 void ClickOnView(ViewID vid) { |
139 ui_test_utils::ClickOnView(browser(), vid); | 139 ui_test_utils::ClickOnView(browser(), vid); |
140 } | 140 } |
141 | 141 |
142 // Set the suppress flag of an event specified by |type|. If |suppress| is | 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 | 143 // true then the web page will suppress all events with |type|. Following |
144 // event types are supported: keydown, keypress, keyup and textInput. | 144 // event types are supported: keydown, keypress, keyup and textInput. |
145 void SuppressEventByType(int tab_index, const wchar_t* type, bool suppress) { | 145 void SuppressEventByType(int tab_index, const char* type, bool suppress) { |
146 ASSERT_LT(tab_index, browser()->tab_count()); | 146 ASSERT_LT(tab_index, browser()->tab_count()); |
147 bool actual; | 147 bool actual; |
148 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 148 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
149 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), | 149 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), |
150 L"", | 150 L"", |
151 base::StringPrintf(kSuppressEventJS, type, GetBoolString(!suppress)), | 151 ASCIIToWide(base::StringPrintf(kSuppressEventJS, type, |
| 152 GetBoolString(!suppress))), |
152 &actual)); | 153 &actual)); |
153 ASSERT_EQ(!suppress, actual); | 154 ASSERT_EQ(!suppress, actual); |
154 } | 155 } |
155 | 156 |
156 void SuppressEvents(int tab_index, bool keydown, bool keypress, | 157 void SuppressEvents(int tab_index, bool keydown, bool keypress, |
157 bool keyup, bool textinput) { | 158 bool keyup, bool textinput) { |
158 ASSERT_NO_FATAL_FAILURE( | 159 ASSERT_NO_FATAL_FAILURE( |
159 SuppressEventByType(tab_index, L"keydown", keydown)); | 160 SuppressEventByType(tab_index, "keydown", keydown)); |
160 ASSERT_NO_FATAL_FAILURE( | 161 ASSERT_NO_FATAL_FAILURE( |
161 SuppressEventByType(tab_index, L"keypress", keypress)); | 162 SuppressEventByType(tab_index, "keypress", keypress)); |
162 ASSERT_NO_FATAL_FAILURE( | 163 ASSERT_NO_FATAL_FAILURE( |
163 SuppressEventByType(tab_index, L"keyup", keyup)); | 164 SuppressEventByType(tab_index, "keyup", keyup)); |
164 ASSERT_NO_FATAL_FAILURE( | 165 ASSERT_NO_FATAL_FAILURE( |
165 SuppressEventByType(tab_index, L"textInput", textinput)); | 166 SuppressEventByType(tab_index, "textInput", textinput)); |
166 } | 167 } |
167 | 168 |
168 void SuppressAllEvents(int tab_index, bool suppress) { | 169 void SuppressAllEvents(int tab_index, bool suppress) { |
169 SuppressEvents(tab_index, suppress, suppress, suppress, suppress); | 170 SuppressEvents(tab_index, suppress, suppress, suppress, suppress); |
170 } | 171 } |
171 | 172 |
172 void GetResultLength(int tab_index, int* length) { | 173 void GetResultLength(int tab_index, int* length) { |
173 ASSERT_LT(tab_index, browser()->tab_count()); | 174 ASSERT_LT(tab_index, browser()->tab_count()); |
174 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt( | 175 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt( |
175 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), | 176 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), |
176 L"", kGetResultLengthJS, length)); | 177 L"", kGetResultLengthJS, length)); |
177 } | 178 } |
178 | 179 |
179 void CheckResult(int tab_index, int length, const char* const result[]) { | 180 void CheckResult(int tab_index, int length, const char* const result[]) { |
180 ASSERT_LT(tab_index, browser()->tab_count()); | 181 ASSERT_LT(tab_index, browser()->tab_count()); |
181 int actual_length; | 182 int actual_length; |
182 ASSERT_NO_FATAL_FAILURE(GetResultLength(tab_index, &actual_length)); | 183 ASSERT_NO_FATAL_FAILURE(GetResultLength(tab_index, &actual_length)); |
183 ASSERT_GE(actual_length, length); | 184 ASSERT_GE(actual_length, length); |
184 for (int i = 0; i < actual_length; ++i) { | 185 for (int i = 0; i < actual_length; ++i) { |
185 std::string actual; | 186 std::string actual; |
186 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 187 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
187 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), | 188 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), |
188 L"", base::StringPrintf(kGetResultJS, i), &actual)); | 189 L"", ASCIIToWide(base::StringPrintf(kGetResultJS, i)), &actual)); |
189 | 190 |
190 // If more events were received than expected, then the additional events | 191 // If more events were received than expected, then the additional events |
191 // must be keyup events. | 192 // must be keyup events. |
192 if (i < length) | 193 if (i < length) |
193 ASSERT_STREQ(result[i], actual.c_str()); | 194 ASSERT_STREQ(result[i], actual.c_str()); |
194 else | 195 else |
195 ASSERT_EQ('U', actual[0]); | 196 ASSERT_EQ('U', actual[0]); |
196 } | 197 } |
197 } | 198 } |
198 | 199 |
199 void CheckFocusedElement(int tab_index, const wchar_t* focused) { | 200 void CheckFocusedElement(int tab_index, const wchar_t* focused) { |
200 ASSERT_LT(tab_index, browser()->tab_count()); | 201 ASSERT_LT(tab_index, browser()->tab_count()); |
201 std::string actual; | 202 std::string actual; |
202 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 203 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
203 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), | 204 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), |
204 L"", kGetFocusedElementJS, &actual)); | 205 L"", kGetFocusedElementJS, &actual)); |
205 ASSERT_EQ(WideToUTF8(focused), actual); | 206 ASSERT_EQ(WideToUTF8(focused), actual); |
206 } | 207 } |
207 | 208 |
208 void SetFocusedElement(int tab_index, const wchar_t* focused) { | 209 void SetFocusedElement(int tab_index, const char* focused) { |
209 ASSERT_LT(tab_index, browser()->tab_count()); | 210 ASSERT_LT(tab_index, browser()->tab_count()); |
210 bool actual; | 211 bool actual; |
211 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 212 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
212 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), | 213 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), |
213 L"", | 214 L"", |
214 base::StringPrintf(kSetFocusedElementJS, focused), | 215 ASCIIToWide(base::StringPrintf(kSetFocusedElementJS, focused)), |
215 &actual)); | 216 &actual)); |
216 ASSERT_TRUE(actual); | 217 ASSERT_TRUE(actual); |
217 } | 218 } |
218 | 219 |
219 void CheckTextBoxValue(int tab_index, const wchar_t* id, | 220 void CheckTextBoxValue(int tab_index, const char* id, |
220 const wchar_t* value) { | 221 const wchar_t* value) { |
221 ASSERT_LT(tab_index, browser()->tab_count()); | 222 ASSERT_LT(tab_index, browser()->tab_count()); |
222 std::string actual; | 223 std::string actual; |
223 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 224 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
224 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), | 225 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), |
225 L"", | 226 L"", |
226 base::StringPrintf(kGetTextBoxValueJS, id), | 227 ASCIIToWide(base::StringPrintf(kGetTextBoxValueJS, id)), |
227 &actual)); | 228 &actual)); |
228 ASSERT_EQ(WideToUTF8(value), actual); | 229 ASSERT_EQ(WideToUTF8(value), actual); |
229 } | 230 } |
230 | 231 |
231 void SetTextBoxValue(int tab_index, const wchar_t* id, | 232 void SetTextBoxValue(int tab_index, const char* id, |
232 const wchar_t* value) { | 233 const char* value) { |
233 ASSERT_LT(tab_index, browser()->tab_count()); | 234 ASSERT_LT(tab_index, browser()->tab_count()); |
234 std::string actual; | 235 std::string actual; |
235 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 236 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
236 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), | 237 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), |
237 L"", | 238 L"", |
238 base::StringPrintf(kSetTextBoxValueJS, id, value), | 239 ASCIIToWide(base::StringPrintf(kSetTextBoxValueJS, id, value)), |
239 &actual)); | 240 &actual)); |
240 ASSERT_EQ(WideToUTF8(value), actual); | 241 ASSERT_STREQ(value, actual.c_str()); |
241 } | 242 } |
242 | 243 |
243 void StartTest(int tab_index, int result_length) { | 244 void StartTest(int tab_index, int result_length) { |
244 ASSERT_LT(tab_index, browser()->tab_count()); | 245 ASSERT_LT(tab_index, browser()->tab_count()); |
245 bool actual; | 246 bool actual; |
246 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 247 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
247 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), | 248 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), |
248 L"", base::StringPrintf(kStartTestJS, result_length), &actual)); | 249 L"", ASCIIToWide(base::StringPrintf(kStartTestJS, result_length)), |
| 250 &actual)); |
249 ASSERT_TRUE(actual); | 251 ASSERT_TRUE(actual); |
250 } | 252 } |
251 | 253 |
252 void TestKeyEvent(int tab_index, const KeyEventTestData& test) { | 254 void TestKeyEvent(int tab_index, const KeyEventTestData& test) { |
253 ASSERT_LT(tab_index, browser()->tab_count()); | 255 ASSERT_LT(tab_index, browser()->tab_count()); |
254 ASSERT_EQ(tab_index, browser()->active_index()); | 256 ASSERT_EQ(tab_index, browser()->active_index()); |
255 | 257 |
256 // Inform our testing web page that we are about to start testing a key | 258 // Inform our testing web page that we are about to start testing a key |
257 // event. | 259 // event. |
258 ASSERT_NO_FATAL_FAILURE(StartTest(tab_index, test.result_length)); | 260 ASSERT_NO_FATAL_FAILURE(StartTest(tab_index, test.result_length)); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 372 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
371 | 373 |
372 int tab_index = browser()->active_index(); | 374 int tab_index = browser()->active_index(); |
373 for (size_t i = 0; i < arraysize(kTestNoInput); ++i) { | 375 for (size_t i = 0; i < arraysize(kTestNoInput); ++i) { |
374 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestNoInput[i])) | 376 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestNoInput[i])) |
375 << "kTestNoInput[" << i << "] failed:\n" | 377 << "kTestNoInput[" << i << "] failed:\n" |
376 << GetTestDataDescription(kTestNoInput[i]); | 378 << GetTestDataDescription(kTestNoInput[i]); |
377 } | 379 } |
378 | 380 |
379 // Input in normal text box. | 381 // Input in normal text box. |
380 ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"A")); | 382 ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, "A")); |
381 for (size_t i = 0; i < arraysize(kTestWithInput); ++i) { | 383 for (size_t i = 0; i < arraysize(kTestWithInput); ++i) { |
382 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestWithInput[i])) | 384 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestWithInput[i])) |
383 << "kTestWithInput[" << i << "] in text box failed:\n" | 385 << "kTestWithInput[" << i << "] in text box failed:\n" |
384 << GetTestDataDescription(kTestWithInput[i]); | 386 << GetTestDataDescription(kTestWithInput[i]); |
385 } | 387 } |
386 EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, L"A", L"aA")); | 388 EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, "A", L"aA")); |
387 | 389 |
388 // Input in password box. | 390 // Input in password box. |
389 ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"B")); | 391 ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, "B")); |
390 for (size_t i = 0; i < arraysize(kTestWithInput); ++i) { | 392 for (size_t i = 0; i < arraysize(kTestWithInput); ++i) { |
391 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestWithInput[i])) | 393 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestWithInput[i])) |
392 << "kTestWithInput[" << i << "] in password box failed:\n" | 394 << "kTestWithInput[" << i << "] in password box failed:\n" |
393 << GetTestDataDescription(kTestWithInput[i]); | 395 << GetTestDataDescription(kTestWithInput[i]); |
394 } | 396 } |
395 EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, L"B", L"aA")); | 397 EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, "B", L"aA")); |
396 } | 398 } |
397 | 399 |
398 #if defined(OS_WIN) || defined(OS_LINUX) | 400 #if defined(OS_WIN) || defined(OS_LINUX) |
399 | 401 |
400 #if defined(OS_LINUX) | 402 #if defined(OS_LINUX) |
401 // http://crbug.com/129235 | 403 // http://crbug.com/129235 |
402 #define MAYBE_CtrlKeyEvents FAILS_CtrlKeyEvents | 404 #define MAYBE_CtrlKeyEvents FAILS_CtrlKeyEvents |
403 #else | 405 #else |
404 #define MAYBE_CtrlKeyEvents CtrlKeyEvents | 406 #define MAYBE_CtrlKeyEvents CtrlKeyEvents |
405 #endif | 407 #endif |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 620 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
619 | 621 |
620 int tab_index = browser()->active_index(); | 622 int tab_index = browser()->active_index(); |
621 // Make sure no element is focused. | 623 // Make sure no element is focused. |
622 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); | 624 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); |
623 // Alt+A should focus the element with accesskey = "A". | 625 // Alt+A should focus the element with accesskey = "A". |
624 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccessA)); | 626 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccessA)); |
625 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"A")); | 627 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"A")); |
626 | 628 |
627 // Blur the focused element. | 629 // Blur the focused element. |
628 EXPECT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"")); | 630 EXPECT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, "")); |
629 // Make sure no element is focused. | 631 // Make sure no element is focused. |
630 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); | 632 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); |
631 | 633 |
632 #if !defined(OS_MACOSX) | 634 #if !defined(OS_MACOSX) |
633 // Alt+D should move the focus to the location entry. | 635 // Alt+D should move the focus to the location entry. |
634 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccessD)); | 636 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccessD)); |
635 | 637 |
636 // TODO(isherman): This is an experimental change to help diagnose | 638 // TODO(isherman): This is an experimental change to help diagnose |
637 // http://crbug.com/55713 | 639 // http://crbug.com/55713 |
638 ui_test_utils::RunAllPendingInMessageLoop(); | 640 ui_test_utils::RunAllPendingInMessageLoop(); |
(...skipping 15 matching lines...) Expand all Loading... |
654 | 656 |
655 // If the keydown event is suppressed, then Alt+D should be handled as an | 657 // 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 | 658 // 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 | 659 // a part of the default action of the key event, so it should not be |
658 // suppressed at all. | 660 // suppressed at all. |
659 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccessDSuppress)); | 661 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccessDSuppress)); |
660 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 662 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
661 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"D")); | 663 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"D")); |
662 | 664 |
663 // Blur the focused element. | 665 // Blur the focused element. |
664 EXPECT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"")); | 666 EXPECT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, "")); |
665 // Make sure no element is focused. | 667 // Make sure no element is focused. |
666 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); | 668 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); |
667 #if !defined(USE_ASH) | 669 #if !defined(USE_ASH) |
668 // On Ash, alt-1..9 are assigned as window selection global accelerators, so | 670 // On Ash, alt-1..9 are assigned as window selection global accelerators, so |
669 // they can not be used as accesskeys. | 671 // they can not be used as accesskeys. |
670 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccess1)); | 672 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccess1)); |
671 #if defined(TOOLKIT_GTK) | 673 #if defined(TOOLKIT_GTK) |
672 // On GTK, alt-0..9 are assigned as tab selection accelerators, so they can | 674 // On GTK, alt-0..9 are assigned as tab selection accelerators, so they can |
673 // not be used as accesskeys. | 675 // not be used as accesskeys. |
674 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); | 676 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 ASSERT_TRUE(test_server()->Start()); | 787 ASSERT_TRUE(test_server()->Start()); |
786 | 788 |
787 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 789 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
788 GURL url = test_server()->GetURL(kTestingPage); | 790 GURL url = test_server()->GetURL(kTestingPage); |
789 ui_test_utils::NavigateToURL(browser(), url); | 791 ui_test_utils::NavigateToURL(browser(), url); |
790 | 792 |
791 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); | 793 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); |
792 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 794 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
793 | 795 |
794 int tab_index = browser()->active_index(); | 796 int tab_index = browser()->active_index(); |
795 ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"A")); | 797 ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, "A")); |
796 ASSERT_NO_FATAL_FAILURE(SetTextBoxValue(tab_index, L"A", L"Hello")); | 798 ASSERT_NO_FATAL_FAILURE(SetTextBoxValue(tab_index, "A", "Hello")); |
797 // Move the caret to the beginning of the line. | 799 // Move the caret to the beginning of the line. |
798 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlA)); | 800 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlA)); |
799 // Forward one character | 801 // Forward one character |
800 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlF)); | 802 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlF)); |
801 // Delete to the end of the line. | 803 // Delete to the end of the line. |
802 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlK)); | 804 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlK)); |
803 EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, L"A", L"H")); | 805 EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, "A", L"H")); |
804 } | 806 } |
805 #endif | 807 #endif |
806 | 808 |
807 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, PageUpDownKeys) { | 809 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, PageUpDownKeys) { |
808 static const KeyEventTestData kTestPageUp = { | 810 static const KeyEventTestData kTestPageUp = { |
809 ui::VKEY_PRIOR, false, false, false, false, | 811 ui::VKEY_PRIOR, false, false, false, false, |
810 false, false, false, false, 2, | 812 false, false, false, false, 2, |
811 { "D 33 0 false false false false", | 813 { "D 33 0 false false false false", |
812 "U 33 0 false false false false" } | 814 "U 33 0 false false false false" } |
813 }; | 815 }; |
814 | 816 |
815 static const KeyEventTestData kTestPageDown = { | 817 static const KeyEventTestData kTestPageDown = { |
816 ui::VKEY_NEXT, false, false, false, false, | 818 ui::VKEY_NEXT, false, false, false, false, |
817 false, false, false, false, 2, | 819 false, false, false, false, 2, |
818 { "D 34 0 false false false false", | 820 { "D 34 0 false false false false", |
819 "U 34 0 false false false false" } | 821 "U 34 0 false false false false" } |
820 }; | 822 }; |
821 | 823 |
822 ASSERT_TRUE(test_server()->Start()); | 824 ASSERT_TRUE(test_server()->Start()); |
823 | 825 |
824 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 826 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
825 GURL url = test_server()->GetURL(kTestingPage); | 827 GURL url = test_server()->GetURL(kTestingPage); |
826 ui_test_utils::NavigateToURL(browser(), url); | 828 ui_test_utils::NavigateToURL(browser(), url); |
827 | 829 |
828 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); | 830 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); |
829 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 831 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
830 | 832 |
831 int tab_index = browser()->active_index(); | 833 int tab_index = browser()->active_index(); |
832 ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"A")); | 834 ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, "A")); |
833 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestPageUp)); | 835 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestPageUp)); |
834 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestPageDown)); | 836 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestPageDown)); |
835 EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, L"A", L"")); | 837 EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, "A", L"")); |
836 } | 838 } |
837 | 839 |
838 #if defined(OS_WIN) | 840 #if defined(OS_WIN) |
839 // AltKey is enabled only on Windows. See crbug.com/114537. | 841 // AltKey is enabled only on Windows. See crbug.com/114537. |
840 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, FocusMenuBarByAltKey) { | 842 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, FocusMenuBarByAltKey) { |
841 static const KeyEventTestData kTestAltKey = { | 843 static const KeyEventTestData kTestAltKey = { |
842 ui::VKEY_MENU, false, false, false, false, | 844 ui::VKEY_MENU, false, false, false, false, |
843 false, false, false, false, 2, | 845 false, false, false, false, 2, |
844 { "D 18 0 false false true false", | 846 { "D 18 0 false false true false", |
845 "U 18 0 false false true false" } | 847 "U 18 0 false false true false" } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltKeySuppress)); | 884 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltKeySuppress)); |
883 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 885 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
884 | 886 |
885 // Ctrl+Alt should have no effect. | 887 // Ctrl+Alt should have no effect. |
886 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlAltKey)); | 888 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlAltKey)); |
887 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 889 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
888 } | 890 } |
889 #endif | 891 #endif |
890 | 892 |
891 } // namespace | 893 } // namespace |
OLD | NEW |