Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: chrome/browser/browser_keyevents_browsertest.cc

Issue 2986004: [Mac]Port browser_keyevents_browsertest.cc and browser_focus_uitest.cc to Mac. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Enable BrowserFocusTest and BrowserKeyEventsTests on Mac. Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/browser_focus_uitest.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "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/keyboard_codes.h" 8 #include "base/keyboard_codes.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 23 matching lines...) Expand all
34 L"window.domAutomationController.send(keyEventResult[%d]);"; 34 L"window.domAutomationController.send(keyEventResult[%d]);";
35 const wchar_t kGetResultLengthJS[] = 35 const wchar_t kGetResultLengthJS[] =
36 L"window.domAutomationController.send(keyEventResult.length);"; 36 L"window.domAutomationController.send(keyEventResult.length);";
37 const wchar_t kGetFocusedElementJS[] = 37 const wchar_t kGetFocusedElementJS[] =
38 L"window.domAutomationController.send(focusedElement);"; 38 L"window.domAutomationController.send(focusedElement);";
39 const wchar_t kSetFocusedElementJS[] = 39 const wchar_t kSetFocusedElementJS[] =
40 L"window.domAutomationController.send(setFocusedElement('%ls'));"; 40 L"window.domAutomationController.send(setFocusedElement('%ls'));";
41 const wchar_t kGetTextBoxValueJS[] = 41 const wchar_t kGetTextBoxValueJS[] =
42 L"window.domAutomationController.send(" 42 L"window.domAutomationController.send("
43 L"document.getElementById('%ls').value);"; 43 L"document.getElementById('%ls').value);";
44 const wchar_t kSetTextBoxValueJS[] =
45 L"window.domAutomationController.send("
46 L"document.getElementById('%ls').value = '%ls');";
44 const wchar_t kStartTestJS[] = 47 const wchar_t kStartTestJS[] =
45 L"window.domAutomationController.send(startTest());"; 48 L"window.domAutomationController.send(startTest(%d));";
46 49
47 // Maximum lenght of the result array in KeyEventTestData structure. 50 // Maximum lenght of the result array in KeyEventTestData structure.
48 const size_t kMaxResultLength = 10; 51 const size_t kMaxResultLength = 10;
49 52
50 // A structure holding test data of a keyboard event. 53 // A structure holding test data of a keyboard event.
51 // Each keyboard event may generate multiple result strings representing 54 // Each keyboard event may generate multiple result strings representing
52 // the result of keydown, keypress, keyup and textInput events. 55 // the result of keydown, keypress, keyup and textInput events.
53 // For keydown, keypress and keyup events, the format of the result string is: 56 // For keydown, keypress and keyup events, the format of the result string is:
54 // <type> <keyCode> <charCode> <ctrlKey> <shiftKey> <altKey> 57 // <type> <keyCode> <charCode> <ctrlKey> <shiftKey> <altKey> <commandKey>
55 // where <type> may be 'D' (keydown), 'P' (keypress) or 'U' (keyup). 58 // where <type> may be 'D' (keydown), 'P' (keypress) or 'U' (keyup).
56 // <ctrlKey>, <shiftKey> and <altKey> are boolean value indicating the state of 59 // <ctrlKey>, <shiftKey> <altKey> and <commandKey> are boolean value indicating
57 // corresponding modifier key. 60 // the state of corresponding modifier key.
58 // For textInput event, the format is: T <text>, where <text> is the text to be 61 // For textInput event, the format is: T <text>, where <text> is the text to be
59 // input. 62 // input.
60 // Please refer to chrome/test/data/keyevents_test.html for details. 63 // Please refer to chrome/test/data/keyevents_test.html for details.
61 struct KeyEventTestData { 64 struct KeyEventTestData {
62 base::KeyboardCode key; 65 base::KeyboardCode key;
63 bool ctrl; 66 bool ctrl;
64 bool shift; 67 bool shift;
65 bool alt; 68 bool alt;
69 bool command;
66 70
67 bool suppress_keydown; 71 bool suppress_keydown;
68 bool suppress_keypress; 72 bool suppress_keypress;
69 bool suppress_keyup; 73 bool suppress_keyup;
70 bool suppress_textinput; 74 bool suppress_textinput;
71 75
72 int result_length; 76 int result_length;
73 const char* const result[kMaxResultLength]; 77 const char* const result[kMaxResultLength];
74 }; 78 };
75 79
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 EnableDOMAutomation(); 128 EnableDOMAutomation();
125 } 129 }
126 130
127 void GetNativeWindow(gfx::NativeWindow* native_window) { 131 void GetNativeWindow(gfx::NativeWindow* native_window) {
128 BrowserWindow* window = browser()->window(); 132 BrowserWindow* window = browser()->window();
129 ASSERT_TRUE(window); 133 ASSERT_TRUE(window);
130 *native_window = window->GetNativeHandle(); 134 *native_window = window->GetNativeHandle();
131 ASSERT_TRUE(*native_window); 135 ASSERT_TRUE(*native_window);
132 } 136 }
133 137
134 void SendKey(base::KeyboardCode key, bool control, bool shift, bool alt) { 138 void BringBrowserWindowToFront() {
139 gfx::NativeWindow window = NULL;
140 ASSERT_NO_FATAL_FAILURE(GetNativeWindow(&window));
141 ui_test_utils::ShowAndFocusNativeWindow(window);
142 }
143
144 void SendKey(base::KeyboardCode key,
145 bool control,
146 bool shift,
147 bool alt,
148 bool command) {
135 gfx::NativeWindow window = NULL; 149 gfx::NativeWindow window = NULL;
136 ASSERT_NO_FATAL_FAILURE(GetNativeWindow(&window)); 150 ASSERT_NO_FATAL_FAILURE(GetNativeWindow(&window));
137 EXPECT_TRUE(ui_controls::SendKeyPressNotifyWhenDone( 151 EXPECT_TRUE(ui_controls::SendKeyPressNotifyWhenDone(
138 window, key, control, shift, alt, 152 window, key, control, shift, alt, command,
139 false /* command, */,
140 new MessageLoop::QuitTask())); 153 new MessageLoop::QuitTask()));
141 ui_test_utils::RunMessageLoop(); 154 ui_test_utils::RunMessageLoop();
142 } 155 }
143 156
144 bool IsViewFocused(ViewID vid) { 157 bool IsViewFocused(ViewID vid) {
145 return ui_test_utils::IsViewFocused(browser(), vid); 158 return ui_test_utils::IsViewFocused(browser(), vid);
146 } 159 }
147 160
148 void ClickOnView(ViewID vid) { 161 void ClickOnView(ViewID vid) {
149 ui_test_utils::ClickOnView(browser(), vid); 162 ui_test_utils::ClickOnView(browser(), vid);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 ASSERT_LT(tab_index, browser()->tab_count()); 244 ASSERT_LT(tab_index, browser()->tab_count());
232 std::string actual; 245 std::string actual;
233 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 246 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
234 browser()->GetTabContentsAt(tab_index)->render_view_host(), 247 browser()->GetTabContentsAt(tab_index)->render_view_host(),
235 L"", 248 L"",
236 StringPrintf(kGetTextBoxValueJS, id), 249 StringPrintf(kGetTextBoxValueJS, id),
237 &actual)); 250 &actual));
238 ASSERT_EQ(WideToUTF8(value), actual); 251 ASSERT_EQ(WideToUTF8(value), actual);
239 } 252 }
240 253
241 void StartTest(int tab_index) { 254 void SetTextBoxValue(int tab_index, const wchar_t* id,
255 const wchar_t* value) {
256 ASSERT_LT(tab_index, browser()->tab_count());
257 std::string actual;
258 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
259 browser()->GetTabContentsAt(tab_index)->render_view_host(),
260 L"",
261 StringPrintf(kSetTextBoxValueJS, id, value),
262 &actual));
263 ASSERT_EQ(WideToUTF8(value), actual);
264 }
265
266 void StartTest(int tab_index, int result_length) {
242 ASSERT_LT(tab_index, browser()->tab_count()); 267 ASSERT_LT(tab_index, browser()->tab_count());
243 bool actual; 268 bool actual;
244 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 269 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
245 browser()->GetTabContentsAt(tab_index)->render_view_host(), 270 browser()->GetTabContentsAt(tab_index)->render_view_host(),
246 L"", kStartTestJS, &actual)); 271 L"", StringPrintf(kStartTestJS, result_length), &actual));
247 ASSERT_TRUE(actual); 272 ASSERT_TRUE(actual);
248 } 273 }
249 274
250 void TestKeyEvent(int tab_index, const KeyEventTestData& test) { 275 void TestKeyEvent(int tab_index, const KeyEventTestData& test) {
251 ASSERT_LT(tab_index, browser()->tab_count()); 276 ASSERT_LT(tab_index, browser()->tab_count());
252 ASSERT_EQ(tab_index, browser()->selected_index()); 277 ASSERT_EQ(tab_index, browser()->selected_index());
253 278
254 // Inform our testing web page that we are about to start testing a key 279 // Inform our testing web page that we are about to start testing a key
255 // event. 280 // event.
256 ASSERT_NO_FATAL_FAILURE(StartTest(tab_index)); 281 ASSERT_NO_FATAL_FAILURE(StartTest(tab_index, test.result_length));
257 ASSERT_NO_FATAL_FAILURE(SuppressEvents( 282 ASSERT_NO_FATAL_FAILURE(SuppressEvents(
258 tab_index, test.suppress_keydown, test.suppress_keypress, 283 tab_index, test.suppress_keydown, test.suppress_keypress,
259 test.suppress_keyup, test.suppress_textinput)); 284 test.suppress_keyup, test.suppress_textinput));
260 285
261 // We need to create a finish observer before sending the key event, 286 // We need to create a finish observer before sending the key event,
262 // because the test finished message might be arrived before returning 287 // because the test finished message might be arrived before returning
263 // from the SendKey() method. 288 // from the SendKey() method.
264 TestFinishObserver finish_observer( 289 TestFinishObserver finish_observer(
265 browser()->GetTabContentsAt(tab_index)->render_view_host()); 290 browser()->GetTabContentsAt(tab_index)->render_view_host());
266 291
267 ASSERT_NO_FATAL_FAILURE(SendKey(test.key, test.ctrl, test.shift, test.alt)); 292 ASSERT_NO_FATAL_FAILURE(
293 SendKey(test.key, test.ctrl, test.shift, test.alt, test.command));
268 ASSERT_TRUE(finish_observer.WaitForFinish()); 294 ASSERT_TRUE(finish_observer.WaitForFinish());
269 ASSERT_NO_FATAL_FAILURE(CheckResult( 295 ASSERT_NO_FATAL_FAILURE(CheckResult(
270 tab_index, test.result_length, test.result)); 296 tab_index, test.result_length, test.result));
271 } 297 }
272 298
273 std::string GetTestDataDescription(const KeyEventTestData& data) { 299 std::string GetTestDataDescription(const KeyEventTestData& data) {
274 std::string desc = StringPrintf( 300 std::string desc = StringPrintf(
275 " VKEY:0x%02x, ctrl:%d, shift:%d, alt:%d\n" 301 " VKEY:0x%02x, ctrl:%d, shift:%d, alt:%d, command:%d\n"
276 " Suppress: keydown:%d, keypress:%d, keyup:%d, textInput:%d\n" 302 " Suppress: keydown:%d, keypress:%d, keyup:%d, textInput:%d\n"
277 " Expected results(%d):\n", 303 " Expected results(%d):\n",
278 data.key, data.ctrl, data.shift, data.alt, 304 data.key, data.ctrl, data.shift, data.alt, data.command,
279 data.suppress_keydown, data.suppress_keypress, data.suppress_keyup, 305 data.suppress_keydown, data.suppress_keypress, data.suppress_keyup,
280 data.suppress_textinput, data.result_length); 306 data.suppress_textinput, data.result_length);
281 for (int i = 0; i < data.result_length; ++i) { 307 for (int i = 0; i < data.result_length; ++i) {
282 desc.append(" "); 308 desc.append(" ");
283 desc.append(data.result[i]); 309 desc.append(data.result[i]);
284 desc.append("\n"); 310 desc.append("\n");
285 } 311 }
286 return desc; 312 return desc;
287 } 313 }
288 }; 314 };
289 315
290 } // namespace 316 } // namespace
291 317
292 // Flaky since r51395. See crbug.com/48671. 318 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, NormalKeyEvents) {
293 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, FLAKY_NormalKeyEvents) {
294 static const KeyEventTestData kTestNoInput[] = { 319 static const KeyEventTestData kTestNoInput[] = {
295 // a 320 // a
296 { base::VKEY_A, false, false, false, 321 { base::VKEY_A, false, false, false, false,
297 false, false, false, false, 3, 322 false, false, false, false, 3,
298 { "D 65 0 false false false", 323 { "D 65 0 false false false false",
299 "P 97 97 false false false", 324 "P 97 97 false false false false",
300 "U 65 0 false false false" } }, 325 "U 65 0 false false false false" } },
301 // shift-a 326 // shift-a
302 { base::VKEY_A, false, true, false, 327 { base::VKEY_A, false, true, false, false,
303 false, false, false, false, 5, 328 false, false, false, false, 5,
304 { "D 16 0 false true false", 329 { "D 16 0 false true false false",
305 "D 65 0 false true false", 330 "D 65 0 false true false false",
306 "P 65 65 false true false", 331 "P 65 65 false true false false",
307 "U 65 0 false true false", 332 "U 65 0 false true false false",
308 "U 16 0 false true false" } }, 333 "U 16 0 false true false false" } },
309 // a, suppress keydown 334 // a, suppress keydown
310 { base::VKEY_A, false, false, false, 335 { base::VKEY_A, false, false, false, false,
311 true, false, false, false, 2, 336 true, false, false, false, 2,
312 { "D 65 0 false false false", 337 { "D 65 0 false false false false",
313 "U 65 0 false false false" } }, 338 "U 65 0 false false false false" } },
314 }; 339 };
315 340
316 static const KeyEventTestData kTestWithInput[] = { 341 static const KeyEventTestData kTestWithInput[] = {
317 // a 342 // a
318 { base::VKEY_A, false, false, false, 343 { base::VKEY_A, false, false, false, false,
319 false, false, false, false, 4, 344 false, false, false, false, 4,
320 { "D 65 0 false false false", 345 { "D 65 0 false false false false",
321 "P 97 97 false false false", 346 "P 97 97 false false false false",
322 "T a", 347 "T a",
323 "U 65 0 false false false" } }, 348 "U 65 0 false false false false" } },
324 // shift-a 349 // shift-a
325 { base::VKEY_A, false, true, false, 350 { base::VKEY_A, false, true, false, false,
326 false, false, false, false, 6, 351 false, false, false, false, 6,
327 { "D 16 0 false true false", 352 { "D 16 0 false true false false",
328 "D 65 0 false true false", 353 "D 65 0 false true false false",
329 "P 65 65 false true false", 354 "P 65 65 false true false false",
330 "T A", 355 "T A",
331 "U 65 0 false true false", 356 "U 65 0 false true false false",
332 "U 16 0 false true false" } }, 357 "U 16 0 false true false false" } },
333 // a, suppress keydown 358 // a, suppress keydown
334 { base::VKEY_A, false, false, false, 359 { base::VKEY_A, false, false, false, false,
335 true, false, false, false, 2, 360 true, false, false, false, 2,
336 { "D 65 0 false false false", 361 { "D 65 0 false false false false",
337 "U 65 0 false false false" } }, 362 "U 65 0 false false false false" } },
338 // a, suppress keypress 363 // a, suppress keypress
339 { base::VKEY_A, false, false, false, 364 { base::VKEY_A, false, false, false, false,
340 false, true, false, false, 3, 365 false, true, false, false, 3,
341 { "D 65 0 false false false", 366 { "D 65 0 false false false false",
342 "P 97 97 false false false", 367 "P 97 97 false false false false",
343 "U 65 0 false false false" } }, 368 "U 65 0 false false false false" } },
344 // a, suppress textInput 369 // a, suppress textInput
345 { base::VKEY_A, false, false, false, 370 { base::VKEY_A, false, false, false, false,
346 false, false, false, true, 4, 371 false, false, false, true, 4,
347 { "D 65 0 false false false", 372 { "D 65 0 false false false false",
348 "P 97 97 false false false", 373 "P 97 97 false false false false",
349 "T a", 374 "T a",
350 "U 65 0 false false false" } }, 375 "U 65 0 false false false false" } },
351 }; 376 };
352 377
353 HTTPTestServer* server = StartHTTPServer(); 378 HTTPTestServer* server = StartHTTPServer();
379 ASSERT_TRUE(server);
354 380
381 BringBrowserWindowToFront();
355 GURL url = server->TestServerPage(kTestingPage); 382 GURL url = server->TestServerPage(kTestingPage);
356 ui_test_utils::NavigateToURL(browser(), url); 383 ui_test_utils::NavigateToURL(browser(), url);
357 384
358 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); 385 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
359 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 386 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
360 387
361 int tab_index = browser()->selected_index(); 388 int tab_index = browser()->selected_index();
362 for (size_t i = 0; i < arraysize(kTestNoInput); ++i) { 389 for (size_t i = 0; i < arraysize(kTestNoInput); ++i) {
363 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestNoInput[i])) 390 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestNoInput[i]))
364 << "kTestNoInput[" << i << "] failed:\n" 391 << "kTestNoInput[" << i << "] failed:\n"
365 << GetTestDataDescription(kTestNoInput[i]); 392 << GetTestDataDescription(kTestNoInput[i]);
366 } 393 }
367 394
395 // Input in normal text box.
368 ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"A")); 396 ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"A"));
369 for (size_t i = 0; i < arraysize(kTestWithInput); ++i) { 397 for (size_t i = 0; i < arraysize(kTestWithInput); ++i) {
370 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestWithInput[i])) 398 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestWithInput[i]))
371 << "kTestWithInput[" << i << "] failed:\n" 399 << "kTestWithInput[" << i << "] in text box failed:\n"
372 << GetTestDataDescription(kTestWithInput[i]); 400 << GetTestDataDescription(kTestWithInput[i]);
373 } 401 }
402 EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, L"A", L"aA"));
374 403
375 EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, L"A", L"aA")); 404 // Input in password box.
405 ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"B"));
406 for (size_t i = 0; i < arraysize(kTestWithInput); ++i) {
407 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestWithInput[i]))
408 << "kTestWithInput[" << i << "] in password box failed:\n"
409 << GetTestDataDescription(kTestWithInput[i]);
410 }
411 EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, L"B", L"aA"));
376 } 412 }
377 413
414 #if defined(OS_WIN) || defined(OS_LINUX)
378 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, CtrlKeyEvents) { 415 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, CtrlKeyEvents) {
379 static const KeyEventTestData kTestCtrlF = { 416 static const KeyEventTestData kTestCtrlF = {
380 base::VKEY_F, true, false, false, 417 base::VKEY_F, true, false, false, false,
381 false, false, false, false, 2, 418 false, false, false, false, 2,
382 { "D 17 0 true false false", 419 { "D 17 0 true false false false",
383 "D 70 0 true false false" } 420 "D 70 0 true false false false" }
384 }; 421 };
385 422
386 static const KeyEventTestData kTestCtrlFSuppressKeyDown = { 423 static const KeyEventTestData kTestCtrlFSuppressKeyDown = {
387 base::VKEY_F, true, false, false, 424 base::VKEY_F, true, false, false, false,
388 true, false, false, false, 4, 425 true, false, false, false, 4,
389 { "D 17 0 true false false", 426 { "D 17 0 true false false false",
390 "D 70 0 true false false", 427 "D 70 0 true false false false",
391 "U 70 0 true false false", 428 "U 70 0 true false false false",
392 "U 17 0 true false false" } 429 "U 17 0 true false false false" }
393 }; 430 };
394 431
395 // Ctrl+Z doesn't bind to any accelerators, which then should generate a 432 // Ctrl+Z doesn't bind to any accelerators, which then should generate a
396 // keypress event with charCode=26. 433 // keypress event with charCode=26.
397 static const KeyEventTestData kTestCtrlZ = { 434 static const KeyEventTestData kTestCtrlZ = {
398 base::VKEY_Z, true, false, false, 435 base::VKEY_Z, true, false, false, false,
399 false, false, false, false, 5, 436 false, false, false, false, 5,
400 { "D 17 0 true false false", 437 { "D 17 0 true false false false",
401 "D 90 0 true false false", 438 "D 90 0 true false false false",
402 "P 26 26 true false false", 439 "P 26 26 true false false false",
403 "U 90 0 true false false", 440 "U 90 0 true false false false",
404 "U 17 0 true false false" } 441 "U 17 0 true false false false" }
405 }; 442 };
406 443
407 static const KeyEventTestData kTestCtrlZSuppressKeyDown = { 444 static const KeyEventTestData kTestCtrlZSuppressKeyDown = {
408 base::VKEY_Z, true, false, false, 445 base::VKEY_Z, true, false, false, false,
409 true, false, false, false, 4, 446 true, false, false, false, 4,
410 { "D 17 0 true false false", 447 { "D 17 0 true false false false",
411 "D 90 0 true false false", 448 "D 90 0 true false false false",
412 "U 90 0 true false false", 449 "U 90 0 true false false false",
413 "U 17 0 true false false" } 450 "U 17 0 true false false false" }
414 }; 451 };
415 452
416 // Ctrl+Enter shall generate a keypress event with charCode=10 (LF). 453 // Ctrl+Enter shall generate a keypress event with charCode=10 (LF).
417 static const KeyEventTestData kTestCtrlEnter = { 454 static const KeyEventTestData kTestCtrlEnter = {
418 base::VKEY_RETURN, true, false, false, 455 base::VKEY_RETURN, true, false, false, false,
419 false, false, false, false, 5, 456 false, false, false, false, 5,
420 { "D 17 0 true false false", 457 { "D 17 0 true false false false",
421 "D 13 0 true false false", 458 "D 13 0 true false false false",
422 "P 10 10 true false false", 459 "P 10 10 true false false false",
423 "U 13 0 true false false", 460 "U 13 0 true false false false",
424 "U 17 0 true false false" } 461 "U 17 0 true false false false" }
425 }; 462 };
426 463
427 HTTPTestServer* server = StartHTTPServer(); 464 HTTPTestServer* server = StartHTTPServer();
465 ASSERT_TRUE(server);
428 466
467 BringBrowserWindowToFront();
429 GURL url = server->TestServerPage(kTestingPage); 468 GURL url = server->TestServerPage(kTestingPage);
430 ui_test_utils::NavigateToURL(browser(), url); 469 ui_test_utils::NavigateToURL(browser(), url);
431 470
432 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); 471 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
433 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 472 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
434 473
435 int tab_index = browser()->selected_index(); 474 int tab_index = browser()->selected_index();
436 // Press Ctrl+F, which will make the Find box open and request focus. 475 // Press Ctrl+F, which will make the Find box open and request focus.
437 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlF)); 476 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlF));
438 EXPECT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); 477 EXPECT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
439 478
440 // Press Escape to close the Find box and move the focus back to the web page. 479 // Press Escape to close the Find box and move the focus back to the web page.
441 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_ESCAPE, false, false, false)); 480 ASSERT_NO_FATAL_FAILURE(
481 SendKey(base::VKEY_ESCAPE, false, false, false, false));
442 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 482 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
443 483
444 // Press Ctrl+F with keydown suppressed shall not open the find box. 484 // Press Ctrl+F with keydown suppressed shall not open the find box.
445 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlFSuppressKeyDown)); 485 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlFSuppressKeyDown));
446 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 486 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
447 487
448 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlZ)); 488 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlZ));
449 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlZSuppressKeyDown)); 489 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlZSuppressKeyDown));
450 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlEnter)); 490 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlEnter));
451 } 491 }
492 #elif defined(OS_MACOSX)
493 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, CommandKeyEvents) {
494 static const KeyEventTestData kTestCmdF = {
495 base::VKEY_F, false, false, false, true,
496 false, false, false, false, 2,
497 { "D 91 0 false false false true",
498 "D 70 0 false false false true" }
499 };
500
501 // On Mac we don't send key up events when command modifier is down.
502 static const KeyEventTestData kTestCmdFSuppressKeyDown = {
503 base::VKEY_F, false, false, false, true,
504 true, false, false, false, 3,
505 { "D 91 0 false false false true",
506 "D 70 0 false false false true",
507 "U 91 0 false false false true" }
508 };
509
510 HTTPTestServer* server = StartHTTPServer();
511 ASSERT_TRUE(server);
512
513 BringBrowserWindowToFront();
514 GURL url = server->TestServerPage(kTestingPage);
515 ui_test_utils::NavigateToURL(browser(), url);
516
517 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
518 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
519
520 int tab_index = browser()->selected_index();
521 // Press Cmd+F, which will make the Find box open and request focus.
522 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCmdF));
523 EXPECT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
524
525 // Press Escape to close the Find box and move the focus back to the web page.
526 ASSERT_NO_FATAL_FAILURE(
527 SendKey(base::VKEY_ESCAPE, false, false, false, false));
528 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
529
530 // Press Cmd+F with keydown suppressed shall not open the find box.
531 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCmdFSuppressKeyDown));
532 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
533 }
534 #endif
452 535
453 #if defined(TOOLKIT_VIEWS) && defined(OS_LINUX) 536 #if defined(TOOLKIT_VIEWS) && defined(OS_LINUX)
454 // See http://crbug.com/40037 for details. 537 // See http://crbug.com/40037 for details.
455 #define MAYBE_AccessKeys DISABLED_AccessKeys 538 #define MAYBE_AccessKeys DISABLED_AccessKeys
456 #else 539 #else
457 #define MAYBE_AccessKeys AccessKeys 540 #define MAYBE_AccessKeys AccessKeys
458 #endif 541 #endif
459 542
460 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, MAYBE_AccessKeys) { 543 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, MAYBE_AccessKeys) {
461 static const KeyEventTestData kTestAltA = { 544 #if defined(OS_MACOSX)
462 base::VKEY_A, false, false, true, 545 // On Mac, access keys use ctrl+alt modifiers.
463 false, false, false, false, 4, 546 static const KeyEventTestData kTestAccessA = {
464 { "D 18 0 false false true", 547 base::VKEY_A, true, false, true, false,
465 "D 65 0 false false true", 548 false, false, false, false, 6,
466 "U 65 0 false false true", 549 { "D 17 0 true false false false",
467 "U 18 0 false false true" } 550 "D 18 0 true false true false",
551 "D 65 0 true false true false",
552 "U 65 0 true false true false",
553 "U 18 0 true false true false",
554 "U 17 0 true false false false" }
468 }; 555 };
469 556
470 static const KeyEventTestData kTestAltD = { 557 static const KeyEventTestData kTestAccessDSuppress = {
471 base::VKEY_D, false, false, true, 558 base::VKEY_D, true, false, true, false,
472 false, false, false, false, 2, 559 true, true, true, false, 6,
473 { "D 18 0 false false true", 560 { "D 17 0 true false false false",
474 "D 68 0 false false true" } 561 "D 18 0 true false true false",
562 "D 68 0 true false true false",
563 "U 68 0 true false true false",
564 "U 18 0 true false true false",
565 "U 17 0 true false false false" }
475 }; 566 };
476 567
477 static const KeyEventTestData kTestAltDSuppress = { 568 static const KeyEventTestData kTestAccess1 = {
478 base::VKEY_D, false, false, true, 569 base::VKEY_1, true, false, true, false,
479 true, true, true, false, 4, 570 false, false, false, false, 6,
480 { "D 18 0 false false true", 571 { "D 17 0 true false false false",
481 "D 68 0 false false true", 572 "D 18 0 true false true false",
482 "U 68 0 false false true", 573 "D 49 0 true false true false",
483 "U 18 0 false false true" } 574 "U 49 0 true false true false",
575 "U 18 0 true false true false",
576 "U 17 0 true false false false" }
577 };
578 #else
579 static const KeyEventTestData kTestAccessA = {
580 base::VKEY_A, false, false, true, false,
581 false, false, false, false, 4,
582 { "D 18 0 false false true false",
583 "D 65 0 false false true false",
584 "U 65 0 false false true false",
585 "U 18 0 false false true false" }
484 }; 586 };
485 587
486 static const KeyEventTestData kTestAlt1 = { 588 static const KeyEventTestData kTestAccessD = {
487 base::VKEY_1, false, false, true, 589 base::VKEY_D, false, false, true, false,
488 false, false, false, false, 4, 590 false, false, false, false, 2,
489 { "D 18 0 false false true", 591 { "D 18 0 false false true false",
490 "D 49 0 false false true", 592 "D 68 0 false false true false" }
491 "U 49 0 false false true",
492 "U 18 0 false false true" }
493 }; 593 };
494 594
595 static const KeyEventTestData kTestAccessDSuppress = {
596 base::VKEY_D, false, false, true, false,
597 true, true, true, false, 4,
598 { "D 18 0 false false true false",
599 "D 68 0 false false true false",
600 "U 68 0 false false true false",
601 "U 18 0 false false true false" }
602 };
603
604 static const KeyEventTestData kTestAccess1 = {
605 base::VKEY_1, false, false, true, false,
606 false, false, false, false, 4,
607 { "D 18 0 false false true false",
608 "D 49 0 false false true false",
609 "U 49 0 false false true false",
610 "U 18 0 false false true false" }
611 };
612 #endif
613
495 HTTPTestServer* server = StartHTTPServer(); 614 HTTPTestServer* server = StartHTTPServer();
615 ASSERT_TRUE(server);
496 616
617 BringBrowserWindowToFront();
497 GURL url = server->TestServerPage(kTestingPage); 618 GURL url = server->TestServerPage(kTestingPage);
498 ui_test_utils::NavigateToURL(browser(), url); 619 ui_test_utils::NavigateToURL(browser(), url);
499 620
500 ui_test_utils::RunAllPendingInMessageLoop(); 621 ui_test_utils::RunAllPendingInMessageLoop();
501 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); 622 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
502 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 623 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
503 624
504 int tab_index = browser()->selected_index(); 625 int tab_index = browser()->selected_index();
505 // Make sure no element is focused. 626 // Make sure no element is focused.
506 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); 627 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L""));
507 // Alt+A should focus the element with accesskey = "A". 628 // Alt+A should focus the element with accesskey = "A".
508 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltA)); 629 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccessA));
509 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"A")); 630 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"A"));
510 631
511 // Blur the focused element. 632 // Blur the focused element.
512 EXPECT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"")); 633 EXPECT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L""));
513 // Make sure no element is focused. 634 // Make sure no element is focused.
514 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); 635 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L""));
636
637 #if !defined(OS_MACOSX)
515 // Alt+D should move the focus to the location entry. 638 // Alt+D should move the focus to the location entry.
516 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltD)); 639 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccessD));
517 EXPECT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); 640 EXPECT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR));
518 // No element should be focused, as Alt+D was handled by the browser. 641 // No element should be focused, as Alt+D was handled by the browser.
519 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); 642 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L""));
520 643
521 // Move the focus back to the web page. 644 // Move the focus back to the web page.
522 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); 645 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
523 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 646 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
524 647
525 // Make sure no element is focused. 648 // Make sure no element is focused.
526 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); 649 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L""));
650 #endif
651
527 // If the keydown event is suppressed, then Alt+D should be handled as an 652 // If the keydown event is suppressed, then Alt+D should be handled as an
528 // accesskey rather than an accelerator key. Activation of an accesskey is not 653 // accesskey rather than an accelerator key. Activation of an accesskey is not
529 // a part of the default action of the key event, so it should not be 654 // a part of the default action of the key event, so it should not be
530 // suppressed at all. 655 // suppressed at all.
531 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltDSuppress)); 656 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccessDSuppress));
532 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 657 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
533 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"D")); 658 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"D"));
534 659
535 // Blur the focused element. 660 // Blur the focused element.
536 EXPECT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"")); 661 EXPECT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L""));
537 // Make sure no element is focused. 662 // Make sure no element is focused.
538 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); 663 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L""));
539 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAlt1)); 664 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccess1));
540 #if defined(TOOLKIT_GTK) 665 #if defined(TOOLKIT_GTK)
541 // On GTK, alt-0..9 are assigned as tab selection accelerators, so they can 666 // On GTK, alt-0..9 are assigned as tab selection accelerators, so they can
542 // not be used as accesskeys. 667 // not be used as accesskeys.
543 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); 668 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L""));
544 #elif defined(OS_WIN) 669 #else
545 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"1")); 670 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"1"));
546 #endif 671 #endif
547 } 672 }
548 673
549 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, ReservedAccelerators) { 674 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, ReservedAccelerators) {
550 HTTPTestServer* server = StartHTTPServer(); 675 HTTPTestServer* server = StartHTTPServer();
676 ASSERT_TRUE(server);
551 677
678 BringBrowserWindowToFront();
552 GURL url = server->TestServerPage(kTestingPage); 679 GURL url = server->TestServerPage(kTestingPage);
553 ui_test_utils::NavigateToURL(browser(), url); 680 ui_test_utils::NavigateToURL(browser(), url);
554 681
555 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); 682 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
556 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 683 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
557 684
558 #if defined(OS_WIN) 685 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
559 static const KeyEventTestData kTestCtrlT = { 686 static const KeyEventTestData kTestCtrlT = {
560 base::VKEY_T, true, false, false, 687 base::VKEY_T, true, false, false, false,
561 true, false, false, false, 1, 688 true, false, false, false, 1,
562 { "D 17 0 true false false" } 689 { "D 17 0 true false false false" }
563 }; 690 };
564 691
565 ASSERT_EQ(1, browser()->tab_count()); 692 ASSERT_EQ(1, browser()->tab_count());
566 // Press Ctrl+T, which will open a new tab. 693 // Press Ctrl+T, which will open a new tab.
567 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlT)); 694 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlT));
568 EXPECT_EQ(2, browser()->tab_count()); 695 EXPECT_EQ(2, browser()->tab_count());
569 browser()->SelectNumberedTab(0); 696 browser()->SelectNumberedTab(0);
570 ASSERT_EQ(0, browser()->selected_index()); 697 ASSERT_EQ(0, browser()->selected_index());
571 698
572 int result_length; 699 int result_length;
573 ASSERT_NO_FATAL_FAILURE(GetResultLength(0, &result_length)); 700 ASSERT_NO_FATAL_FAILURE(GetResultLength(0, &result_length));
574 EXPECT_EQ(1, result_length); 701 EXPECT_EQ(1, result_length);
575 702
576 // Reserved accelerators can't be suppressed. 703 // Reserved accelerators can't be suppressed.
577 ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(0, true)); 704 ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(0, true));
578 // Press Ctrl+W, which will close the tab. 705 // Press Ctrl+W, which will close the tab.
579 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_W, true, false, false)); 706 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_W, true, false, false, false));
580 EXPECT_EQ(1, browser()->tab_count()); 707 EXPECT_EQ(1, browser()->tab_count());
708 #elif defined(OS_MACOSX)
709 static const KeyEventTestData kTestCmdT = {
710 base::VKEY_T, false, false, false, true,
711 true, false, false, false, 1,
712 { "D 91 0 false false false true" }
713 };
581 714
715 ASSERT_EQ(1, browser()->tab_count());
716 // Press Cmd+T, which will open a new tab.
717 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCmdT));
718 EXPECT_EQ(2, browser()->tab_count());
719 browser()->SelectNumberedTab(0);
720 ASSERT_EQ(0, browser()->selected_index());
721
722 int result_length;
723 ASSERT_NO_FATAL_FAILURE(GetResultLength(0, &result_length));
724 EXPECT_EQ(1, result_length);
725
726 // Reserved accelerators can't be suppressed.
727 ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(0, true));
728 // Press Cmd+W, which will close the tab.
729 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_W, false, false, false, true));
730 EXPECT_EQ(1, browser()->tab_count());
582 #elif defined(TOOLKIT_GTK) 731 #elif defined(TOOLKIT_GTK)
583 // Ctrl-[a-z] are not treated as reserved accelerators on GTK. 732 // Ctrl-[a-z] are not treated as reserved accelerators on GTK.
584 static const KeyEventTestData kTestCtrlT = { 733 static const KeyEventTestData kTestCtrlT = {
585 base::VKEY_T, true, false, false, 734 base::VKEY_T, true, false, false, false,
586 false, false, false, false, 2, 735 false, false, false, false, 2,
587 { "D 17 0 true false false", 736 { "D 17 0 true false false false",
588 "D 84 0 true false false" } 737 "D 84 0 true false false false" }
589 }; 738 };
590 739
591 static const KeyEventTestData kTestCtrlPageDown = { 740 static const KeyEventTestData kTestCtrlPageDown = {
592 base::VKEY_NEXT, true, false, false, 741 base::VKEY_NEXT, true, false, false, false,
593 true, false, false, false, 1, 742 true, false, false, false, 1,
594 { "D 17 0 true false false" } 743 { "D 17 0 true false false false" }
595 }; 744 };
596 745
597 static const KeyEventTestData kTestCtrlTab = { 746 static const KeyEventTestData kTestCtrlTab = {
598 base::VKEY_TAB, true, false, false, 747 base::VKEY_TAB, true, false, false, false,
599 true, false, false, false, 1, 748 true, false, false, false, 1,
600 { "D 17 0 true false false" } 749 { "D 17 0 true false false false" }
601 }; 750 };
602 751
603 static const KeyEventTestData kTestCtrlTBlocked = { 752 static const KeyEventTestData kTestCtrlTBlocked = {
604 base::VKEY_T, true, false, false, 753 base::VKEY_T, true, false, false, false,
605 true, false, false, false, 4, 754 true, false, false, false, 4,
606 { "D 17 0 true false false", 755 { "D 17 0 true false false false",
607 "D 84 0 true false false", 756 "D 84 0 true false false false",
608 "U 84 0 true false false", 757 "U 84 0 true false false false",
609 "U 17 0 true false false" } 758 "U 17 0 true false false false" }
610 }; 759 };
611 760
612 static const KeyEventTestData kTestCtrlWBlocked = { 761 static const KeyEventTestData kTestCtrlWBlocked = {
613 base::VKEY_W, true, false, false, 762 base::VKEY_W, true, false, false, false,
614 true, false, false, false, 4, 763 true, false, false, false, 4,
615 { "D 17 0 true false false", 764 { "D 17 0 true false false false",
616 "D 87 0 true false false", 765 "D 87 0 true false false false",
617 "U 87 0 true false false", 766 "U 87 0 true false false false",
618 "U 17 0 true false false" } 767 "U 17 0 true false false false" }
619 }; 768 };
620 769
621 ASSERT_EQ(1, browser()->tab_count()); 770 ASSERT_EQ(1, browser()->tab_count());
622 771
623 // Ctrl+T should be blockable. 772 // Ctrl+T should be blockable.
624 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlTBlocked)); 773 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlTBlocked));
625 ASSERT_EQ(1, browser()->tab_count()); 774 ASSERT_EQ(1, browser()->tab_count());
626 775
627 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlT)); 776 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlT));
628 ASSERT_EQ(2, browser()->tab_count()); 777 ASSERT_EQ(2, browser()->tab_count());
(...skipping 11 matching lines...) Expand all
640 ASSERT_EQ(1, browser()->selected_index()); 789 ASSERT_EQ(1, browser()->selected_index());
641 790
642 // Ctrl+W should be blockable. 791 // Ctrl+W should be blockable.
643 browser()->SelectNumberedTab(0); 792 browser()->SelectNumberedTab(0);
644 ASSERT_EQ(0, browser()->selected_index()); 793 ASSERT_EQ(0, browser()->selected_index());
645 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlWBlocked)); 794 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlWBlocked));
646 ASSERT_EQ(2, browser()->tab_count()); 795 ASSERT_EQ(2, browser()->tab_count());
647 796
648 // Ctrl+F4 to close the tab. 797 // Ctrl+F4 to close the tab.
649 ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(0, true)); 798 ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(0, true));
650 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_F4, true, false, false)); 799 ASSERT_NO_FATAL_FAILURE( SendKey(base::VKEY_F4, true, false, false, false));
651 ASSERT_EQ(1, browser()->tab_count()); 800 ASSERT_EQ(1, browser()->tab_count());
652 #endif 801 #endif
653 } 802 }
803
804 #if defined(OS_MACOSX)
805 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, EditorKeyBindings) {
806 static const KeyEventTestData kTestCtrlA = {
807 base::VKEY_A, true, false, false, false,
808 false, false, false, false, 4,
809 { "D 17 0 true false false false",
810 "D 65 0 true false false false",
811 "U 65 0 true false false false",
812 "U 17 0 true false false false" }
813 };
814
815 static const KeyEventTestData kTestCtrlF = {
816 base::VKEY_F, true, false, false, false,
817 false, false, false, false, 4,
818 { "D 17 0 true false false false",
819 "D 70 0 true false false false",
820 "U 70 0 true false false false",
821 "U 17 0 true false false false" }
822 };
823
824 static const KeyEventTestData kTestCtrlK = {
825 base::VKEY_K, true, false, false, false,
826 false, false, false, false, 4,
827 { "D 17 0 true false false false",
828 "D 75 0 true false false false",
829 "U 75 0 true false false false",
830 "U 17 0 true false false false" }
831 };
832
833 HTTPTestServer* server = StartHTTPServer();
834 ASSERT_TRUE(server);
835
836 BringBrowserWindowToFront();
837 GURL url = server->TestServerPage(kTestingPage);
838 ui_test_utils::NavigateToURL(browser(), url);
839
840 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
841 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
842
843 int tab_index = browser()->selected_index();
844 ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"A"));
845 ASSERT_NO_FATAL_FAILURE(SetTextBoxValue(tab_index, L"A", L"Hello"));
846 // Move the caret to the beginning of the line.
847 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlA));
848 // Forward one character
849 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlF));
850 // Delete to the end of the line.
851 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlK));
852 EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, L"A", L"H"));
853 }
854 #endif
855
856 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, PageUpDownKeys) {
857 static const KeyEventTestData kTestPageUp = {
858 base::VKEY_PRIOR, false, false, false, false,
859 false, false, false, false, 2,
860 { "D 33 0 false false false false",
861 "U 33 0 false false false false" }
862 };
863
864 static const KeyEventTestData kTestPageDown = {
865 base::VKEY_NEXT, false, false, false, false,
866 false, false, false, false, 2,
867 { "D 34 0 false false false false",
868 "U 34 0 false false false false" }
869 };
870
871 HTTPTestServer* server = StartHTTPServer();
872 ASSERT_TRUE(server);
873
874 BringBrowserWindowToFront();
875 GURL url = server->TestServerPage(kTestingPage);
876 ui_test_utils::NavigateToURL(browser(), url);
877
878 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
879 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
880
881 int tab_index = browser()->selected_index();
882 ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"A"));
883 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestPageUp));
884 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestPageDown));
885 EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, L"A", L""));
886 }
OLDNEW
« no previous file with comments | « chrome/browser/browser_focus_uitest.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698