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

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

Issue 268035: Implements tests for testing browser's overall key events handling behavior.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/browser_focus_uitest.cc ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
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"
8 #include "base/keyboard_codes.h"
9 #include "base/logging.h"
10 #include "base/message_loop.h"
11 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h"
13 #include "base/values.h"
14 #include "chrome/browser/automation/ui_controls.h"
15 #include "chrome/browser/browser.h"
16 #include "chrome/browser/browser_window.h"
17 #include "chrome/browser/dom_operation_notification_details.h"
18 #include "chrome/browser/renderer_host/render_view_host.h"
19 #include "chrome/browser/renderer_host/render_widget_host_view.h"
20 #include "chrome/browser/tab_contents/tab_contents.h"
21 #include "chrome/browser/tab_contents/tab_contents_view.h"
22 #include "chrome/common/chrome_paths.h"
23 #include "chrome/common/notification_registrar.h"
24 #include "chrome/common/notification_service.h"
25 #include "chrome/test/in_process_browser_test.h"
26 #include "chrome/test/ui_test_utils.h"
27
28 namespace {
29
30 const wchar_t kTestingPage[] = L"files/keyevents_test.html";
31 const wchar_t kSuppressEventJS[] =
32 L"window.domAutomationController.send(setDefaultAction('%ls', %ls));";
33 const wchar_t kGetResultJS[] =
34 L"window.domAutomationController.send(keyEventResult[%d]);";
35 const wchar_t kGetResultLengthJS[] =
36 L"window.domAutomationController.send(keyEventResult.length);";
37 const wchar_t kGetFocusedElementJS[] =
38 L"window.domAutomationController.send(focusedElement);";
39 const wchar_t kSetFocusedElementJS[] =
40 L"window.domAutomationController.send(setFocusedElement('%ls'));";
41 const wchar_t kGetTextBoxValueJS[] =
42 L"window.domAutomationController.send("
43 L"document.getElementById('%ls').value);";
44 const wchar_t kStartTestJS[] =
45 L"window.domAutomationController.send(startTest());";
46
47 // Maximum lenght of the result array in KeyEventTestData structure.
48 const size_t kMaxResultLength = 10;
49
50 // A structure holding test data of a keyboard event.
51 // Each keyboard event may generate multiple result strings representing
52 // the result of keydown, keypress, keyup and textInput events.
53 // For keydown, keypress and keyup events, the format of the result string is:
54 // <type> <keyCode> <charCode> <ctrlKey> <shiftKey> <altKey>
55 // where <type> may be 'D' (keydown), 'P' (keypress) or 'U' (keyup).
56 // <ctrlKey>, <shiftKey> and <altKey> are boolean value indicating the state of
57 // corresponding modifier key.
58 // For textInput event, the format is: T <text>, where <text> is the text to be
59 // input.
60 // Please refer to chrome/test/data/keyevents_test.html for details.
61 struct KeyEventTestData {
62 base::KeyboardCode key;
63 bool ctrl;
64 bool shift;
65 bool alt;
66
67 bool suppress_keydown;
68 bool suppress_keypress;
69 bool suppress_keyup;
70 bool suppress_textinput;
71
72 int result_length;
73 const char* const result[kMaxResultLength];
74 };
75
76 const wchar_t* GetBoolString(bool value) {
77 return value ? L"true" : L"false";
78 }
79
80 // A class to help wait for the finish of a key event test.
81 class TestFinishObserver : public NotificationObserver {
82 public:
83 explicit TestFinishObserver(RenderViewHost* render_view_host)
84 : finished_(false), waiting_(false) {
85 registrar_.Add(this, NotificationType::DOM_OPERATION_RESPONSE,
86 Source<RenderViewHost>(render_view_host));
87 }
88
89 bool WaitForFinish() {
90 if (!finished_) {
91 waiting_ = true;
92 ui_test_utils::RunMessageLoop();
93 waiting_ = false;
94 }
95 return finished_;
96 }
97
98 virtual void Observe(NotificationType type,
99 const NotificationSource& source,
100 const NotificationDetails& details) {
101 DCHECK(type == NotificationType::DOM_OPERATION_RESPONSE);
102 Details<DomOperationNotificationDetails> dom_op_details(details);
103 // We might receive responses for other script execution, but we only
104 // care about the test finished message.
105 if (dom_op_details->json() == "\"FINISHED\"") {
106 finished_ = true;
107 if (waiting_)
108 MessageLoopForUI::current()->Quit();
109 }
110 }
111
112 private:
113 bool finished_;
114 bool waiting_;
115 NotificationRegistrar registrar_;
116
117 DISALLOW_COPY_AND_ASSIGN(TestFinishObserver);
118 };
119
120 class BrowserKeyEventsTest : public InProcessBrowserTest {
121 public:
122 BrowserKeyEventsTest() {
123 set_show_window(true);
124 EnableDOMAutomation();
125 }
126
127 void GetNativeWindow(gfx::NativeWindow* native_window) {
128 BrowserWindow* window = browser()->window();
129 ASSERT_TRUE(window);
130 *native_window = window->GetNativeHandle();
131 ASSERT_TRUE(*native_window);
132 }
133
134 void SendKey(base::KeyboardCode key, bool control, bool shift, bool alt) {
135 gfx::NativeWindow window = NULL;
136 ASSERT_NO_FATAL_FAILURE(GetNativeWindow(&window));
137 ui_controls::SendKeyPressNotifyWhenDone(window, key, control, shift, alt,
138 new MessageLoop::QuitTask());
139 ui_test_utils::RunMessageLoop();
140 }
141
142 bool IsViewFocused(ViewID vid) {
143 return ui_test_utils::IsViewFocused(browser(), vid);
144 }
145
146 void ClickOnView(ViewID vid) {
147 ui_test_utils::ClickOnView(browser(), vid);
148 }
149
150 // Set the suppress flag of an event specified by |type|. If |suppress| is
151 // true then the web page will suppress all events with |type|. Following
152 // event types are supported: keydown, keypress, keyup and textInput.
153 void SuppressEventByType(int tab_index, const wchar_t* type, bool suppress) {
154 ASSERT_LT(tab_index, browser()->tab_count());
155 bool actual;
156 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
157 browser()->GetTabContentsAt(tab_index)->render_view_host(),
158 L"",
159 StringPrintf(kSuppressEventJS, type, GetBoolString(!suppress)),
160 &actual));
161 ASSERT_EQ(!suppress, actual);
162 }
163
164 void SuppressEvents(int tab_index, bool keydown, bool keypress,
165 bool keyup, bool textinput) {
166 ASSERT_NO_FATAL_FAILURE(
167 SuppressEventByType(tab_index, L"keydown", keydown));
168 ASSERT_NO_FATAL_FAILURE(
169 SuppressEventByType(tab_index, L"keypress", keypress));
170 ASSERT_NO_FATAL_FAILURE(
171 SuppressEventByType(tab_index, L"keyup", keyup));
172 ASSERT_NO_FATAL_FAILURE(
173 SuppressEventByType(tab_index, L"textInput", textinput));
174 }
175
176 void SuppressAllEvents(int tab_index, bool suppress) {
177 SuppressEvents(tab_index, suppress, suppress, suppress, suppress);
178 }
179
180 void GetResultLength(int tab_index, int* length) {
181 ASSERT_LT(tab_index, browser()->tab_count());
182 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt(
183 browser()->GetTabContentsAt(tab_index)->render_view_host(),
184 L"", kGetResultLengthJS, length));
185 }
186
187 void CheckResult(int tab_index, int length, const char* const result[]) {
188 ASSERT_LT(tab_index, browser()->tab_count());
189 int actual_length;
190 ASSERT_NO_FATAL_FAILURE(GetResultLength(tab_index, &actual_length));
191 ASSERT_GE(actual_length, length);
192 for (int i = 0; i < actual_length; ++i) {
193 std::string actual;
194 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
195 browser()->GetTabContentsAt(tab_index)->render_view_host(),
196 L"", StringPrintf(kGetResultJS, i), &actual));
197
198 // If more events were received than expected, then the additional events
199 // must be keyup events.
200 if (i < length)
201 ASSERT_STREQ(result[i], actual.c_str());
202 else
203 ASSERT_EQ('U', actual[0]);
204 }
205 }
206
207 void CheckFocusedElement(int tab_index, const wchar_t* focused) {
208 ASSERT_LT(tab_index, browser()->tab_count());
209 std::string actual;
210 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
211 browser()->GetTabContentsAt(tab_index)->render_view_host(),
212 L"", kGetFocusedElementJS, &actual));
213 ASSERT_EQ(WideToUTF8(focused), actual);
214 }
215
216 void SetFocusedElement(int tab_index, const wchar_t* focused) {
217 ASSERT_LT(tab_index, browser()->tab_count());
218 bool actual;
219 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
220 browser()->GetTabContentsAt(tab_index)->render_view_host(),
221 L"",
222 StringPrintf(kSetFocusedElementJS, focused),
223 &actual));
224 ASSERT_TRUE(actual);
225 }
226
227 void CheckTextBoxValue(int tab_index, const wchar_t* id,
228 const wchar_t* value) {
229 ASSERT_LT(tab_index, browser()->tab_count());
230 std::string actual;
231 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
232 browser()->GetTabContentsAt(tab_index)->render_view_host(),
233 L"",
234 StringPrintf(kGetTextBoxValueJS, id),
235 &actual));
236 ASSERT_EQ(WideToUTF8(value), actual);
237 }
238
239 void StartTest(int tab_index) {
240 ASSERT_LT(tab_index, browser()->tab_count());
241 bool actual;
242 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
243 browser()->GetTabContentsAt(tab_index)->render_view_host(),
244 L"", kStartTestJS, &actual));
245 ASSERT_TRUE(actual);
246 }
247
248 void TestKeyEvent(int tab_index, const KeyEventTestData& test) {
249 ASSERT_LT(tab_index, browser()->tab_count());
250 ASSERT_EQ(tab_index, browser()->selected_index());
251
252 // Inform our testing web page that we are about to start testing a key
253 // event.
254 ASSERT_NO_FATAL_FAILURE(StartTest(tab_index));
255 ASSERT_NO_FATAL_FAILURE(SuppressEvents(
256 tab_index, test.suppress_keydown, test.suppress_keypress,
257 test.suppress_keyup, test.suppress_textinput));
258
259 // We need to create a finish observer before sending the key event,
260 // because the test finished message might be arrived before returning
261 // from the SendKey() method.
262 TestFinishObserver finish_observer(
263 browser()->GetTabContentsAt(tab_index)->render_view_host());
264
265 ASSERT_NO_FATAL_FAILURE(SendKey(test.key, test.ctrl, test.shift, test.alt));
266 ASSERT_TRUE(finish_observer.WaitForFinish());
267 ASSERT_NO_FATAL_FAILURE(CheckResult(
268 tab_index, test.result_length, test.result));
269 }
270
271 std::string GetTestDataDescription(const KeyEventTestData& data) {
272 std::string desc = StringPrintf(
273 " VKEY:0x%02x, ctrl:%d, shift:%d, alt:%d\n"
274 " Suppress: keydown:%d, keypress:%d, keyup:%d, textInput:%d\n"
275 " Expected results(%d):\n",
276 data.key, data.ctrl, data.shift, data.alt,
277 data.suppress_keydown, data.suppress_keypress, data.suppress_keyup,
278 data.suppress_textinput, data.result_length);
279 for (int i = 0; i < data.result_length; ++i) {
280 desc.append(" ");
281 desc.append(data.result[i]);
282 desc.append("\n");
283 }
284 return desc;
285 }
286 };
287
288 } // namespace
289
290 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, NormalKeyEvents) {
291 static const KeyEventTestData kTestNoInput[] = {
292 // a
293 { base::VKEY_A, false, false, false,
294 false, false, false, false, 3,
295 { "D 65 0 false false false",
296 "P 97 97 false false false",
297 "U 65 0 false false false" } },
298 // shift-a
299 { base::VKEY_A, false, true, false,
300 false, false, false, false, 5,
301 { "D 16 0 false true false",
302 "D 65 0 false true false",
303 "P 65 65 false true false",
304 "U 65 0 false true false",
305 "U 16 0 false true false" } },
306 // a, suppress keydown
307 { base::VKEY_A, false, false, false,
308 true, false, false, false, 2,
309 { "D 65 0 false false false",
310 "U 65 0 false false false" } },
311 };
312
313 static const KeyEventTestData kTestWithInput[] = {
314 // a
315 { base::VKEY_A, false, false, false,
316 false, false, false, false, 4,
317 { "D 65 0 false false false",
318 "P 97 97 false false false",
319 "T a",
320 "U 65 0 false false false" } },
321 // shift-a
322 { base::VKEY_A, false, true, false,
323 false, false, false, false, 6,
324 { "D 16 0 false true false",
325 "D 65 0 false true false",
326 "P 65 65 false true false",
327 "T A",
328 "U 65 0 false true false",
329 "U 16 0 false true false" } },
330 // a, suppress keydown
331 { base::VKEY_A, false, false, false,
332 true, false, false, false, 2,
333 { "D 65 0 false false false",
334 "U 65 0 false false false" } },
335 // a, suppress keypress
336 { base::VKEY_A, false, false, false,
337 false, true, false, false, 3,
338 { "D 65 0 false false false",
339 "P 97 97 false false false",
340 "U 65 0 false false false" } },
341 // a, suppress textInput
342 { base::VKEY_A, false, false, false,
343 false, false, false, true, 4,
344 { "D 65 0 false false false",
345 "P 97 97 false false false",
346 "T a",
347 "U 65 0 false false false" } },
348 };
349
350 HTTPTestServer* server = StartHTTPServer();
351
352 GURL url = server->TestServerPageW(kTestingPage);
353 ui_test_utils::NavigateToURL(browser(), url);
354
355 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
356 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
357
358 int tab_index = browser()->selected_index();
359 for (size_t i = 0; i < arraysize(kTestNoInput); ++i) {
360 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestNoInput[i]))
361 << "kTestNoInput[" << i << "] failed:\n"
362 << GetTestDataDescription(kTestNoInput[i]);
363 }
364
365 ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"A"));
366 for (size_t i = 0; i < arraysize(kTestWithInput); ++i) {
367 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestWithInput[i]))
368 << "kTestWithInput[" << i << "] failed:\n"
369 << GetTestDataDescription(kTestWithInput[i]);
370 }
371
372 EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, L"A", L"aA"));
373 }
374
375 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, CtrlKeyEvents) {
376 static const KeyEventTestData kTestCtrlF = {
377 base::VKEY_F, true, false, false,
378 false, false, false, false, 2,
379 { "D 17 0 true false false",
380 "D 70 0 true false false" }
381 };
382
383 static const KeyEventTestData kTestCtrlFSuppressKeyDown = {
384 base::VKEY_F, true, false, false,
385 true, false, false, false, 4,
386 { "D 17 0 true false false",
387 "D 70 0 true false false",
388 "U 70 0 true false false",
389 "U 17 0 true false false" }
390 };
391
392 // Ctrl+Z doesn't bind to any accelerators, which then should generate a
393 // keypress event with charCode=26.
394 static const KeyEventTestData kTestCtrlZ = {
395 base::VKEY_Z, true, false, false,
396 false, false, false, false, 5,
397 { "D 17 0 true false false",
398 "D 90 0 true false false",
399 "P 26 26 true false false",
400 "U 90 0 true false false",
401 "U 17 0 true false false" }
402 };
403
404 static const KeyEventTestData kTestCtrlZSuppressKeyDown = {
405 base::VKEY_Z, true, false, false,
406 true, false, false, false, 4,
407 { "D 17 0 true false false",
408 "D 90 0 true false false",
409 "U 90 0 true false false",
410 "U 17 0 true false false" }
411 };
412
413 // Ctrl+Enter shall generate a keypress event with charCode=10 (LF).
414 static const KeyEventTestData kTestCtrlEnter = {
415 base::VKEY_RETURN, true, false, false,
416 false, false, false, false, 5,
417 { "D 17 0 true false false",
418 "D 13 0 true false false",
419 "P 10 10 true false false",
420 "U 13 0 true false false",
421 "U 17 0 true false false" }
422 };
423
424 HTTPTestServer* server = StartHTTPServer();
425
426 GURL url = server->TestServerPageW(kTestingPage);
427 ui_test_utils::NavigateToURL(browser(), url);
428
429 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
430 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
431
432 int tab_index = browser()->selected_index();
433 // Press Ctrl+F, which will make the Find box open and request focus.
434 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlF));
435 EXPECT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
436
437 // Press Escape to close the Find box and move the focus back to the web page.
438 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_ESCAPE, false, false, false));
439 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
440
441 // Press Ctrl+F with keydown suppressed shall not open the find box.
442 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlFSuppressKeyDown));
443 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
444
445 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlZ));
446 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlZSuppressKeyDown));
447 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlEnter));
448 }
449
450 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, AccessKeys) {
451 static const KeyEventTestData kTestAltA = {
452 base::VKEY_A, false, false, true,
453 false, false, false, false, 4,
454 { "D 18 0 false false true",
455 "D 65 0 false false true",
456 "U 65 0 false false true",
457 "U 18 0 false false true" }
458 };
459
460 static const KeyEventTestData kTestAltD = {
461 base::VKEY_D, false, false, true,
462 false, false, false, false, 2,
463 { "D 18 0 false false true",
464 "D 68 0 false false true" }
465 };
466
467 static const KeyEventTestData kTestAltDSuppress = {
468 base::VKEY_D, false, false, true,
469 true, true, true, false, 4,
470 { "D 18 0 false false true",
471 "D 68 0 false false true",
472 "U 68 0 false false true",
473 "U 18 0 false false true" }
474 };
475
476 static const KeyEventTestData kTestAlt1 = {
477 base::VKEY_1, false, false, true,
478 false, false, false, false, 4,
479 { "D 18 0 false false true",
480 "D 49 0 false false true",
481 "U 49 0 false false true",
482 "U 18 0 false false true" }
483 };
484
485 HTTPTestServer* server = StartHTTPServer();
486
487 GURL url = server->TestServerPageW(kTestingPage);
488 ui_test_utils::NavigateToURL(browser(), url);
489
490 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
491 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
492
493 int tab_index = browser()->selected_index();
494 // Make sure no element is focused.
495 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L""));
496 // Alt+A should focus the element with accesskey = "A".
497 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltA));
498 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"A"));
499
500 // Blur the focused element.
501 EXPECT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L""));
502 // Make sure no element is focused.
503 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L""));
504 // Alt+D should move the focus to the location entry.
505 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltD));
506 EXPECT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR));
507 // No element should be focused, as Alt+D was handled by the browser.
508 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L""));
509
510 // Move the focus back to the web page.
511 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
512 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
513
514 // Make sure no element is focused.
515 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L""));
516 // If the keydown event is suppressed, then Alt+D should be handled as an
517 // accesskey rather than an accelerator key. Activation of an accesskey is not
518 // a part of the default action of the key event, so it should not be
519 // suppressed at all.
520 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltDSuppress));
521 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
522 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"D"));
523
524 // Blur the focused element.
525 EXPECT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L""));
526 // Make sure no element is focused.
527 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L""));
528 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAlt1));
529 #if defined(OS_LINUX)
530 // On Linux, alt-0..9 are assigned as tab selection accelerators, so they can
531 // not be used as accesskeys.
532 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L""));
533 #elif defined(OS_WIN)
534 EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"1"));
535 #endif
536 }
537
538 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, ReservedAccelerators) {
539 static const KeyEventTestData kTestCtrlT = {
540 base::VKEY_T, true, false, false,
541 false, false, false, false, 1,
542 { "D 17 0 true false false" }
543 };
544
545 HTTPTestServer* server = StartHTTPServer();
546
547 GURL url = server->TestServerPageW(kTestingPage);
548 ui_test_utils::NavigateToURL(browser(), url);
549
550 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
551 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
552
553 int tab_index = browser()->selected_index();
554 ASSERT_EQ(1, browser()->tab_count());
555 // Press Ctrl+T, which will open a new tab.
556 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlT));
557 EXPECT_EQ(2, browser()->tab_count());
558 browser()->SelectNumberedTab(tab_index);
559 ASSERT_EQ(tab_index, browser()->selected_index());
560
561 int result_length;
562 ASSERT_NO_FATAL_FAILURE(GetResultLength(tab_index, &result_length));
563 EXPECT_EQ(1, result_length);
564
565 // Reserved accelerators can't be suppressed.
566 ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(tab_index, true));
567 // Press Ctrl+W, which will close the tab.
568 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_W, true, false, false));
569 EXPECT_EQ(1, browser()->tab_count());
570 }
OLDNEW
« no previous file with comments | « chrome/browser/browser_focus_uitest.cc ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698