OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
13 #include "chrome/browser/autocomplete/autocomplete.h" | 13 #include "chrome/browser/autocomplete/autocomplete.h" |
14 #include "chrome/browser/autocomplete/autocomplete_match.h" | 14 #include "chrome/browser/autocomplete/autocomplete_match.h" |
15 #include "chrome/browser/autocomplete/history_quick_provider.h" | 15 #include "chrome/browser/autocomplete/history_quick_provider.h" |
16 #include "chrome/browser/bookmarks/bookmark_model.h" | 16 #include "chrome/browser/bookmarks/bookmark_model.h" |
17 #include "chrome/browser/bookmarks/bookmark_utils.h" | 17 #include "chrome/browser/bookmarks/bookmark_utils.h" |
18 #include "chrome/browser/history/history.h" | 18 #include "chrome/browser/history/history.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/search_engines/template_url.h" | 20 #include "chrome/browser/search_engines/template_url.h" |
21 #include "chrome/browser/search_engines/template_url_service.h" | 21 #include "chrome/browser/search_engines/template_url_service.h" |
22 #include "chrome/browser/search_engines/template_url_service_factory.h" | 22 #include "chrome/browser/search_engines/template_url_service_factory.h" |
23 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/ui/browser_commands.h" | 24 #include "chrome/browser/ui/browser_commands.h" |
| 25 #include "chrome/browser/ui/browser_tabstrip.h" |
25 #include "chrome/browser/ui/browser_window.h" | 26 #include "chrome/browser/ui/browser_window.h" |
26 #include "chrome/browser/ui/omnibox/location_bar.h" | 27 #include "chrome/browser/ui/omnibox/location_bar.h" |
27 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 28 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
28 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 29 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
29 #include "chrome/common/chrome_notification_types.h" | 30 #include "chrome/common/chrome_notification_types.h" |
30 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
31 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
32 #include "chrome/test/base/in_process_browser_test.h" | 33 #include "chrome/test/base/in_process_browser_test.h" |
33 #include "chrome/test/base/ui_test_utils.h" | 34 #include "chrome/test/base/ui_test_utils.h" |
34 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 | 577 |
577 // Test ctrl-Enter. | 578 // Test ctrl-Enter. |
578 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kDesiredTLDKeys)); | 579 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kDesiredTLDKeys)); |
579 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | 580 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
580 ASSERT_TRUE(popup_model->IsOpen()); | 581 ASSERT_TRUE(popup_model->IsOpen()); |
581 // ctrl-Enter triggers desired_tld feature, thus www.bar.com shall be | 582 // ctrl-Enter triggers desired_tld feature, thus www.bar.com shall be |
582 // opened. | 583 // opened. |
583 ASSERT_TRUE(SendKeyAndWait(browser(), ui::VKEY_RETURN, ui::EF_CONTROL_DOWN, | 584 ASSERT_TRUE(SendKeyAndWait(browser(), ui::VKEY_RETURN, ui::EF_CONTROL_DOWN, |
584 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 585 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
585 content::Source<content::NavigationController>( | 586 content::Source<content::NavigationController>( |
586 &browser()->GetActiveWebContents()->GetController()))); | 587 &chrome::GetActiveWebContents(browser())->GetController()))); |
587 | 588 |
588 GURL url = browser()->GetActiveWebContents()->GetURL(); | 589 GURL url = chrome::GetActiveWebContents(browser())->GetURL(); |
589 EXPECT_STREQ(kDesiredTLDHostname, url.host().c_str()); | 590 EXPECT_STREQ(kDesiredTLDHostname, url.host().c_str()); |
590 } | 591 } |
591 | 592 |
592 void AltEnterTest() { | 593 void AltEnterTest() { |
593 OmniboxView* omnibox_view = NULL; | 594 OmniboxView* omnibox_view = NULL; |
594 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | 595 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
595 | 596 |
596 omnibox_view->SetUserText(ASCIIToUTF16(chrome::kChromeUIHistoryURL)); | 597 omnibox_view->SetUserText(ASCIIToUTF16(chrome::kChromeUIHistoryURL)); |
597 int tab_count = browser()->tab_count(); | 598 int tab_count = browser()->tab_count(); |
598 // alt-Enter opens a new tab. | 599 // alt-Enter opens a new tab. |
(...skipping 13 matching lines...) Expand all Loading... |
612 ASSERT_TRUE(popup_model->IsOpen()); | 613 ASSERT_TRUE(popup_model->IsOpen()); |
613 | 614 |
614 // Check if the default match result is Search Primary Provider. | 615 // Check if the default match result is Search Primary Provider. |
615 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, | 616 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, |
616 popup_model->result().default_match()->type); | 617 popup_model->result().default_match()->type); |
617 | 618 |
618 // Open the default match. | 619 // Open the default match. |
619 ASSERT_TRUE(SendKeyAndWait(browser(), ui::VKEY_RETURN, 0, | 620 ASSERT_TRUE(SendKeyAndWait(browser(), ui::VKEY_RETURN, 0, |
620 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 621 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
621 content::Source<content::NavigationController>( | 622 content::Source<content::NavigationController>( |
622 &browser()->GetActiveWebContents()->GetController()))); | 623 &chrome::GetActiveWebContents(browser())->GetController()))); |
623 GURL url = browser()->GetActiveWebContents()->GetURL(); | 624 GURL url = chrome::GetActiveWebContents(browser())->GetURL(); |
624 EXPECT_STREQ(kSearchTextURL, url.spec().c_str()); | 625 EXPECT_STREQ(kSearchTextURL, url.spec().c_str()); |
625 | 626 |
626 // Test that entering a single character then Enter performs a search. | 627 // Test that entering a single character then Enter performs a search. |
627 chrome::FocusLocationBar(browser()); | 628 chrome::FocusLocationBar(browser()); |
628 EXPECT_TRUE(omnibox_view->IsSelectAll()); | 629 EXPECT_TRUE(omnibox_view->IsSelectAll()); |
629 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchSingleCharKeys)); | 630 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchSingleCharKeys)); |
630 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | 631 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
631 ASSERT_TRUE(popup_model->IsOpen()); | 632 ASSERT_TRUE(popup_model->IsOpen()); |
632 EXPECT_EQ(kSearchSingleChar, UTF16ToUTF8(omnibox_view->GetText())); | 633 EXPECT_EQ(kSearchSingleChar, UTF16ToUTF8(omnibox_view->GetText())); |
633 | 634 |
634 // Check if the default match result is Search Primary Provider. | 635 // Check if the default match result is Search Primary Provider. |
635 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, | 636 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, |
636 popup_model->result().default_match()->type); | 637 popup_model->result().default_match()->type); |
637 | 638 |
638 // Open the default match. | 639 // Open the default match. |
639 ASSERT_TRUE(SendKeyAndWait(browser(), ui::VKEY_RETURN, 0, | 640 ASSERT_TRUE(SendKeyAndWait(browser(), ui::VKEY_RETURN, 0, |
640 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 641 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
641 content::Source<content::NavigationController>( | 642 content::Source<content::NavigationController>( |
642 &browser()->GetActiveWebContents()->GetController()))); | 643 &chrome::GetActiveWebContents(browser())->GetController()))); |
643 url = browser()->GetActiveWebContents()->GetURL(); | 644 url = chrome::GetActiveWebContents(browser())->GetURL(); |
644 EXPECT_STREQ(kSearchSingleCharURL, url.spec().c_str()); | 645 EXPECT_STREQ(kSearchSingleCharURL, url.spec().c_str()); |
645 } | 646 } |
646 | 647 |
647 void EscapeToDefaultMatchTest() { | 648 void EscapeToDefaultMatchTest() { |
648 OmniboxView* omnibox_view = NULL; | 649 OmniboxView* omnibox_view = NULL; |
649 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | 650 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
650 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model(); | 651 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model(); |
651 ASSERT_TRUE(popup_model); | 652 ASSERT_TRUE(popup_model); |
652 | 653 |
653 // Input something to trigger inline autocomplete. | 654 // Input something to trigger inline autocomplete. |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); | 1234 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); |
1234 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword())); | 1235 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword())); |
1235 | 1236 |
1236 // Input something as search text. | 1237 // Input something as search text. |
1237 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); | 1238 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); |
1238 | 1239 |
1239 // Create a new tab. | 1240 // Create a new tab. |
1240 chrome::NewTab(browser()); | 1241 chrome::NewTab(browser()); |
1241 | 1242 |
1242 // Switch back to the first tab. | 1243 // Switch back to the first tab. |
1243 browser()->ActivateTabAt(0, true); | 1244 chrome::ActivateTabAt(browser(), 0, true); |
1244 | 1245 |
1245 // Make sure we're still in keyword mode. | 1246 // Make sure we're still in keyword mode. |
1246 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword())); | 1247 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword())); |
1247 } | 1248 } |
1248 | 1249 |
1249 void CtrlKeyPressedWithInlineAutocompleteTest() { | 1250 void CtrlKeyPressedWithInlineAutocompleteTest() { |
1250 OmniboxView* omnibox_view = NULL; | 1251 OmniboxView* omnibox_view = NULL; |
1251 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | 1252 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
1252 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model(); | 1253 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model(); |
1253 ASSERT_TRUE(popup_model); | 1254 ASSERT_TRUE(popup_model); |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1665 | 1666 |
1666 // Middle-clicking shouldn't select all the text either. | 1667 // Middle-clicking shouldn't select all the text either. |
1667 ASSERT_NO_FATAL_FAILURE( | 1668 ASSERT_NO_FATAL_FAILURE( |
1668 ClickFocusViewOrigin(ui_controls::LEFT, kClickOffset, kClickOffset)); | 1669 ClickFocusViewOrigin(ui_controls::LEFT, kClickOffset, kClickOffset)); |
1669 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); | 1670 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); |
1670 ASSERT_NO_FATAL_FAILURE( | 1671 ASSERT_NO_FATAL_FAILURE( |
1671 ClickFocusViewOrigin(ui_controls::MIDDLE, kClickOffset, kClickOffset)); | 1672 ClickFocusViewOrigin(ui_controls::MIDDLE, kClickOffset, kClickOffset)); |
1672 EXPECT_FALSE(omnibox_view->IsSelectAll()); | 1673 EXPECT_FALSE(omnibox_view->IsSelectAll()); |
1673 } | 1674 } |
1674 #endif // defined(USE_AURA) | 1675 #endif // defined(USE_AURA) |
OLD | NEW |