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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc

Issue 3354005: Re-lands 58186: (Closed)
Patch Set: Created 10 years, 3 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 | « base/win_util.cc ('k') | chrome/browser/autocomplete/autocomplete_edit_view_win.cc » ('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 <stdio.h> 5 #include <stdio.h>
6 6
7 #include "base/keyboard_codes.h" 7 #include "app/keyboard_codes.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/platform_thread.h" 10 #include "base/platform_thread.h"
11 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
12 #include "base/string16.h" 12 #include "base/string16.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/app/chrome_dll_resource.h" 16 #include "chrome/app/chrome_dll_resource.h"
17 #include "chrome/browser/autocomplete/autocomplete.h" 17 #include "chrome/browser/autocomplete/autocomplete.h"
(...skipping 18 matching lines...) Expand all
36 #include "net/base/mock_host_resolver.h" 36 #include "net/base/mock_host_resolver.h"
37 #include "views/event.h" 37 #include "views/event.h"
38 38
39 using base::Time; 39 using base::Time;
40 using base::TimeDelta; 40 using base::TimeDelta;
41 41
42 namespace { 42 namespace {
43 43
44 const char kSearchKeyword[] = "foo"; 44 const char kSearchKeyword[] = "foo";
45 const wchar_t kSearchKeywordKeys[] = { 45 const wchar_t kSearchKeywordKeys[] = {
46 base::VKEY_F, base::VKEY_O, base::VKEY_O, 0 46 app::VKEY_F, app::VKEY_O, app::VKEY_O, 0
47 }; 47 };
48 const char kSearchURL[] = "http://www.foo.com/search?q={searchTerms}"; 48 const char kSearchURL[] = "http://www.foo.com/search?q={searchTerms}";
49 const char kSearchShortName[] = "foo"; 49 const char kSearchShortName[] = "foo";
50 const char kSearchText[] = "abc"; 50 const char kSearchText[] = "abc";
51 const wchar_t kSearchTextKeys[] = { 51 const wchar_t kSearchTextKeys[] = {
52 base::VKEY_A, base::VKEY_B, base::VKEY_C, 0 52 app::VKEY_A, app::VKEY_B, app::VKEY_C, 0
53 }; 53 };
54 const char kSearchTextURL[] = "http://www.foo.com/search?q=abc"; 54 const char kSearchTextURL[] = "http://www.foo.com/search?q=abc";
55 const char kSearchSingleChar[] = "z"; 55 const char kSearchSingleChar[] = "z";
56 const wchar_t kSearchSingleCharKeys[] = { base::VKEY_Z, 0 }; 56 const wchar_t kSearchSingleCharKeys[] = { app::VKEY_Z, 0 };
57 const char kSearchSingleCharURL[] = "http://www.foo.com/search?q=z"; 57 const char kSearchSingleCharURL[] = "http://www.foo.com/search?q=z";
58 58
59 const char kHistoryPageURL[] = "chrome://history/#q=abc"; 59 const char kHistoryPageURL[] = "chrome://history/#q=abc";
60 60
61 const char kDesiredTLDHostname[] = "www.bar.com"; 61 const char kDesiredTLDHostname[] = "www.bar.com";
62 const wchar_t kDesiredTLDKeys[] = { 62 const wchar_t kDesiredTLDKeys[] = {
63 base::VKEY_B, base::VKEY_A, base::VKEY_R, 0 63 app::VKEY_B, app::VKEY_A, app::VKEY_R, 0
64 }; 64 };
65 65
66 // Hostnames that shall be blocked by host resolver. 66 // Hostnames that shall be blocked by host resolver.
67 const char *kBlockedHostnames[] = { 67 const char *kBlockedHostnames[] = {
68 "foo", 68 "foo",
69 "*.foo.com", 69 "*.foo.com",
70 "bar", 70 "bar",
71 "*.bar.com", 71 "*.bar.com",
72 "abc", 72 "abc",
73 "*.abc.com", 73 "*.abc.com",
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 115
116 void GetAutocompleteEditView(AutocompleteEditView** edit_view) { 116 void GetAutocompleteEditView(AutocompleteEditView** edit_view) {
117 BrowserWindow* window = browser()->window(); 117 BrowserWindow* window = browser()->window();
118 ASSERT_TRUE(window); 118 ASSERT_TRUE(window);
119 LocationBar* loc_bar = window->GetLocationBar(); 119 LocationBar* loc_bar = window->GetLocationBar();
120 ASSERT_TRUE(loc_bar); 120 ASSERT_TRUE(loc_bar);
121 *edit_view = loc_bar->location_entry(); 121 *edit_view = loc_bar->location_entry();
122 ASSERT_TRUE(*edit_view); 122 ASSERT_TRUE(*edit_view);
123 } 123 }
124 124
125 void SendKey(base::KeyboardCode key, bool control, bool shift, bool alt) { 125 void SendKey(app::KeyboardCode key, bool control, bool shift, bool alt) {
126 gfx::NativeWindow window = NULL; 126 gfx::NativeWindow window = NULL;
127 ASSERT_NO_FATAL_FAILURE(GetNativeWindow(&window)); 127 ASSERT_NO_FATAL_FAILURE(GetNativeWindow(&window));
128 ASSERT_TRUE( 128 ASSERT_TRUE(
129 ui_test_utils::SendKeyPressSync( 129 ui_test_utils::SendKeyPressSync(
130 window, key, control, shift, alt, false /* command */)); 130 window, key, control, shift, alt, false /* command */));
131 } 131 }
132 132
133 void SendKeySequence(const wchar_t* keys) { 133 void SendKeySequence(const wchar_t* keys) {
134 for (; *keys; ++keys) 134 for (; *keys; ++keys)
135 ASSERT_NO_FATAL_FAILURE(SendKey(static_cast<base::KeyboardCode>(*keys), 135 ASSERT_NO_FATAL_FAILURE(SendKey(static_cast<app::KeyboardCode>(*keys),
136 false, false, false)); 136 false, false, false));
137 } 137 }
138 138
139 void WaitForTabOpenOrClose(int expected_tab_count) { 139 void WaitForTabOpenOrClose(int expected_tab_count) {
140 int tab_count = browser()->tab_count(); 140 int tab_count = browser()->tab_count();
141 if (tab_count == expected_tab_count) 141 if (tab_count == expected_tab_count)
142 return; 142 return;
143 143
144 NotificationRegistrar registrar; 144 NotificationRegistrar registrar;
145 registrar.Add(this, 145 registrar.Add(this,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 AutocompleteEditView* edit_view = NULL; 292 AutocompleteEditView* edit_view = NULL;
293 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 293 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
294 294
295 int tab_count = browser()->tab_count(); 295 int tab_count = browser()->tab_count();
296 296
297 // Create a new Tab. 297 // Create a new Tab.
298 browser()->NewTab(); 298 browser()->NewTab();
299 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1)); 299 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1));
300 300
301 // Select the first Tab. 301 // Select the first Tab.
302 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_1, true, false, false)); 302 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_1, true, false, false));
303 ASSERT_EQ(0, browser()->selected_index()); 303 ASSERT_EQ(0, browser()->selected_index());
304 304
305 browser()->FocusLocationBar(); 305 browser()->FocusLocationBar();
306 306
307 // Select the second Tab. 307 // Select the second Tab.
308 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_2, true, false, false)); 308 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_2, true, false, false));
309 ASSERT_EQ(1, browser()->selected_index()); 309 ASSERT_EQ(1, browser()->selected_index());
310 310
311 browser()->FocusLocationBar(); 311 browser()->FocusLocationBar();
312 312
313 // Close a Tab. 313 // Close a Tab.
314 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_W, true, false, false)); 314 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_W, true, false, false));
315 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count)); 315 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count));
316 316
317 // Try ctrl-l to focus location bar. 317 // Try ctrl-l to focus location bar.
318 edit_view->SetUserText(L"Hello world"); 318 edit_view->SetUserText(L"Hello world");
319 EXPECT_FALSE(edit_view->IsSelectAll()); 319 EXPECT_FALSE(edit_view->IsSelectAll());
320 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_L, true, false, false)); 320 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_L, true, false, false));
321 EXPECT_TRUE(edit_view->IsSelectAll()); 321 EXPECT_TRUE(edit_view->IsSelectAll());
322 } 322 }
323 323
324 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BackspaceInKeywordMode) { 324 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BackspaceInKeywordMode) {
325 ASSERT_NO_FATAL_FAILURE(SetupComponents()); 325 ASSERT_NO_FATAL_FAILURE(SetupComponents());
326 browser()->FocusLocationBar(); 326 browser()->FocusLocationBar();
327 327
328 AutocompleteEditView* edit_view = NULL; 328 AutocompleteEditView* edit_view = NULL;
329 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 329 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
330 330
331 // Trigger keyword hint mode. 331 // Trigger keyword hint mode.
332 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); 332 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
333 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); 333 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
334 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); 334 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword()));
335 335
336 // Trigger keyword mode. 336 // Trigger keyword mode.
337 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_TAB, false, false, false)); 337 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_TAB, false, false, false));
338 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); 338 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
339 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); 339 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword()));
340 340
341 // Backspace without search text should bring back keyword hint mode. 341 // Backspace without search text should bring back keyword hint mode.
342 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_BACK, false, false, false)); 342 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_BACK, false, false, false));
343 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); 343 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
344 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); 344 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword()));
345 345
346 // Trigger keyword mode again. 346 // Trigger keyword mode again.
347 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_TAB, false, false, false)); 347 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_TAB, false, false, false));
348 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); 348 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
349 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); 349 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword()));
350 350
351 // Input something as search text. 351 // Input something as search text.
352 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); 352 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
353 353
354 // Should stay in keyword mode while deleting search text by pressing 354 // Should stay in keyword mode while deleting search text by pressing
355 // backspace. 355 // backspace.
356 for (size_t i = 0; i < arraysize(kSearchText) - 1; ++i) { 356 for (size_t i = 0; i < arraysize(kSearchText) - 1; ++i) {
357 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_BACK, false, false, false)); 357 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_BACK, false, false, false));
358 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); 358 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
359 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); 359 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword()));
360 } 360 }
361 361
362 // Input something as search text. 362 // Input something as search text.
363 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); 363 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
364 364
365 // Move cursor to the beginning of the search text. 365 // Move cursor to the beginning of the search text.
366 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_HOME, false, false, false)); 366 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_HOME, false, false, false));
367 // Backspace at the beginning of the search text shall turn off 367 // Backspace at the beginning of the search text shall turn off
368 // the keyword mode. 368 // the keyword mode.
369 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_BACK, false, false, false)); 369 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_BACK, false, false, false));
370 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); 370 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
371 ASSERT_EQ(std::string(), WideToUTF8(edit_view->model()->keyword())); 371 ASSERT_EQ(std::string(), WideToUTF8(edit_view->model()->keyword()));
372 ASSERT_EQ(std::string(kSearchKeyword) + kSearchText, 372 ASSERT_EQ(std::string(kSearchKeyword) + kSearchText,
373 WideToUTF8(edit_view->GetText())); 373 WideToUTF8(edit_view->GetText()));
374 } 374 }
375 375
376 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, Escape) { 376 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, Escape) {
377 ASSERT_NO_FATAL_FAILURE(SetupComponents()); 377 ASSERT_NO_FATAL_FAILURE(SetupComponents());
378 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIHistoryURL)); 378 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIHistoryURL));
379 browser()->FocusLocationBar(); 379 browser()->FocusLocationBar();
380 380
381 AutocompleteEditView* edit_view = NULL; 381 AutocompleteEditView* edit_view = NULL;
382 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 382 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
383 383
384 std::wstring old_text = edit_view->GetText(); 384 std::wstring old_text = edit_view->GetText();
385 EXPECT_FALSE(old_text.empty()); 385 EXPECT_FALSE(old_text.empty());
386 EXPECT_TRUE(edit_view->IsSelectAll()); 386 EXPECT_TRUE(edit_view->IsSelectAll());
387 387
388 // Delete all text in omnibox. 388 // Delete all text in omnibox.
389 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_BACK, false, false, false)); 389 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_BACK, false, false, false));
390 EXPECT_TRUE(edit_view->GetText().empty()); 390 EXPECT_TRUE(edit_view->GetText().empty());
391 391
392 // Escape shall revert the text in omnibox. 392 // Escape shall revert the text in omnibox.
393 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_ESCAPE, false, false, false)); 393 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_ESCAPE, false, false, false));
394 EXPECT_EQ(old_text, edit_view->GetText()); 394 EXPECT_EQ(old_text, edit_view->GetText());
395 EXPECT_TRUE(edit_view->IsSelectAll()); 395 EXPECT_TRUE(edit_view->IsSelectAll());
396 } 396 }
397 397
398 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, DesiredTLD) { 398 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, DesiredTLD) {
399 ASSERT_NO_FATAL_FAILURE(SetupComponents()); 399 ASSERT_NO_FATAL_FAILURE(SetupComponents());
400 browser()->FocusLocationBar(); 400 browser()->FocusLocationBar();
401 401
402 AutocompleteEditView* edit_view = NULL; 402 AutocompleteEditView* edit_view = NULL;
403 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 403 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
404 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); 404 AutocompletePopupModel* popup_model = edit_view->model()->popup_model();
405 ASSERT_TRUE(popup_model); 405 ASSERT_TRUE(popup_model);
406 406
407 // Test ctrl-Enter. 407 // Test ctrl-Enter.
408 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kDesiredTLDKeys)); 408 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kDesiredTLDKeys));
409 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 409 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
410 ASSERT_TRUE(popup_model->IsOpen()); 410 ASSERT_TRUE(popup_model->IsOpen());
411 // ctrl-Enter triggers desired_tld feature, thus www.bar.com shall be opened. 411 // ctrl-Enter triggers desired_tld feature, thus www.bar.com shall be opened.
412 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_RETURN, true, false, false)); 412 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_RETURN, true, false, false));
413 413
414 GURL url = browser()->GetSelectedTabContents()->GetURL(); 414 GURL url = browser()->GetSelectedTabContents()->GetURL();
415 EXPECT_STREQ(kDesiredTLDHostname, url.host().c_str()); 415 EXPECT_STREQ(kDesiredTLDHostname, url.host().c_str());
416 } 416 }
417 417
418 // This test is disabled. See bug 23213. 418 // This test is disabled. See bug 23213.
419 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AltEnter) { 419 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AltEnter) {
420 ASSERT_NO_FATAL_FAILURE(SetupComponents()); 420 ASSERT_NO_FATAL_FAILURE(SetupComponents());
421 browser()->FocusLocationBar(); 421 browser()->FocusLocationBar();
422 422
423 AutocompleteEditView* edit_view = NULL; 423 AutocompleteEditView* edit_view = NULL;
424 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 424 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
425 425
426 edit_view->SetUserText(ASCIIToWide(chrome::kChromeUIHistoryURL)); 426 edit_view->SetUserText(ASCIIToWide(chrome::kChromeUIHistoryURL));
427 int tab_count = browser()->tab_count(); 427 int tab_count = browser()->tab_count();
428 // alt-Enter opens a new tab. 428 // alt-Enter opens a new tab.
429 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_RETURN, false, false, true)); 429 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_RETURN, false, false, true));
430 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1)); 430 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1));
431 } 431 }
432 432
433 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EnterToSearch) { 433 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EnterToSearch) {
434 ASSERT_NO_FATAL_FAILURE(SetupHostResolver()); 434 ASSERT_NO_FATAL_FAILURE(SetupHostResolver());
435 ASSERT_NO_FATAL_FAILURE(SetupSearchEngine()); 435 ASSERT_NO_FATAL_FAILURE(SetupSearchEngine());
436 browser()->FocusLocationBar(); 436 browser()->FocusLocationBar();
437 437
438 AutocompleteEditView* edit_view = NULL; 438 AutocompleteEditView* edit_view = NULL;
439 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 439 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
440 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); 440 AutocompletePopupModel* popup_model = edit_view->model()->popup_model();
441 ASSERT_TRUE(popup_model); 441 ASSERT_TRUE(popup_model);
442 442
443 // Test Enter to search. 443 // Test Enter to search.
444 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); 444 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
445 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 445 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
446 ASSERT_TRUE(popup_model->IsOpen()); 446 ASSERT_TRUE(popup_model->IsOpen());
447 447
448 // Check if the default match result is Search Primary Provider. 448 // Check if the default match result is Search Primary Provider.
449 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, 449 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED,
450 popup_model->result().default_match()->type); 450 popup_model->result().default_match()->type);
451 451
452 // Open the default match. 452 // Open the default match.
453 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_RETURN, false, false, false)); 453 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_RETURN, false, false, false));
454 GURL url = browser()->GetSelectedTabContents()->GetURL(); 454 GURL url = browser()->GetSelectedTabContents()->GetURL();
455 EXPECT_STREQ(kSearchTextURL, url.spec().c_str()); 455 EXPECT_STREQ(kSearchTextURL, url.spec().c_str());
456 456
457 // Test that entering a single character then Enter performs a search. 457 // Test that entering a single character then Enter performs a search.
458 browser()->FocusLocationBar(); 458 browser()->FocusLocationBar();
459 EXPECT_TRUE(edit_view->IsSelectAll()); 459 EXPECT_TRUE(edit_view->IsSelectAll());
460 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchSingleCharKeys)); 460 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchSingleCharKeys));
461 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 461 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
462 ASSERT_TRUE(popup_model->IsOpen()); 462 ASSERT_TRUE(popup_model->IsOpen());
463 EXPECT_EQ(kSearchSingleChar, WideToUTF8(edit_view->GetText())); 463 EXPECT_EQ(kSearchSingleChar, WideToUTF8(edit_view->GetText()));
464 464
465 // Check if the default match result is Search Primary Provider. 465 // Check if the default match result is Search Primary Provider.
466 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, 466 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED,
467 popup_model->result().default_match()->type); 467 popup_model->result().default_match()->type);
468 468
469 // Open the default match. 469 // Open the default match.
470 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_RETURN, false, false, false)); 470 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_RETURN, false, false, false));
471 url = browser()->GetSelectedTabContents()->GetURL(); 471 url = browser()->GetSelectedTabContents()->GetURL();
472 EXPECT_STREQ(kSearchSingleCharURL, url.spec().c_str()); 472 EXPECT_STREQ(kSearchSingleCharURL, url.spec().c_str());
473 } 473 }
474 474
475 // See http://crbug.com/20934: Omnibox keyboard behavior wrong for 475 // See http://crbug.com/20934: Omnibox keyboard behavior wrong for
476 // "See recent pages in history" 476 // "See recent pages in history"
477 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EnterToOpenHistoryPage) { 477 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EnterToOpenHistoryPage) {
478 ASSERT_NO_FATAL_FAILURE(SetupComponents()); 478 ASSERT_NO_FATAL_FAILURE(SetupComponents());
479 browser()->FocusLocationBar(); 479 browser()->FocusLocationBar();
480 480
481 AutocompleteEditView* edit_view = NULL; 481 AutocompleteEditView* edit_view = NULL;
482 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 482 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
483 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); 483 AutocompletePopupModel* popup_model = edit_view->model()->popup_model();
484 ASSERT_TRUE(popup_model); 484 ASSERT_TRUE(popup_model);
485 485
486 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); 486 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
487 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 487 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
488 ASSERT_TRUE(popup_model->IsOpen()); 488 ASSERT_TRUE(popup_model->IsOpen());
489 EXPECT_EQ(0U, popup_model->selected_line()); 489 EXPECT_EQ(0U, popup_model->selected_line());
490 490
491 // Move to the history page item. 491 // Move to the history page item.
492 size_t size = popup_model->result().size(); 492 size_t size = popup_model->result().size();
493 while (true) { 493 while (true) {
494 if (popup_model->result().match_at(popup_model->selected_line()).type == 494 if (popup_model->result().match_at(popup_model->selected_line()).type ==
495 AutocompleteMatch::OPEN_HISTORY_PAGE) 495 AutocompleteMatch::OPEN_HISTORY_PAGE)
496 break; 496 break;
497 size_t old_selected_line = popup_model->selected_line(); 497 size_t old_selected_line = popup_model->selected_line();
498 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_DOWN, false, false, false)); 498 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_DOWN, false, false, false));
499 ASSERT_EQ(old_selected_line + 1, popup_model->selected_line()); 499 ASSERT_EQ(old_selected_line + 1, popup_model->selected_line());
500 if (popup_model->selected_line() == size - 1) 500 if (popup_model->selected_line() == size - 1)
501 break; 501 break;
502 } 502 }
503 503
504 // Make sure the history page item is selected. 504 // Make sure the history page item is selected.
505 ASSERT_EQ(AutocompleteMatch::OPEN_HISTORY_PAGE, 505 ASSERT_EQ(AutocompleteMatch::OPEN_HISTORY_PAGE,
506 popup_model->result().match_at(popup_model->selected_line()).type); 506 popup_model->result().match_at(popup_model->selected_line()).type);
507 507
508 // Open the history page item. 508 // Open the history page item.
509 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_RETURN, false, false, false)); 509 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_RETURN, false, false, false));
510 GURL url = browser()->GetSelectedTabContents()->GetURL(); 510 GURL url = browser()->GetSelectedTabContents()->GetURL();
511 EXPECT_STREQ(kHistoryPageURL, url.spec().c_str()); 511 EXPECT_STREQ(kHistoryPageURL, url.spec().c_str());
512 } 512 }
513 513
514 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EscapeToDefaultMatch) { 514 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EscapeToDefaultMatch) {
515 ASSERT_NO_FATAL_FAILURE(SetupComponents()); 515 ASSERT_NO_FATAL_FAILURE(SetupComponents());
516 browser()->FocusLocationBar(); 516 browser()->FocusLocationBar();
517 517
518 AutocompleteEditView* edit_view = NULL; 518 AutocompleteEditView* edit_view = NULL;
519 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 519 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
520 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); 520 AutocompletePopupModel* popup_model = edit_view->model()->popup_model();
521 ASSERT_TRUE(popup_model); 521 ASSERT_TRUE(popup_model);
522 522
523 // Input something to trigger inline autocomplete. 523 // Input something to trigger inline autocomplete.
524 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); 524 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
525 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 525 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
526 ASSERT_TRUE(popup_model->IsOpen()); 526 ASSERT_TRUE(popup_model->IsOpen());
527 527
528 std::wstring old_text = edit_view->GetText(); 528 std::wstring old_text = edit_view->GetText();
529 529
530 // Make sure inline autocomplete is triggerred. 530 // Make sure inline autocomplete is triggerred.
531 EXPECT_GT(old_text.length(), arraysize(kSearchText) - 1); 531 EXPECT_GT(old_text.length(), arraysize(kSearchText) - 1);
532 532
533 size_t old_selected_line = popup_model->selected_line(); 533 size_t old_selected_line = popup_model->selected_line();
534 EXPECT_EQ(0U, old_selected_line); 534 EXPECT_EQ(0U, old_selected_line);
535 535
536 // Move to another line with different text. 536 // Move to another line with different text.
537 size_t size = popup_model->result().size(); 537 size_t size = popup_model->result().size();
538 while (popup_model->selected_line() < size - 1) { 538 while (popup_model->selected_line() < size - 1) {
539 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_DOWN, false, false, false)); 539 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_DOWN, false, false, false));
540 ASSERT_NE(old_selected_line, popup_model->selected_line()); 540 ASSERT_NE(old_selected_line, popup_model->selected_line());
541 if (old_text != edit_view->GetText()) 541 if (old_text != edit_view->GetText())
542 break; 542 break;
543 } 543 }
544 544
545 EXPECT_NE(old_text, edit_view->GetText()); 545 EXPECT_NE(old_text, edit_view->GetText());
546 546
547 // Escape shall revert back to the default match item. 547 // Escape shall revert back to the default match item.
548 ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_ESCAPE, false, false, false)); 548 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_ESCAPE, false, false, false));
549 EXPECT_EQ(old_text, edit_view->GetText()); 549 EXPECT_EQ(old_text, edit_view->GetText());
550 EXPECT_EQ(old_selected_line, popup_model->selected_line()); 550 EXPECT_EQ(old_selected_line, popup_model->selected_line());
551 } 551 }
OLDNEW
« no previous file with comments | « base/win_util.cc ('k') | chrome/browser/autocomplete/autocomplete_edit_view_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698