Chromium Code Reviews| 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" |
| 20 #include "chrome/browser/history/history_types.h" | 21 #include "chrome/browser/history/history_types.h" |
| 21 #include "chrome/browser/history/top_sites.h" | 22 #include "chrome/browser/history/top_sites.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/search/instant_service.h" | 24 #include "chrome/browser/search/instant_service.h" |
| 24 #include "chrome/browser/search/instant_service_factory.h" | 25 #include "chrome/browser/search/instant_service_factory.h" |
| 25 #include "chrome/browser/search/search.h" | 26 #include "chrome/browser/search/search.h" |
| 26 #include "chrome/browser/themes/theme_service.h" | 27 #include "chrome/browser/themes/theme_service.h" |
| 27 #include "chrome/browser/themes/theme_service_factory.h" | 28 #include "chrome/browser/themes/theme_service_factory.h" |
| 28 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 29 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 29 #include "chrome/browser/ui/search/instant_commit_type.h" | 30 #include "chrome/browser/ui/search/instant_commit_type.h" |
| 30 #include "chrome/browser/ui/search/instant_ntp.h" | 31 #include "chrome/browser/ui/search/instant_ntp.h" |
| 31 #include "chrome/browser/ui/search/instant_overlay.h" | 32 #include "chrome/browser/ui/search/instant_overlay.h" |
| 32 #include "chrome/browser/ui/search/instant_tab.h" | 33 #include "chrome/browser/ui/search/instant_tab.h" |
| 33 #include "chrome/browser/ui/search/instant_test_utils.h" | 34 #include "chrome/browser/ui/search/instant_test_utils.h" |
| 34 #include "chrome/browser/ui/search/search_tab_helper.h" | 35 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 35 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 36 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 36 #include "chrome/browser/ui/webui/theme_source.h" | 37 #include "chrome/browser/ui/webui/theme_source.h" |
| 37 #include "chrome/common/chrome_notification_types.h" | 38 #include "chrome/common/chrome_notification_types.h" |
| 39 #include "chrome/common/chrome_switches.h" | |
| 38 #include "chrome/common/pref_names.h" | 40 #include "chrome/common/pref_names.h" |
| 39 #include "chrome/common/thumbnail_score.h" | 41 #include "chrome/common/thumbnail_score.h" |
| 40 #include "chrome/common/url_constants.h" | 42 #include "chrome/common/url_constants.h" |
| 41 #include "chrome/test/base/in_process_browser_test.h" | 43 #include "chrome/test/base/in_process_browser_test.h" |
| 42 #include "chrome/test/base/interactive_test_utils.h" | 44 #include "chrome/test/base/interactive_test_utils.h" |
| 43 #include "chrome/test/base/ui_test_utils.h" | 45 #include "chrome/test/base/ui_test_utils.h" |
| 44 #include "content/public/browser/navigation_controller.h" | 46 #include "content/public/browser/navigation_controller.h" |
| 45 #include "content/public/browser/navigation_entry.h" | 47 #include "content/public/browser/navigation_entry.h" |
| 46 #include "content/public/browser/notification_service.h" | 48 #include "content/public/browser/notification_service.h" |
| 47 #include "content/public/browser/render_process_host.h" | 49 #include "content/public/browser/render_process_host.h" |
| (...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 813 browser()->tab_strip_model()->GetActiveWebContents(); | 815 browser()->tab_strip_model()->GetActiveWebContents(); |
| 814 EXPECT_TRUE(instant_service->IsInstantProcess( | 816 EXPECT_TRUE(instant_service->IsInstantProcess( |
| 815 active_tab->GetRenderProcessHost()->GetID())); | 817 active_tab->GetRenderProcessHost()->GetID())); |
| 816 | 818 |
| 817 // Navigating elsewhere should not use the Instant render process. | 819 // Navigating elsewhere should not use the Instant render process. |
| 818 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); | 820 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); |
| 819 EXPECT_FALSE(instant_service->IsInstantProcess( | 821 EXPECT_FALSE(instant_service->IsInstantProcess( |
| 820 active_tab->GetRenderProcessHost()->GetID())); | 822 active_tab->GetRenderProcessHost()->GetID())); |
| 821 } | 823 } |
| 822 | 824 |
| 825 // Test that a search query will not be displayed for navsuggest queries. | |
| 826 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | |
| 827 SearchQueryNotDisplayedForNavsuggest) { | |
| 828 // Use only the local overlay. | |
| 829 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 830 switches::kEnableLocalOnlyInstantExtendedAPI); | |
| 831 ASSERT_TRUE(chrome::IsLocalOnlyInstantExtendedAPIEnabled()); | |
| 832 | |
| 833 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | |
| 834 | |
| 835 // The second argument indicates to use only the local overlay and NTP. | |
| 836 instant()->SetInstantEnabled(true, true); | |
| 837 | |
| 838 // Focus omnibox and confirm overlay isn't shown. | |
| 839 FocusOmniboxAndWaitForInstantSupport(); | |
| 840 | |
| 841 // Typing in the omnibox should show the overlay. | |
| 842 SetOmniboxText("face"); | |
| 843 | |
| 844 // Add a navsuggest suggestion. | |
| 845 instant()->SetSuggestions( | |
| 846 instant()->overlay()->contents(), | |
| 847 std::vector<InstantSuggestion>( | |
| 848 1, | |
| 849 InstantSuggestion(ASCIIToUTF16("http://facemash.com/"), | |
| 850 INSTANT_COMPLETE_NOW, | |
| 851 INSTANT_SUGGESTION_URL, | |
| 852 ASCIIToUTF16("face")))); | |
| 853 | |
| 854 while (!omnibox()->model()->autocomplete_controller()->done()) { | |
| 855 content::WindowedNotificationObserver autocomplete_observer( | |
| 856 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, | |
| 857 content::NotificationService::AllSources()); | |
| 858 autocomplete_observer.Wait(); | |
| 859 } | |
| 860 | |
| 861 EXPECT_TRUE(ExecuteScript( | |
| 862 "var sorted = chrome.embeddedSearch.searchBox.nativeSuggestions.sort(" | |
| 863 "function (a,b) {" | |
| 864 "return b.rankingData.relevance - a.rankingData.relevance;" | |
| 865 "});")); | |
| 866 | |
| 867 content::WebContents* overlay = instant()->GetOverlayContents(); | |
|
samarth
2013/04/30 01:03:47
Earlier in this function, L846, you use overlay()-
dougw
2013/04/30 01:29:44
Done.
| |
| 868 | |
| 869 int suggestions_count = -1; | |
| 870 EXPECT_TRUE(GetIntFromJS( | |
| 871 overlay, "sorted.length", &suggestions_count)); | |
| 872 EXPECT_GT(suggestions_count, 0); | |
|
samarth
2013/04/30 01:03:47
ASSERT_GT .. doesn't make to continue if this fail
dougw
2013/04/30 01:29:44
Done.
| |
| 873 | |
| 874 std::string type; | |
| 875 EXPECT_TRUE( | |
| 876 GetStringFromJS(overlay, "sorted[0].type", &type)); | |
| 877 EXPECT_EQ("navsuggest", type); | |
|
samarth
2013/04/30 01:03:47
Likewise, ASSERT
dougw
2013/04/30 01:29:44
Done.
| |
| 878 | |
| 879 bool is_search_property_defined; | |
| 880 EXPECT_TRUE( | |
| 881 GetBoolFromJS( | |
| 882 overlay, "sorted[0].hasOwnProperty('is_search')", | |
|
samarth
2013/04/30 01:03:47
What it you just look up "!!sorted[0].is_search" a
dougw
2013/04/30 01:29:44
Done.
| |
| 883 &is_search_property_defined)); | |
| 884 | |
| 885 if (is_search_property_defined) { | |
| 886 bool is_search; | |
| 887 EXPECT_TRUE(GetBoolFromJS( | |
| 888 overlay, "sorted[0].is_search", &is_search)); | |
| 889 EXPECT_FALSE(is_search); | |
| 890 } | |
| 891 } | |
| 892 | |
| 823 // Verification of fix for BUG=176365. Ensure that each Instant WebContents in | 893 // Verification of fix for BUG=176365. Ensure that each Instant WebContents in |
| 824 // a tab uses a new BrowsingInstance, to avoid conflicts in the | 894 // a tab uses a new BrowsingInstance, to avoid conflicts in the |
| 825 // NavigationController. | 895 // NavigationController. |
| 826 // Flaky: http://crbug.com/177516 | 896 // Flaky: http://crbug.com/177516 |
| 827 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_UnrelatedSiteInstance) { | 897 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_UnrelatedSiteInstance) { |
| 828 // Setup Instant. | 898 // Setup Instant. |
| 829 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 899 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 830 FocusOmniboxAndWaitForInstantExtendedSupport(); | 900 FocusOmniboxAndWaitForInstantExtendedSupport(); |
| 831 | 901 |
| 832 // Check that the uncommited ntp page and uncommited overlay have unrelated | 902 // Check that the uncommited ntp page and uncommited overlay have unrelated |
| (...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1736 SendEscape(); | 1806 SendEscape(); |
| 1737 EXPECT_TRUE(GetStringFromJS(contents, "chrome.embeddedSearch.searchBox.value", | 1807 EXPECT_TRUE(GetStringFromJS(contents, "chrome.embeddedSearch.searchBox.value", |
| 1738 &query)); | 1808 &query)); |
| 1739 EXPECT_EQ("", query); | 1809 EXPECT_EQ("", query); |
| 1740 EXPECT_EQ("", GetOmniboxText()); | 1810 EXPECT_EQ("", GetOmniboxText()); |
| 1741 | 1811 |
| 1742 EXPECT_TRUE(UpdateSearchState(contents)); | 1812 EXPECT_TRUE(UpdateSearchState(contents)); |
| 1743 EXPECT_LT(0, on_change_calls_); | 1813 EXPECT_LT(0, on_change_calls_); |
| 1744 EXPECT_EQ(0, submit_count_); | 1814 EXPECT_EQ(0, submit_count_); |
| 1745 } | 1815 } |
| OLD | NEW |