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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 #include "chrome/browser/history/top_sites.h" | 28 #include "chrome/browser/history/top_sites.h" |
| 29 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 30 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 31 #include "chrome/browser/search/instant_service.h" | 31 #include "chrome/browser/search/instant_service.h" |
| 32 #include "chrome/browser/search/instant_service_factory.h" | 32 #include "chrome/browser/search/instant_service_factory.h" |
| 33 #include "chrome/browser/search/search.h" | 33 #include "chrome/browser/search/search.h" |
| 34 #include "chrome/browser/search_engines/template_url_service.h" | 34 #include "chrome/browser/search_engines/template_url_service.h" |
| 35 #include "chrome/browser/search_engines/template_url_service_factory.h" | 35 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 36 #include "chrome/browser/themes/theme_service.h" | 36 #include "chrome/browser/themes/theme_service.h" |
| 37 #include "chrome/browser/themes/theme_service_factory.h" | 37 #include "chrome/browser/themes/theme_service_factory.h" |
| 38 #include "chrome/browser/ui/browser_list.h" | |
| 39 #include "chrome/browser/ui/browser_tabstrip.h" | |
| 38 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 40 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 39 #include "chrome/browser/ui/search/instant_commit_type.h" | 41 #include "chrome/browser/ui/search/instant_commit_type.h" |
| 40 #include "chrome/browser/ui/search/instant_ntp.h" | 42 #include "chrome/browser/ui/search/instant_ntp.h" |
| 41 #include "chrome/browser/ui/search/instant_overlay.h" | 43 #include "chrome/browser/ui/search/instant_overlay.h" |
| 42 #include "chrome/browser/ui/search/instant_tab.h" | 44 #include "chrome/browser/ui/search/instant_tab.h" |
| 43 #include "chrome/browser/ui/search/instant_test_utils.h" | 45 #include "chrome/browser/ui/search/instant_test_utils.h" |
| 44 #include "chrome/browser/ui/search/search_tab_helper.h" | 46 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 45 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 47 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 46 #include "chrome/browser/ui/webui/theme_source.h" | 48 #include "chrome/browser/ui/webui/theme_source.h" |
| 47 #include "chrome/common/chrome_notification_types.h" | 49 #include "chrome/common/chrome_notification_types.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 public: | 108 public: |
| 107 InstantExtendedTest() | 109 InstantExtendedTest() |
| 108 : on_most_visited_change_calls_(0), | 110 : on_most_visited_change_calls_(0), |
| 109 most_visited_items_count_(0), | 111 most_visited_items_count_(0), |
| 110 first_most_visited_item_id_(0), | 112 first_most_visited_item_id_(0), |
| 111 on_native_suggestions_calls_(0), | 113 on_native_suggestions_calls_(0), |
| 112 on_change_calls_(0), | 114 on_change_calls_(0), |
| 113 submit_count_(0) { | 115 submit_count_(0) { |
| 114 } | 116 } |
| 115 protected: | 117 protected: |
| 116 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 118 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 117 chrome::EnableInstantExtendedAPIForTesting(); | 119 command_line->AppendSwitch(switches::kEnableInstantExtendedAPI); |
| 118 ASSERT_TRUE(https_test_server().Start()); | 120 ASSERT_TRUE(https_test_server().Start()); |
| 119 GURL instant_url = https_test_server().GetURL( | 121 GURL instant_url = https_test_server().GetURL( |
| 120 "files/instant_extended.html?strk=1&"); | 122 "files/instant_extended.html?strk=1&"); |
| 121 InstantTestBase::Init(instant_url); | 123 InstantTestBase::Init(instant_url); |
| 122 } | 124 } |
| 123 | 125 |
| 124 virtual void SetUpOnMainThread() OVERRIDE { | 126 virtual void SetUpOnMainThread() OVERRIDE { |
| 125 browser()->toolbar_model()->SetSupportsExtractionOfURLLikeSearchTerms(true); | 127 browser()->toolbar_model()->SetSupportsExtractionOfURLLikeSearchTerms(true); |
| 126 } | 128 } |
| 127 | 129 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 }; | 217 }; |
| 216 | 218 |
| 217 // Test class used to verify chrome-search: scheme and access policy from the | 219 // Test class used to verify chrome-search: scheme and access policy from the |
| 218 // Instant overlay. This is a subclass of |ExtensionBrowserTest| because it | 220 // Instant overlay. This is a subclass of |ExtensionBrowserTest| because it |
| 219 // loads a theme that provides a background image. | 221 // loads a theme that provides a background image. |
| 220 class InstantPolicyTest : public ExtensionBrowserTest, public InstantTestBase { | 222 class InstantPolicyTest : public ExtensionBrowserTest, public InstantTestBase { |
| 221 public: | 223 public: |
| 222 InstantPolicyTest() {} | 224 InstantPolicyTest() {} |
| 223 | 225 |
| 224 protected: | 226 protected: |
| 227 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 228 command_line->AppendSwitch(switches::kEnableInstantExtendedAPI); | |
| 229 } | |
| 230 | |
| 225 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 231 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 226 chrome::EnableInstantExtendedAPIForTesting(); | |
| 227 ASSERT_TRUE(https_test_server().Start()); | 232 ASSERT_TRUE(https_test_server().Start()); |
| 228 GURL instant_url = https_test_server().GetURL( | 233 GURL instant_url = https_test_server().GetURL( |
| 229 "files/instant_extended.html?strk=1&"); | 234 "files/instant_extended.html?strk=1&"); |
| 230 InstantTestBase::Init(instant_url); | 235 InstantTestBase::Init(instant_url); |
| 231 } | 236 } |
| 232 | 237 |
| 233 void InstallThemeSource() { | 238 void InstallThemeSource() { |
| 234 ThemeSource* theme = new ThemeSource(profile()); | 239 ThemeSource* theme = new ThemeSource(profile()); |
| 235 content::URLDataSource::Add(profile(), theme); | 240 content::URLDataSource::Add(profile(), theme); |
| 236 } | 241 } |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 796 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec()); | 801 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec()); |
| 797 } | 802 } |
| 798 | 803 |
| 799 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPDoesntSupportInstant) { | 804 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPDoesntSupportInstant) { |
| 800 // Setup Instant. | 805 // Setup Instant. |
| 801 GURL instant_url = test_server()->GetURL("files/empty.html?strk=1"); | 806 GURL instant_url = test_server()->GetURL("files/empty.html?strk=1"); |
| 802 InstantTestBase::Init(instant_url); | 807 InstantTestBase::Init(instant_url); |
| 803 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 808 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 804 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | 809 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
| 805 | 810 |
| 806 // NTP contents should not be preloaded. | 811 // NTP contents should have fallen back to the local page. |
| 807 ASSERT_EQ(static_cast<InstantNTP*>(NULL), instant()->ntp()); | 812 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); |
| 813 EXPECT_TRUE(instant()->ntp()->IsLocal()); | |
| 808 | 814 |
| 809 // Open new tab. Should use local NTP. | 815 // Open new tab. Should use local NTP. |
| 810 ui_test_utils::NavigateToURLWithDisposition( | 816 ui_test_utils::NavigateToURLWithDisposition( |
| 811 browser(), | 817 browser(), |
| 812 GURL(chrome::kChromeUINewTabURL), | 818 GURL(chrome::kChromeUINewTabURL), |
| 813 NEW_FOREGROUND_TAB, | 819 NEW_FOREGROUND_TAB, |
| 814 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 820 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 815 content::WebContents* active_tab = | 821 content::WebContents* active_tab = |
| 816 browser()->tab_strip_model()->GetActiveWebContents(); | 822 browser()->tab_strip_model()->GetActiveWebContents(); |
| 817 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec()); | 823 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec()); |
| (...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2051 FocusOmnibox(); | 2057 FocusOmnibox(); |
| 2052 EXPECT_FALSE(instant()->overlay()->IsLocal()); | 2058 EXPECT_FALSE(instant()->overlay()->IsLocal()); |
| 2053 } | 2059 } |
| 2054 | 2060 |
| 2055 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OverlayDoesntSupportInstant) { | 2061 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OverlayDoesntSupportInstant) { |
| 2056 GURL instant_url = test_server()->GetURL("files/empty.html?strk=1"); | 2062 GURL instant_url = test_server()->GetURL("files/empty.html?strk=1"); |
| 2057 InstantTestBase::Init(instant_url); | 2063 InstantTestBase::Init(instant_url); |
| 2058 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 2064 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 2059 | 2065 |
| 2060 // Focus the omnibox. When the support determination response comes back, | 2066 // Focus the omnibox. When the support determination response comes back, |
| 2061 // Instant will destroy the non-Instant page. | 2067 // Instant will destroy the non-Instant page and fall back to the local page. |
| 2062 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | 2068 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
| 2063 EXPECT_EQ(NULL, instant()->GetOverlayContents()); | 2069 ASSERT_NE(static_cast<InstantOverlay*>(NULL), instant()->overlay()); |
| 2070 EXPECT_TRUE(instant()->overlay()->IsLocal()); | |
| 2064 | 2071 |
| 2065 // The local overlay is used on the next Update(). | 2072 // The local overlay is used on the next Update(). |
| 2066 SetOmniboxText("query"); | 2073 SetOmniboxText("query"); |
| 2067 EXPECT_TRUE(instant()->overlay()->IsLocal()); | 2074 EXPECT_TRUE(instant()->overlay()->IsLocal()); |
| 2068 | 2075 |
| 2069 // Switched back to the remote overlay when omnibox loses and regains focus. | 2076 // Switched back to the remote overlay when omnibox loses and regains focus. |
| 2070 instant()->HideOverlay(); | 2077 instant()->HideOverlay(); |
| 2071 browser()->tab_strip_model()->GetActiveWebContents()->GetView()->Focus(); | 2078 browser()->tab_strip_model()->GetActiveWebContents()->GetView()->Focus(); |
| 2072 FocusOmnibox(); | 2079 FocusOmnibox(); |
| 2073 EXPECT_FALSE(instant()->overlay()->IsLocal()); | 2080 EXPECT_FALSE(instant()->overlay()->IsLocal()); |
| 2074 | 2081 |
| 2075 // Overlay destroyed again after determining support. | 2082 // Overlay falls back to local again after determining support. |
| 2076 FocusOmniboxAndWaitForInstantOverlaySupport(); | 2083 FocusOmniboxAndWaitForInstantOverlaySupport(); |
| 2077 EXPECT_EQ(NULL, instant()->GetOverlayContents()); | 2084 ASSERT_NE(static_cast<InstantOverlay*>(NULL), instant()->overlay()); |
| 2085 EXPECT_TRUE(instant()->overlay()->IsLocal()); | |
| 2078 } | 2086 } |
| 2079 | 2087 |
| 2080 // Test that if Instant alters the input from URL to search, it's respected. | 2088 // Test that if Instant alters the input from URL to search, it's respected. |
| 2081 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputChangedFromURLToSearch) { | 2089 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputChangedFromURLToSearch) { |
| 2082 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 2090 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 2083 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | 2091 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
| 2084 | 2092 |
| 2085 content::WebContents* overlay = instant()->GetOverlayContents(); | 2093 content::WebContents* overlay = instant()->GetOverlayContents(); |
| 2086 EXPECT_TRUE(ExecuteScript("suggestions = ['mcqueen.com'];")); | 2094 EXPECT_TRUE(ExecuteScript("suggestions = ['mcqueen.com'];")); |
| 2087 | 2095 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2278 ASSERT_TRUE(AddSearchToHistory(ASCIIToUTF16("query"), 10000)); | 2286 ASSERT_TRUE(AddSearchToHistory(ASCIIToUTF16("query"), 10000)); |
| 2279 BlockUntilHistoryProcessesPendingRequests(); | 2287 BlockUntilHistoryProcessesPendingRequests(); |
| 2280 | 2288 |
| 2281 SetOmniboxText("quer"); | 2289 SetOmniboxText("quer"); |
| 2282 | 2290 |
| 2283 // Should get 2 suggestions from SearchProvider: | 2291 // Should get 2 suggestions from SearchProvider: |
| 2284 // - SWYT for "quer" | 2292 // - SWYT for "quer" |
| 2285 // - Search history suggestion for "query" | 2293 // - Search history suggestion for "query" |
| 2286 EXPECT_EQ(2, CountSearchProviderSuggestions()); | 2294 EXPECT_EQ(2, CountSearchProviderSuggestions()); |
| 2287 } | 2295 } |
| 2296 | |
| 2297 class InstantExtendedFirstTabTest : public InProcessBrowserTest, | |
| 2298 public InstantTestBase { | |
|
Jered
2013/05/05 15:08:00
indent more
David Black
2013/05/05 20:02:42
Done.
| |
| 2299 public: | |
| 2300 InstantExtendedFirstTabTest() {} | |
| 2301 protected: | |
| 2302 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 2303 command_line->AppendSwitch(switches::kEnableInstantExtendedAPI); | |
| 2304 command_line->AppendSwitch(switches::kDisableLocalFirstLoadNTP); | |
| 2305 } | |
| 2306 }; | |
| 2307 | |
| 2308 IN_PROC_BROWSER_TEST_F( | |
| 2309 InstantExtendedFirstTabTest, RedirectToLocalOnLoadFailure) { | |
| 2310 // Create a new window to test the first NTP load. | |
| 2311 ui_test_utils::NavigateToURLWithDisposition( | |
| 2312 browser(), | |
| 2313 GURL(chrome::kChromeUINewTabURL), | |
| 2314 NEW_WINDOW, | |
| 2315 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); | |
| 2316 | |
| 2317 const BrowserList* native_browser_list = BrowserList::GetInstance( | |
| 2318 chrome::HOST_DESKTOP_TYPE_NATIVE); | |
| 2319 ASSERT_EQ(2u, native_browser_list->size()); | |
| 2320 set_browser(native_browser_list->get(1)); | |
| 2321 | |
| 2322 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | |
| 2323 | |
| 2324 // Also make sure our instant_tab_ is loaded. | |
| 2325 if (!instant()->instant_tab_) { | |
| 2326 content::WindowedNotificationObserver instant_tab_observer( | |
| 2327 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | |
| 2328 content::NotificationService::AllSources()); | |
| 2329 instant_tab_observer.Wait(); | |
| 2330 } | |
| 2331 | |
| 2332 // NTP contents should be preloaded. | |
| 2333 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); | |
| 2334 EXPECT_TRUE(instant()->ntp()->IsLocal()); | |
| 2335 | |
| 2336 // Overlay contents should be preloaded. | |
| 2337 ASSERT_NE(static_cast<InstantOverlay*>(NULL), instant()->overlay()); | |
| 2338 EXPECT_TRUE(instant()->overlay()->IsLocal()); | |
| 2339 | |
| 2340 // Instant tab contents should be preloaded. | |
| 2341 ASSERT_NE(static_cast<InstantTab*>(NULL), instant()->instant_tab()); | |
| 2342 EXPECT_TRUE(instant()->instant_tab()->IsLocal()); | |
| 2343 } | |
| OLD | NEW |