diff options
20 files changed, 247 insertions, 1481 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 4932f51..f2a0306 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -4515,12 +4515,6 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_FLAGS_MULTI_PROFILES_DESCRIPTION" desc="Description for the flag to enable multiprofile support"> Associates every browser window with a profile, and adds a profile switcher in the upper right corner. Every profile has its own bookmarks, extensions, apps, etc. </message> - <message name="IDS_FLAGS_RESTRICT_INSTANT_TO_SEARCH_NAME" desc="Title for the flag to restrict Instant to search"> - Restrict Instant To Search - </message> - <message name="IDS_FLAGS_RESTRICT_INSTANT_TO_SEARCH_DESCRIPTION" desc="Description for the flag to restrict Instant to search"> - Restrict Instant to loading only search pages. - </message> <message name="IDS_FLAGS_PRELOAD_INSTANT_SEARCH_NAME" desc="Title for the flag to preload Instant search"> Preload Instant Search </message> @@ -4659,13 +4653,13 @@ Keep your key file in a safe place. You will need it to create new versions of y No thanks </message> <message name="IDS_INSTANT_OPT_IN_LABEL" desc="Label shown in the omnibox dropdown for enabling instant"> - Enable Instant for faster searching and browsing? + Enable Instant for faster searching? </message> <message name="IDS_INSTANT_OPT_IN_MESSAGE" desc="Message shown in the instant opt-in dialog"> - With Instant enabled, most webpages begin loading as soon as you type a URL in the omnibox, before you hit Enter. In addition, if supported by your default search engine, search results appear instantly as you type queries in the omnibox, and in-line predictions help guide your search.\n\nBecause search results are requested even while you're typing your query, your default search engine may be logging these as search queries.\n + With Instant enabled and if supported by your default search engine, search results appear instantly as you type queries in the omnibox, and in-line predictions help guide your search.\n\nBecause search results are requested even while you're typing your query, your default search engine may be logging these as search queries.\n </message> <message name="IDS_INSTANT_PREF" desc="Preference for enabling instant"> - Enable Instant for faster searching and browsing + Enable Instant for faster searching </message> <message name="IDS_INSTANT_PREF_WARNING" desc="Warning displayed beneath instant pref"> Omnibox input may be logged diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index 2f9a968..5f2f158 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -274,13 +274,6 @@ const Experiment kExperiments[] = { SINGLE_VALUE_TYPE(switches::kMultiProfiles) }, { - "restrict-instant-to-search", - IDS_FLAGS_RESTRICT_INSTANT_TO_SEARCH_NAME, - IDS_FLAGS_RESTRICT_INSTANT_TO_SEARCH_DESCRIPTION, - kOsAll, - SINGLE_VALUE_TYPE(switches::kRestrictInstantToSearch) - }, - { "preload-instant-search", IDS_FLAGS_PRELOAD_INSTANT_SEARCH_NAME, IDS_FLAGS_PRELOAD_INSTANT_SEARCH_DESCRIPTION, diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc index 6dea848..8309378 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.cc +++ b/chrome/browser/autocomplete/autocomplete_edit.cc @@ -221,8 +221,9 @@ void AutocompleteEditModel::OnChanged() { prerender::GetOmniboxHistogramSuffix(), recommended_action, NetworkActionPredictor::LAST_PREDICT_ACTION); - bool might_support_instant = false; - if (!DoInstant(current_match, &suggested_text, &might_support_instant)) { + if (DoInstant(current_match, &suggested_text)) { + SetSuggestedText(suggested_text, instant_complete_behavior_); + } else { // Ignore the recommended action if Omnibox prerendering is not enabled. if (!prerender::IsOmniboxEnabled(profile_)) recommended_action = NetworkActionPredictor::ACTION_NONE; @@ -240,16 +241,12 @@ void AutocompleteEditModel::OnChanged() { NOTREACHED() << "Unexpected recommended action: " << recommended_action; break; } - } - if (!might_support_instant) { // Hide any suggestions we might be showing. view_->SetInstantSuggestion(string16(), false); // No need to wait any longer for instant. FinalizeInstantQuery(string16(), string16(), false); - } else { - SetSuggestedText(suggested_text, instant_complete_behavior_); } controller_->OnChanged(); @@ -981,12 +978,8 @@ bool AutocompleteEditModel::ShouldAllowExactKeywordMatch( } bool AutocompleteEditModel::DoInstant(const AutocompleteMatch& match, - string16* suggested_text, - bool* might_support_instant) { + string16* suggested_text) { DCHECK(suggested_text); - DCHECK(might_support_instant); - - *might_support_instant = false; if (in_revert_) return false; @@ -1001,19 +994,8 @@ bool AutocompleteEditModel::DoInstant(const AutocompleteMatch& match, if (!tab) return false; - // The destination is typically the current URL when the user presses the - // down arrow in the omnibox, in which case we shouldn't load a preview. - bool instant_is_active = false; - if (user_input_in_progress() && popup_->IsOpen() && - match.destination_url != PermanentURL()) { - instant_is_active = instant->Update(tab, match, view_->GetText(), - UseVerbatimInstant(), suggested_text); - } else { - instant->DestroyPreviewContentsAndLeaveActive(); - } - - *might_support_instant = instant->MightSupportInstant(); - return instant_is_active; + return instant->Update(tab, match, view_->GetText(), UseVerbatimInstant(), + suggested_text); } void AutocompleteEditModel::DoPrerender(const AutocompleteMatch& match) { diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h index b31b2a6..8639536 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.h +++ b/chrome/browser/autocomplete/autocomplete_edit.h @@ -422,12 +422,9 @@ class AutocompleteEditModel : public AutocompleteControllerDelegate { const string16& new_user_text, size_t caret_position); - // Tries to start an instant preview for |match|. Returns true if instant is - // showing and sets |might_support_instant| to true if instant is supported. - // |suggested_text| and |might_support_instant| must be non-NULL. - bool DoInstant(const AutocompleteMatch& match, - string16* suggested_text, - bool* might_support_instant); + // Tries to start an instant preview for |match|. Returns true if instant + // processed the match. + bool DoInstant(const AutocompleteMatch& match, string16* suggested_text); // Starts a prerender for the given |match|. void DoPrerender(const AutocompleteMatch& match); diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index a81f581..2a0739a 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -3518,7 +3518,7 @@ void TestingAutomationProvider::GetInstantInfo(Browser* browser, if (browser->instant()) { InstantController* instant = browser->instant(); info->SetBoolean("enabled", true); - info->SetBoolean("showing", instant->IsShowingInstant()); + info->SetBoolean("showing", instant->is_displayable()); info->SetBoolean("active", instant->is_active()); info->SetBoolean("current", instant->IsCurrent()); if (instant->GetPreviewContents() && diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc index c6fb545..cf80cf4 100644 --- a/chrome/browser/instant/instant_browsertest.cc +++ b/chrome/browser/instant/instant_browsertest.cc @@ -9,7 +9,6 @@ #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/instant/instant_controller.h" #include "chrome/browser/instant/instant_loader.h" -#include "chrome/browser/instant/instant_loader_manager.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_service.h" @@ -32,6 +31,65 @@ #define EXPECT_STR_EQ(ascii, utf16) \ EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16)) +#if defined(OS_LINUX) +// These tests are disabled on linux because of http://crbug.com/80118 . +#define MAYBE_OnChangeEvent DISABLED_OnChangeEvent +#define MAYBE_SetSuggestionsArrayOfStrings DISABLED_SetSuggestionsArrayOfStrings +#define MAYBE_SetSuggestionsEmptyArray DISABLED_SetSuggestionsEmptyArray +#define MAYBE_SetSuggestionsValidJson DISABLED_SetSuggestionsValidJson +#define MAYBE_SetSuggestionsInvalidSuggestions \ + DISABLED_SetSuggestionsInvalidSuggestions +#define MAYBE_SetSuggestionsEmptyJson DISABLED_SetSuggestionsEmptyJson +#define MAYBE_SetSuggestionsEmptySuggestions \ + DISABLED_SetSuggestionsEmptySuggestions +#define MAYBE_SetSuggestionsEmptySuggestion \ + DISABLED_SetSuggestionsEmptySuggestion +#define MAYBE_ShowPreviewNonSearch DISABLED_ShowPreviewNonSearch +#define MAYBE_NonSearchToSearch DISABLED_NonSearchToSearch +#define MAYBE_ValidHeight DISABLED_ValidHeight +#define MAYBE_OnSubmitEvent DISABLED_OnSubmitEvent +#define MAYBE_OnCancelEvent DISABLED_OnCancelEvent +#define MAYBE_InstantCompleteNever DISABLED_InstantCompleteNever +#define MAYBE_InstantCompleteDelayed DISABLED_InstantCompleteDelayed +#define MAYBE_DontCrashOnBlockedJS DISABLED_DontCrashOnBlockedJS +#define MAYBE_DontPersistSearchbox DISABLED_DontPersistSearchbox +#define MAYBE_PreloadsInstant DISABLED_PreloadsInstant +#else +#define MAYBE_OnChangeEvent OnChangeEvent +#define MAYBE_SetSuggestionsArrayOfStrings SetSuggestionsArrayOfStrings +#define MAYBE_SetSuggestionsEmptyArray SetSuggestionsEmptyArray +#define MAYBE_SetSuggestionsValidJson SetSuggestionsValidJson +#define MAYBE_SetSuggestionsInvalidSuggestions SetSuggestionsInvalidSuggestions +#define MAYBE_SetSuggestionsEmptyJson SetSuggestionsEmptyJson +#define MAYBE_SetSuggestionsEmptySuggestions SetSuggestionsEmptySuggestions +#define MAYBE_SetSuggestionsEmptySuggestion SetSuggestionsEmptySuggestion +#define MAYBE_ShowPreviewNonSearch ShowPreviewNonSearch +#define MAYBE_NonSearchToSearch NonSearchToSearch +#define MAYBE_ValidHeight ValidHeight +#define MAYBE_OnSubmitEvent OnSubmitEvent +#define MAYBE_OnCancelEvent OnCancelEvent +#define MAYBE_InstantCompleteNever InstantCompleteNever +#define MAYBE_InstantCompleteDelayed InstantCompleteDelayed +#define MAYBE_DontCrashOnBlockedJS DontCrashOnBlockedJS +#define MAYBE_DontPersistSearchbox DontPersistSearchbox +#define MAYBE_PreloadsInstant PreloadsInstant +#endif + +#if defined(OS_MACOSX) || defined(OS_LINUX) +// Showing as flaky on Mac and Linux. +// http://crbug.com/70860 +#define MAYBE_SearchServerDoesntSupportInstant \ + DISABLED_SearchServerDoesntSupportInstant +#define MAYBE_NonSearchToSearchDoesntSupportInstant \ + DISABLED_NonSearchToSearchDoesntSupportInstant +#else +#define MAYBE_SearchServerDoesntSupportInstant \ + SearchServerDoesntSupportInstant +#define MAYBE_NonSearchToSearchDoesntSupportInstant \ + NonSearchToSearchDoesntSupportInstant +#endif + + class InstantTest : public InProcessBrowserTest { public: InstantTest() @@ -85,10 +143,6 @@ class InstantTest : public InProcessBrowserTest { ASSERT_TRUE(location_bar_); } - TabContentsWrapper* GetPendingPreviewContents() { - return browser()->instant()->GetPendingPreviewContents(); - } - // Type a character to get instant to trigger. void SetupLocationBar() { FindLocationBar(); @@ -98,11 +152,10 @@ class InstantTest : public InProcessBrowserTest { } // Waits for preview to be shown. - void WaitForPreviewToNavigate(bool use_current) { + void WaitForPreviewToNavigate() { InstantController* instant = browser()->instant(); ASSERT_TRUE(instant); - TabContentsWrapper* tab = use_current ? - instant->GetPreviewContents() : GetPendingPreviewContents(); + TabContentsWrapper* tab = instant->GetPreviewContents(); ASSERT_TRUE(tab); preview_ = tab->tab_contents(); ASSERT_TRUE(preview_); @@ -112,9 +165,8 @@ class InstantTest : public InProcessBrowserTest { // Wait for instant to load and ensure it is in the state we expect. void SetupPreview() { // Wait for the preview to navigate. - WaitForPreviewToNavigate(true); + WaitForPreviewToNavigate(); - ASSERT_TRUE(browser()->instant()->IsShowingInstant()); ASSERT_FALSE(browser()->instant()->is_displayable()); ASSERT_TRUE(browser()->instant()->is_active()); @@ -134,8 +186,12 @@ class InstantTest : public InProcessBrowserTest { } const string16& GetSuggestion() const { - return browser()->instant()->loader_manager_-> - current_loader()->complete_suggested_text_; + return browser()->instant()->loader_->complete_suggested_text_; + } + + GURL GetCurrentURL() { + return browser()->instant()->loader_.get() ? + browser()->instant()->loader_.get()->url() : GURL(); } void SendKey(ui::KeyboardCode key) { @@ -308,10 +364,6 @@ class InstantTest : public InProcessBrowserTest { CheckBoolValueFromJavascript(true, "true", tab->tab_contents())); } - InstantLoaderManager* manager() const { - return browser()->instant()->loader_manager_.get(); - } - protected: LocationBar* location_bar_; TabContents* preview_; @@ -326,12 +378,7 @@ class InstantTest : public InProcessBrowserTest { // - Test resize events. // Verify that the onchange event is dispatched upon typing in the box. -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_OnChangeEvent) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, OnChangeEvent) { -#endif // !OS_LINUX +IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnChangeEvent) { ASSERT_TRUE(test_server()->Start()); EnableInstant(); ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); @@ -351,19 +398,14 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnChangeEvent) { ASSERT_TRUE(default_turl->url()); EXPECT_EQ(default_turl->url()->ReplaceSearchTerms( *default_turl, ASCIIToUTF16("defghi"), 0, string16()), - browser()->instant()->GetCurrentURL().spec()); + GetCurrentURL().spec()); // Check that the value is reflected and onchange is called. EXPECT_EQ("true 0 0 1 true d false def false 3 3", GetSearchStateAsString(preview_, true)); } -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_SetSuggestionsArrayOfStrings) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsArrayOfStrings) { -#endif // OS_LINUX +IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsArrayOfStrings) { ASSERT_TRUE(test_server()->Start()); EnableInstant(); ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); @@ -375,12 +417,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsArrayOfStrings) { EXPECT_STR_EQ("defgh", GetSuggestion()); } -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_SetSuggestionsEmptyArray) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsEmptyArray) { -#endif // OS_LINUX +IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsEmptyArray) { ASSERT_TRUE(test_server()->Start()); EnableInstant(); ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); @@ -392,12 +429,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsEmptyArray) { EXPECT_STR_EQ("", GetSuggestion()); } -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_SetSuggestionsValidJson) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsValidJson) { -#endif // OS_LINUX +IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsValidJson) { ASSERT_TRUE(test_server()->Start()); EnableInstant(); ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); @@ -411,12 +443,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsValidJson) { EXPECT_STR_EQ("defghij", GetSuggestion()); } -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_SetSuggestionsInvalidSuggestions) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsInvalidSuggestions) { -#endif // OS_LINUX +IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsInvalidSuggestions) { ASSERT_TRUE(test_server()->Start()); EnableInstant(); ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); @@ -430,12 +457,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsInvalidSuggestions) { EXPECT_STR_EQ("", GetSuggestion()); } -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_SetSuggestionsEmptyJson) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsEmptyJson) { -#endif // OS_LINUX +IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsEmptyJson) { ASSERT_TRUE(test_server()->Start()); EnableInstant(); ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); @@ -447,12 +469,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsEmptyJson) { EXPECT_STR_EQ("", GetSuggestion()); } -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_SetSuggestionsEmptySuggestions) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsEmptySuggestions) { -#endif // OS_LINUX +IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsEmptySuggestions) { ASSERT_TRUE(test_server()->Start()); EnableInstant(); ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); @@ -464,12 +481,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsEmptySuggestions) { EXPECT_STR_EQ("", GetSuggestion()); } -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_SetSuggestionsEmptySuggestion) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsEmptySuggestion) { -#endif // OS_LINUX +IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsEmptySuggestion) { ASSERT_TRUE(test_server()->Start()); EnableInstant(); ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); @@ -481,117 +493,77 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsEmptySuggestion) { EXPECT_STR_EQ("", GetSuggestion()); } -// Verify instant preview is shown correctly for a non-search query. -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_ShowPreviewNonSearch) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, ShowPreviewNonSearch) { -#endif // OS_LINUX +IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_ShowPreviewNonSearch) { ASSERT_TRUE(test_server()->Start()); EnableInstant(); GURL url(test_server()->GetURL("files/instant/empty.html")); - ASSERT_NO_FATAL_FAILURE(SetLocationBarText(url.spec())); - // The preview should be active and showing. - ASSERT_TRUE(browser()->instant()->is_active()); - ASSERT_TRUE(browser()->instant()->is_displayable()); - ASSERT_TRUE(browser()->instant()->IsCurrent()); - ASSERT_TRUE(browser()->instant()->GetPreviewContents()); - RenderWidgetHostView* rwhv = - browser()->instant()->GetPreviewContents()->tab_contents()-> - GetRenderWidgetHostView(); - ASSERT_TRUE(rwhv); - ASSERT_TRUE(rwhv->IsShowing()); + ASSERT_NO_FATAL_FAILURE(FindLocationBar()); + location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); + + // The preview should not be active or showing. + ASSERT_FALSE(browser()->instant()->is_active()); + ASSERT_FALSE(browser()->instant()->is_displayable()); + ASSERT_FALSE(browser()->instant()->IsCurrent()); + ASSERT_EQ(NULL, browser()->instant()->GetPreviewContents()); } // Transition from non-search to search and make sure everything is shown // correctly. -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_NonSearchToSearch) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, NonSearchToSearch) { -#endif // OS_LINUX +IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_NonSearchToSearch) { ASSERT_TRUE(test_server()->Start()); EnableInstant(); GURL url(test_server()->GetURL("files/instant/empty.html")); - ASSERT_NO_FATAL_FAILURE(SetLocationBarText(url.spec())); - // The preview should be active and showing. - ASSERT_TRUE(browser()->instant()->is_active()); - ASSERT_TRUE(browser()->instant()->is_displayable()); - TabContentsWrapper* initial_tab = browser()->instant()->GetPreviewContents(); - ASSERT_TRUE(initial_tab); - RenderWidgetHostView* rwhv = - initial_tab->tab_contents()->GetRenderWidgetHostView(); - ASSERT_TRUE(rwhv); - ASSERT_TRUE(rwhv->IsShowing()); + ASSERT_NO_FATAL_FAILURE(FindLocationBar()); + location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); + // The preview not should be active and not showing. + ASSERT_FALSE(browser()->instant()->is_active()); + ASSERT_FALSE(browser()->instant()->is_displayable()); + ASSERT_EQ(NULL, browser()->instant()->GetPreviewContents()); // Now type in some search text. ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); location_bar_->location_entry()->SetUserText(ASCIIToUTF16("def")); // Wait for the preview to navigate. - ASSERT_NO_FATAL_FAILURE(WaitForPreviewToNavigate(false)); + ASSERT_NO_FATAL_FAILURE(WaitForPreviewToNavigate()); // The controller is still determining if the provider really supports - // instant. As a result the tabcontents should not have changed. + // instant. TabContentsWrapper* current_tab = browser()->instant()->GetPreviewContents(); - ASSERT_EQ(current_tab, initial_tab); - // The preview should still be showing. - rwhv = current_tab->tab_contents()->GetRenderWidgetHostView(); - ASSERT_TRUE(rwhv); - ASSERT_TRUE(rwhv->IsShowing()); + ASSERT_TRUE(current_tab); - // Use MightSupportInstant as the controller is still determining if the - // page supports instant and hasn't actually commited yet. - EXPECT_TRUE(browser()->instant()->MightSupportInstant()); - - // Instant should still be active. + // Instant should be active. EXPECT_TRUE(browser()->instant()->is_active()); - EXPECT_TRUE(browser()->instant()->is_displayable()); + EXPECT_FALSE(browser()->instant()->is_displayable()); // Because we're waiting on the page, instant isn't current. ASSERT_FALSE(browser()->instant()->IsCurrent()); // Bounce a message to the renderer so that we know the instant has gotten a // response back from the renderer as to whether the page supports instant. - ASSERT_NO_FATAL_FAILURE( - WaitForMessageToBeProcessedByRenderer(GetPendingPreviewContents())); + ASSERT_NO_FATAL_FAILURE(WaitForMessageToBeProcessedByRenderer(current_tab)); // Reset the user text so that the page is told the text changed. We should be // able to nuke this once 66104 is fixed. location_bar_->location_entry()->SetUserText(ASCIIToUTF16("defg")); // Wait for the renderer to process it. - ASSERT_NO_FATAL_FAILURE( - WaitForMessageToBeProcessedByRenderer(GetPendingPreviewContents())); + ASSERT_NO_FATAL_FAILURE(WaitForMessageToBeProcessedByRenderer(current_tab)); // We should have gotten a response back from the renderer that resulted in // committing. - ASSERT_FALSE(GetPendingPreviewContents()); ASSERT_TRUE(browser()->instant()->is_active()); ASSERT_TRUE(browser()->instant()->is_displayable()); TabContentsWrapper* new_tab = browser()->instant()->GetPreviewContents(); ASSERT_TRUE(new_tab); - ASSERT_NE(new_tab, initial_tab); RenderWidgetHostView* new_rwhv = new_tab->tab_contents()->GetRenderWidgetHostView(); ASSERT_TRUE(new_rwhv); - ASSERT_NE(new_rwhv, rwhv); ASSERT_TRUE(new_rwhv->IsShowing()); } // Makes sure that if the server doesn't support the instant API we don't show // anything. -#if defined(OS_MACOSX) || defined(OS_LINUX) -// Showing as flaky on Mac and Linux. -// http://crbug.com/70860 -#define MAYBE_SearchServerDoesntSupportInstant \ - DISABLED_SearchServerDoesntSupportInstant -#else -#define MAYBE_SearchServerDoesntSupportInstant \ - SearchServerDoesntSupportInstant -#endif IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SearchServerDoesntSupportInstant) { ASSERT_TRUE(test_server()->Start()); EnableInstant(); @@ -604,9 +576,6 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SearchServerDoesntSupportInstant) { location_bar_->location_entry()->SetUserText(ASCIIToUTF16("d")); ASSERT_TRUE(browser()->instant()); - // Because we typed in a search string we should think we're showing instant - // results. - EXPECT_TRUE(browser()->instant()->IsShowingInstant()); // But because we're waiting to determine if the page really supports instant // we shouldn't be showing the preview. EXPECT_FALSE(browser()->instant()->is_displayable()); @@ -616,7 +585,6 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SearchServerDoesntSupportInstant) { // When the response comes back that the page doesn't support instant the tab // should be closed. tab_closed_observer.Wait(); - EXPECT_FALSE(browser()->instant()->IsShowingInstant()); EXPECT_FALSE(browser()->instant()->is_displayable()); EXPECT_TRUE(browser()->instant()->is_active()); EXPECT_FALSE(browser()->instant()->IsCurrent()); @@ -630,37 +598,23 @@ IN_PROC_BROWSER_TEST_F(InstantTest, CrashUrlCancelsInstant) { ASSERT_NO_FATAL_FAILURE(FindLocationBar()); location_bar_->location_entry()->SetUserText(ASCIIToUTF16("chrome://crash")); ASSERT_TRUE(browser()->instant()); - EXPECT_FALSE(browser()->instant()->IsShowingInstant()); + EXPECT_FALSE(browser()->instant()->is_displayable()); } // Verifies transitioning from loading a non-search string to a search string // with the provider not supporting instant works (meaning we don't display // anything). -#if defined(OS_MACOSX) || defined(OS_LINUX) -// Showing as flaky on Mac and Linux/ChromeOS -// http://crbug.com/70810 -#define MAYBE_NonSearchToSearchDoesntSupportInstant \ - DISABLED_NonSearchToSearchDoesntSupportInstant -#else -#define MAYBE_NonSearchToSearchDoesntSupportInstant \ - NonSearchToSearchDoesntSupportInstant -#endif IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_NonSearchToSearchDoesntSupportInstant) { ASSERT_TRUE(test_server()->Start()); EnableInstant(); ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html")); GURL url(test_server()->GetURL("files/instant/empty.html")); - ASSERT_NO_FATAL_FAILURE(SetLocationBarText(url.spec())); - // The preview should be active and showing. - ASSERT_TRUE(browser()->instant()->is_displayable()); - ASSERT_TRUE(browser()->instant()->is_active()); - TabContentsWrapper* initial_tab = browser()->instant()->GetPreviewContents(); - ASSERT_TRUE(initial_tab); - RenderWidgetHostView* rwhv = - initial_tab->tab_contents()->GetRenderWidgetHostView(); - ASSERT_TRUE(rwhv); - ASSERT_TRUE(rwhv->IsShowing()); + ASSERT_NO_FATAL_FAILURE(FindLocationBar()); + location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); + // The preview should not be showing or active. + EXPECT_FALSE(browser()->instant()->is_displayable()); + EXPECT_FALSE(browser()->instant()->is_active()); ui_test_utils::WindowedNotificationObserver tab_closed_observer( content::NOTIFICATION_TAB_CLOSED, @@ -669,31 +623,24 @@ IN_PROC_BROWSER_TEST_F(InstantTest, // Now type in some search text. location_bar_->location_entry()->SetUserText(ASCIIToUTF16("d")); - // Instant should still be live. - ASSERT_TRUE(browser()->instant()->is_displayable()); + // Instant should be active. ASSERT_TRUE(browser()->instant()->is_active()); - // Because we typed in a search string we should think we're showing instant - // results. - EXPECT_TRUE(browser()->instant()->MightSupportInstant()); // Instant should not be current (it's still loading). EXPECT_FALSE(browser()->instant()->IsCurrent()); // When the response comes back that the page doesn't support instant the tab // should be closed. tab_closed_observer.Wait(); - EXPECT_FALSE(browser()->instant()->IsShowingInstant()); EXPECT_FALSE(browser()->instant()->is_displayable()); // But because the omnibox is still open, instant should be active. - ASSERT_TRUE(browser()->instant()->is_active()); + EXPECT_TRUE(browser()->instant()->is_active()); + EXPECT_FALSE(browser()->instant()->is_displayable()); + EXPECT_FALSE(browser()->instant()->IsCurrent()); + EXPECT_EQ(NULL, browser()->instant()->GetPreviewContents()); } // Verifies the page was told a non-zero height. -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_ValidHeight) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, ValidHeight) { -#endif // OS_LINUX +IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_ValidHeight) { ASSERT_TRUE(test_server()->Start()); EnableInstant(); ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); @@ -717,51 +664,8 @@ IN_PROC_BROWSER_TEST_F(InstantTest, ValidHeight) { EXPECT_GT(height, 0); } -// Verifies that if the server returns a 403 we don't show the preview and -// query the host again. -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_HideOn403) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, HideOn403) { -#endif // OS_LINUX - ASSERT_TRUE(test_server()->Start()); - EnableInstant(); - GURL url(test_server()->GetURL("files/instant/403.html")); - ASSERT_NO_FATAL_FAILURE(FindLocationBar()); - - ui_test_utils::WindowedNotificationObserver tab_closed_observer( - content::NOTIFICATION_TAB_CLOSED, - NotificationService::AllSources()); - - location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); - // The preview shouldn't be showing, but it should be loading. - ASSERT_TRUE(browser()->instant()->GetPreviewContents()); - ASSERT_TRUE(browser()->instant()->is_active()); - ASSERT_FALSE(browser()->instant()->is_displayable()); - - // When instant sees the 403, it should close the tab. - tab_closed_observer.Wait(); - ASSERT_FALSE(browser()->instant()->GetPreviewContents()); - ASSERT_TRUE(browser()->instant()->is_active()); - ASSERT_FALSE(browser()->instant()->is_displayable()); - - // Try loading another url on the server. Instant shouldn't create a new tab - // as the server returned 403. - GURL url2(test_server()->GetURL("files/instant/empty.html")); - location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url2.spec())); - ASSERT_FALSE(browser()->instant()->GetPreviewContents()); - ASSERT_TRUE(browser()->instant()->is_active()); - ASSERT_FALSE(browser()->instant()->is_displayable()); -} - // Verify that the onsubmit event is dispatched upon pressing enter. -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_OnSubmitEvent) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { -#endif // !OS_LINUX +IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnSubmitEvent) { ASSERT_TRUE(test_server()->Start()); EnableInstant(); ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); @@ -793,12 +697,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { } // Verify that the oncancel event is dispatched upon losing focus. -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_OnCancelEvent) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { -#endif // !OS_LINUX +IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnCancelEvent) { ASSERT_TRUE(test_server()->Start()); EnableInstant(); ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); @@ -811,7 +710,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER)); - // Check that the preview contents have been committed. + // Check that the preview contents has been committed. ASSERT_FALSE(browser()->instant()->GetPreviewContents()); ASSERT_FALSE(browser()->instant()->is_active()); TabContents* contents = browser()->GetSelectedTabContents(); @@ -826,12 +725,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { GetSearchStateAsString(preview_, false)); } -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_InstantCompleteNever) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, InstantCompleteNever) { -#endif // OS_LINUX +IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_InstantCompleteNever) { ASSERT_TRUE(test_server()->Start()); EnableInstant(); ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); @@ -849,11 +743,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, InstantCompleteNever) { } // DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_InstantCompleteDelayed) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, InstantCompleteDelayed) { -#endif // OS_LINUX +IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_InstantCompleteDelayed) { ASSERT_TRUE(test_server()->Start()); EnableInstant(); ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); @@ -871,12 +761,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, InstantCompleteDelayed) { } // Make sure the renderer doesn't crash if javascript is blocked. -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_DontCrashOnBlockedJS) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, DontCrashOnBlockedJS) { -#endif // OS_LINUX +IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_DontCrashOnBlockedJS) { browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); ASSERT_TRUE(test_server()->Start()); @@ -893,60 +778,8 @@ IN_PROC_BROWSER_TEST_F(InstantTest, DontCrashOnBlockedJS) { // As long as we get the notification we're good (the renderer didn't crash). } -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_DownloadOnEnter) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, DownloadOnEnter) { -#endif // OS_LINUX - ASSERT_TRUE(test_server()->Start()); - EnableInstant(); - // Make sure the browser window is the front most window. - ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); - ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); - ASSERT_NO_FATAL_FAILURE(FindLocationBar()); - GURL url(test_server()->GetURL("files/instant/empty.html")); - location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); - printf("0\n"); - ASSERT_NO_FATAL_FAILURE(WaitForPreviewToNavigate(true)); - url = test_server()->GetURL("files/instant/download.zip"); - - ui_test_utils::WindowedNotificationObserver load_fail_observer( - content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR, - NotificationService::AllSources()); - location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); - // Wait for the load to fail (because instant disables downloads). - printf("1\n"); - load_fail_observer.Wait(); - - printf("2\n"); - ui_test_utils::WindowedNotificationObserver download_observer( - chrome::NOTIFICATION_DOWNLOAD_INITIATED, - NotificationService::AllSources()); - ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN)); - printf("3\n"); - download_observer.Wait(); - printf("4\n"); - - // And we should end up at about:blank. - TabContents* contents = browser()->GetSelectedTabContents(); - ASSERT_TRUE(contents); - EXPECT_EQ("about:blank", - contents->controller().GetLastCommittedEntry()->url().spec()); - if (contents->controller().pending_entry()) { - // If there is a pending entry, the url should correspond to the download. - EXPECT_EQ(url.spec(), - contents->controller().pending_entry()->url().spec()); - } -} - // Makes sure window.chrome.searchbox doesn't persist when a new page is loaded. -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_DontPersistSearchbox) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, DontPersistSearchbox) { -#endif // OS_LINUX +IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_DontPersistSearchbox) { ASSERT_TRUE(test_server()->Start()); EnableInstant(); ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); @@ -977,72 +810,8 @@ IN_PROC_BROWSER_TEST_F(InstantTest, DontPersistSearchbox) { EXPECT_TRUE(result); } -// Verify that when the TabContents has a pending RenderViewHost, we won't use -// the Instant TabContents. -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_PendingRenderViewHost) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, PendingRenderViewHost) { -#endif // OS_LINUX - ASSERT_TRUE(test_server()->Start()); - EnableInstant(); - - // Open and load URL. - GURL url(test_server()->GetURL("files/instant/empty.html")); - ASSERT_NO_FATAL_FAILURE(SetLocationBarText(url.spec())); - - // Check that we have a preview TabContents. - ASSERT_TRUE(browser()->instant()); - TabContentsWrapper* preview_contents_wrapper = - browser()->instant()->GetPreviewContents(); - ASSERT_TRUE(preview_contents_wrapper); - ASSERT_TRUE(preview_contents_wrapper->tab_contents()); - - // Enter "chrome://about" in the location bar, as it will trigger a cross-site - // navigation in Instant's TabContents. - ASSERT_NO_FATAL_FAILURE(FindLocationBar()); - location_bar_->location_entry()->SetUserText( - ASCIIToUTF16(chrome::kChromeUIAboutURL)); - - // Check that we reused the same Instant TabContentsWrapper. - ASSERT_TRUE(browser()->instant()); - ASSERT_EQ(preview_contents_wrapper, - browser()->instant()->GetPreviewContents()); - - // Check that a new site instance is pending, indicating a cross-site - // navigation that has yet to complete. - ASSERT_NE(preview_contents_wrapper->tab_contents()->GetSiteInstance(), - preview_contents_wrapper->tab_contents()->GetPendingSiteInstance()); - - // We want to be able to wait until the old TabContents has navigated to - // the about page. Since we navigate while the preview still has a pending - // RenderView, the navigation will occur in the original TabContents instead. - TabContents* contents = browser()->GetSelectedTabContents(); - ui_test_utils::WindowedNotificationObserver notification_observer( - content::NOTIFICATION_LOAD_STOP, - Source<NavigationController>(&contents->controller())); - - ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN)); - - // Check that we did not swap in the Instant TabContents, but destroyed it - // instead. - ASSERT_EQ(browser()->GetSelectedTabContents(), contents); - ASSERT_FALSE(browser()->instant()->GetPreviewContents()); - ASSERT_FALSE(browser()->instant()->is_active()); - - // Make sure we navigated to the correct URL. - notification_observer.Wait(); - EXPECT_EQ(contents->GetURL().spec(), std::string(chrome::kChromeUIAboutURL)); -} - // Tests that instant search is preloaded whenever the omnibox gets focus. -// DISABLED http://crbug.com/80118 -#if defined(OS_LINUX) -IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_PreloadsInstant) { -#else -IN_PROC_BROWSER_TEST_F(InstantTest, PreloadsInstant) { -#endif // OS_LINUX +IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_PreloadsInstant) { CommandLine::ForCurrentProcess()->AppendSwitch( switches::kPreloadInstantSearch); @@ -1056,8 +825,8 @@ IN_PROC_BROWSER_TEST_F(InstantTest, PreloadsInstant) { ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); - // Verify that there are no instant loaders initially. - EXPECT_TRUE(!manager() || !manager()->num_instant_loaders()); + // Verify that there is no previews contents. + EXPECT_EQ(NULL, browser()->instant()->GetPreviewContents()); ui_test_utils::WindowedNotificationObserver instant_support_observer( chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, @@ -1066,37 +835,27 @@ IN_PROC_BROWSER_TEST_F(InstantTest, PreloadsInstant) { // Focusing the omnibox should cause instant to be preloaded. FindLocationBar(); location_bar_->FocusLocation(false); - ASSERT_TRUE(manager()); - EXPECT_EQ(1u, manager()->num_instant_loaders()); - - // Stash a pointer to the instant loader for use below. - InstantLoader* loader = manager()->GetInstantLoader(template_url_id_); - ASSERT_TRUE(loader); + TabContentsWrapper* tab_contents = browser()->instant()->GetPreviewContents(); + EXPECT_TRUE(tab_contents); + EXPECT_FALSE(browser()->instant()->is_active()); + EXPECT_FALSE(browser()->instant()->is_displayable()); instant_support_observer.Wait(); // However, instant should still not be active. EXPECT_FALSE(browser()->instant()->is_active()); EXPECT_FALSE(browser()->instant()->is_displayable()); - EXPECT_FALSE(browser()->instant()->IsShowingInstant()); - EXPECT_FALSE(browser()->instant()->MightSupportInstant()); - // Adding a new tab shouldn't delete (or recreate) the loader, since the - // omnibox doesn't lose focus. Comparing pointers is not the best way to - // assert this, but short of hooking the loader constructor or destructor, - // there seems to be no cleaner way. + // Adding a new tab shouldn't delete (or recreate) the TabContentsWrapper. AddBlankTabAndShow(browser()); - EXPECT_EQ(loader, manager()->GetInstantLoader(template_url_id_)); + EXPECT_EQ(tab_contents, browser()->instant()->GetPreviewContents()); // Doing a search should still use the same loader for the preview. SetLocationBarText("def"); - EXPECT_EQ(loader, manager()->GetInstantLoader(template_url_id_)); - EXPECT_EQ(loader, manager()->current_loader()); + EXPECT_EQ(tab_contents, browser()->instant()->GetPreviewContents()); // Verify that the preview is in fact showing instant search. EXPECT_TRUE(browser()->instant()->is_active()); EXPECT_TRUE(browser()->instant()->is_displayable()); - EXPECT_TRUE(browser()->instant()->IsShowingInstant()); - EXPECT_TRUE(browser()->instant()->MightSupportInstant()); EXPECT_TRUE(browser()->instant()->IsCurrent()); } diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index bad0184..0ade80a 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -13,7 +13,6 @@ #include "chrome/browser/instant/instant_delegate.h" #include "chrome/browser/instant/instant_field_trial.h" #include "chrome/browser/instant/instant_loader.h" -#include "chrome/browser/instant/instant_loader_manager.h" #include "chrome/browser/instant/promo_counter.h" #include "chrome/browser/platform_util.h" #include "chrome/browser/prefs/pref_service.h" @@ -26,7 +25,6 @@ #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" -#include "chrome/common/url_constants.h" #include "content/browser/renderer_host/render_widget_host_view.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/common/notification_service.h" @@ -37,33 +35,12 @@ #include "views/widget/widget.h" #endif -namespace { - -// Number of ms to delay between loading urls. -const int kUpdateDelayMS = 200; - -// Amount of time we delay before showing pages that have a non-200 status. -const int kShowDelayMS = 800; - -bool IsBlacklistedUrl(const GURL& url) { - for (int i = 0; i < chrome::kNumberOfChromeDebugURLs; ++i) { - if (url == GURL(chrome::kChromeDebugURLs[i])) - return true; - } - return false; -} - -} - -// static -InstantController::HostBlacklist* InstantController::host_blacklist_ = NULL; - InstantController::InstantController(Profile* profile, InstantDelegate* delegate) : delegate_(delegate), tab_contents_(NULL), is_active_(false), - displayable_loader_(NULL), + is_displayable_(false), commit_on_mouse_up_(false), last_transition_type_(PageTransition::LINK), ALLOW_THIS_IN_INITIALIZER_LIST(destroy_factory_(this)) { @@ -179,44 +156,26 @@ bool InstantController::Update(TabContentsWrapper* tab_contents, string16* suggested_text) { suggested_text->clear(); - const GURL& url = match.destination_url; tab_contents_ = tab_contents; commit_on_mouse_up_ = false; last_transition_type_ = match.transition; - const TemplateURL* template_url = NULL; - - // The url should not normally be empty or invalid. - if (url.is_empty() || !url.is_valid()) { - DestroyPreviewContentsAndLeaveActive(); - return false; - } - - PreviewCondition preview_condition = GetPreviewConditionFor(match, - &template_url); - if (preview_condition != PREVIEW_CONDITION_SUCCESS) { - // Just destroy the preview and cancel the update. + if (!ShouldUseInstant(match)) { DestroyPreviewContentsAndLeaveActive(); return false; } - if (!loader_manager_.get()) - loader_manager_.reset(new InstantLoaderManager(this)); + const TemplateURL* template_url = match.template_url; + DCHECK(template_url); // ShouldUseInstant returns false if no turl. + if (!loader_.get()) + loader_.reset(new InstantLoader(this, template_url->id())); if (!is_active_) { is_active_ = true; delegate_->PrepareForInstant(); } - TemplateURLID template_url_id = template_url ? template_url->id() : 0; - // Verbatim only makes sense if the search engines supports instant. - bool real_verbatim = template_url_id ? verbatim : false; - - if (ShouldUpdateNow(template_url_id, match.destination_url)) { - UpdateLoader(template_url, match.destination_url, match.transition, - user_text, real_verbatim, suggested_text); - } else { - ScheduleUpdate(match.destination_url); - } + UpdateLoader(template_url, match.destination_url, match.transition, user_text, + verbatim, suggested_text); NotificationService::current()->Notify( chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED, @@ -232,16 +191,12 @@ void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) { // Always track the omnibox bounds. That way if Update is later invoked the // bounds are in sync. omnibox_bounds_ = bounds; - if (loader_manager_.get()) { - if (loader_manager_->current_loader()) - loader_manager_->current_loader()->SetOmniboxBounds(bounds); - if (loader_manager_->pending_loader()) - loader_manager_->pending_loader()->SetOmniboxBounds(bounds); - } + if (loader_.get()) + loader_->SetOmniboxBounds(bounds); } void InstantController::DestroyPreviewContents() { - if (!loader_manager_.get()) { + if (!loader_.get()) { // We're not showing anything, nothing to do. return; } @@ -256,38 +211,22 @@ void InstantController::DestroyPreviewContents() { void InstantController::DestroyPreviewContentsAndLeaveActive() { commit_on_mouse_up_ = false; - if (displayable_loader_) { - displayable_loader_ = NULL; + if (is_displayable_) { + is_displayable_ = false; delegate_->HideInstant(); } - - if (loader_manager_.get()) - loader_manager_->DestroyNonInstantLoaders(); - show_timer_.Stop(); - update_timer_.Stop(); } bool InstantController::IsCurrent() { // TODO(mmenke): See if we can do something more intelligent in the // navigation pending case. - return loader_manager_.get() && loader_manager_->active_loader() && - loader_manager_->active_loader()->ready() && - !loader_manager_->active_loader()->IsNavigationPending() && - !loader_manager_->active_loader()->needs_reload() && - !update_timer_.IsRunning(); + return is_displayable_ && !loader_->IsNavigationPending() && + !loader_->needs_reload(); } TabContentsWrapper* InstantController::CommitCurrentPreview( InstantCommitType type) { - if (type == INSTANT_COMMIT_PRESSED_ENTER && show_timer_.IsRunning()) { - // The user pressed enter and the show timer is running. This means the - // pending_loader returned an error code and we're not showing it. Force it - // to be shown. - show_timer_.Stop(); - ShowTimerFired(); - } - DCHECK(loader_manager_.get()); - DCHECK(loader_manager_->current_loader()); + DCHECK(loader_.get()); TabContentsWrapper* tab = ReleasePreviewContents(type); tab->controller().CopyStateFromAndPrune(&tab_contents_->controller()); delegate_->CommitInstant(tab); @@ -300,9 +239,8 @@ void InstantController::SetCommitOnMouseUp() { } bool InstantController::IsMouseDownFromActivate() { - DCHECK(loader_manager_.get()); - DCHECK(loader_manager_->current_loader()); - return loader_manager_->current_loader()->IsMouseDownFromActivate(); + DCHECK(loader_.get()); + return loader_->IsMouseDownFromActivate(); } #if defined(OS_MACOSX) @@ -311,21 +249,15 @@ void InstantController::OnAutocompleteLostFocus( // If |IsMouseDownFromActivate()| returns false, the RenderWidgetHostView did // not receive a mouseDown event. Therefore, we should destroy the preview. // Otherwise, the RWHV was clicked, so we commit the preview. - if (!is_displayable() || !GetPreviewContents() || - !IsMouseDownFromActivate() || - loader_manager_->active_loader()->IsNavigationPending()) { + if (!IsCurrent() || !IsMouseDownFromActivate()) DestroyPreviewContents(); - } else if (IsShowingInstant()) { + else SetCommitOnMouseUp(); - } else { - CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); - } } #else void InstantController::OnAutocompleteLostFocus( gfx::NativeView view_gaining_focus) { - if (!is_active() || !GetPreviewContents() || - loader_manager_->active_loader()->IsNavigationPending()) { + if (!IsCurrent()) { DestroyPreviewContents(); return; } @@ -368,15 +300,10 @@ void InstantController::OnAutocompleteLostFocus( return; } - if (IsShowingInstant()) { - // We're showing instant results. As instant results may shift when - // committing we commit on the mouse up. This way a slow click still - // works fine. - SetCommitOnMouseUp(); - return; - } - - CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); + // We're showing instant results. As instant results may shift when + // committing we commit on the mouse up. This way a slow click still works + // fine. + SetCommitOnMouseUp(); return; } @@ -414,49 +341,28 @@ void InstantController::OnAutocompleteGotFocus( return; const TemplateURL* template_url = model->GetDefaultSearchProvider(); - if (!template_url || !template_url->instant_url() || !template_url->id()) + if (!IsValidInstantTemplateURL(template_url)) return; tab_contents_ = tab_contents; - if (!loader_manager_.get()) - loader_manager_.reset(new InstantLoaderManager(this)); - loader_manager_->GetInstantLoader(template_url->id()) - ->MaybeLoadInstantURL(tab_contents, template_url); + if (!loader_.get()) + loader_.reset(new InstantLoader(this, template_url->id())); + loader_->MaybeLoadInstantURL(tab_contents, template_url); } TabContentsWrapper* InstantController::ReleasePreviewContents( InstantCommitType type) { - if (!loader_manager_.get()) + if (!loader_.get()) return NULL; - // Make sure the pending loader is active. Ideally we would call - // ShowTimerFired, but if Release is invoked from the browser we don't want to - // attempt to show the tab contents (since its being added to a new tab). - if (type == INSTANT_COMMIT_PRESSED_ENTER && show_timer_.IsRunning()) { - InstantLoader* loader = loader_manager_->active_loader(); - if (loader && loader->ready() && - loader == loader_manager_->pending_loader()) { - scoped_ptr<InstantLoader> old_loader; - loader_manager_->MakePendingCurrent(&old_loader); - } - } - - // Loader may be null if the url blacklisted instant. - scoped_ptr<InstantLoader> loader; - if (loader_manager_->current_loader()) - loader.reset(loader_manager_->ReleaseCurrentLoader()); - TabContentsWrapper* tab = loader.get() ? - loader->ReleasePreviewContents(type) : NULL; - + TabContentsWrapper* tab = loader_->ReleasePreviewContents(type); ClearBlacklist(); is_active_ = false; - displayable_loader_ = NULL; + is_displayable_ = false; commit_on_mouse_up_ = false; omnibox_bounds_ = gfx::Rect(); - loader_manager_.reset(); - update_timer_.Stop(); - show_timer_.Stop(); + loader_.reset(); return tab; } @@ -465,46 +371,19 @@ void InstantController::CompleteRelease(TabContentsWrapper* tab) { } TabContentsWrapper* InstantController::GetPreviewContents() { - return loader_manager_.get() && loader_manager_->current_loader() ? - loader_manager_->current_loader()->preview_contents() : NULL; -} - -bool InstantController::IsShowingInstant() { - return loader_manager_.get() && loader_manager_->current_loader() && - loader_manager_->current_loader()->is_showing_instant(); -} - -bool InstantController::MightSupportInstant() { - return loader_manager_.get() && loader_manager_->active_loader() && - loader_manager_->active_loader()->is_showing_instant(); -} - -GURL InstantController::GetCurrentURL() { - return loader_manager_.get() && loader_manager_->active_loader() ? - loader_manager_->active_loader()->url() : GURL(); + return loader_.get() ? loader_->preview_contents() : NULL; } void InstantController::InstantStatusChanged(InstantLoader* loader) { - if (!loader->http_status_ok()) { - // Status isn't ok, start a timer that when fires shows the result. This - // delays showing 403 pages and the like. - show_timer_.Stop(); - show_timer_.Start(FROM_HERE, - base::TimeDelta::FromMilliseconds(kShowDelayMS), - this, &InstantController::ShowTimerFired); - UpdateDisplayableLoader(); - return; - } - - ProcessInstantStatusChanged(loader); + DCHECK(loader_.get()); + UpdateIsDisplayable(); } void InstantController::SetSuggestedTextFor( InstantLoader* loader, const string16& text, InstantCompleteBehavior behavior) { - if (loader_manager_->current_loader() == loader) - delegate_->SetSuggestedText(text, behavior); + delegate_->SetSuggestedText(text, behavior); } gfx::Rect InstantController::GetInstantBounds() { @@ -516,7 +395,7 @@ bool InstantController::ShouldCommitInstantOnMouseUp() { } void InstantController::CommitInstantLoader(InstantLoader* loader) { - if (loader_manager_.get() && loader_manager_->current_loader() == loader) { + if (loader_.get() && loader_.get() == loader) { CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); } else { // This can happen if the mouse was down, we swapped out the preview and @@ -528,71 +407,37 @@ void InstantController::CommitInstantLoader(InstantLoader* loader) { void InstantController::InstantLoaderDoesntSupportInstant( InstantLoader* loader) { - DCHECK(!loader->ready()); // We better not be showing this loader. - DCHECK(loader->template_url_id()); - VLOG(1) << "provider does not support instant"; // Don't attempt to use instant for this search engine again. - BlacklistFromInstant(loader->template_url_id()); - - // Because of the state of the stack we can't destroy the loader now. - bool was_pending = loader_manager_->pending_loader() == loader; - ScheduleDestroy(loader_manager_->ReleaseLoader(loader)); - if (was_pending) { - // |loader| was the pending loader. We may be showing another TabContents to - // the user (what was current). Destroy it. - DestroyPreviewContentsAndLeaveActive(); - } else { - // |loader| wasn't pending, yet it may still be the displayed loader. - UpdateDisplayableLoader(); - } + BlacklistFromInstant(); } void InstantController::AddToBlacklist(InstantLoader* loader, const GURL& url) { - std::string host = url.host(); - if (host.empty()) - return; - - if (!host_blacklist_) - host_blacklist_ = new HostBlacklist; - host_blacklist_->insert(host); - - if (!loader_manager_.get()) - return; + // Don't attempt to use instant for this search engine again. + BlacklistFromInstant(); // Because of the state of the stack we can't destroy the loader now. - ScheduleDestroy(loader); - - loader_manager_->ReleaseLoader(loader); - - UpdateDisplayableLoader(); + ScheduleDestroy(loader_.release()); + UpdateIsDisplayable(); } void InstantController::SwappedTabContents(InstantLoader* loader) { - if (displayable_loader_ == loader) - delegate_->ShowInstant(displayable_loader_->preview_contents()); -} - -void InstantController::UpdateDisplayableLoader() { - InstantLoader* loader = NULL; - // As soon as the pending loader is displayable it becomes the current loader, - // so we need only concern ourselves with the current loader here. - if (loader_manager_.get() && loader_manager_->current_loader() && - loader_manager_->current_loader()->ready() && - (!show_timer_.IsRunning() || - loader_manager_->current_loader()->http_status_ok())) { - loader = loader_manager_->current_loader(); - } - if (loader == displayable_loader_) - return; + if (is_displayable_) + delegate_->ShowInstant(loader->preview_contents()); +} - displayable_loader_ = loader; +void InstantController::UpdateIsDisplayable() { + bool displayable = + (loader_.get() && loader_->ready() && loader_->http_status_ok()); + if (displayable == is_displayable_) + return; - if (!displayable_loader_) { + is_displayable_ = displayable; + if (!is_displayable_) { delegate_->HideInstant(); } else { - delegate_->ShowInstant(displayable_loader_->preview_contents()); + delegate_->ShowInstant(loader_->preview_contents()); NotificationService::current()->Notify( chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN, Source<InstantController>(this), @@ -600,153 +445,49 @@ void InstantController::UpdateDisplayableLoader() { } } -TabContentsWrapper* InstantController::GetPendingPreviewContents() { - return loader_manager_.get() && loader_manager_->pending_loader() ? - loader_manager_->pending_loader()->preview_contents() : NULL; -} - -bool InstantController::ShouldUpdateNow(TemplateURLID instant_id, - const GURL& url) { - DCHECK(loader_manager_.get()); - - if (instant_id) { - // Update sites that support instant immediately, they can do their own - // throttling. - return true; - } - - if (url.SchemeIsFile()) - return true; // File urls should load quickly, so don't delay loading them. - - if (loader_manager_->WillUpdateChangeActiveLoader(instant_id)) { - // If Update would change loaders, update now. This indicates transitioning - // from an instant to non-instant loader. - return true; - } - - InstantLoader* active_loader = loader_manager_->active_loader(); - // WillUpdateChangeActiveLoader should return true if no active loader, so - // we know there will be an active loader if we get here. - DCHECK(active_loader); - // Immediately update if the url is the same (which should result in nothing - // happening) or the hosts differ, otherwise we'll delay the update. - return (active_loader->url() == url) || - (active_loader->url().host() != url.host()); -} - -void InstantController::ScheduleUpdate(const GURL& url) { - scheduled_url_ = url; - - update_timer_.Stop(); - update_timer_.Start(FROM_HERE, - base::TimeDelta::FromMilliseconds(kUpdateDelayMS), - this, &InstantController::ProcessScheduledUpdate); +void InstantController::UpdateLoader(const TemplateURL* template_url, + const GURL& url, + PageTransition::Type transition_type, + const string16& user_text, + bool verbatim, + string16* suggested_text) { + loader_->SetOmniboxBounds(omnibox_bounds_); + loader_->Update(tab_contents_, template_url, url, transition_type, user_text, + verbatim, suggested_text); + UpdateIsDisplayable(); } -void InstantController::ProcessScheduledUpdate() { - DCHECK(loader_manager_.get()); +bool InstantController::ShouldUseInstant(const AutocompleteMatch& match) { + TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( + tab_contents_->profile()); + if (!model) + return false; - // We only delay loading of sites that don't support instant, so we can ignore - // suggested_text here. - string16 suggested_text; - UpdateLoader(NULL, scheduled_url_, last_transition_type_, string16(), false, - &suggested_text); + const TemplateURL* default_t_url = model->GetDefaultSearchProvider(); + const TemplateURL* match_t_url = match.template_url; + return IsValidInstantTemplateURL(default_t_url) && + IsValidInstantTemplateURL(match_t_url) && + (match_t_url->id() == default_t_url->id()); } -void InstantController::ProcessInstantStatusChanged(InstantLoader* loader) { - DCHECK(loader_manager_.get()); - scoped_ptr<InstantLoader> old_loader; - if (loader == loader_manager_->pending_loader()) { - loader_manager_->MakePendingCurrent(&old_loader); - } else if (loader != loader_manager_->current_loader()) { - // Notification from a loader that is no longer the current (either we have - // a pending, or its an instant loader). Ignore it. - return; - } - - UpdateDisplayableLoader(); +// Returns true if |template_url| is a valid TemplateURL for use by instant. +bool InstantController::IsValidInstantTemplateURL( + const TemplateURL* template_url) { + return template_url && template_url->instant_url() && template_url->id() && + template_url->instant_url()->SupportsReplacement() && + !IsBlacklistedFromInstant(template_url->id()); } -void InstantController::ShowTimerFired() { - if (!loader_manager_.get()) +void InstantController::BlacklistFromInstant() { + if (!loader_.get()) return; - InstantLoader* loader = loader_manager_->active_loader(); - if (loader && loader->ready()) - ProcessInstantStatusChanged(loader); -} + DCHECK(loader_->template_url_id()); + blacklisted_ids_.insert(loader_->template_url_id()); -void InstantController::UpdateLoader(const TemplateURL* template_url, - const GURL& url, - PageTransition::Type transition_type, - const string16& user_text, - bool verbatim, - string16* suggested_text) { - update_timer_.Stop(); - - scoped_ptr<InstantLoader> owned_loader; - TemplateURLID template_url_id = template_url ? template_url->id() : 0; - InstantLoader* new_loader = - loader_manager_->UpdateLoader(template_url_id, &owned_loader); - - new_loader->SetOmniboxBounds(omnibox_bounds_); - if (new_loader->Update(tab_contents_, template_url, url, transition_type, - user_text, verbatim, suggested_text)) { - show_timer_.Stop(); - if (!new_loader->http_status_ok()) { - show_timer_.Start(FROM_HERE, - base::TimeDelta::FromMilliseconds(kShowDelayMS), - this, &InstantController::ShowTimerFired); - } - } - UpdateDisplayableLoader(); -} - -InstantController::PreviewCondition InstantController::GetPreviewConditionFor( - const AutocompleteMatch& match, const TemplateURL** template_url) { - const TemplateURL* t_url = match.template_url; - if (t_url) { - if (!t_url->id() || - !t_url->instant_url() || - IsBlacklistedFromInstant(t_url->id()) || - !t_url->instant_url()->SupportsReplacement()) { - // To avoid extra load on other search engines we only enable previews if - // they support the instant API. - return PREVIEW_CONDITION_INVALID_TEMPLATE_URL; - } - } - *template_url = t_url; - - if (match.destination_url.SchemeIs(chrome::kJavaScriptScheme)) - return PREVIEW_CONDITION_JAVASCRIPT_SCHEME; - - // Extension keywords don't have a real destination URL. - if (match.template_url && match.template_url->IsExtensionKeyword()) - return PREVIEW_CONDITION_EXTENSION_KEYWORD; - - // Was the host blacklisted? - if (host_blacklist_ && host_blacklist_->count(match.destination_url.host())) - return PREVIEW_CONDITION_BLACKLISTED_HOST; - - // Was the URL blacklisted? - if (IsBlacklistedUrl(match.destination_url)) - return PREVIEW_CONDITION_BLACKLISTED_URL; - - const CommandLine* cl = CommandLine::ForCurrentProcess(); - if ((cl->HasSwitch(switches::kRestrictInstantToSearch) || - InstantFieldTrial::IsExperimentGroup(tab_contents_->profile())) && - match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED && - match.type != AutocompleteMatch::SEARCH_HISTORY && - match.type != AutocompleteMatch::SEARCH_SUGGEST && - match.type != AutocompleteMatch::SEARCH_OTHER_ENGINE) { - return PREVIEW_CONDITION_INSTANT_SEARCH_ONLY; - } - - return PREVIEW_CONDITION_SUCCESS; -} - -void InstantController::BlacklistFromInstant(TemplateURLID id) { - blacklisted_ids_.insert(id); + // Because of the state of the stack we can't destroy the loader now. + ScheduleDestroy(loader_.release()); + UpdateIsDisplayable(); } bool InstantController::IsBlacklistedFromInstant(TemplateURLID id) { diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h index b02e898..1faf3e3 100644 --- a/chrome/browser/instant/instant_controller.h +++ b/chrome/browser/instant/instant_controller.h @@ -14,7 +14,6 @@ #include "base/memory/scoped_vector.h" #include "base/string16.h" #include "base/task.h" -#include "base/timer.h" #include "chrome/browser/instant/instant_commit_type.h" #include "chrome/browser/instant/instant_loader_delegate.h" #include "chrome/browser/search_engines/template_url_id.h" @@ -27,7 +26,6 @@ struct AutocompleteMatch; class InstantDelegate; class InstantLoader; -class InstantLoaderManager; class InstantTest; class PrefService; class Profile; @@ -149,34 +147,13 @@ class InstantController : public InstantLoaderDelegate { // Returns true if the preview TabContents is ready to be displayed. In some // situations this may return false yet GetPreviewContents() returns non-NULL. - bool is_displayable() const { return displayable_loader_ != NULL; } + bool is_displayable() const { return is_displayable_; } // Returns the transition type of the last AutocompleteMatch passed to Update. PageTransition::Type last_transition_type() const { return last_transition_type_; } - // Returns true if we're showing results from a provider that supports the - // instant API. See description of |MightSupportInstant| for how this - // differs from actual loading state. - bool IsShowingInstant(); - - // Returns true if we're attempting to use the instant API with the last URL - // passed to |Update|. The value of this may change if it turns the provider - // doesn't really support the instant API. - // The value of |IsShowingInstant| indicates whether what is currently - // displayed supports instant, whereas this returns the loading state. The - // state of |IsShowingInstant| differs when transitioning from a non-search - // provider to a search provider that supports instant (or the other way - // around). For example, if |Update| is passed www.foo.com, followed by a - // search string then this returns true, but |IsShowingInstant| returns false - // (until the search provider loads, then both return true). - bool MightSupportInstant(); - - // Returns the URL currently being loaded or shown if everything has finished - // loading. - GURL GetCurrentURL(); - // InstantLoaderDelegate virtual void InstantStatusChanged(InstantLoader* loader) OVERRIDE; virtual void SetSuggestedTextFor(InstantLoader* loader, @@ -194,41 +171,10 @@ class InstantController : public InstantLoaderDelegate { private: friend class InstantTest; - enum PreviewCondition { - PREVIEW_CONDITION_SUCCESS, - PREVIEW_CONDITION_INVALID_TEMPLATE_URL, - PREVIEW_CONDITION_JAVASCRIPT_SCHEME, - PREVIEW_CONDITION_EXTENSION_KEYWORD, - PREVIEW_CONDITION_BLACKLISTED_HOST, - PREVIEW_CONDITION_BLACKLISTED_URL, - PREVIEW_CONDITION_INSTANT_SEARCH_ONLY, - }; - typedef std::set<std::string> HostBlacklist; - // Updates |displayable_loader_| and if necessary notifies the delegate. - void UpdateDisplayableLoader(); - - // Returns the TabContents of the pending loader (or NULL). This is only used - // for testing. - TabContentsWrapper* GetPendingPreviewContents(); - - // Returns true if we should update immediately. - bool ShouldUpdateNow(TemplateURLID instant_id, const GURL& url); - - // Schedules a delayed update to load the specified url. - void ScheduleUpdate(const GURL& url); - - // Invoked from the timer to process the last scheduled url. - void ProcessScheduledUpdate(); - - // Does the work of processing a change in the status (ready or - // http_status_ok) of a loader. - void ProcessInstantStatusChanged(InstantLoader* loader); - - // Callback when the |show_timer_| fires. Invokes - // |ProcessInstantStatusChanged| with the appropriate arguments. - void ShowTimerFired(); + // Updates |is_displayable_| and if necessary notifies the delegate. + void UpdateIsDisplayable(); // Updates InstantLoaderManager and its current InstantLoader. This is invoked // internally from Update. @@ -239,14 +185,15 @@ class InstantController : public InstantLoaderDelegate { bool verbatim, string16* suggested_text); - // Returns a PreviewCondition indicating why we might decide not to show a - // preview for |match|. If |match| has a TemplateURL that supports the instant - // API it is set in |template_url|. - PreviewCondition GetPreviewConditionFor(const AutocompleteMatch& match, - const TemplateURL** template_url); + // Returns true if instant should be used for the specified match. Instant is + // only used if |match| corresponds to the default search provider. + bool ShouldUseInstant(const AutocompleteMatch& match); - // Marks the specified search engine id as not supporting instant. - void BlacklistFromInstant(TemplateURLID id); + // Returns true if |template_url| is a valid TemplateURL for use by instant. + bool IsValidInstantTemplateURL(const TemplateURL* template_url); + + // Marks the loader as not supporting instant. + void BlacklistFromInstant(); // Returns true if the specified id has been blacklisted from supporting // instant. @@ -273,8 +220,10 @@ class InstantController : public InstantLoaderDelegate { // See description above getter for details. bool is_active_; - // The loader that is ready to be displayed. - InstantLoader* displayable_loader_; + scoped_ptr<InstantLoader> loader_; + + // True if |loader_| is ready to be displayed. + bool is_displayable_; // See description above setter. gfx::Rect omnibox_bounds_; @@ -285,33 +234,18 @@ class InstantController : public InstantLoaderDelegate { // See description above getter. PageTransition::Type last_transition_type_; - scoped_ptr<InstantLoaderManager> loader_manager_; - // The IDs of any search engines that don't support instant. We assume all // search engines support instant, but if we determine an engine doesn't // support instant it is added to this list. The list is cleared out on every // reset/commit. std::set<TemplateURLID> blacklisted_ids_; - // Timer used to delay calls to |UpdateLoader|. - base::OneShotTimer<InstantController> update_timer_; - - // Timer used to delay showing loaders whose status isn't ok. - base::OneShotTimer<InstantController> show_timer_; - // Used by ScheduleForDestroy; see it for details. ScopedRunnableMethodFactory<InstantController> destroy_factory_; - // URL last pased to ScheduleUpdate. - GURL scheduled_url_; - // List of InstantLoaders to destroy. See ScheduleForDestroy for details. ScopedVector<InstantLoader> loaders_to_destroy_; - // The set of hosts that we don't use instant with. This is shared across all - // instances and only maintained for the current session. - static HostBlacklist* host_blacklist_; - DISALLOW_COPY_AND_ASSIGN(InstantController); }; diff --git a/chrome/browser/instant/instant_loader.h b/chrome/browser/instant/instant_loader.h index e95164d..d50f8f2 100644 --- a/chrome/browser/instant/instant_loader.h +++ b/chrome/browser/instant/instant_loader.h @@ -92,7 +92,9 @@ class InstantLoader : public NotificationObserver { return preview_contents_.get(); } - // Returns true if the preview TabContents is ready to be shown. + // Returns true if the preview TabContents is ready to be shown. A non-instant + // loader is ready once the renderer paints, otherwise it isn't ready until we + // get a response back from the page. bool ready() const { return ready_; } // Returns true if the current load returned a 200. diff --git a/chrome/browser/instant/instant_loader_manager.cc b/chrome/browser/instant/instant_loader_manager.cc deleted file mode 100644 index d47288c..0000000 --- a/chrome/browser/instant/instant_loader_manager.cc +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/instant/instant_loader_manager.h" - -#include "base/logging.h" -#include "chrome/browser/instant/instant_loader.h" -#include "chrome/browser/instant/instant_loader_delegate.h" -#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "content/browser/tab_contents/tab_contents.h" - -InstantLoaderManager::InstantLoaderManager( - InstantLoaderDelegate* loader_delegate) - : loader_delegate_(loader_delegate), - current_loader_(NULL), - pending_loader_(NULL) { -} - -InstantLoaderManager::~InstantLoaderManager() { - for (Loaders::iterator i = instant_loaders_.begin(); - i != instant_loaders_.end(); ++i) { - if (i->second == current_loader_) - current_loader_ = NULL; - if (i->second == pending_loader_) - pending_loader_ = NULL; - delete i->second; - } - instant_loaders_.clear(); - - delete current_loader_; - delete pending_loader_; -} - -InstantLoader* InstantLoaderManager::UpdateLoader( - TemplateURLID instant_id, - scoped_ptr<InstantLoader>* old_loader) { - InstantLoader* old_current_loader = current_loader_; - InstantLoader* old_pending_loader = pending_loader_; - - // Determine the new loader. - InstantLoader* loader = NULL; - if (instant_id) { - loader = GetInstantLoader(instant_id); - } else { - if (current_loader_ && !current_loader_->template_url_id()) - loader = current_loader_; - else if (pending_loader_ && !pending_loader_->template_url_id()) - loader = pending_loader_; - else - loader = CreateLoader(0); - } - - if (loader->ready()) { - // The loader is ready, make it the current loader no matter what. - current_loader_ = loader; - pending_loader_ = NULL; - } else { - // The loader isn't ready make it the current only if the current isn't - // ready. If the current is ready, then stop the current and make the new - // loader pending. - if (!current_loader_ || !current_loader_->ready()) { - current_loader_ = loader; - DCHECK(!pending_loader_); - } else { - // preview_contents() may be null for tests. - if (!current_loader_->template_url_id() && - current_loader_->preview_contents()) { - current_loader_->preview_contents()->tab_contents()->Stop(); - } - pending_loader_ = loader; - } - } - - if (current_loader_ != old_current_loader && old_current_loader && - !old_current_loader->template_url_id()) { - old_loader->reset(old_current_loader); - } - if (pending_loader_ != old_pending_loader && old_pending_loader && - !old_pending_loader->template_url_id() && - old_pending_loader != current_loader_) { - DCHECK(!old_loader->get()); - old_loader->reset(old_pending_loader); - } - - return active_loader(); -} - -bool InstantLoaderManager::WillUpdateChangeActiveLoader( - TemplateURLID instant_id) { - return !active_loader() || active_loader()->template_url_id() != instant_id; -} - -void InstantLoaderManager::MakePendingCurrent( - scoped_ptr<InstantLoader>* old_loader) { - DCHECK(current_loader_); - DCHECK(pending_loader_); - - if (!current_loader_->template_url_id()) - old_loader->reset(current_loader_); - - current_loader_ = pending_loader_; - pending_loader_ = NULL; -} - -InstantLoader* InstantLoaderManager::ReleaseCurrentLoader() { - DCHECK(current_loader_); - InstantLoader* loader = current_loader_; - RemoveLoaderFromInstant(current_loader_); - current_loader_ = NULL; - return loader; -} - -void InstantLoaderManager::DestroyLoader(InstantLoader* loader) { - delete ReleaseLoader(loader); -} - -InstantLoader* InstantLoaderManager::ReleaseLoader(InstantLoader* loader) { - DCHECK(loader == current_loader_ || loader == pending_loader_ || - (loader->template_url_id() && - instant_loaders_.find(loader->template_url_id()) != - instant_loaders_.end())); - - if (current_loader_ == loader) - current_loader_ = pending_loader_; - - if (pending_loader_ == loader) - pending_loader_ = NULL; - - RemoveLoaderFromInstant(loader); - - return loader; -} - -void InstantLoaderManager::RemoveLoaderFromInstant(InstantLoader* loader) { - if (!loader->template_url_id()) - return; - - Loaders::iterator i = instant_loaders_.find(loader->template_url_id()); - DCHECK(i != instant_loaders_.end()); - instant_loaders_.erase(i); -} - -void InstantLoaderManager::DestroyNonInstantLoaders() { - if (current_loader_ && !current_loader_->template_url_id()) - delete current_loader_; - current_loader_ = NULL; - - if (pending_loader_ && !pending_loader_->template_url_id()) - delete pending_loader_; - pending_loader_ = NULL; -} - -InstantLoader* InstantLoaderManager::GetInstantLoader(TemplateURLID id) { - Loaders::iterator i = instant_loaders_.find(id); - return i == instant_loaders_.end() ? CreateLoader(id) : i->second; -} - -InstantLoader* InstantLoaderManager::CreateLoader(TemplateURLID id) { - InstantLoader* loader = new InstantLoader(loader_delegate_, id); - if (id) - instant_loaders_[id] = loader; - return loader; -} diff --git a/chrome/browser/instant/instant_loader_manager.h b/chrome/browser/instant/instant_loader_manager.h deleted file mode 100644 index 7202190..0000000 --- a/chrome/browser/instant/instant_loader_manager.h +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_INSTANT_INSTANT_LOADER_MANAGER_H_ -#define CHROME_BROWSER_INSTANT_INSTANT_LOADER_MANAGER_H_ -#pragma once - -#include <map> - -#include "base/memory/scoped_ptr.h" -#include "chrome/browser/search_engines/template_url_id.h" - -class InstantLoader; -class InstantLoaderDelegate; - -// InstantLoaderManager is responsible for maintaining the InstantLoaders for -// InstantController. InstantLoaderManager keeps track of one loader for loading -// non-instant urls, and a loader per TemplateURLID for loading instant urls. A -// loader per TemplateURLID is necessitated due to not knowing in advance if a -// site really supports instant (for example, the user might have opted out even -// though it's supported). -// -// Users of InstantLoaderManager need only concern themselves with the current -// and pending loaders. The current loader is the loader that if ready is shown -// by InstantController. The pending loader is used if the current loader is -// ready and update is invoked with a different id. In this case the current -// loader is left as current (and it's preview contents stopped) and the newly -// created loader is set to pending. Once the pending loader is ready -// MakePendingCurrent should be invoked to make the pending the current loader. -// -// InstantLoader owns all the InstantLoaders returned. You can take -// ownership of the current loader by invoking ReleaseCurrentLoader. -class InstantLoaderManager { - public: - explicit InstantLoaderManager(InstantLoaderDelegate* loader_delegate); - ~InstantLoaderManager(); - - // Updates the current loader. If the current loader is replaced and should be - // deleted it is set in |old_loader|. This is done to allow the caller to - // notify delegates before the old loader is destroyed. This returns the - // active InstantLoader that should be used. - InstantLoader* UpdateLoader(TemplateURLID instant_id, - scoped_ptr<InstantLoader>* old_loader); - - // Returns true if invoking |UpdateLoader| with |instant_id| would change the - // active loader. - bool WillUpdateChangeActiveLoader(TemplateURLID instant_id); - - // Makes the pending loader the current loader. If ownership of the old - // loader is to pass to the caller |old_loader| is set appropriately. - void MakePendingCurrent(scoped_ptr<InstantLoader>* old_loader); - - // Returns the current loader and clears internal references to it. This - // should be used prior to destroying the InstantLoaderManager when the owner - // of InstantLoaderManager wants to take ownership of the loader. - InstantLoader* ReleaseCurrentLoader(); - - // Destroys the specified loader. - void DestroyLoader(InstantLoader* loader); - - // Removes references to loader. - InstantLoader* ReleaseLoader(InstantLoader* loader); - - // If |loader| is in |instant_loaders_| it is removed. - void RemoveLoaderFromInstant(InstantLoader* loader); - - // Destroys non-instant loaders (leaves instant loaders alone). - void DestroyNonInstantLoaders(); - - // Returns the loader for loading instant results with the specified id. If - // there is no loader for the specified id a new one is created. - InstantLoader* GetInstantLoader(TemplateURLID id); - - // Returns the current loader, may be null. - InstantLoader* current_loader() const { return current_loader_; } - - // Returns the pending loader, may be null. - InstantLoader* pending_loader() const { return pending_loader_; } - - // The active loader is the loader that should be used for new loads. It is - // either the pending loader or the current loader. - InstantLoader* active_loader() const { - return pending_loader_ ? pending_loader_ : current_loader_; - } - - // Returns the number of instant loaders. - // This is exposed for tests. - size_t num_instant_loaders() const { return instant_loaders_.size(); } - - private: - typedef std::map<TemplateURLID, InstantLoader*> Loaders; - - // Creates a loader and if |id| is non-zero registers it in instant_loaders_. - InstantLoader* CreateLoader(TemplateURLID id); - - InstantLoaderDelegate* loader_delegate_; - - // The current loader. - InstantLoader* current_loader_; - - // Loader we want to use as soon as ready. This is only non-null if - // current_loader_ is ready and Update is invoked with a different template - // url id. - InstantLoader* pending_loader_; - - // Maps for template url id to loader used for that template url id. - Loaders instant_loaders_; - - DISALLOW_COPY_AND_ASSIGN(InstantLoaderManager); -}; - -#endif // CHROME_BROWSER_INSTANT_INSTANT_LOADER_MANAGER_H_ diff --git a/chrome/browser/instant/instant_loader_manager_unittest.cc b/chrome/browser/instant/instant_loader_manager_unittest.cc deleted file mode 100644 index fc877ab..0000000 --- a/chrome/browser/instant/instant_loader_manager_unittest.cc +++ /dev/null @@ -1,340 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/memory/scoped_ptr.h" -#include "chrome/browser/instant/instant_loader.h" -#include "chrome/browser/instant/instant_loader_delegate.h" -#include "chrome/browser/instant/instant_loader_manager.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -class InstantLoaderDelegateImpl : public InstantLoaderDelegate { - public: - InstantLoaderDelegateImpl() {} - - virtual void InstantStatusChanged(InstantLoader* loader) OVERRIDE {} - - virtual void SetSuggestedTextFor(InstantLoader* loader, - const string16& text, - InstantCompleteBehavior behavior) OVERRIDE {} - - virtual gfx::Rect GetInstantBounds() OVERRIDE { - return gfx::Rect(); - } - - virtual bool ShouldCommitInstantOnMouseUp() OVERRIDE { - return false; - } - - virtual void CommitInstantLoader(InstantLoader* loader) OVERRIDE { - } - - virtual void InstantLoaderDoesntSupportInstant( - InstantLoader* loader) OVERRIDE { - } - - virtual void AddToBlacklist(InstantLoader* loader, - const GURL& url) OVERRIDE { - } - - virtual void SwappedTabContents(InstantLoader* loader) OVERRIDE { - } - - private: - DISALLOW_COPY_AND_ASSIGN(InstantLoaderDelegateImpl); -}; - -} - -class InstantLoaderManagerTest : public testing::Test { - public: - InstantLoaderManagerTest() {} - - void MarkReady(InstantLoader* loader) { - loader->ready_ = true; - } - - private: - DISALLOW_COPY_AND_ASSIGN(InstantLoaderManagerTest); -}; - -// Makes sure UpdateLoader works when invoked once. -TEST_F(InstantLoaderManagerTest, Basic) { - InstantLoaderDelegateImpl delegate; - InstantLoaderManager manager(&delegate); - scoped_ptr<InstantLoader> loader; - manager.UpdateLoader(0, &loader); - EXPECT_EQ(NULL, loader.get()); - EXPECT_TRUE(manager.current_loader()); - EXPECT_EQ(NULL, manager.pending_loader()); - EXPECT_EQ(0, manager.current_loader()->template_url_id()); -} - -// Make sure invoking update twice for non-instant results keeps the same -// loader. -TEST_F(InstantLoaderManagerTest, UpdateTwice) { - InstantLoaderDelegateImpl delegate; - InstantLoaderManager manager(&delegate); - scoped_ptr<InstantLoader> loader; - manager.UpdateLoader(0, &loader); - InstantLoader* current_loader = manager.current_loader(); - manager.UpdateLoader(0, &loader); - EXPECT_EQ(NULL, loader.get()); - EXPECT_EQ(current_loader, manager.current_loader()); - EXPECT_EQ(NULL, manager.pending_loader()); -} - -// Make sure invoking update twice for instant results keeps the same loader. -TEST_F(InstantLoaderManagerTest, UpdateInstantTwice) { - InstantLoaderDelegateImpl delegate; - InstantLoaderManager manager(&delegate); - scoped_ptr<InstantLoader> loader; - manager.UpdateLoader(1, &loader); - InstantLoader* current_loader = manager.current_loader(); - manager.UpdateLoader(1, &loader); - EXPECT_EQ(NULL, loader.get()); - EXPECT_EQ(current_loader, manager.current_loader()); - EXPECT_EQ(NULL, manager.pending_loader()); - EXPECT_EQ(1u, manager.num_instant_loaders()); -} - -// Makes sure transitioning from non-instant to instant works. -TEST_F(InstantLoaderManagerTest, NonInstantToInstant) { - InstantLoaderDelegateImpl delegate; - InstantLoaderManager manager(&delegate); - scoped_ptr<InstantLoader> loader; - manager.UpdateLoader(0, &loader); - InstantLoader* current_loader = manager.current_loader(); - manager.UpdateLoader(1, &loader); - EXPECT_TRUE(loader.get() != NULL); - EXPECT_NE(current_loader, manager.current_loader()); - EXPECT_EQ(NULL, manager.pending_loader()); - EXPECT_EQ(1u, manager.num_instant_loaders()); -} - -// Makes sure instant loaders aren't deleted when invoking update with different -// ids. -TEST_F(InstantLoaderManagerTest, DontDeleteInstantLoaders) { - InstantLoaderDelegateImpl delegate; - InstantLoaderManager manager(&delegate); - scoped_ptr<InstantLoader> loader; - manager.UpdateLoader(1, &loader); - InstantLoader* current_loader = manager.current_loader(); - manager.UpdateLoader(2, &loader); - EXPECT_EQ(NULL, loader.get()); - EXPECT_NE(current_loader, manager.current_loader()); - EXPECT_EQ(NULL, manager.pending_loader()); - EXPECT_EQ(2u, manager.num_instant_loaders()); -} - -// Makes sure a new loader is created and assigned to secondary when -// transitioning from a ready non-instant to instant. -TEST_F(InstantLoaderManagerTest, CreateSecondaryWhenReady) { - InstantLoaderDelegateImpl delegate; - InstantLoaderManager manager(&delegate); - scoped_ptr<InstantLoader> loader; - manager.UpdateLoader(0, &loader); - InstantLoader* current_loader = manager.current_loader(); - ASSERT_TRUE(current_loader); - MarkReady(current_loader); - - manager.UpdateLoader(1, &loader); - EXPECT_EQ(NULL, loader.get()); - EXPECT_EQ(current_loader, manager.current_loader()); - EXPECT_TRUE(manager.pending_loader()); - EXPECT_NE(current_loader, manager.pending_loader()); - EXPECT_EQ(1u, manager.num_instant_loaders()); - - // Make the pending loader current. - InstantLoader* pending_loader = manager.pending_loader(); - manager.MakePendingCurrent(&loader); - EXPECT_TRUE(loader.get()); - EXPECT_EQ(pending_loader, manager.current_loader()); - EXPECT_EQ(NULL, manager.pending_loader()); - EXPECT_EQ(1u, manager.num_instant_loaders()); -} - -// Makes sure releasing an instant updates maps currectly. -TEST_F(InstantLoaderManagerTest, ReleaseInstant) { - InstantLoaderDelegateImpl delegate; - InstantLoaderManager manager(&delegate); - scoped_ptr<InstantLoader> loader; - manager.UpdateLoader(1, &loader); - scoped_ptr<InstantLoader> current_loader(manager.ReleaseCurrentLoader()); - EXPECT_TRUE(current_loader.get()); - EXPECT_EQ(NULL, manager.current_loader()); - EXPECT_EQ(0u, manager.num_instant_loaders()); -} - -// Tests transitioning from a non-instant ready loader to an instant ready -// loader is immediate. -TEST_F(InstantLoaderManagerTest, NonInstantToInstantWhenReady) { - InstantLoaderDelegateImpl delegate; - InstantLoaderManager manager(&delegate); - scoped_ptr<InstantLoader> loader; - manager.UpdateLoader(1, &loader); - ASSERT_TRUE(manager.current_loader()); - EXPECT_EQ(1, manager.current_loader()->template_url_id()); - InstantLoader* instant_loader = manager.current_loader(); - - manager.UpdateLoader(0, &loader); - InstantLoader* non_instant_loader = manager.current_loader(); - ASSERT_TRUE(non_instant_loader); - MarkReady(non_instant_loader); - EXPECT_NE(non_instant_loader, instant_loader); - - MarkReady(instant_loader); - manager.UpdateLoader(1, &loader); - EXPECT_EQ(non_instant_loader, loader.get()); - EXPECT_EQ(instant_loader, manager.current_loader()); - EXPECT_EQ(NULL, manager.pending_loader()); - EXPECT_EQ(1u, manager.num_instant_loaders()); -} - -// Tests transitioning between 3 instant loaders, all ready. -TEST_F(InstantLoaderManagerTest, ThreeInstant) { - InstantLoaderDelegateImpl delegate; - InstantLoaderManager manager(&delegate); - scoped_ptr<InstantLoader> loader; - manager.UpdateLoader(1, &loader); - ASSERT_TRUE(manager.current_loader()); - EXPECT_EQ(1, manager.current_loader()->template_url_id()); - InstantLoader* instant_loader1 = manager.current_loader(); - MarkReady(instant_loader1); - - manager.UpdateLoader(2, &loader); - InstantLoader* instant_loader2 = manager.pending_loader(); - ASSERT_TRUE(instant_loader2); - EXPECT_EQ(2, instant_loader2->template_url_id()); - EXPECT_NE(instant_loader1, instant_loader2); - EXPECT_EQ(instant_loader1, manager.current_loader()); - - manager.UpdateLoader(3, &loader); - InstantLoader* instant_loader3 = manager.pending_loader(); - ASSERT_TRUE(instant_loader3); - EXPECT_EQ(3, instant_loader3->template_url_id()); - EXPECT_NE(instant_loader1, instant_loader3); - EXPECT_NE(instant_loader2, instant_loader3); - EXPECT_EQ(instant_loader1, manager.current_loader()); -} - -// Tests DestroyLoader with an instant loader. -TEST_F(InstantLoaderManagerTest, DestroyInstantLoader) { - InstantLoaderDelegateImpl delegate; - InstantLoaderManager manager(&delegate); - scoped_ptr<InstantLoader> loader; - manager.UpdateLoader(1, &loader); - ASSERT_TRUE(manager.current_loader()); - EXPECT_EQ(1, manager.current_loader()->template_url_id()); - // Now destroy it. - manager.DestroyLoader(manager.current_loader()); - - // There should be no current, pending and 0 instant loaders. - ASSERT_EQ(NULL, manager.current_loader()); - ASSERT_EQ(NULL, manager.pending_loader()); - EXPECT_EQ(0u, manager.num_instant_loaders()); -} - -// Tests DestroyLoader when the loader is pending. -TEST_F(InstantLoaderManagerTest, DestroyPendingLoader) { - InstantLoaderDelegateImpl delegate; - InstantLoaderManager manager(&delegate); - scoped_ptr<InstantLoader> loader; - manager.UpdateLoader(1, &loader); - InstantLoader* first_loader = manager.active_loader(); - MarkReady(first_loader); - - // Create another loader. - manager.UpdateLoader(0, &loader); - InstantLoader* second_loader = manager.pending_loader(); - ASSERT_TRUE(second_loader); - ASSERT_NE(second_loader, first_loader); - - // Destroy it. - manager.DestroyLoader(second_loader); - EXPECT_EQ(NULL, manager.pending_loader()); - EXPECT_EQ(first_loader, manager.current_loader()); -} - -// Makes sure WillUpdateChangeActiveLoader works. -TEST_F(InstantLoaderManagerTest, WillUpdateChangeActiveLoader) { - InstantLoaderDelegateImpl delegate; - InstantLoaderManager manager(&delegate); - scoped_ptr<InstantLoader> loader; - - // When there is no loader WillUpdateChangeActiveLoader should return true. - EXPECT_TRUE(manager.WillUpdateChangeActiveLoader(0)); - EXPECT_TRUE(manager.WillUpdateChangeActiveLoader(1)); - - // Add a loder with id 0 and test again. - manager.UpdateLoader(0, &loader); - EXPECT_FALSE(manager.WillUpdateChangeActiveLoader(0)); - EXPECT_TRUE(manager.WillUpdateChangeActiveLoader(1)); - ASSERT_TRUE(manager.active_loader()); - MarkReady(manager.active_loader()); - - // Add a loader with id 1 and test again. - manager.UpdateLoader(1, &loader); - EXPECT_TRUE(manager.WillUpdateChangeActiveLoader(0)); - EXPECT_FALSE(manager.WillUpdateChangeActiveLoader(1)); -} - -// Makes sure UpdateLoader doesn't schedule a loader for deletion when asked -// to update and the pending loader is ready. -TEST_F(InstantLoaderManagerTest, UpdateWithReadyPending) { - InstantLoaderDelegateImpl delegate; - InstantLoaderManager manager(&delegate); - - { - scoped_ptr<InstantLoader> loader; - manager.UpdateLoader(1, &loader); - } - InstantLoader* instant_loader = manager.current_loader(); - ASSERT_TRUE(instant_loader); - MarkReady(instant_loader); - - { - scoped_ptr<InstantLoader> loader; - manager.UpdateLoader(0, &loader); - } - InstantLoader* non_instant_loader = manager.active_loader(); - ASSERT_TRUE(non_instant_loader); - ASSERT_NE(instant_loader, non_instant_loader); - MarkReady(non_instant_loader); - - // This makes the non_instant_loader the current loader since it was ready. - scoped_ptr<InstantLoader> loader; - manager.UpdateLoader(0, &loader); - ASSERT_NE(loader.get(), non_instant_loader); -} - -// Make sure that DestroyNonInstantLoaders works. -TEST_F(InstantLoaderManagerTest, DestroyNonInstantLoaders) { - InstantLoaderDelegateImpl delegate; - InstantLoaderManager manager(&delegate); - scoped_ptr<InstantLoader> loader; - - manager.UpdateLoader(0, &loader); - InstantLoader* non_instant_loader = manager.current_loader(); - EXPECT_TRUE(non_instant_loader); - EXPECT_EQ(0, non_instant_loader->template_url_id()); - EXPECT_EQ(NULL, loader.get()); - MarkReady(non_instant_loader); - - manager.UpdateLoader(1, &loader); - InstantLoader* instant_loader = manager.pending_loader(); - EXPECT_TRUE(instant_loader); - EXPECT_EQ(1, instant_loader->template_url_id()); - EXPECT_EQ(NULL, loader.get()); - EXPECT_EQ(1u, manager.num_instant_loaders()); - - manager.DestroyNonInstantLoaders(); - - EXPECT_EQ(NULL, manager.current_loader()); - EXPECT_EQ(NULL, manager.pending_loader()); - - // The instant loader should still exist. - EXPECT_EQ(1u, manager.num_instant_loaders()); -} diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 64112fd..9c656e3 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1446,8 +1446,6 @@ 'browser/instant/instant_loader.cc', 'browser/instant/instant_loader.h', 'browser/instant/instant_loader_delegate.h', - 'browser/instant/instant_loader_manager.cc', - 'browser/instant/instant_loader_manager.h', 'browser/instant/instant_unload_handler.cc', 'browser/instant/instant_unload_handler.h', 'browser/instant/promo_counter.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 534b96c..3f660d2 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1350,7 +1350,6 @@ 'browser/importer/importer_unittest.cc', 'browser/importer/safari_importer_unittest.mm', 'browser/importer/toolbar_importer_unittest.cc', - 'browser/instant/instant_loader_manager_unittest.cc', 'browser/instant/promo_counter_unittest.cc', 'browser/intents/register_intent_handler_infobar_delegate_unittest.cc', 'browser/intents/web_intents_registry_unittest.cc', diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 6204e68..7edc07f 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -903,12 +903,6 @@ const char kRemoteDebuggingPort[] = "remote-debugging-port"; // 'load completed' is sent to the ui_test. const char kRestoreLastSession[] = "restore-last-session"; -// Restrict the automatic loading of web pages when typing in the omnibox to -// only search pages, and disable it for all other types (URLs, history pages, -// extensions, etc). Only has an effect if Instant is turned on (via "Enable -// Instant for faster searching and browsing" in Preferences -> Basics). -const char kRestrictInstantToSearch[] = "restrict-instant-to-search"; - // URL prefix used by safebrowsing to fetch hash, download data and // report malware. const char kSbInfoURLPrefix[] = "safebrowsing-info-url-prefix"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 98ab18b..7e8995d 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -246,7 +246,6 @@ extern const char kPurgeMemoryButton[]; extern const char kReloadKilledTabs[]; extern const char kRemoteDebuggingPort[]; extern const char kRestoreLastSession[]; -extern const char kRestrictInstantToSearch[]; extern const char kSbInfoURLPrefix[]; extern const char kSbMacKeyURLPrefix[]; extern const char kSbDisableAutoUpdate[]; diff --git a/chrome/test/data/instant/403.html b/chrome/test/data/instant/403.html deleted file mode 100644 index 90531a4..0000000 --- a/chrome/test/data/instant/403.html +++ /dev/null @@ -1,2 +0,0 @@ -<html> -</html> diff --git a/chrome/test/data/instant/403.html.mock-http-headers b/chrome/test/data/instant/403.html.mock-http-headers deleted file mode 100644 index 78537b6..0000000 --- a/chrome/test/data/instant/403.html.mock-http-headers +++ /dev/null @@ -1 +0,0 @@ -HTTP/1.1 403 Unauthorized diff --git a/chrome/test/data/instant/download.zip b/chrome/test/data/instant/download.zip deleted file mode 100644 index 8b13789..0000000 --- a/chrome/test/data/instant/download.zip +++ /dev/null @@ -1 +0,0 @@ - diff --git a/chrome/test/data/instant/download.zip.mock-http-headers b/chrome/test/data/instant/download.zip.mock-http-headers deleted file mode 100644 index ef07401..0000000 --- a/chrome/test/data/instant/download.zip.mock-http-headers +++ /dev/null @@ -1,5 +0,0 @@ -HTTP/1.1 200 OK -Content-Type: application/zip -Content-Length: 0 -Date: Mon, 13 Nov 2006 21:38:09 GMT -Expires: Tue, 14 Nov 2006 19:23:58 GMT |