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 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec()); | 798 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec()); |
797 } | 799 } |
798 | 800 |
799 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPDoesntSupportInstant) { | 801 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPDoesntSupportInstant) { |
800 // Setup Instant. | 802 // Setup Instant. |
801 GURL instant_url = test_server()->GetURL("files/empty.html?strk=1"); | 803 GURL instant_url = test_server()->GetURL("files/empty.html?strk=1"); |
802 InstantTestBase::Init(instant_url); | 804 InstantTestBase::Init(instant_url); |
803 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 805 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
804 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | 806 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
805 | 807 |
806 // NTP contents should not be preloaded. | 808 // NTP contents should have fallen back to the local page. |
807 ASSERT_EQ(static_cast<InstantNTP*>(NULL), instant()->ntp()); | 809 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); |
| 810 EXPECT_TRUE(instant()->ntp()->IsLocal()); |
808 | 811 |
809 // Open new tab. Should use local NTP. | 812 // Open new tab. Should use local NTP. |
810 ui_test_utils::NavigateToURLWithDisposition( | 813 ui_test_utils::NavigateToURLWithDisposition( |
811 browser(), | 814 browser(), |
812 GURL(chrome::kChromeUINewTabURL), | 815 GURL(chrome::kChromeUINewTabURL), |
813 NEW_FOREGROUND_TAB, | 816 NEW_FOREGROUND_TAB, |
814 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 817 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
815 content::WebContents* active_tab = | 818 content::WebContents* active_tab = |
816 browser()->tab_strip_model()->GetActiveWebContents(); | 819 browser()->tab_strip_model()->GetActiveWebContents(); |
817 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec()); | 820 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec()); |
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2051 FocusOmnibox(); | 2054 FocusOmnibox(); |
2052 EXPECT_FALSE(instant()->overlay()->IsLocal()); | 2055 EXPECT_FALSE(instant()->overlay()->IsLocal()); |
2053 } | 2056 } |
2054 | 2057 |
2055 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OverlayDoesntSupportInstant) { | 2058 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OverlayDoesntSupportInstant) { |
2056 GURL instant_url = test_server()->GetURL("files/empty.html?strk=1"); | 2059 GURL instant_url = test_server()->GetURL("files/empty.html?strk=1"); |
2057 InstantTestBase::Init(instant_url); | 2060 InstantTestBase::Init(instant_url); |
2058 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 2061 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
2059 | 2062 |
2060 // Focus the omnibox. When the support determination response comes back, | 2063 // Focus the omnibox. When the support determination response comes back, |
2061 // Instant will destroy the non-Instant page. | 2064 // Instant will destroy the non-Instant page and fall back to the local page. |
2062 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | 2065 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
2063 EXPECT_EQ(NULL, instant()->GetOverlayContents()); | 2066 ASSERT_NE(static_cast<InstantOverlay*>(NULL), instant()->overlay()); |
| 2067 EXPECT_TRUE(instant()->overlay()->IsLocal()); |
2064 | 2068 |
2065 // The local overlay is used on the next Update(). | 2069 // The local overlay is used on the next Update(). |
2066 SetOmniboxText("query"); | 2070 SetOmniboxText("query"); |
2067 EXPECT_TRUE(instant()->overlay()->IsLocal()); | 2071 EXPECT_TRUE(instant()->overlay()->IsLocal()); |
2068 | 2072 |
2069 // Switched back to the remote overlay when omnibox loses and regains focus. | 2073 // Switched back to the remote overlay when omnibox loses and regains focus. |
2070 instant()->HideOverlay(); | 2074 instant()->HideOverlay(); |
2071 browser()->tab_strip_model()->GetActiveWebContents()->GetView()->Focus(); | 2075 browser()->tab_strip_model()->GetActiveWebContents()->GetView()->Focus(); |
2072 FocusOmnibox(); | 2076 FocusOmnibox(); |
2073 EXPECT_FALSE(instant()->overlay()->IsLocal()); | 2077 EXPECT_FALSE(instant()->overlay()->IsLocal()); |
2074 | 2078 |
2075 // Overlay destroyed again after determining support. | 2079 // Overlay falls back to local again after determining support. |
2076 FocusOmniboxAndWaitForInstantOverlaySupport(); | 2080 FocusOmniboxAndWaitForInstantOverlaySupport(); |
2077 EXPECT_EQ(NULL, instant()->GetOverlayContents()); | 2081 ASSERT_NE(static_cast<InstantOverlay*>(NULL), instant()->overlay()); |
| 2082 EXPECT_TRUE(instant()->overlay()->IsLocal()); |
2078 } | 2083 } |
2079 | 2084 |
2080 // Test that if Instant alters the input from URL to search, it's respected. | 2085 // Test that if Instant alters the input from URL to search, it's respected. |
2081 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputChangedFromURLToSearch) { | 2086 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputChangedFromURLToSearch) { |
2082 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 2087 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
2083 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | 2088 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
2084 | 2089 |
2085 content::WebContents* overlay = instant()->GetOverlayContents(); | 2090 content::WebContents* overlay = instant()->GetOverlayContents(); |
2086 EXPECT_TRUE(ExecuteScript("suggestions = ['mcqueen.com'];")); | 2091 EXPECT_TRUE(ExecuteScript("suggestions = ['mcqueen.com'];")); |
2087 | 2092 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2278 ASSERT_TRUE(AddSearchToHistory(ASCIIToUTF16("query"), 10000)); | 2283 ASSERT_TRUE(AddSearchToHistory(ASCIIToUTF16("query"), 10000)); |
2279 BlockUntilHistoryProcessesPendingRequests(); | 2284 BlockUntilHistoryProcessesPendingRequests(); |
2280 | 2285 |
2281 SetOmniboxText("quer"); | 2286 SetOmniboxText("quer"); |
2282 | 2287 |
2283 // Should get 2 suggestions from SearchProvider: | 2288 // Should get 2 suggestions from SearchProvider: |
2284 // - SWYT for "quer" | 2289 // - SWYT for "quer" |
2285 // - Search history suggestion for "query" | 2290 // - Search history suggestion for "query" |
2286 EXPECT_EQ(2, CountSearchProviderSuggestions()); | 2291 EXPECT_EQ(2, CountSearchProviderSuggestions()); |
2287 } | 2292 } |
| 2293 |
| 2294 class InstantExtendedFirstTabTest : public InProcessBrowserTest, |
| 2295 public InstantTestBase { |
| 2296 public: |
| 2297 InstantExtendedFirstTabTest() {} |
| 2298 protected: |
| 2299 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 2300 command_line->AppendSwitch(switches::kEnableInstantExtendedAPI); |
| 2301 command_line->AppendSwitch(switches::kDisableLocalFirstLoadNTP); |
| 2302 } |
| 2303 }; |
| 2304 |
| 2305 IN_PROC_BROWSER_TEST_F( |
| 2306 InstantExtendedFirstTabTest, RedirectToLocalOnLoadFailure) { |
| 2307 // Create a new window to test the first NTP load. |
| 2308 ui_test_utils::NavigateToURLWithDisposition( |
| 2309 browser(), |
| 2310 GURL(chrome::kChromeUINewTabURL), |
| 2311 NEW_WINDOW, |
| 2312 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); |
| 2313 |
| 2314 const BrowserList* native_browser_list = BrowserList::GetInstance( |
| 2315 chrome::HOST_DESKTOP_TYPE_NATIVE); |
| 2316 ASSERT_EQ(2u, native_browser_list->size()); |
| 2317 set_browser(native_browser_list->get(1)); |
| 2318 |
| 2319 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
| 2320 |
| 2321 // Also make sure our instant_tab_ is loaded. |
| 2322 if (!instant()->instant_tab_) { |
| 2323 content::WindowedNotificationObserver instant_tab_observer( |
| 2324 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
| 2325 content::NotificationService::AllSources()); |
| 2326 instant_tab_observer.Wait(); |
| 2327 } |
| 2328 |
| 2329 // NTP contents should be preloaded. |
| 2330 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); |
| 2331 EXPECT_TRUE(instant()->ntp()->IsLocal()); |
| 2332 |
| 2333 // Overlay contents should be preloaded. |
| 2334 ASSERT_NE(static_cast<InstantOverlay*>(NULL), instant()->overlay()); |
| 2335 EXPECT_TRUE(instant()->overlay()->IsLocal()); |
| 2336 |
| 2337 // Instant tab contents should be preloaded. |
| 2338 ASSERT_NE(static_cast<InstantTab*>(NULL), instant()->instant_tab()); |
| 2339 EXPECT_TRUE(instant()->instant_tab()->IsLocal()); |
| 2340 } |
OLD | NEW |