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

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

Issue 6252003: Accept keyword by pressing space. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update Created 9 years, 11 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 const wchar_t kSearchSingleCharKeys[] = { ui::VKEY_Z, 0 }; 58 const wchar_t kSearchSingleCharKeys[] = { ui::VKEY_Z, 0 };
59 const char kSearchSingleCharURL[] = "http://www.foo.com/search?q=z"; 59 const char kSearchSingleCharURL[] = "http://www.foo.com/search?q=z";
60 60
61 const char kHistoryPageURL[] = "chrome://history/#q=abc"; 61 const char kHistoryPageURL[] = "chrome://history/#q=abc";
62 62
63 const char kDesiredTLDHostname[] = "www.bar.com"; 63 const char kDesiredTLDHostname[] = "www.bar.com";
64 const wchar_t kDesiredTLDKeys[] = { 64 const wchar_t kDesiredTLDKeys[] = {
65 ui::VKEY_B, ui::VKEY_A, ui::VKEY_R, 0 65 ui::VKEY_B, ui::VKEY_A, ui::VKEY_R, 0
66 }; 66 };
67 67
68 const char kInlineAutocompleteText[] = "def";
69 const wchar_t kInlineAutocompleteTextKeys[] = {
70 ui::VKEY_D, ui::VKEY_E, ui::VKEY_F, 0
71 };
72
68 // Hostnames that shall be blocked by host resolver. 73 // Hostnames that shall be blocked by host resolver.
69 const char *kBlockedHostnames[] = { 74 const char *kBlockedHostnames[] = {
70 "foo", 75 "foo",
71 "*.foo.com", 76 "*.foo.com",
72 "bar", 77 "bar",
73 "*.bar.com", 78 "*.bar.com",
74 "abc", 79 "abc",
75 "*.abc.com", 80 "*.abc.com",
81 "def",
82 "*.def.com",
76 "history", 83 "history",
77 "z" 84 "z"
78 }; 85 };
79 86
80 const struct TestHistoryEntry { 87 const struct TestHistoryEntry {
81 const char* url; 88 const char* url;
82 const char* title; 89 const char* title;
83 const char* body; 90 const char* body;
84 int visit_count; 91 int visit_count;
85 int typed_count; 92 int typed_count;
86 bool starred; 93 bool starred;
87 } kHistoryEntries[] = { 94 } kHistoryEntries[] = {
88 {"http://www.bar.com/1", "Page 1", kSearchText, 1, 1, false }, 95 {"http://www.bar.com/1", "Page 1", kSearchText, 1, 1, false },
89 {"http://www.bar.com/2", "Page 2", kSearchText, 1, 1, false }, 96 {"http://www.bar.com/2", "Page 2", kSearchText, 1, 1, false },
90 {"http://www.bar.com/3", "Page 3", kSearchText, 1, 1, false }, 97 {"http://www.bar.com/3", "Page 3", kSearchText, 1, 1, false },
91 {"http://www.bar.com/4", "Page 4", kSearchText, 1, 1, false }, 98 {"http://www.bar.com/4", "Page 4", kSearchText, 1, 1, false },
92 {"http://www.bar.com/5", "Page 5", kSearchText, 1, 1, false }, 99 {"http://www.bar.com/5", "Page 5", kSearchText, 1, 1, false },
93 {"http://www.bar.com/6", "Page 6", kSearchText, 1, 1, false }, 100 {"http://www.bar.com/6", "Page 6", kSearchText, 1, 1, false },
94 {"http://www.bar.com/7", "Page 7", kSearchText, 1, 1, false }, 101 {"http://www.bar.com/7", "Page 7", kSearchText, 1, 1, false },
95 {"http://www.bar.com/8", "Page 8", kSearchText, 1, 1, false }, 102 {"http://www.bar.com/8", "Page 8", kSearchText, 1, 1, false },
96 {"http://www.bar.com/9", "Page 9", kSearchText, 1, 1, false }, 103 {"http://www.bar.com/9", "Page 9", kSearchText, 1, 1, false },
97 104
98 // To trigger inline autocomplete. 105 // To trigger inline autocomplete.
99 {"http://www.abc.com", "Page abc", kSearchText, 10000, 10000, true }, 106 {"http://www.def.com", "Page def", kSearchText, 10000, 10000, true },
100 }; 107 };
101 108
102 #if defined(OS_LINUX) 109 #if defined(OS_LINUX)
103 // Returns the text stored in the PRIMARY clipboard. 110 // Returns the text stored in the PRIMARY clipboard.
104 std::string GetPrimarySelectionText() { 111 std::string GetPrimarySelectionText() {
105 GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); 112 GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
106 DCHECK(clipboard); 113 DCHECK(clipboard);
107 114
108 gchar* selection_text = gtk_clipboard_wait_for_text(clipboard); 115 gchar* selection_text = gtk_clipboard_wait_for_text(clipboard);
109 std::string result(selection_text ? selection_text : ""); 116 std::string result(selection_text ? selection_text : "");
(...skipping 12 matching lines...) Expand all
122 129
123 } // namespace 130 } // namespace
124 131
125 class AutocompleteEditViewTest : public InProcessBrowserTest, 132 class AutocompleteEditViewTest : public InProcessBrowserTest,
126 public NotificationObserver { 133 public NotificationObserver {
127 protected: 134 protected:
128 AutocompleteEditViewTest() { 135 AutocompleteEditViewTest() {
129 set_show_window(true); 136 set_show_window(true);
130 } 137 }
131 138
139 virtual void SetUpOnMainThread() {
140 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
141 ASSERT_NO_FATAL_FAILURE(SetupComponents());
142 browser()->FocusLocationBar();
143 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR));
144 }
145
132 static void GetAutocompleteEditViewForBrowser( 146 static void GetAutocompleteEditViewForBrowser(
133 const Browser* browser, 147 const Browser* browser,
134 AutocompleteEditView** edit_view) { 148 AutocompleteEditView** edit_view) {
135 BrowserWindow* window = browser->window(); 149 BrowserWindow* window = browser->window();
136 ASSERT_TRUE(window); 150 ASSERT_TRUE(window);
137 LocationBar* loc_bar = window->GetLocationBar(); 151 LocationBar* loc_bar = window->GetLocationBar();
138 ASSERT_TRUE(loc_bar); 152 ASSERT_TRUE(loc_bar);
139 *edit_view = loc_bar->location_entry(); 153 *edit_view = loc_bar->location_entry();
140 ASSERT_TRUE(*edit_view); 154 ASSERT_TRUE(*edit_view);
141 } 155 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 } 314 }
301 MessageLoopForUI::current()->Quit(); 315 MessageLoopForUI::current()->Quit();
302 } 316 }
303 }; 317 };
304 318
305 // Test if ctrl-* accelerators are workable in omnibox. 319 // Test if ctrl-* accelerators are workable in omnibox.
306 // See http://crbug.com/19193: omnibox blocks ctrl-* commands 320 // See http://crbug.com/19193: omnibox blocks ctrl-* commands
307 // 321 //
308 // Flaky on interactive tests (dbg), http://crbug.com/69433 322 // Flaky on interactive tests (dbg), http://crbug.com/69433
309 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, FLAKY_BrowserAccelerators) { 323 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, FLAKY_BrowserAccelerators) {
310 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
311
312 browser()->FocusLocationBar();
313 AutocompleteEditView* edit_view = NULL; 324 AutocompleteEditView* edit_view = NULL;
314 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 325 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
315 326
316 int tab_count = browser()->tab_count(); 327 int tab_count = browser()->tab_count();
317 328
318 // Create a new Tab. 329 // Create a new Tab.
319 browser()->NewTab(); 330 browser()->NewTab();
320 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1)); 331 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1));
321 332
322 // Select the first Tab. 333 // Select the first Tab.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 NotificationType::BROWSER_CLOSED, Source<Browser>(browser()))); 371 NotificationType::BROWSER_CLOSED, Source<Browser>(browser())));
361 #endif 372 #endif
362 } 373 }
363 374
364 // Flakily fails and times out on Win only. http://crbug.com/69941 375 // Flakily fails and times out on Win only. http://crbug.com/69941
365 #if defined(OS_WIN) 376 #if defined(OS_WIN)
366 #define MAYBE_PopupAccelerators DISABLED_PopupAccelerators 377 #define MAYBE_PopupAccelerators DISABLED_PopupAccelerators
367 #else 378 #else
368 #define MAYBE_PopupAccelerators PopupAccelerators 379 #define MAYBE_PopupAccelerators PopupAccelerators
369 #endif 380 #endif
370
371 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, MAYBE_PopupAccelerators) { 381 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, MAYBE_PopupAccelerators) {
372 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
373
374 // Create a popup. 382 // Create a popup.
375 Browser* popup = CreateBrowserForPopup(browser()->profile()); 383 Browser* popup = CreateBrowserForPopup(browser()->profile());
376 AutocompleteEditView* edit_view = NULL; 384 AutocompleteEditView* edit_view = NULL;
377 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditViewForBrowser(popup, &edit_view)); 385 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditViewForBrowser(popup, &edit_view));
378 popup->FocusLocationBar(); 386 popup->FocusLocationBar();
379 EXPECT_TRUE(edit_view->IsSelectAll()); 387 EXPECT_TRUE(edit_view->IsSelectAll());
380 388
381 // Try ctrl-w to close the popup. 389 // Try ctrl-w to close the popup.
382 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 390 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
383 popup, ui::VKEY_W, true, false, false, false, 391 popup, ui::VKEY_W, true, false, false, false,
(...skipping 27 matching lines...) Expand all
411 419
412 #if !defined(OS_CHROMEOS) 420 #if !defined(OS_CHROMEOS)
413 // Try alt-f4 to close the popup. 421 // Try alt-f4 to close the popup.
414 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 422 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
415 popup, ui::VKEY_F4, false, false, true, false, 423 popup, ui::VKEY_F4, false, false, true, false,
416 NotificationType::BROWSER_CLOSED, Source<Browser>(popup))); 424 NotificationType::BROWSER_CLOSED, Source<Browser>(popup)));
417 #endif 425 #endif
418 } 426 }
419 427
420 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BackspaceInKeywordMode) { 428 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BackspaceInKeywordMode) {
421 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
422
423 ASSERT_NO_FATAL_FAILURE(SetupComponents());
424 browser()->FocusLocationBar();
425
426 AutocompleteEditView* edit_view = NULL; 429 AutocompleteEditView* edit_view = NULL;
427 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 430 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
428 431
429 // Trigger keyword hint mode. 432 // Trigger keyword hint mode.
430 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); 433 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
431 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); 434 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
432 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); 435 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword()));
433 436
434 // Trigger keyword mode. 437 // Trigger keyword mode.
435 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, false, false, false)); 438 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, false, false, false));
(...skipping 29 matching lines...) Expand all
465 // Backspace at the beginning of the search text shall turn off 468 // Backspace at the beginning of the search text shall turn off
466 // the keyword mode. 469 // the keyword mode.
467 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); 470 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false));
468 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); 471 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
469 ASSERT_EQ(std::string(), WideToUTF8(edit_view->model()->keyword())); 472 ASSERT_EQ(std::string(), WideToUTF8(edit_view->model()->keyword()));
470 ASSERT_EQ(std::string(kSearchKeyword) + kSearchText, 473 ASSERT_EQ(std::string(kSearchKeyword) + kSearchText,
471 WideToUTF8(edit_view->GetText())); 474 WideToUTF8(edit_view->GetText()));
472 } 475 }
473 476
474 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, Escape) { 477 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, Escape) {
475 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
476
477 ASSERT_NO_FATAL_FAILURE(SetupComponents());
478 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIHistoryURL)); 478 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIHistoryURL));
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 483
484 std::wstring old_text = edit_view->GetText(); 484 std::wstring old_text = edit_view->GetText();
485 EXPECT_FALSE(old_text.empty()); 485 EXPECT_FALSE(old_text.empty());
486 EXPECT_TRUE(edit_view->IsSelectAll()); 486 EXPECT_TRUE(edit_view->IsSelectAll());
487 487
488 // Delete all text in omnibox. 488 // Delete all text in omnibox.
489 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); 489 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false));
490 EXPECT_TRUE(edit_view->GetText().empty()); 490 EXPECT_TRUE(edit_view->GetText().empty());
491 491
492 // Escape shall revert the text in omnibox. 492 // Escape shall revert the text in omnibox.
493 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, false, false, false)); 493 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, false, false, false));
494 EXPECT_EQ(old_text, edit_view->GetText()); 494 EXPECT_EQ(old_text, edit_view->GetText());
495 EXPECT_TRUE(edit_view->IsSelectAll()); 495 EXPECT_TRUE(edit_view->IsSelectAll());
496 } 496 }
497 497
498 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, DesiredTLD) { 498 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, DesiredTLD) {
499 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
500
501 ASSERT_NO_FATAL_FAILURE(SetupComponents());
502 browser()->FocusLocationBar();
503
504 AutocompleteEditView* edit_view = NULL; 499 AutocompleteEditView* edit_view = NULL;
505 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 500 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
506 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); 501 AutocompletePopupModel* popup_model = edit_view->model()->popup_model();
507 ASSERT_TRUE(popup_model); 502 ASSERT_TRUE(popup_model);
508 503
509 // Test ctrl-Enter. 504 // Test ctrl-Enter.
510 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kDesiredTLDKeys)); 505 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kDesiredTLDKeys));
511 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 506 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
512 ASSERT_TRUE(popup_model->IsOpen()); 507 ASSERT_TRUE(popup_model->IsOpen());
513 // ctrl-Enter triggers desired_tld feature, thus www.bar.com shall be opened. 508 // ctrl-Enter triggers desired_tld feature, thus www.bar.com shall be opened.
514 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, true, false, false)); 509 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, true, false, false));
515 510
516 GURL url = browser()->GetSelectedTabContents()->GetURL(); 511 GURL url = browser()->GetSelectedTabContents()->GetURL();
517 EXPECT_STREQ(kDesiredTLDHostname, url.host().c_str()); 512 EXPECT_STREQ(kDesiredTLDHostname, url.host().c_str());
518 } 513 }
519 514
520 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AltEnter) { 515 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AltEnter) {
521 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
522
523 ASSERT_NO_FATAL_FAILURE(SetupComponents());
524 browser()->FocusLocationBar();
525
526 AutocompleteEditView* edit_view = NULL; 516 AutocompleteEditView* edit_view = NULL;
527 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 517 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
528 518
529 edit_view->SetUserText(ASCIIToWide(chrome::kChromeUIHistoryURL)); 519 edit_view->SetUserText(ASCIIToWide(chrome::kChromeUIHistoryURL));
530 int tab_count = browser()->tab_count(); 520 int tab_count = browser()->tab_count();
531 // alt-Enter opens a new tab. 521 // alt-Enter opens a new tab.
532 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, false, false, true)); 522 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, false, false, true));
533 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1)); 523 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1));
534 } 524 }
535 525
536 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EnterToSearch) { 526 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EnterToSearch) {
537 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
538
539 ASSERT_NO_FATAL_FAILURE(SetupHostResolver());
540 ASSERT_NO_FATAL_FAILURE(SetupSearchEngine());
541 browser()->FocusLocationBar();
542
543 AutocompleteEditView* edit_view = NULL; 527 AutocompleteEditView* edit_view = NULL;
544 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 528 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
545 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); 529 AutocompletePopupModel* popup_model = edit_view->model()->popup_model();
546 ASSERT_TRUE(popup_model); 530 ASSERT_TRUE(popup_model);
547 531
548 // Test Enter to search. 532 // Test Enter to search.
549 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); 533 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
550 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 534 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
551 ASSERT_TRUE(popup_model->IsOpen()); 535 ASSERT_TRUE(popup_model->IsOpen());
552 536
(...skipping 20 matching lines...) Expand all
573 557
574 // Open the default match. 558 // Open the default match.
575 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, false, false, false)); 559 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, false, false, false));
576 url = browser()->GetSelectedTabContents()->GetURL(); 560 url = browser()->GetSelectedTabContents()->GetURL();
577 EXPECT_STREQ(kSearchSingleCharURL, url.spec().c_str()); 561 EXPECT_STREQ(kSearchSingleCharURL, url.spec().c_str());
578 } 562 }
579 563
580 // See http://crbug.com/20934: Omnibox keyboard behavior wrong for 564 // See http://crbug.com/20934: Omnibox keyboard behavior wrong for
581 // "See recent pages in history" 565 // "See recent pages in history"
582 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EnterToOpenHistoryPage) { 566 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EnterToOpenHistoryPage) {
583 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
584
585 ASSERT_NO_FATAL_FAILURE(SetupComponents());
586 browser()->FocusLocationBar();
587
588 AutocompleteEditView* edit_view = NULL; 567 AutocompleteEditView* edit_view = NULL;
589 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 568 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
590 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); 569 AutocompletePopupModel* popup_model = edit_view->model()->popup_model();
591 ASSERT_TRUE(popup_model); 570 ASSERT_TRUE(popup_model);
592 571
593 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); 572 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
594 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 573 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
595 ASSERT_TRUE(popup_model->IsOpen()); 574 ASSERT_TRUE(popup_model->IsOpen());
596 EXPECT_EQ(0U, popup_model->selected_line()); 575 EXPECT_EQ(0U, popup_model->selected_line());
597 576
(...skipping 14 matching lines...) Expand all
612 ASSERT_EQ(AutocompleteMatch::OPEN_HISTORY_PAGE, 591 ASSERT_EQ(AutocompleteMatch::OPEN_HISTORY_PAGE,
613 popup_model->result().match_at(popup_model->selected_line()).type); 592 popup_model->result().match_at(popup_model->selected_line()).type);
614 593
615 // Open the history page item. 594 // Open the history page item.
616 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, false, false, false)); 595 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, false, false, false));
617 GURL url = browser()->GetSelectedTabContents()->GetURL(); 596 GURL url = browser()->GetSelectedTabContents()->GetURL();
618 EXPECT_STREQ(kHistoryPageURL, url.spec().c_str()); 597 EXPECT_STREQ(kHistoryPageURL, url.spec().c_str());
619 } 598 }
620 599
621 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EscapeToDefaultMatch) { 600 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EscapeToDefaultMatch) {
622 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
623
624 ASSERT_NO_FATAL_FAILURE(SetupComponents());
625 browser()->FocusLocationBar();
626
627 AutocompleteEditView* edit_view = NULL; 601 AutocompleteEditView* edit_view = NULL;
628 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 602 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
629 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); 603 AutocompletePopupModel* popup_model = edit_view->model()->popup_model();
630 ASSERT_TRUE(popup_model); 604 ASSERT_TRUE(popup_model);
631 605
632 // Input something to trigger inline autocomplete. 606 // Input something to trigger inline autocomplete.
633 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); 607 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kInlineAutocompleteTextKeys));
634 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 608 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
635 ASSERT_TRUE(popup_model->IsOpen()); 609 ASSERT_TRUE(popup_model->IsOpen());
636 610
637 std::wstring old_text = edit_view->GetText(); 611 std::wstring old_text = edit_view->GetText();
638 612
639 // Make sure inline autocomplete is triggerred. 613 // Make sure inline autocomplete is triggerred.
640 EXPECT_GT(old_text.length(), arraysize(kSearchText) - 1); 614 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1);
641 615
642 size_t old_selected_line = popup_model->selected_line(); 616 size_t old_selected_line = popup_model->selected_line();
643 EXPECT_EQ(0U, old_selected_line); 617 EXPECT_EQ(0U, old_selected_line);
644 618
645 // Move to another line with different text. 619 // Move to another line with different text.
646 size_t size = popup_model->result().size(); 620 size_t size = popup_model->result().size();
647 while (popup_model->selected_line() < size - 1) { 621 while (popup_model->selected_line() < size - 1) {
648 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DOWN, false, false, false)); 622 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DOWN, false, false, false));
649 ASSERT_NE(old_selected_line, popup_model->selected_line()); 623 ASSERT_NE(old_selected_line, popup_model->selected_line());
650 if (old_text != edit_view->GetText()) 624 if (old_text != edit_view->GetText())
651 break; 625 break;
652 } 626 }
653 627
654 EXPECT_NE(old_text, edit_view->GetText()); 628 EXPECT_NE(old_text, edit_view->GetText());
655 629
656 // Escape shall revert back to the default match item. 630 // Escape shall revert back to the default match item.
657 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, false, false, false)); 631 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, false, false, false));
658 EXPECT_EQ(old_text, edit_view->GetText()); 632 EXPECT_EQ(old_text, edit_view->GetText());
659 EXPECT_EQ(old_selected_line, popup_model->selected_line()); 633 EXPECT_EQ(old_selected_line, popup_model->selected_line());
660 } 634 }
661 635
662 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BasicTextOperations) { 636 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BasicTextOperations) {
663 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
664
665 ASSERT_NO_FATAL_FAILURE(SetupComponents());
666 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); 637 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL));
667 browser()->FocusLocationBar(); 638 browser()->FocusLocationBar();
668 639
669 AutocompleteEditView* edit_view = NULL; 640 AutocompleteEditView* edit_view = NULL;
670 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 641 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
671 642
672 std::wstring old_text = edit_view->GetText(); 643 std::wstring old_text = edit_view->GetText();
673 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text); 644 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text);
674 EXPECT_TRUE(edit_view->IsSelectAll()); 645 EXPECT_TRUE(edit_view->IsSelectAll());
675 646
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 684
714 // Check if RevertAll() can set text and cursor correctly. 685 // Check if RevertAll() can set text and cursor correctly.
715 edit_view->RevertAll(); 686 edit_view->RevertAll();
716 EXPECT_FALSE(edit_view->IsSelectAll()); 687 EXPECT_FALSE(edit_view->IsSelectAll());
717 EXPECT_EQ(old_text, edit_view->GetText()); 688 EXPECT_EQ(old_text, edit_view->GetText());
718 edit_view->GetSelectionBounds(&start, &end); 689 edit_view->GetSelectionBounds(&start, &end);
719 EXPECT_EQ(old_text.size(), start); 690 EXPECT_EQ(old_text.size(), start);
720 EXPECT_EQ(old_text.size(), end); 691 EXPECT_EQ(old_text.size(), end);
721 } 692 }
722 693
694 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AcceptKeywordBySpace) {
695 AutocompleteEditView* edit_view = NULL;
696 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
697
698 std::wstring text = UTF8ToWide(kSearchKeyword);
699
700 // Trigger keyword hint mode.
701 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
702 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
703 ASSERT_EQ(text, edit_view->model()->keyword());
704 ASSERT_EQ(text, edit_view->GetText());
705
706 // Trigger keyword mode by space.
707 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false));
708 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
709 ASSERT_EQ(text, edit_view->model()->keyword());
710 ASSERT_TRUE(edit_view->GetText().empty());
711
712 // Revert to keyword hint mode.
713 edit_view->model()->ClearKeyword(std::wstring());
714 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
715 ASSERT_EQ(text, edit_view->model()->keyword());
716 ASSERT_EQ(text, edit_view->GetText());
717
718 // Keyword should also be accepted by typing an ideographic space.
719 edit_view->OnBeforePossibleChange();
720 edit_view->SetWindowTextAndCaretPos(text + L"\x3000", text.length() + 1);
721 edit_view->OnAfterPossibleChange();
722 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
723 ASSERT_EQ(text, edit_view->model()->keyword());
724 ASSERT_TRUE(edit_view->GetText().empty());
725
726 // Revert to keyword hint mode.
727 edit_view->model()->ClearKeyword(std::wstring());
728 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
729 ASSERT_EQ(text, edit_view->model()->keyword());
730 ASSERT_EQ(text, edit_view->GetText());
731
732 // Keyword shouldn't be accepted by pasting.
733 // Simulate pasting a whitespace to the end of content.
734 edit_view->OnBeforePossibleChange();
735 edit_view->model()->on_paste();
736 edit_view->SetWindowTextAndCaretPos(text + L" ", text.length() + 1);
737 edit_view->OnAfterPossibleChange();
738 // Should be still in keyword hint mode.
739 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
740 ASSERT_EQ(text, edit_view->model()->keyword());
741 ASSERT_EQ(text + L" ", edit_view->GetText());
742
743 // Keyword shouldn't be accepted by pressing space with a trailing whitespace.
744 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false));
745 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
746 ASSERT_EQ(text, edit_view->model()->keyword());
747 ASSERT_EQ(text + L" ", edit_view->GetText());
748
749 // Keyword shouldn't be accepted by deleting the trailing space.
750 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false));
751 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
752 ASSERT_EQ(text, edit_view->model()->keyword());
753 ASSERT_EQ(text + L" ", edit_view->GetText());
754
755 // Keyword shouldn't be accepted by pressing space in the middle of content.
756 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, false, false, false));
757 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false));
758 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
759 ASSERT_EQ(text, edit_view->model()->keyword());
760 ASSERT_EQ(text + L" ", edit_view->GetText());
761
762 // Keyword shouldn't be accepted by pasting "foo bar".
763 edit_view->SetUserText(std::wstring());
764 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
765 ASSERT_TRUE(edit_view->model()->keyword().empty());
766
767 edit_view->OnBeforePossibleChange();
768 edit_view->model()->on_paste();
769 edit_view->SetWindowTextAndCaretPos(text + L" bar", text.length() + 4);
770 edit_view->OnAfterPossibleChange();
771 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
772 ASSERT_TRUE(edit_view->model()->keyword().empty());
773 ASSERT_EQ(text + L" bar", edit_view->GetText());
774
775 // Keyword shouldn't be accepted by pressing space with a selected range.
776 edit_view->OnBeforePossibleChange();
777 edit_view->OnInlineAutocompleteTextMaybeChanged(text + L" ", text.length());
778 edit_view->OnAfterPossibleChange();
779 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
780 ASSERT_EQ(text, edit_view->model()->keyword());
781 ASSERT_EQ(text + L" ", edit_view->GetText());
782
783 std::wstring::size_type start, end;
784 edit_view->GetSelectionBounds(&start, &end);
785 ASSERT_NE(start, end);
786 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false));
787 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
788 ASSERT_EQ(text, edit_view->model()->keyword());
789 ASSERT_EQ(text + L" ", edit_view->GetText());
790
791 edit_view->GetSelectionBounds(&start, &end);
792 ASSERT_EQ(start, end);
793 }
794
723 #if defined(OS_LINUX) 795 #if defined(OS_LINUX)
724 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, UndoRedoLinux) { 796 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, UndoRedoLinux) {
725 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
726
727 ASSERT_NO_FATAL_FAILURE(SetupComponents());
728 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); 797 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL));
729 browser()->FocusLocationBar(); 798 browser()->FocusLocationBar();
730 799
731 AutocompleteEditView* edit_view = NULL; 800 AutocompleteEditView* edit_view = NULL;
732 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 801 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
733 802
734 std::wstring old_text = edit_view->GetText(); 803 std::wstring old_text = edit_view->GetText();
735 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text); 804 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text);
736 EXPECT_TRUE(edit_view->IsSelectAll()); 805 EXPECT_TRUE(edit_view->IsSelectAll());
737 806
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, true, false, false)); 851 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, true, false, false));
783 EXPECT_EQ(old_text, edit_view->GetText()); 852 EXPECT_EQ(old_text, edit_view->GetText());
784 853
785 // Undo again. 854 // Undo again.
786 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, true, false, false)); 855 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, true, false, false));
787 EXPECT_TRUE(edit_view->GetText().empty()); 856 EXPECT_TRUE(edit_view->GetText().empty());
788 } 857 }
789 858
790 // See http://crbug.com/63860 859 // See http://crbug.com/63860
791 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, PrimarySelection) { 860 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, PrimarySelection) {
792 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
793
794 browser()->FocusLocationBar();
795 AutocompleteEditView* edit_view = NULL; 861 AutocompleteEditView* edit_view = NULL;
796 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 862 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
797 edit_view->SetUserText(L"Hello world"); 863 edit_view->SetUserText(L"Hello world");
798 EXPECT_FALSE(edit_view->IsSelectAll()); 864 EXPECT_FALSE(edit_view->IsSelectAll());
799 865
800 // Move the cursor to the end. 866 // Move the cursor to the end.
801 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, false, false, false)); 867 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, false, false, false));
802 868
803 // Select all text by pressing Shift+Home 869 // Select all text by pressing Shift+Home
804 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME, false, true, false)); 870 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME, false, true, false));
805 EXPECT_TRUE(edit_view->IsSelectAll()); 871 EXPECT_TRUE(edit_view->IsSelectAll());
806 872
807 // The selected content should be saved to the PRIMARY clipboard. 873 // The selected content should be saved to the PRIMARY clipboard.
808 EXPECT_EQ("Hello world", GetPrimarySelectionText()); 874 EXPECT_EQ("Hello world", GetPrimarySelectionText());
809 875
810 // Move the cursor to the end. 876 // Move the cursor to the end.
811 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, false, false, false)); 877 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, false, false, false));
812 EXPECT_FALSE(edit_view->IsSelectAll()); 878 EXPECT_FALSE(edit_view->IsSelectAll());
813 879
814 // The content in the PRIMARY clipboard should not be cleared. 880 // The content in the PRIMARY clipboard should not be cleared.
815 EXPECT_EQ("Hello world", GetPrimarySelectionText()); 881 EXPECT_EQ("Hello world", GetPrimarySelectionText());
816 } 882 }
817 883
818 // See http://crosbug.com/10306 884 // See http://crosbug.com/10306
819 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, 885 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest,
820 BackspaceDeleteHalfWidthKatakana) { 886 BackspaceDeleteHalfWidthKatakana) {
821 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
822
823 browser()->FocusLocationBar();
824 AutocompleteEditView* edit_view = NULL; 887 AutocompleteEditView* edit_view = NULL;
825 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 888 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
826 // Insert text: ダ 889 // Insert text: ダ
827 edit_view->SetUserText(UTF8ToWide("\357\276\200\357\276\236")); 890 edit_view->SetUserText(UTF8ToWide("\357\276\200\357\276\236"));
828 891
829 // Move the cursor to the end. 892 // Move the cursor to the end.
830 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, false, false, false)); 893 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, false, false, false));
831 894
832 // Backspace should delete one character. 895 // Backspace should delete one character.
833 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); 896 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false));
834 EXPECT_EQ(UTF8ToWide("\357\276\200"), edit_view->GetText()); 897 EXPECT_EQ(UTF8ToWide("\357\276\200"), edit_view->GetText());
835 } 898 }
836 899
837 // http://crbug.com/12316 900 // http://crbug.com/12316
838 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, PasteReplacingAll) { 901 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, PasteReplacingAll) {
839 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
840
841 ASSERT_NO_FATAL_FAILURE(SetupComponents());
842 browser()->FocusLocationBar();
843
844 AutocompleteEditView* edit_view = NULL; 902 AutocompleteEditView* edit_view = NULL;
845 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 903 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
846 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); 904 AutocompletePopupModel* popup_model = edit_view->model()->popup_model();
847 ASSERT_TRUE(popup_model); 905 ASSERT_TRUE(popup_model);
848 906
849 SetClipboardText(kSearchText); 907 SetClipboardText(kSearchText);
850 908
851 // Paste text. 909 // Paste text.
852 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, true, false, false)); 910 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, true, false, false));
853 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 911 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
854 ASSERT_TRUE(popup_model->IsOpen()); 912 ASSERT_TRUE(popup_model->IsOpen());
855 913
856 // Inline autocomplete shouldn't be triggered. 914 // Inline autocomplete shouldn't be triggered.
857 ASSERT_EQ(L"abc", edit_view->GetText()); 915 ASSERT_EQ(L"abc", edit_view->GetText());
858 } 916 }
859 #endif 917 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698