| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 12 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
| 12 #include "chrome/browser/autocomplete/autocomplete_match.h" | 13 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 13 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 14 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
| 14 #include "chrome/browser/autocomplete/autocomplete_result.h" | 15 #include "chrome/browser/autocomplete/autocomplete_result.h" |
| 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 16 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 16 #include "chrome/browser/bookmarks/bookmark_utils.h" | 17 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 17 #include "chrome/browser/extensions/extension_browsertest.h" | 18 #include "chrome/browser/extensions/extension_browsertest.h" |
| 18 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/favicon/favicon_tab_helper.h" | 20 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 30 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 31 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 31 #include "chrome/browser/ui/search/instant_commit_type.h" | 32 #include "chrome/browser/ui/search/instant_commit_type.h" |
| 32 #include "chrome/browser/ui/search/instant_ntp.h" | 33 #include "chrome/browser/ui/search/instant_ntp.h" |
| 33 #include "chrome/browser/ui/search/instant_overlay.h" | 34 #include "chrome/browser/ui/search/instant_overlay.h" |
| 34 #include "chrome/browser/ui/search/instant_tab.h" | 35 #include "chrome/browser/ui/search/instant_tab.h" |
| 35 #include "chrome/browser/ui/search/instant_test_utils.h" | 36 #include "chrome/browser/ui/search/instant_test_utils.h" |
| 36 #include "chrome/browser/ui/search/search_tab_helper.h" | 37 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 37 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 38 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 38 #include "chrome/browser/ui/webui/theme_source.h" | 39 #include "chrome/browser/ui/webui/theme_source.h" |
| 39 #include "chrome/common/chrome_notification_types.h" | 40 #include "chrome/common/chrome_notification_types.h" |
| 41 #include "chrome/common/chrome_switches.h" |
| 40 #include "chrome/common/pref_names.h" | 42 #include "chrome/common/pref_names.h" |
| 41 #include "chrome/common/thumbnail_score.h" | 43 #include "chrome/common/thumbnail_score.h" |
| 42 #include "chrome/common/url_constants.h" | 44 #include "chrome/common/url_constants.h" |
| 43 #include "chrome/test/base/in_process_browser_test.h" | 45 #include "chrome/test/base/in_process_browser_test.h" |
| 44 #include "chrome/test/base/interactive_test_utils.h" | 46 #include "chrome/test/base/interactive_test_utils.h" |
| 45 #include "chrome/test/base/ui_test_utils.h" | 47 #include "chrome/test/base/ui_test_utils.h" |
| 46 #include "content/public/browser/navigation_controller.h" | 48 #include "content/public/browser/navigation_controller.h" |
| 47 #include "content/public/browser/navigation_entry.h" | 49 #include "content/public/browser/navigation_entry.h" |
| 48 #include "content/public/browser/notification_service.h" | 50 #include "content/public/browser/notification_service.h" |
| 49 #include "content/public/browser/render_process_host.h" | 51 #include "content/public/browser/render_process_host.h" |
| (...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 browser()->tab_strip_model()->GetActiveWebContents(); | 826 browser()->tab_strip_model()->GetActiveWebContents(); |
| 825 EXPECT_TRUE(instant_service->IsInstantProcess( | 827 EXPECT_TRUE(instant_service->IsInstantProcess( |
| 826 active_tab->GetRenderProcessHost()->GetID())); | 828 active_tab->GetRenderProcessHost()->GetID())); |
| 827 | 829 |
| 828 // Navigating elsewhere should not use the Instant render process. | 830 // Navigating elsewhere should not use the Instant render process. |
| 829 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); | 831 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); |
| 830 EXPECT_FALSE(instant_service->IsInstantProcess( | 832 EXPECT_FALSE(instant_service->IsInstantProcess( |
| 831 active_tab->GetRenderProcessHost()->GetID())); | 833 active_tab->GetRenderProcessHost()->GetID())); |
| 832 } | 834 } |
| 833 | 835 |
| 836 // Test that a search query will not be displayed for navsuggest queries. |
| 837 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
| 838 SearchQueryNotDisplayedForNavsuggest) { |
| 839 // Use only the local overlay. |
| 840 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 841 switches::kEnableLocalOnlyInstantExtendedAPI); |
| 842 ASSERT_TRUE(chrome::IsLocalOnlyInstantExtendedAPIEnabled()); |
| 843 |
| 844 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 845 |
| 846 // The second argument indicates to use only the local overlay and NTP. |
| 847 instant()->SetInstantEnabled(true, true); |
| 848 |
| 849 // Focus omnibox and confirm overlay isn't shown. |
| 850 FocusOmniboxAndWaitForInstantOverlaySupport(); |
| 851 |
| 852 // Typing in the omnibox should show the overlay. |
| 853 SetOmniboxText("face"); |
| 854 |
| 855 content::WebContents* overlay = instant()->GetOverlayContents(); |
| 856 |
| 857 // Add a navsuggest suggestion. |
| 858 instant()->SetSuggestions( |
| 859 overlay, |
| 860 std::vector<InstantSuggestion>( |
| 861 1, |
| 862 InstantSuggestion(ASCIIToUTF16("http://facemash.com/"), |
| 863 INSTANT_COMPLETE_NOW, |
| 864 INSTANT_SUGGESTION_URL, |
| 865 ASCIIToUTF16("face")))); |
| 866 |
| 867 while (!omnibox()->model()->autocomplete_controller()->done()) { |
| 868 content::WindowedNotificationObserver autocomplete_observer( |
| 869 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, |
| 870 content::NotificationService::AllSources()); |
| 871 autocomplete_observer.Wait(); |
| 872 } |
| 873 |
| 874 EXPECT_TRUE(ExecuteScript( |
| 875 "var sorted = chrome.embeddedSearch.searchBox.nativeSuggestions.sort(" |
| 876 "function (a,b) {" |
| 877 "return b.rankingData.relevance - a.rankingData.relevance;" |
| 878 "});")); |
| 879 |
| 880 int suggestions_count = -1; |
| 881 EXPECT_TRUE(GetIntFromJS( |
| 882 overlay, "sorted.length", &suggestions_count)); |
| 883 ASSERT_GT(suggestions_count, 0); |
| 884 |
| 885 std::string type; |
| 886 EXPECT_TRUE( |
| 887 GetStringFromJS(overlay, "sorted[0].type", &type)); |
| 888 ASSERT_EQ("navsuggest", type); |
| 889 |
| 890 bool is_search; |
| 891 EXPECT_TRUE(GetBoolFromJS( |
| 892 overlay, "!!sorted[0].is_search", &is_search)); |
| 893 EXPECT_FALSE(is_search); |
| 894 } |
| 895 |
| 834 // Verification of fix for BUG=176365. Ensure that each Instant WebContents in | 896 // Verification of fix for BUG=176365. Ensure that each Instant WebContents in |
| 835 // a tab uses a new BrowsingInstance, to avoid conflicts in the | 897 // a tab uses a new BrowsingInstance, to avoid conflicts in the |
| 836 // NavigationController. | 898 // NavigationController. |
| 837 // Flaky: http://crbug.com/177516 | 899 // Flaky: http://crbug.com/177516 |
| 838 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_UnrelatedSiteInstance) { | 900 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_UnrelatedSiteInstance) { |
| 839 // Setup Instant. | 901 // Setup Instant. |
| 840 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 902 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 841 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | 903 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
| 842 | 904 |
| 843 // Check that the uncommited ntp page and uncommited overlay have unrelated | 905 // Check that the uncommited ntp page and uncommited overlay have unrelated |
| (...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1854 | 1916 |
| 1855 SendDownArrow(); | 1917 SendDownArrow(); |
| 1856 EXPECT_EQ("result 1", GetOmniboxText()); | 1918 EXPECT_EQ("result 1", GetOmniboxText()); |
| 1857 | 1919 |
| 1858 // Press Enter. | 1920 // Press Enter. |
| 1859 browser()->window()->GetLocationBar()->AcceptInput(); | 1921 browser()->window()->GetLocationBar()->AcceptInput(); |
| 1860 | 1922 |
| 1861 // Confirm that the Instant overlay was NOT committed. | 1923 // Confirm that the Instant overlay was NOT committed. |
| 1862 EXPECT_NE(overlay, browser()->tab_strip_model()->GetActiveWebContents()); | 1924 EXPECT_NE(overlay, browser()->tab_strip_model()->GetActiveWebContents()); |
| 1863 } | 1925 } |
| OLD | NEW |