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

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: Only allow 0x0020 and 0x3000 for now. 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 18 matching lines...) Expand all
571 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, 555 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED,
572 popup_model->result().default_match()->type); 556 popup_model->result().default_match()->type);
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 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EscapeToDefaultMatch) { 564 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EscapeToDefaultMatch) {
581 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
582
583 ASSERT_NO_FATAL_FAILURE(SetupComponents());
584 browser()->FocusLocationBar();
585
586 AutocompleteEditView* edit_view = NULL; 565 AutocompleteEditView* edit_view = NULL;
587 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 566 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
588 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); 567 AutocompletePopupModel* popup_model = edit_view->model()->popup_model();
589 ASSERT_TRUE(popup_model); 568 ASSERT_TRUE(popup_model);
590 569
591 // Input something to trigger inline autocomplete. 570 // Input something to trigger inline autocomplete.
592 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); 571 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kInlineAutocompleteTextKeys));
593 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 572 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
594 ASSERT_TRUE(popup_model->IsOpen()); 573 ASSERT_TRUE(popup_model->IsOpen());
595 574
596 std::wstring old_text = edit_view->GetText(); 575 std::wstring old_text = edit_view->GetText();
597 576
598 // Make sure inline autocomplete is triggerred. 577 // Make sure inline autocomplete is triggerred.
599 EXPECT_GT(old_text.length(), arraysize(kSearchText) - 1); 578 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1);
600 579
601 size_t old_selected_line = popup_model->selected_line(); 580 size_t old_selected_line = popup_model->selected_line();
602 EXPECT_EQ(0U, old_selected_line); 581 EXPECT_EQ(0U, old_selected_line);
603 582
604 // Move to another line with different text. 583 // Move to another line with different text.
605 size_t size = popup_model->result().size(); 584 size_t size = popup_model->result().size();
606 while (popup_model->selected_line() < size - 1) { 585 while (popup_model->selected_line() < size - 1) {
607 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DOWN, false, false, false)); 586 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DOWN, false, false, false));
608 ASSERT_NE(old_selected_line, popup_model->selected_line()); 587 ASSERT_NE(old_selected_line, popup_model->selected_line());
609 if (old_text != edit_view->GetText()) 588 if (old_text != edit_view->GetText())
610 break; 589 break;
611 } 590 }
612 591
613 EXPECT_NE(old_text, edit_view->GetText()); 592 EXPECT_NE(old_text, edit_view->GetText());
614 593
615 // Escape shall revert back to the default match item. 594 // Escape shall revert back to the default match item.
616 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, false, false, false)); 595 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, false, false, false));
617 EXPECT_EQ(old_text, edit_view->GetText()); 596 EXPECT_EQ(old_text, edit_view->GetText());
618 EXPECT_EQ(old_selected_line, popup_model->selected_line()); 597 EXPECT_EQ(old_selected_line, popup_model->selected_line());
619 } 598 }
620 599
621 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BasicTextOperations) { 600 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BasicTextOperations) {
622 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
623
624 ASSERT_NO_FATAL_FAILURE(SetupComponents());
625 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); 601 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL));
626 browser()->FocusLocationBar(); 602 browser()->FocusLocationBar();
627 603
628 AutocompleteEditView* edit_view = NULL; 604 AutocompleteEditView* edit_view = NULL;
629 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 605 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
630 606
631 std::wstring old_text = edit_view->GetText(); 607 std::wstring old_text = edit_view->GetText();
632 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text); 608 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text);
633 EXPECT_TRUE(edit_view->IsSelectAll()); 609 EXPECT_TRUE(edit_view->IsSelectAll());
634 610
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 648
673 // Check if RevertAll() can set text and cursor correctly. 649 // Check if RevertAll() can set text and cursor correctly.
674 edit_view->RevertAll(); 650 edit_view->RevertAll();
675 EXPECT_FALSE(edit_view->IsSelectAll()); 651 EXPECT_FALSE(edit_view->IsSelectAll());
676 EXPECT_EQ(old_text, edit_view->GetText()); 652 EXPECT_EQ(old_text, edit_view->GetText());
677 edit_view->GetSelectionBounds(&start, &end); 653 edit_view->GetSelectionBounds(&start, &end);
678 EXPECT_EQ(old_text.size(), start); 654 EXPECT_EQ(old_text.size(), start);
679 EXPECT_EQ(old_text.size(), end); 655 EXPECT_EQ(old_text.size(), end);
680 } 656 }
681 657
658 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AcceptKeywordBySpace) {
659 AutocompleteEditView* edit_view = NULL;
660 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
661
662 std::wstring text = UTF8ToWide(kSearchKeyword);
663
664 // Trigger keyword hint mode.
665 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
666 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
667 ASSERT_EQ(text, edit_view->model()->keyword());
668 ASSERT_EQ(text, edit_view->GetText());
669
670 // Trigger keyword mode by space.
671 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false));
672 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
673 ASSERT_EQ(text, edit_view->model()->keyword());
674 ASSERT_TRUE(edit_view->GetText().empty());
675
676 // Revert to keyword hint mode.
677 edit_view->model()->ClearKeyword(std::wstring());
678 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
679 ASSERT_EQ(text, edit_view->model()->keyword());
680 ASSERT_EQ(text, edit_view->GetText());
681
682 // Keyword should also be accepted by typing an ideographic space.
683 edit_view->OnBeforePossibleChange();
684 edit_view->SetWindowTextAndCaretPos(text + L"\x3000", text.length() + 1);
685 edit_view->OnAfterPossibleChange();
686 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
687 ASSERT_EQ(text, edit_view->model()->keyword());
688 ASSERT_TRUE(edit_view->GetText().empty());
689
690 // Revert to keyword hint mode.
691 edit_view->model()->ClearKeyword(std::wstring());
692 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
693 ASSERT_EQ(text, edit_view->model()->keyword());
694 ASSERT_EQ(text, edit_view->GetText());
695
696 // Keyword shouldn't be accepted by pasting.
697 // Simulate pasting a whitespace to the end of content.
698 edit_view->OnBeforePossibleChange();
699 edit_view->model()->on_paste();
700 edit_view->SetWindowTextAndCaretPos(text + L" ", text.length() + 1);
701 edit_view->OnAfterPossibleChange();
702 // Should be still in keyword hint mode.
703 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
704 ASSERT_EQ(text, edit_view->model()->keyword());
705 ASSERT_EQ(text + L" ", edit_view->GetText());
706
707 // Keyword shouldn't be accepted by pressing space with a trailing whitespace.
708 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false));
709 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
710 ASSERT_EQ(text, edit_view->model()->keyword());
711 ASSERT_EQ(text + L" ", edit_view->GetText());
712
713 // Keyword shouldn't be accepted by deleting the trailing space.
714 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false));
715 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
716 ASSERT_EQ(text, edit_view->model()->keyword());
717 ASSERT_EQ(text + L" ", edit_view->GetText());
718
719 // Keyword shouldn't be accepted by pressing space in the middle of content.
720 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, false, false, false));
721 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false));
722 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
723 ASSERT_EQ(text, edit_view->model()->keyword());
724 ASSERT_EQ(text + L" ", edit_view->GetText());
725
726 // Keyword shouldn't be accepted by pasting "foo bar".
727 edit_view->SetUserText(std::wstring());
728 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
729 ASSERT_TRUE(edit_view->model()->keyword().empty());
730
731 edit_view->OnBeforePossibleChange();
732 edit_view->model()->on_paste();
733 edit_view->SetWindowTextAndCaretPos(text + L" bar", text.length() + 4);
734 edit_view->OnAfterPossibleChange();
735 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
736 ASSERT_TRUE(edit_view->model()->keyword().empty());
737 ASSERT_EQ(text + L" bar", edit_view->GetText());
738
739 // Keyword shouldn't be accepted by pressing space with a selected range.
740 edit_view->OnBeforePossibleChange();
741 edit_view->OnInlineAutocompleteTextMaybeChanged(text + L" ", text.length());
742 edit_view->OnAfterPossibleChange();
743 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
744 ASSERT_EQ(text, edit_view->model()->keyword());
745 ASSERT_EQ(text + L" ", edit_view->GetText());
746
747 std::wstring::size_type start, end;
748 edit_view->GetSelectionBounds(&start, &end);
749 ASSERT_NE(start, end);
750 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 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 edit_view->GetSelectionBounds(&start, &end);
756 ASSERT_EQ(start, end);
757 }
758
682 #if defined(OS_LINUX) 759 #if defined(OS_LINUX)
683 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, UndoRedoLinux) { 760 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, UndoRedoLinux) {
684 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
685
686 ASSERT_NO_FATAL_FAILURE(SetupComponents());
687 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); 761 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL));
688 browser()->FocusLocationBar(); 762 browser()->FocusLocationBar();
689 763
690 AutocompleteEditView* edit_view = NULL; 764 AutocompleteEditView* edit_view = NULL;
691 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 765 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
692 766
693 std::wstring old_text = edit_view->GetText(); 767 std::wstring old_text = edit_view->GetText();
694 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text); 768 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text);
695 EXPECT_TRUE(edit_view->IsSelectAll()); 769 EXPECT_TRUE(edit_view->IsSelectAll());
696 770
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, true, false, false)); 815 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, true, false, false));
742 EXPECT_EQ(old_text, edit_view->GetText()); 816 EXPECT_EQ(old_text, edit_view->GetText());
743 817
744 // Undo again. 818 // Undo again.
745 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, true, false, false)); 819 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, true, false, false));
746 EXPECT_TRUE(edit_view->GetText().empty()); 820 EXPECT_TRUE(edit_view->GetText().empty());
747 } 821 }
748 822
749 // See http://crbug.com/63860 823 // See http://crbug.com/63860
750 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, PrimarySelection) { 824 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, PrimarySelection) {
751 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
752
753 browser()->FocusLocationBar();
754 AutocompleteEditView* edit_view = NULL; 825 AutocompleteEditView* edit_view = NULL;
755 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 826 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
756 edit_view->SetUserText(L"Hello world"); 827 edit_view->SetUserText(L"Hello world");
757 EXPECT_FALSE(edit_view->IsSelectAll()); 828 EXPECT_FALSE(edit_view->IsSelectAll());
758 829
759 // Move the cursor to the end. 830 // Move the cursor to the end.
760 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, false, false, false)); 831 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, false, false, false));
761 832
762 // Select all text by pressing Shift+Home 833 // Select all text by pressing Shift+Home
763 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME, false, true, false)); 834 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME, false, true, false));
764 EXPECT_TRUE(edit_view->IsSelectAll()); 835 EXPECT_TRUE(edit_view->IsSelectAll());
765 836
766 // The selected content should be saved to the PRIMARY clipboard. 837 // The selected content should be saved to the PRIMARY clipboard.
767 EXPECT_EQ("Hello world", GetPrimarySelectionText()); 838 EXPECT_EQ("Hello world", GetPrimarySelectionText());
768 839
769 // Move the cursor to the end. 840 // Move the cursor to the end.
770 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, false, false, false)); 841 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, false, false, false));
771 EXPECT_FALSE(edit_view->IsSelectAll()); 842 EXPECT_FALSE(edit_view->IsSelectAll());
772 843
773 // The content in the PRIMARY clipboard should not be cleared. 844 // The content in the PRIMARY clipboard should not be cleared.
774 EXPECT_EQ("Hello world", GetPrimarySelectionText()); 845 EXPECT_EQ("Hello world", GetPrimarySelectionText());
775 } 846 }
776 847
777 // See http://crosbug.com/10306 848 // See http://crosbug.com/10306
778 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, 849 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest,
779 BackspaceDeleteHalfWidthKatakana) { 850 BackspaceDeleteHalfWidthKatakana) {
780 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
781
782 browser()->FocusLocationBar();
783 AutocompleteEditView* edit_view = NULL; 851 AutocompleteEditView* edit_view = NULL;
784 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 852 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
785 // Insert text: ダ 853 // Insert text: ダ
786 edit_view->SetUserText(UTF8ToWide("\357\276\200\357\276\236")); 854 edit_view->SetUserText(UTF8ToWide("\357\276\200\357\276\236"));
787 855
788 // Move the cursor to the end. 856 // Move the cursor to the end.
789 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, false, false, false)); 857 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, false, false, false));
790 858
791 // Backspace should delete one character. 859 // Backspace should delete one character.
792 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); 860 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false));
793 EXPECT_EQ(UTF8ToWide("\357\276\200"), edit_view->GetText()); 861 EXPECT_EQ(UTF8ToWide("\357\276\200"), edit_view->GetText());
794 } 862 }
795 863
796 // http://crbug.com/12316 864 // http://crbug.com/12316
797 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, PasteReplacingAll) { 865 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, PasteReplacingAll) {
798 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
799
800 ASSERT_NO_FATAL_FAILURE(SetupComponents());
801 browser()->FocusLocationBar();
802
803 AutocompleteEditView* edit_view = NULL; 866 AutocompleteEditView* edit_view = NULL;
804 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 867 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
805 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); 868 AutocompletePopupModel* popup_model = edit_view->model()->popup_model();
806 ASSERT_TRUE(popup_model); 869 ASSERT_TRUE(popup_model);
807 870
808 SetClipboardText(kSearchText); 871 SetClipboardText(kSearchText);
809 872
810 // Paste text. 873 // Paste text.
811 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, true, false, false)); 874 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, true, false, false));
812 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 875 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
813 ASSERT_TRUE(popup_model->IsOpen()); 876 ASSERT_TRUE(popup_model->IsOpen());
814 877
815 // Inline autocomplete shouldn't be triggered. 878 // Inline autocomplete shouldn't be triggered.
816 ASSERT_EQ(L"abc", edit_view->GetText()); 879 ASSERT_EQ(L"abc", edit_view->GetText());
817 } 880 }
818 #endif 881 #endif
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit.cc ('k') | chrome/browser/autocomplete/autocomplete_edit_view_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698