Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: chrome/browser/ui/search/instant_extended_interactive_uitest.cc

Issue 14043009: Fall back to local page if online NTP fails to load. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix failing tests Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 11 matching lines...) Expand all
22 #include "chrome/browser/history/history_types.h" 22 #include "chrome/browser/history/history_types.h"
23 #include "chrome/browser/history/top_sites.h" 23 #include "chrome/browser/history/top_sites.h"
24 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/search/instant_service.h" 25 #include "chrome/browser/search/instant_service.h"
26 #include "chrome/browser/search/instant_service_factory.h" 26 #include "chrome/browser/search/instant_service_factory.h"
27 #include "chrome/browser/search/search.h" 27 #include "chrome/browser/search/search.h"
28 #include "chrome/browser/search_engines/template_url_service.h" 28 #include "chrome/browser/search_engines/template_url_service.h"
29 #include "chrome/browser/search_engines/template_url_service_factory.h" 29 #include "chrome/browser/search_engines/template_url_service_factory.h"
30 #include "chrome/browser/themes/theme_service.h" 30 #include "chrome/browser/themes/theme_service.h"
31 #include "chrome/browser/themes/theme_service_factory.h" 31 #include "chrome/browser/themes/theme_service_factory.h"
32 #include "chrome/browser/ui/browser_list.h"
33 #include "chrome/browser/ui/browser_tabstrip.h"
32 #include "chrome/browser/ui/omnibox/omnibox_view.h" 34 #include "chrome/browser/ui/omnibox/omnibox_view.h"
33 #include "chrome/browser/ui/search/instant_commit_type.h" 35 #include "chrome/browser/ui/search/instant_commit_type.h"
34 #include "chrome/browser/ui/search/instant_ntp.h" 36 #include "chrome/browser/ui/search/instant_ntp.h"
35 #include "chrome/browser/ui/search/instant_overlay.h" 37 #include "chrome/browser/ui/search/instant_overlay.h"
36 #include "chrome/browser/ui/search/instant_tab.h" 38 #include "chrome/browser/ui/search/instant_tab.h"
37 #include "chrome/browser/ui/search/instant_test_utils.h" 39 #include "chrome/browser/ui/search/instant_test_utils.h"
38 #include "chrome/browser/ui/search/search_tab_helper.h" 40 #include "chrome/browser/ui/search/search_tab_helper.h"
39 #include "chrome/browser/ui/tabs/tab_strip_model.h" 41 #include "chrome/browser/ui/tabs/tab_strip_model.h"
40 #include "chrome/browser/ui/webui/theme_source.h" 42 #include "chrome/browser/ui/webui/theme_source.h"
41 #include "chrome/common/chrome_notification_types.h" 43 #include "chrome/common/chrome_notification_types.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 public: 80 public:
79 InstantExtendedTest() 81 InstantExtendedTest()
80 : on_most_visited_change_calls_(0), 82 : on_most_visited_change_calls_(0),
81 most_visited_items_count_(0), 83 most_visited_items_count_(0),
82 first_most_visited_item_id_(0), 84 first_most_visited_item_id_(0),
83 on_native_suggestions_calls_(0), 85 on_native_suggestions_calls_(0),
84 on_change_calls_(0), 86 on_change_calls_(0),
85 submit_count_(0) { 87 submit_count_(0) {
86 } 88 }
87 protected: 89 protected:
88 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 90 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
89 chrome::EnableInstantExtendedAPIForTesting(); 91 command_line->AppendSwitch(switches::kEnableInstantExtendedAPI);
90 ASSERT_TRUE(https_test_server().Start()); 92 ASSERT_TRUE(https_test_server().Start());
91 GURL instant_url = https_test_server().GetURL( 93 GURL instant_url = https_test_server().GetURL(
92 "files/instant_extended.html?strk=1&"); 94 "files/instant_extended.html?strk=1&");
93 InstantTestBase::Init(instant_url); 95 InstantTestBase::Init(instant_url);
94 } 96 }
95 97
96 virtual void SetUpOnMainThread() OVERRIDE { 98 virtual void SetUpOnMainThread() OVERRIDE {
97 browser()->toolbar_model()->SetSupportsExtractionOfURLLikeSearchTerms(true); 99 browser()->toolbar_model()->SetSupportsExtractionOfURLLikeSearchTerms(true);
98 } 100 }
99 101
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 }; 148 };
147 149
148 // Test class used to verify chrome-search: scheme and access policy from the 150 // Test class used to verify chrome-search: scheme and access policy from the
149 // Instant overlay. This is a subclass of |ExtensionBrowserTest| because it 151 // Instant overlay. This is a subclass of |ExtensionBrowserTest| because it
150 // loads a theme that provides a background image. 152 // loads a theme that provides a background image.
151 class InstantPolicyTest : public ExtensionBrowserTest, public InstantTestBase { 153 class InstantPolicyTest : public ExtensionBrowserTest, public InstantTestBase {
152 public: 154 public:
153 InstantPolicyTest() {} 155 InstantPolicyTest() {}
154 156
155 protected: 157 protected:
158 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
159 command_line->AppendSwitch(switches::kEnableInstantExtendedAPI);
160 }
161
156 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 162 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
157 chrome::EnableInstantExtendedAPIForTesting();
158 ASSERT_TRUE(https_test_server().Start()); 163 ASSERT_TRUE(https_test_server().Start());
159 GURL instant_url = https_test_server().GetURL( 164 GURL instant_url = https_test_server().GetURL(
160 "files/instant_extended.html?strk=1&"); 165 "files/instant_extended.html?strk=1&");
161 InstantTestBase::Init(instant_url); 166 InstantTestBase::Init(instant_url);
162 } 167 }
163 168
164 void InstallThemeSource() { 169 void InstallThemeSource() {
165 ThemeSource* theme = new ThemeSource(profile()); 170 ThemeSource* theme = new ThemeSource(profile());
166 content::URLDataSource::Add(profile(), theme); 171 content::URLDataSource::Add(profile(), theme);
167 } 172 }
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec()); 732 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec());
728 } 733 }
729 734
730 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPDoesntSupportInstant) { 735 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPDoesntSupportInstant) {
731 // Setup Instant. 736 // Setup Instant.
732 GURL instant_url = test_server()->GetURL("files/empty.html?strk=1"); 737 GURL instant_url = test_server()->GetURL("files/empty.html?strk=1");
733 InstantTestBase::Init(instant_url); 738 InstantTestBase::Init(instant_url);
734 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 739 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
735 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 740 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
736 741
737 // NTP contents should not be preloaded. 742 // NTP contents should have fallen back to the local page.
738 ASSERT_EQ(static_cast<InstantNTP*>(NULL), instant()->ntp()); 743 ASSERT_TRUE(instant()->ntp_);
samarth 2013/05/03 04:39:17 nit: just write: ASSERT_NE(NULL, instant()->ntp())
David Black 2013/05/03 06:14:44 Done.
744 content::WebContents* ntp_contents = instant()->ntp_->contents();
745 EXPECT_TRUE(ntp_contents);
746 GURL ntp_url = ntp_contents->GetURL();
747 EXPECT_EQ(chrome::kChromeSearchLocalNtpUrl, ntp_url.spec()); //asdf
739 748
740 // Open new tab. Should use local NTP. 749 // Open new tab. Should use local NTP.
741 ui_test_utils::NavigateToURLWithDisposition( 750 ui_test_utils::NavigateToURLWithDisposition(
742 browser(), 751 browser(),
743 GURL(chrome::kChromeUINewTabURL), 752 GURL(chrome::kChromeUINewTabURL),
744 NEW_FOREGROUND_TAB, 753 NEW_FOREGROUND_TAB,
745 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 754 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
746 content::WebContents* active_tab = 755 content::WebContents* active_tab =
747 browser()->tab_strip_model()->GetActiveWebContents(); 756 browser()->tab_strip_model()->GetActiveWebContents();
748 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec()); 757 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec());
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1982 FocusOmnibox(); 1991 FocusOmnibox();
1983 EXPECT_FALSE(instant()->overlay()->IsLocal()); 1992 EXPECT_FALSE(instant()->overlay()->IsLocal());
1984 } 1993 }
1985 1994
1986 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OverlayDoesntSupportInstant) { 1995 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OverlayDoesntSupportInstant) {
1987 GURL instant_url = test_server()->GetURL("files/empty.html?strk=1"); 1996 GURL instant_url = test_server()->GetURL("files/empty.html?strk=1");
1988 InstantTestBase::Init(instant_url); 1997 InstantTestBase::Init(instant_url);
1989 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1998 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1990 1999
1991 // Focus the omnibox. When the support determination response comes back, 2000 // Focus the omnibox. When the support determination response comes back,
1992 // Instant will destroy the non-Instant page. 2001 // Instant will destroy the non-Instant page and fall back to the local page.
1993 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 2002 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1994 EXPECT_EQ(NULL, instant()->GetOverlayContents()); 2003 ASSERT_TRUE(instant()->overlay_);
samarth 2013/05/03 04:39:17 Same here and elsewhere
David Black 2013/05/03 06:14:44 Done.
2004 content::WebContents* overlay_contents = instant()->overlay_->contents();
2005 EXPECT_TRUE(overlay_contents);//asdf
2006 GURL overlay_url = overlay_contents->GetURL();
2007 EXPECT_EQ(chrome::kChromeSearchLocalNtpUrl, overlay_url.spec());
1995 2008
1996 // The local overlay is used on the next Update(). 2009 // The local overlay is used on the next Update().
1997 SetOmniboxText("query"); 2010 SetOmniboxText("query");
1998 EXPECT_TRUE(instant()->overlay()->IsLocal()); 2011 EXPECT_TRUE(instant()->overlay()->IsLocal());
1999 2012
2000 // Switched back to the remote overlay when omnibox loses and regains focus. 2013 // Switched back to the remote overlay when omnibox loses and regains focus.
2001 instant()->HideOverlay(); 2014 instant()->HideOverlay();
2002 browser()->tab_strip_model()->GetActiveWebContents()->GetView()->Focus(); 2015 browser()->tab_strip_model()->GetActiveWebContents()->GetView()->Focus();
2003 FocusOmnibox(); 2016 FocusOmnibox();
2004 EXPECT_FALSE(instant()->overlay()->IsLocal()); 2017 EXPECT_FALSE(instant()->overlay()->IsLocal());
2005 2018
2006 // Overlay destroyed again after determining support. 2019 // Overlay falls back to local again after determining support.
2007 FocusOmniboxAndWaitForInstantOverlaySupport(); 2020 FocusOmniboxAndWaitForInstantOverlaySupport();
2008 EXPECT_EQ(NULL, instant()->GetOverlayContents()); 2021 ASSERT_TRUE(instant()->overlay_);
2022 overlay_contents = instant()->overlay_->contents();
2023 EXPECT_TRUE(overlay_contents);//asdf
2024 overlay_url = overlay_contents->GetURL();
2025 EXPECT_EQ(chrome::kChromeSearchLocalNtpUrl, overlay_url.spec());
2026
2009 } 2027 }
2010 2028
2011 // Test that if Instant alters the input from URL to search, it's respected. 2029 // Test that if Instant alters the input from URL to search, it's respected.
2012 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputChangedFromURLToSearch) { 2030 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputChangedFromURLToSearch) {
2013 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 2031 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2014 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 2032 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
2015 2033
2016 content::WebContents* overlay = instant()->GetOverlayContents(); 2034 content::WebContents* overlay = instant()->GetOverlayContents();
2017 EXPECT_TRUE(ExecuteScript("suggestions = ['mcqueen.com'];")); 2035 EXPECT_TRUE(ExecuteScript("suggestions = ['mcqueen.com'];"));
2018 2036
(...skipping 23 matching lines...) Expand all
2042 2060
2043 SendDownArrow(); 2061 SendDownArrow();
2044 EXPECT_EQ("result 1", GetOmniboxText()); 2062 EXPECT_EQ("result 1", GetOmniboxText());
2045 2063
2046 // Press Enter. 2064 // Press Enter.
2047 browser()->window()->GetLocationBar()->AcceptInput(); 2065 browser()->window()->GetLocationBar()->AcceptInput();
2048 2066
2049 // Confirm that the Instant overlay was NOT committed. 2067 // Confirm that the Instant overlay was NOT committed.
2050 EXPECT_NE(overlay, browser()->tab_strip_model()->GetActiveWebContents()); 2068 EXPECT_NE(overlay, browser()->tab_strip_model()->GetActiveWebContents());
2051 } 2069 }
2070
2071 class InstantExtendedOnlineTest : public InProcessBrowserTest,
samarth 2013/05/03 04:39:17 nit: how about InstantExtendedFirstTabTest or some
David Black 2013/05/03 06:14:44 Done.
2072 public InstantTestBase {
2073 public:
2074 InstantExtendedOnlineTest() {}
2075 protected:
2076 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
2077 command_line->AppendSwitch(switches::kEnableInstantExtendedAPI);
2078 command_line->AppendSwitch(switches::kEnableLocalFirstLoadNTP);
2079 }
2080 };
2081
2082 IN_PROC_BROWSER_TEST_F(
2083 InstantExtendedOnlineTest, RedirectToLocalOnLoadFailure) {
2084 // Create a new window to test the first NTP load.
2085 ui_test_utils::NavigateToURLWithDisposition(
2086 browser(),
2087 GURL(chrome::kChromeUINewTabURL),
2088 NEW_WINDOW,
2089 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
2090
2091 const BrowserList* native_browser_list = BrowserList::GetInstance(
2092 chrome::HOST_DESKTOP_TYPE_NATIVE);
2093 ASSERT_EQ(2u, native_browser_list->size());
2094 set_browser(native_browser_list->get(1));
2095
2096 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
2097
2098 // Also make sure our instant_tab_ is loaded.
2099 if (!instant()->instant_tab_) {
2100 content::WindowedNotificationObserver instant_tab_observer(
2101 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
2102 content::NotificationService::AllSources());
2103 instant_tab_observer.Wait();
2104 }
2105
2106 // NTP contents should be preloaded.
samarth 2013/05/03 04:39:17 So you're relying on the fact that initially we tr
David Black 2013/05/03 06:14:44 Yep. I can't use the normal way of overriding the
sreeram 2013/05/05 08:40:39 I think the right way would be to set the template
2107 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
2108 content::WebContents* ntp_contents = instant()->ntp_->contents();
2109 EXPECT_TRUE(ntp_contents);
2110 GURL ntp_url = ntp_contents->GetURL();
2111 EXPECT_EQ(chrome::kChromeSearchLocalGoogleNtpUrl, ntp_url.spec());
2112
2113 // Overlay contents should be preloaded.
2114 ASSERT_NE(static_cast<InstantOverlay*>(NULL), instant()->overlay());
2115 content::WebContents* overlay_contents = instant()->overlay_->contents();
2116 EXPECT_TRUE(overlay_contents);
2117 GURL overlay_url = overlay_contents->GetURL();
2118 EXPECT_EQ(chrome::kChromeSearchLocalGoogleNtpUrl, overlay_url.spec());
2119
2120 // Instant tab contents should be preloaded.
2121 ASSERT_NE(static_cast<InstantTab*>(NULL), instant()->instant_tab());
2122 content::WebContents* instant_tab_contents =
2123 instant()->instant_tab_->contents();
2124 EXPECT_TRUE(instant_tab_contents);
2125 GURL instant_tab_url = instant_tab_contents->GetURL();
2126 EXPECT_EQ(chrome::kChromeSearchLocalGoogleNtpUrl, instant_tab_url.spec());
2127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698