Index: chrome/browser/instant/instant_browsertest.cc |
diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc |
index d5cb8c84ee71541c3a180afc5db4bc4e17964a0f..055043c9cdd3e02ba217f90926de748bc57d8a51 100644 |
--- a/chrome/browser/instant/instant_browsertest.cc |
+++ b/chrome/browser/instant/instant_browsertest.cc |
@@ -2,44 +2,52 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "base/prefs/pref_service.h" |
#include "chrome/browser/content_settings/host_content_settings_map.h" |
#include "chrome/browser/history/history_service_factory.h" |
-#include "chrome/browser/instant/instant_overlay.h" |
+#include "chrome/browser/instant/instant_controller.h" |
+#include "chrome/browser/instant/instant_loader.h" |
+#include "chrome/browser/instant/instant_model.h" |
#include "chrome/browser/instant/instant_service.h" |
-#include "chrome/browser/instant/instant_service_factory.h" |
#include "chrome/browser/instant/instant_test_utils.h" |
-#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/search_engines/template_url_service.h" |
#include "chrome/browser/search_engines/template_url_service_factory.h" |
#include "chrome/browser/task_manager/task_manager.h" |
#include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
-#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/browser_commands.h" |
-#include "chrome/browser/ui/host_desktop.h" |
+#include "chrome/browser/ui/browser_window.h" |
+#include "chrome/browser/ui/omnibox/location_bar.h" |
+#include "chrome/browser/ui/omnibox/omnibox_view.h" |
#include "chrome/browser/ui/tabs/tab_strip_model.h" |
-#include "chrome/common/chrome_notification_types.h" |
+#include "chrome/common/pref_names.h" |
#include "chrome/common/url_constants.h" |
+#include "chrome/test/base/in_process_browser_test.h" |
#include "chrome/test/base/interactive_test_utils.h" |
-#include "chrome/test/base/ui_test_utils.h" |
-#include "content/public/browser/notification_service.h" |
#include "content/public/browser/render_process_host.h" |
#include "content/public/browser/web_contents.h" |
+#include "content/public/test/browser_test_utils.h" |
#include "grit/generated_resources.h" |
#include "ui/base/l10n/l10n_util.h" |
-class InstantTest : public InstantTestBase { |
+class InstantTest : public InProcessBrowserTest, |
+ public InstantTestBase { |
protected: |
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
ASSERT_TRUE(test_server()->Start()); |
- instant_url_ = test_server()->GetURL("files/instant.html?"); |
+ set_instant_url(test_server()->GetURL("files/instant.html")); |
} |
- void FocusOmniboxAndWaitForInstantSupport() { |
- content::WindowedNotificationObserver observer( |
- chrome::NOTIFICATION_INSTANT_OVERLAY_SUPPORT_DETERMINED, |
- content::NotificationService::AllSources()); |
- FocusOmnibox(); |
- observer.Wait(); |
+ virtual void SetUpOnMainThread() OVERRIDE { |
+ set_browser(browser()); |
+ } |
+ |
+ void SetupInstant() { |
+ TemplateURLData template_data; |
+ template_data.SetURL("http://does/not/exist?q={searchTerms}"); |
+ template_data.instant_url = instant_url().spec(); |
+ SetupDefaultSearchProvider(template_data); |
+ |
+ browser()->profile()->GetPrefs()->SetBoolean(prefs::kInstantEnabled, true); |
} |
bool UpdateSearchState(content::WebContents* contents) WARN_UNUSED_RESULT { |
@@ -66,8 +74,6 @@ class InstantTest : public InstantTestBase { |
// Test that Instant is preloaded when the omnibox is focused. |
IN_PROC_BROWSER_TEST_F(InstantTest, OmniboxFocusLoadsInstant) { |
- ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
- |
// Explicitly unfocus the omnibox. |
EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
@@ -75,58 +81,51 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OmniboxFocusLoadsInstant) { |
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
EXPECT_FALSE(omnibox()->model()->has_focus()); |
- // Delete any existing preview. |
- instant()->overlay_.reset(); |
- EXPECT_FALSE(instant()->GetPreviewContents()); |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
+ EXPECT_FALSE(service()->loader()->contents()); |
- // Refocus the omnibox. The InstantController should've preloaded Instant. |
+ // Refocus the omnibox. The InstantLoader should preload an Instant page. |
FocusOmniboxAndWaitForInstantSupport(); |
EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
EXPECT_TRUE(omnibox()->model()->has_focus()); |
- content::WebContents* preview_tab = instant()->GetPreviewContents(); |
- EXPECT_TRUE(preview_tab); |
+ content::WebContents* overlay = service()->loader()->contents(); |
+ EXPECT_TRUE(overlay); |
// Check that the page supports Instant, but it isn't showing. |
- EXPECT_TRUE(instant()->overlay_->supports_instant()); |
- EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_default()); |
+ EXPECT_TRUE(service()->loader()->supports_instant()); |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
+ EXPECT_FALSE(instant()->GetOverlayContents()); |
- // Adding a new tab shouldn't delete or recreate the preview; otherwise, |
+ // Adding a new tab shouldn't delete or recreate the overlay; otherwise, |
// what's the point of preloading? |
AddBlankTabAndShow(browser()); |
- EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); |
+ EXPECT_EQ(overlay, service()->loader()->contents()); |
- // Unfocusing and refocusing the omnibox should also preserve the preview. |
+ // Unfocusing and refocusing the omnibox should also preserve the overlay. |
ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
FocusOmnibox(); |
EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
- EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); |
+ EXPECT_EQ(overlay, service()->loader()->contents()); |
// Doing a search should also use the same preloaded page. |
- SetOmniboxTextAndWaitForInstantToShow("query"); |
- EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); |
- EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); |
+ SetOmniboxTextAndWaitForOverlayToShow("query"); |
+ EXPECT_TRUE(instant()->IsOverlayingSearchResults()); |
+ EXPECT_EQ(overlay, instant()->GetOverlayContents()); |
} |
-// Flakes on Windows and Mac: http://crbug.com/170677 |
-#if defined(OS_WIN) || defined(OS_MACOSX) |
-#define MAYBE_OnChangeEvent DISABLED_OnChangeEvent |
-#else |
-#define MAYBE_OnChangeEvent OnChangeEvent |
-#endif |
// Test that the onchange event is dispatched upon typing in the omnibox. |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnChangeEvent) { |
+IN_PROC_BROWSER_TEST_F(InstantTest, OnChangeEvent) { |
ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
FocusOmniboxAndWaitForInstantSupport(); |
// Use the Instant page as the active tab, so we can exploit its visibility |
// handler to check visibility transitions. |
- ui_test_utils::NavigateToURL(browser(), instant_url_); |
+ ui_test_utils::NavigateToURL(browser(), instant_url()); |
content::WebContents* active_tab = |
browser()->tab_strip_model()->GetActiveWebContents(); |
@@ -135,25 +134,24 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnChangeEvent) { |
&active_tab_onvisibilitycalls)); |
EXPECT_EQ(0, active_tab_onvisibilitycalls); |
- // Typing "query" into the omnibox causes one or more onchange events. The |
- // page suggested "query suggestion" is inline autocompleted into the omnibox, |
- // causing another onchange event. |
- SetOmniboxTextAndWaitForInstantToShow("query"); |
+ // Typing "query" into the omnibox causes the first onchange event. The page |
+ // suggested "query suggestion" is inline autocompleted into the omnibox, |
+ // causing the second onchange event. |
+ SetOmniboxTextAndWaitForOverlayToShow("query"); |
EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); |
- int min_onchangecalls = 2; |
- EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
- EXPECT_LE(min_onchangecalls, onchangecalls_); |
- min_onchangecalls = onchangecalls_; |
+ EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); |
+ EXPECT_EQ(2, onchangecalls_); |
- // Change the query and confirm more onchange events are sent. |
+ // Change the query and confirm that a third onchange event is sent. The |
+ // hardcoded "query suggestion" doesn't start with "search", so no inline |
+ // autocompletion or fourth onchange event happens. |
SetOmniboxText("search"); |
- ++min_onchangecalls; |
- EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
- EXPECT_LE(min_onchangecalls, onchangecalls_); |
+ EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); |
+ EXPECT_EQ(3, onchangecalls_); |
- // The preview was shown once, and the active tab was never hidden. |
+ // The overlay was shown once, and the active tab was never hidden. |
EXPECT_EQ(1, onvisibilitycalls_); |
active_tab_onvisibilitycalls = -1; |
EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls", |
@@ -165,23 +163,23 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnChangeEvent) { |
IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { |
ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
FocusOmniboxAndWaitForInstantSupport(); |
- SetOmniboxTextAndWaitForInstantToShow("search"); |
+ SetOmniboxTextAndWaitForOverlayToShow("search"); |
- // Stash a reference to the preview, so we can refer to it after commit. |
- content::WebContents* preview_tab = instant()->GetPreviewContents(); |
- EXPECT_TRUE(preview_tab); |
+ // Stash a reference to the overlay, so we can refer to it after commit. |
+ content::WebContents* overlay = instant()->GetOverlayContents(); |
+ EXPECT_TRUE(overlay); |
// The state of the searchbox before the commit. |
- EXPECT_TRUE(UpdateSearchState(preview_tab)); |
+ EXPECT_TRUE(UpdateSearchState(overlay)); |
EXPECT_EQ("search", value_); |
EXPECT_FALSE(verbatim_); |
EXPECT_EQ(0, onsubmitcalls_); |
EXPECT_EQ(1, onvisibilitycalls_); |
- // Before the commit, the active tab is the NTP (i.e., not Instant). |
+ // Before the commit, the active tab is a blank page (i.e., not Instant). |
content::WebContents* active_tab = |
browser()->tab_strip_model()->GetActiveWebContents(); |
- EXPECT_NE(preview_tab, active_tab); |
+ EXPECT_NE(overlay, active_tab); |
EXPECT_EQ(1, active_tab->GetController().GetEntryCount()); |
EXPECT_EQ(std::string(chrome::kAboutBlankURL), |
omnibox()->model()->PermanentURL().spec()); |
@@ -190,113 +188,92 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { |
browser()->window()->GetLocationBar()->AcceptInput(); |
// After the commit, Instant should not be showing. |
- EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_default()); |
- |
- // The old overlay is deleted and a new one is created. |
- EXPECT_TRUE(instant()->GetPreviewContents()); |
- EXPECT_NE(instant()->GetPreviewContents(), preview_tab); |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
- // Check that the current active tab is indeed what was once the preview. |
- EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveWebContents()); |
+ // Check that the current active tab is indeed what was once the overlay. |
+ EXPECT_EQ(overlay, browser()->tab_strip_model()->GetActiveWebContents()); |
- // We should have two navigation entries, one for the NTP, and one for the |
- // Instant search that was committed. |
- EXPECT_EQ(2, preview_tab->GetController().GetEntryCount()); |
+ // We should have two navigation entries, one for the blank page, and one for |
+ // the Instant search that was committed. |
+ EXPECT_EQ(2, overlay->GetController().GetEntryCount()); |
// Check that the omnibox contains the Instant URL we loaded. |
- EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); |
+ EXPECT_EQ(instant_url(), omnibox()->model()->PermanentURL()); |
- // Check that the searchbox API values have been reset. |
- std::string value; |
- EXPECT_TRUE(GetStringFromJS(preview_tab, |
- "chrome.embeddedSearch.searchBox.value", &value)); |
- EXPECT_EQ("", value); |
- |
- // However, the page should've correctly received the committed query. |
- EXPECT_TRUE(UpdateSearchState(preview_tab)); |
+ // The page should've correctly received the committed query. |
+ EXPECT_TRUE(UpdateSearchState(overlay)); |
EXPECT_EQ("search", value_); |
EXPECT_TRUE(verbatim_); |
EXPECT_EQ(1, onsubmitcalls_); |
EXPECT_EQ(1, onvisibilitycalls_); |
} |
-// Test that the oncancel event is dispatched upon clicking on the preview. |
+// Test that the oncancel event is dispatched upon clicking on the overlay. |
IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { |
ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
FocusOmniboxAndWaitForInstantSupport(); |
- SetOmniboxTextAndWaitForInstantToShow("search"); |
+ SetOmniboxTextAndWaitForOverlayToShow("search"); |
- // Stash a reference to the preview, so we can refer to it after commit. |
- content::WebContents* preview_tab = instant()->GetPreviewContents(); |
- EXPECT_TRUE(preview_tab); |
+ // Stash a reference to the overlay, so we can refer to it after commit. |
+ content::WebContents* overlay = instant()->GetOverlayContents(); |
+ EXPECT_TRUE(overlay); |
// The state of the searchbox before the commit. |
- EXPECT_TRUE(UpdateSearchState(preview_tab)); |
+ EXPECT_TRUE(UpdateSearchState(overlay)); |
EXPECT_EQ("search", value_); |
EXPECT_FALSE(verbatim_); |
EXPECT_EQ(0, oncancelcalls_); |
EXPECT_EQ(1, onvisibilitycalls_); |
- // Before the commit, the active tab is the NTP (i.e., not Instant). |
+ // Before the commit, the active tab is a blank page (i.e., not Instant). |
content::WebContents* active_tab = |
browser()->tab_strip_model()->GetActiveWebContents(); |
- EXPECT_NE(preview_tab, active_tab); |
+ EXPECT_NE(overlay, active_tab); |
EXPECT_EQ(1, active_tab->GetController().GetEntryCount()); |
EXPECT_EQ(std::string(chrome::kAboutBlankURL), |
omnibox()->model()->PermanentURL().spec()); |
- // Commit the search by clicking on the preview. |
+ // Commit the search by clicking on the overlay. |
ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
// After the commit, Instant should not be showing. |
- EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_default()); |
- |
- // The old overlay is deleted and a new one is created. |
- EXPECT_TRUE(instant()->GetPreviewContents()); |
- EXPECT_NE(instant()->GetPreviewContents(), preview_tab); |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
- // Check that the current active tab is indeed what was once the preview. |
- EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveWebContents()); |
+ // Check that the current active tab is indeed what was once the overlay. |
+ EXPECT_EQ(overlay, browser()->tab_strip_model()->GetActiveWebContents()); |
- // We should have two navigation entries, one for the NTP, and one for the |
- // Instant search that was committed. |
- EXPECT_EQ(2, preview_tab->GetController().GetEntryCount()); |
+ // We should have two navigation entries, one for the blank page, and one for |
+ // the Instant search that was committed. |
+ EXPECT_EQ(2, overlay->GetController().GetEntryCount()); |
// Check that the omnibox contains the Instant URL we loaded. |
- EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); |
+ EXPECT_EQ(instant_url(), omnibox()->model()->PermanentURL()); |
- // Check that the searchbox API values have been reset. |
- std::string value; |
- EXPECT_TRUE(GetStringFromJS(preview_tab, |
- "chrome.embeddedSearch.searchBox.value", &value)); |
- EXPECT_EQ("", value); |
- |
- // However, the page should've correctly received the committed query. |
- EXPECT_TRUE(UpdateSearchState(preview_tab)); |
+ // The page should've correctly received the committed query. |
+ EXPECT_TRUE(UpdateSearchState(overlay)); |
EXPECT_EQ("search", value_); |
EXPECT_TRUE(verbatim_); |
EXPECT_EQ(1, oncancelcalls_); |
EXPECT_EQ(1, onvisibilitycalls_); |
} |
-// Test that the onreisze event is dispatched upon typing in the omnibox. |
+// Test that the onresize event is dispatched upon typing in the omnibox. |
IN_PROC_BROWSER_TEST_F(InstantTest, OnResizeEvent) { |
ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
- |
FocusOmniboxAndWaitForInstantSupport(); |
+ content::WebContents* overlay = service()->loader()->contents(); |
- EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
+ EXPECT_TRUE(UpdateSearchState(overlay)); |
EXPECT_EQ(0, onresizecalls_); |
EXPECT_EQ(0, height_); |
// Type a query into the omnibox. This should cause an onresize() event, with |
// a valid (non-zero) height. |
- SetOmniboxTextAndWaitForInstantToShow("search"); |
+ SetOmniboxTextAndWaitForOverlayToShow("search"); |
+ EXPECT_EQ(overlay, instant()->GetOverlayContents()); |
- EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
+ EXPECT_TRUE(UpdateSearchState(overlay)); |
EXPECT_EQ(1, onresizecalls_); |
EXPECT_LT(0, height_); |
} |
@@ -306,11 +283,8 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNow) { |
ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
FocusOmniboxAndWaitForInstantSupport(); |
- // Tell the JS to request the given behavior. |
- EXPECT_TRUE(ExecuteScript("behavior = 'now'")); |
- |
// Type a query, causing the hardcoded "query suggestion" to be returned. |
- SetOmniboxTextAndWaitForInstantToShow("query"); |
+ SetOmniboxTextAndWaitForOverlayToShow("query"); |
// Get what's showing in the omnibox, and what's highlighted. |
string16 text = omnibox()->GetText(); |
@@ -324,39 +298,17 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNow) { |
EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); |
} |
-// Test that the INSTANT_COMPLETE_NEVER behavior works as expected. |
-IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNever) { |
- ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
- FocusOmniboxAndWaitForInstantSupport(); |
- |
- // Tell the JS to request the given behavior. |
- EXPECT_TRUE(ExecuteScript("behavior = 'never'")); |
- |
- // Type a query, causing the hardcoded "query suggestion" to be returned. |
- SetOmniboxTextAndWaitForInstantToShow("query"); |
- |
- // Get what's showing in the omnibox, and what's highlighted. |
- string16 text = omnibox()->GetText(); |
- size_t start = 0, end = 0; |
- omnibox()->GetSelectionBounds(&start, &end); |
- if (start > end) |
- std::swap(start, end); |
- |
- EXPECT_EQ(ASCIIToUTF16("query"), text); |
- EXPECT_EQ(ASCIIToUTF16(""), text.substr(start, end - start)); |
- EXPECT_EQ(ASCIIToUTF16(" suggestion"), omnibox()->GetInstantSuggestion()); |
-} |
- |
// Test that a valid suggestion is accepted. |
IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsValidObject) { |
ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
FocusOmniboxAndWaitForInstantSupport(); |
// Tell the JS to use the given suggestion. |
- EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'query completion' } ]")); |
+ EXPECT_TRUE(content::ExecuteScript(service()->loader()->contents(), |
+ "suggestion = { suggestions: [ { value: 'query completion' } ] }")); |
// Type a query, causing "query completion" to be returned as the suggestion. |
- SetOmniboxTextAndWaitForInstantToShow("query"); |
+ SetOmniboxTextAndWaitForOverlayToShow("query"); |
EXPECT_EQ(ASCIIToUTF16("query completion"), omnibox()->GetText()); |
} |
@@ -366,32 +318,38 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsInvalidObject) { |
FocusOmniboxAndWaitForInstantSupport(); |
// Tell the JS to use an object in an invalid format. |
- EXPECT_TRUE(ExecuteScript("suggestion = { value: 'query completion' }")); |
+ EXPECT_TRUE(content::ExecuteScript(service()->loader()->contents(), |
+ "suggestion = { suggestions: { value: 'query completion' } }")); |
// Type a query, but expect no suggestion. |
- SetOmniboxTextAndWaitForInstantToShow("query"); |
+ SetOmniboxTextAndWaitForOverlayToShow("query"); |
EXPECT_EQ(ASCIIToUTF16("query"), omnibox()->GetText()); |
} |
// Test that various forms of empty suggestions are rejected. |
IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsEmpty) { |
ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
- FocusOmniboxAndWaitForInstantSupport(); |
- EXPECT_TRUE(ExecuteScript("suggestion = {}")); |
- SetOmniboxTextAndWaitForInstantToShow("query"); |
+ FocusOmniboxAndWaitForInstantSupport(); |
+ EXPECT_TRUE(content::ExecuteScript(service()->loader()->contents(), |
+ "suggestion = {}")); |
+ SetOmniboxTextAndWaitForOverlayToShow("query"); |
EXPECT_EQ(ASCIIToUTF16("query"), omnibox()->GetText()); |
omnibox()->RevertAll(); |
- EXPECT_TRUE(ExecuteScript("suggestion = []")); |
- SetOmniboxTextAndWaitForInstantToShow("query sugg"); |
+ FocusOmniboxAndWaitForInstantSupport(); |
+ EXPECT_TRUE(content::ExecuteScript(service()->loader()->contents(), |
+ "suggestion = []")); |
+ SetOmniboxTextAndWaitForOverlayToShow("query sugg"); |
EXPECT_EQ(ASCIIToUTF16("query sugg"), omnibox()->GetText()); |
omnibox()->RevertAll(); |
- EXPECT_TRUE(ExecuteScript("suggestion = [{}]")); |
- SetOmniboxTextAndWaitForInstantToShow("query suggest"); |
+ FocusOmniboxAndWaitForInstantSupport(); |
+ EXPECT_TRUE(content::ExecuteScript(service()->loader()->contents(), |
+ "suggestion = [{}]")); |
+ SetOmniboxTextAndWaitForOverlayToShow("query suggest"); |
EXPECT_EQ(ASCIIToUTF16("query suggest"), omnibox()->GetText()); |
} |
@@ -404,20 +362,15 @@ IN_PROC_BROWSER_TEST_F(InstantTest, RejectsURLs) { |
// typing them into the omnibox (without pressing Enter) and checking that |
// Instant doesn't try to process them. |
SetOmniboxText(chrome::kChromeUICrashURL); |
- EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_default()); |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
SetOmniboxText(chrome::kChromeUIHangURL); |
- EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_default()); |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
SetOmniboxText(chrome::kChromeUIKillURL); |
- EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_default()); |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
- // Make sure that the URLs were never sent to the preview page. |
- EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
- EXPECT_EQ("", value_); |
+ EXPECT_FALSE(instant()->GetOverlayContents()); |
} |
// Test that Instant doesn't fire for intranet paths that look like searches. |
@@ -431,9 +384,8 @@ IN_PROC_BROWSER_TEST_F(InstantTest, IntranetPathLooksLikeSearch) { |
ui_test_utils::NavigateToURL(browser(), GURL("http://baby/beluga")); |
EXPECT_EQ(ASCIIToUTF16("baby/beluga"), omnibox()->GetText()); |
- EXPECT_TRUE(instant()->GetPreviewContents()); |
- EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_default()); |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
+ EXPECT_FALSE(instant()->GetOverlayContents()); |
} |
// Test that transitions between searches and non-searches work as expected. |
@@ -442,98 +394,68 @@ IN_PROC_BROWSER_TEST_F(InstantTest, TransitionsBetweenSearchAndURL) { |
FocusOmniboxAndWaitForInstantSupport(); |
// Type a search, and immediately a URL, without waiting for Instant to show. |
- // The page is told about the search. Though the page isn't told about the |
- // subsequent URL, it invalidates the search, so a blank query is sent in its |
- // place to indicate that the search is "out of date". |
+ // This should cause the overlay to be discarded. |
SetOmniboxText("query"); |
- SetOmniboxText("http://monstrous/nightmare"); |
- int min_onchangecalls = 2; |
+ EXPECT_TRUE(instant()->GetOverlayContents()); |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
- EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
- EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_default()); |
- EXPECT_EQ("", value_); |
- EXPECT_LE(min_onchangecalls, onchangecalls_); |
- min_onchangecalls = onchangecalls_; |
+ SetOmniboxText("http://monstrous/nightmare"); |
+ EXPECT_FALSE(instant()->GetOverlayContents()); |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
// Type a search. Instant should show. |
- SetOmniboxTextAndWaitForInstantToShow("search"); |
- ++min_onchangecalls; |
+ FocusOmniboxAndWaitForInstantSupport(); |
+ SetOmniboxTextAndWaitForOverlayToShow("search"); |
+ EXPECT_TRUE(instant()->IsOverlayingSearchResults()); |
- EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
- EXPECT_TRUE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); |
+ EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); |
EXPECT_EQ("search", value_); |
- EXPECT_LE(min_onchangecalls, onchangecalls_); |
- min_onchangecalls = onchangecalls_; |
- // Type another URL. The preview should be hidden. |
+ // Type another URL. The overlay should be hidden. |
SetOmniboxText("http://terrible/terror"); |
- ++min_onchangecalls; |
- |
- EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
- EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_default()); |
- EXPECT_EQ("", value_); |
- EXPECT_LE(min_onchangecalls, onchangecalls_); |
- min_onchangecalls = onchangecalls_; |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
// Type the same search as before. |
- SetOmniboxTextAndWaitForInstantToShow("search"); |
- min_onchangecalls++; |
- |
- EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
- EXPECT_TRUE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); |
- EXPECT_EQ("search", value_); |
- EXPECT_LE(min_onchangecalls, onchangecalls_); |
- min_onchangecalls = onchangecalls_; |
+ FocusOmniboxAndWaitForInstantSupport(); |
+ SetOmniboxTextAndWaitForOverlayToShow("search"); |
+ EXPECT_TRUE(instant()->IsOverlayingSearchResults()); |
// Revert the omnibox. |
omnibox()->RevertAll(); |
- min_onchangecalls++; |
- |
- EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
- EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_default()); |
- EXPECT_EQ("", value_); |
- EXPECT_LE(min_onchangecalls, onchangecalls_); |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
} |
// Test that Instant can't be fooled into committing a URL. |
IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsOne) { |
ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
+ FocusOmniboxAndWaitForInstantSupport(); |
EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
- // Type a URL. The Instant preview shouldn't be showing. |
+ content::WebContents* overlay = service()->loader()->contents(); |
+ |
+ // Type a URL. The Instant overlay shouldn't be showing. |
SetOmniboxText("http://deadly/nadder"); |
- EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_default()); |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
// Unfocus and refocus the omnibox. |
ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
FocusOmnibox(); |
- content::WebContents* preview_tab = instant()->GetPreviewContents(); |
- EXPECT_TRUE(preview_tab); |
- |
// The omnibox text hasn't changed, so Instant still shouldn't be showing. |
EXPECT_EQ(ASCIIToUTF16("http://deadly/nadder"), omnibox()->GetText()); |
- EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_default()); |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
// Commit the URL. The omnibox should reflect the URL minus the scheme. |
browser()->window()->GetLocationBar()->AcceptInput(); |
content::WebContents* active_tab = |
browser()->tab_strip_model()->GetActiveWebContents(); |
- EXPECT_NE(preview_tab, active_tab); |
+ EXPECT_NE(overlay, active_tab); |
EXPECT_EQ(ASCIIToUTF16("deadly/nadder"), omnibox()->GetText()); |
// Instant shouldn't have done anything. |
- EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); |
- EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_default()); |
+ EXPECT_EQ(overlay, service()->loader()->contents()); |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
} |
// Test that Instant can't be fooled into committing a URL. |
@@ -541,16 +463,14 @@ IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsTwo) { |
ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
FocusOmniboxAndWaitForInstantSupport(); |
- // Type a query. This causes the preview to be shown. |
- SetOmniboxTextAndWaitForInstantToShow("query"); |
+ // Type a query. This causes the overlay to be shown. |
+ SetOmniboxTextAndWaitForOverlayToShow("query"); |
- content::WebContents* preview_tab = instant()->GetPreviewContents(); |
- EXPECT_TRUE(preview_tab); |
+ content::WebContents* overlay = instant()->GetOverlayContents(); |
- // Type a URL. This causes the preview to be hidden. |
+ // Type a URL. This causes the overlay to be hidden. |
SetOmniboxText("http://hideous/zippleback"); |
- EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_default()); |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
// Pretend the omnibox got focus. It already had focus, so we are just trying |
// to tickle a different code path. |
@@ -561,26 +481,25 @@ IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsTwo) { |
browser()->window()->GetLocationBar()->AcceptInput(); |
content::WebContents* active_tab = |
browser()->tab_strip_model()->GetActiveWebContents(); |
- EXPECT_NE(preview_tab, active_tab); |
+ EXPECT_NE(overlay, active_tab); |
EXPECT_EQ(ASCIIToUTF16("hideous/zippleback"), omnibox()->GetText()); |
// As before, Instant shouldn't have done anything. |
- EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); |
- EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_default()); |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
} |
-// Test that a non-Instant search provider shows no previews. |
+// Test that a non-Instant search provider shows no overlays. |
IN_PROC_BROWSER_TEST_F(InstantTest, NonInstantSearchProvider) { |
- instant_url_ = test_server()->GetURL("files/empty.html"); |
+ set_instant_url(test_server()->GetURL("files/empty.html")); |
ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
// Focus the omnibox. When the support determination response comes back, |
- // Instant will destroy the non-Instant page, and attempt to recreate it. |
- // We can know this happened by looking at the blacklist. |
- EXPECT_EQ(0, instant()->blacklisted_urls_[instant_url_.spec()]); |
+ // Instant will destroy the non-Instant page. |
+ FocusOmnibox(); |
+ EXPECT_TRUE(service()->loader()->contents()); |
+ |
FocusOmniboxAndWaitForInstantSupport(); |
- EXPECT_EQ(1, instant()->blacklisted_urls_[instant_url_.spec()]); |
+ EXPECT_FALSE(service()->loader()->contents()); |
} |
// Test that the renderer doesn't crash if JavaScript is blocked. |
@@ -592,43 +511,47 @@ IN_PROC_BROWSER_TEST_F(InstantTest, NoCrashOnBlockedJS) { |
// Wait for notification that the Instant API has been determined. As long as |
// we get the notification we're good (the renderer didn't crash). |
FocusOmniboxAndWaitForInstantSupport(); |
+ EXPECT_FALSE(service()->loader()->contents()); |
} |
-// Test that the preview and active tab's visibility states are set correctly. |
+// Test that the overlay and active tab's visibility states are set correctly. |
IN_PROC_BROWSER_TEST_F(InstantTest, PageVisibility) { |
ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
FocusOmniboxAndWaitForInstantSupport(); |
content::WebContents* active_tab = |
browser()->tab_strip_model()->GetActiveWebContents(); |
- content::WebContents* preview_tab = instant()->GetPreviewContents(); |
+ content::WebContents* overlay = service()->loader()->contents(); |
- // Inititally, the active tab is showing; the preview is not. |
+ // Inititally, the active tab is showing; the overlay is not. |
EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); |
- EXPECT_TRUE(CheckVisibilityIs(preview_tab, false)); |
+ EXPECT_TRUE(CheckVisibilityIs(overlay, false)); |
// Type a query and wait for Instant to show. |
- SetOmniboxTextAndWaitForInstantToShow("query"); |
+ SetOmniboxTextAndWaitForOverlayToShow("query"); |
EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); |
- EXPECT_TRUE(CheckVisibilityIs(preview_tab, true)); |
+ EXPECT_TRUE(CheckVisibilityIs(overlay, true)); |
- // Deleting the omnibox text should hide the preview. |
+ // Deleting the omnibox text should hide the overlay. |
SetOmniboxText(""); |
EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); |
- EXPECT_TRUE(CheckVisibilityIs(preview_tab, false)); |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
- // Typing a query should show the preview again. |
- SetOmniboxTextAndWaitForInstantToShow("query"); |
+ // Typing a query should show the overlay again. |
+ FocusOmniboxAndWaitForInstantSupport(); |
+ overlay = service()->loader()->contents(); |
+ |
+ SetOmniboxTextAndWaitForOverlayToShow("query"); |
EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); |
- EXPECT_TRUE(CheckVisibilityIs(preview_tab, true)); |
+ EXPECT_TRUE(CheckVisibilityIs(overlay, true)); |
- // Commit the preview. |
+ // Commit the overlay. |
browser()->window()->GetLocationBar()->AcceptInput(); |
- EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveWebContents()); |
- EXPECT_TRUE(CheckVisibilityIs(preview_tab, true)); |
+ EXPECT_EQ(overlay, browser()->tab_strip_model()->GetActiveWebContents()); |
+ EXPECT_TRUE(CheckVisibilityIs(overlay, true)); |
} |
-// Test that the task manager identifies Instant's preview tab correctly. |
+// Test that the task manager identifies Instant's overlay tab correctly. |
IN_PROC_BROWSER_TEST_F(InstantTest, TaskManagerPrefix) { |
// The browser starts with a new tab, so there's just one renderer initially. |
TaskManagerModel* task_manager = TaskManager::GetInstance()->model(); |
@@ -636,27 +559,66 @@ IN_PROC_BROWSER_TEST_F(InstantTest, TaskManagerPrefix) { |
TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); |
string16 prefix = l10n_util::GetStringFUTF16( |
- IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX, string16()); |
+ IDS_TASK_MANAGER_INSTANT_OVERLAY_PREFIX, string16()); |
- // There should be no Instant preview yet. |
+ // There should be no Instant overlay yet. |
for (int i = 0; i < task_manager->ResourceCount(); ++i) { |
string16 title = task_manager->GetResourceTitle(i); |
EXPECT_FALSE(StartsWith(title, prefix, true)) << title << " vs " << prefix; |
} |
ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
- FocusOmnibox(); |
+ FocusOmniboxAndWaitForInstantSupport(); |
+ content::WebContents* overlay = service()->loader()->contents(); |
- // Now there should be two renderers, the second being the Instant preview. |
+ // Now there should be two renderers, the second being the Instant overlay. |
TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); |
- int instant_previews = 0; |
+ int instant_overlays = 0; |
+ for (int i = 0; i < task_manager->ResourceCount(); ++i) { |
+ string16 title = task_manager->GetResourceTitle(i); |
+ if (StartsWith(title, prefix, true)) |
+ ++instant_overlays; |
+ } |
+ EXPECT_EQ(1, instant_overlays); |
+ |
+ // Type something into the omnibox. This causes the overlay to be shown and |
+ // another Instant page to be spun up in the background. |
+ SetOmniboxTextAndWaitForOverlayToShow("query"); |
+ |
+ // So now there are three renderers, two of which are Instant. |
+ TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); |
+ |
+ instant_overlays = 0; |
+ for (int i = 0; i < task_manager->ResourceCount(); ++i) { |
+ string16 title = task_manager->GetResourceTitle(i); |
+ if (StartsWith(title, prefix, true)) |
+ ++instant_overlays; |
+ } |
+ EXPECT_EQ(2, instant_overlays); |
+ |
+ // Commit the overlay. It should now be considered a regular tab. |
+ browser()->window()->GetLocationBar()->AcceptInput(); |
+ |
+ // The task manager caches titles, so we need to force the cache to clear. |
+ task_manager->StopUpdating(); |
+ task_manager->StartUpdating(); |
+ |
+ int overlay_index = -1; |
+ instant_overlays = 0; |
for (int i = 0; i < task_manager->ResourceCount(); ++i) { |
string16 title = task_manager->GetResourceTitle(i); |
if (StartsWith(title, prefix, true)) |
- ++instant_previews; |
+ ++instant_overlays; |
+ if (task_manager->GetResourceWebContents(i) == overlay) |
+ overlay_index = i; |
} |
- EXPECT_EQ(1, instant_previews); |
+ EXPECT_EQ(1, instant_overlays); |
+ |
+ // We should've found the overlay (which is now a committed tab). |
+ EXPECT_LE(0, overlay_index); |
+ string16 title = task_manager->GetResourceTitle(overlay_index); |
+ EXPECT_FALSE(StartsWith(title, prefix, true)) << title << " vs " << prefix; |
} |
void HistoryQueryDone(base::RunLoop* run_loop, |
@@ -696,7 +658,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, History) { |
ui_test_utils::WaitForHistoryToLoad(history); |
// Perform a search. |
- SetOmniboxTextAndWaitForInstantToShow("search"); |
+ SetOmniboxTextAndWaitForOverlayToShow("search"); |
// Commit the search. |
browser()->window()->GetLocationBar()->AcceptInput(); |
@@ -713,7 +675,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, History) { |
// The Instant URL should not be in history. |
base::RunLoop run_loop2; |
- history->QueryURL(instant_url_, false, &consumer, |
+ history->QueryURL(instant_url(), false, &consumer, |
base::Bind(&HistoryQueryDone, &run_loop2, &found)); |
run_loop2.Run(); |
EXPECT_FALSE(found); |
@@ -729,140 +691,128 @@ IN_PROC_BROWSER_TEST_F(InstantTest, History) { |
EXPECT_EQ(ASCIIToUTF16("search"), queries[0]); |
} |
-// TODO(jered): Fix this test on Mac. It fails currently, but the behavior is |
-// actually closer to what we'd like. |
-#if defined(OS_MACOSX) |
-#define MAYBE_NewWindowDismissesInstant DISABLED_NewWindowDismissesInstant |
-#else |
-#define MAYBE_NewWindowDismissesInstant NewWindowDismissesInstant |
-#endif |
-// Test that creating a new window hides any currently showing Instant preview. |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_NewWindowDismissesInstant) { |
+// Test that creating a new window hides any currently showing Instant overlay. |
+IN_PROC_BROWSER_TEST_F(InstantTest, NewWindowDismissesInstant) { |
ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
FocusOmniboxAndWaitForInstantSupport(); |
- SetOmniboxTextAndWaitForInstantToShow("search"); |
+ SetOmniboxTextAndWaitForOverlayToShow("search"); |
Browser* previous_window = browser(); |
- EXPECT_TRUE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); |
+ EXPECT_TRUE(instant()->IsOverlayingSearchResults()); |
- InstantTestModelObserver observer(instant()->model(), |
- chrome::search::Mode::MODE_DEFAULT); |
chrome::NewEmptyWindow(browser()->profile(), |
chrome::HOST_DESKTOP_TYPE_NATIVE); |
- observer.WaitUntilDesiredPreviewState(); |
// Even though we just created a new Browser object (for the new window), the |
// browser() accessor should still give us the first window's Browser object. |
EXPECT_EQ(previous_window, browser()); |
- EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_default()); |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
} |
-// Test that the Instant overlay is recreated when all these conditions are met: |
-// - The stale overlay timer has fired. |
-// - The preview is not showing. |
-// - The omnibox doesn't have focus. |
-IN_PROC_BROWSER_TEST_F(InstantTest, InstantOverlayRefresh) { |
+// Test that the Instant overlay is recreated when the stale page timer fires. |
+IN_PROC_BROWSER_TEST_F(InstantTest, InstantLoaderRefresh) { |
ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
FocusOmniboxAndWaitForInstantSupport(); |
- // The preview is refreshed only after all three conditions above are met. |
- SetOmniboxTextAndWaitForInstantToShow("query"); |
- instant()->overlay_->is_stale_ = true; |
- instant()->ReloadOverlayIfStale(); |
- EXPECT_TRUE(instant()->overlay_->supports_instant()); |
- instant()->HideOverlay(); |
- EXPECT_TRUE(instant()->overlay_->supports_instant()); |
- instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_NONE, |
- OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL); |
- EXPECT_FALSE(instant()->overlay_->supports_instant()); |
- |
- // Try with a different ordering. |
- SetOmniboxTextAndWaitForInstantToShow("query"); |
- instant()->overlay_->is_stale_ = true; |
- instant()->ReloadOverlayIfStale(); |
- EXPECT_TRUE(instant()->overlay_->supports_instant()); |
- instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_NONE, |
- OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL); |
- // TODO(sreeram): Currently, OmniboxLostFocus() calls HideOverlay(). When it |
- // stops hiding the preview eventually, uncomment these two lines: |
- // EXPECT_TRUE(instant()->overlay_->supports_instant()); |
- // instant()->HideOverlay(); |
- EXPECT_FALSE(instant()->overlay_->supports_instant()); |
+ // The timer should be running, with a non-zero delay. |
+ base::Timer* timer = &service()->loader()->stale_page_timer_; |
+ EXPECT_TRUE(service()->loader()->supports_instant()); |
+ EXPECT_TRUE(timer->IsRunning()); |
+ EXPECT_LT(base::TimeDelta(), timer->GetCurrentDelay()); |
+ |
+ // Restart the timer at zero delay, and wait for it to fire. |
+ timer->Start(FROM_HERE, base::TimeDelta(), timer->user_task()); |
+ EXPECT_EQ(base::TimeDelta(), timer->GetCurrentDelay()); |
+ content::RunAllPendingInMessageLoop(); |
+ |
+ // The overlay was deleted and recreated, so its Instant support hasn't been |
+ // determined yet. The timer would've been reset as usual. |
+ EXPECT_FALSE(service()->loader()->supports_instant()); |
+ EXPECT_TRUE(timer->IsRunning()); |
+ EXPECT_LT(base::TimeDelta(), timer->GetCurrentDelay()); |
} |
// Test that suggestions are case insensitive. http://crbug.com/150728 |
-IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreCaseInsensitive) { |
+IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreCaseInsensitiveOne) { |
ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
- FocusOmniboxAndWaitForInstantSupport(); |
- EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'INSTANT' } ]")); |
- |
- SetOmniboxTextAndWaitForInstantToShow("in"); |
- EXPECT_EQ(ASCIIToUTF16("instant"), omnibox()->GetText()); |
+ const std::string script = |
+ "suggestion = { suggestions: [ { value: 'INSTANT' } ] }"; |
+ |
+ const struct { |
+ const char* const user_text; |
+ const string16 omnibox_text; |
+ } kTestCases[] = { |
+ {"in", ASCIIToUTF16("instant")}, |
+ {"IN", ASCIIToUTF16("INSTANT")}, |
+ }; |
+ |
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
+ FocusOmniboxAndWaitForInstantSupport(); |
+ EXPECT_TRUE(content::ExecuteScript(service()->loader()->contents(), |
+ script)); |
+ SetOmniboxTextAndWaitForOverlayToShow(kTestCases[i].user_text); |
+ EXPECT_EQ(kTestCases[i].omnibox_text, omnibox()->GetText()); |
+ omnibox()->RevertAll(); |
+ } |
+} |
- omnibox()->RevertAll(); |
- SetOmniboxTextAndWaitForInstantToShow("IN"); |
- EXPECT_EQ(ASCIIToUTF16("INSTANT"), omnibox()->GetText()); |
+// Test that suggestions are case insensitive. http://crbug.com/150728 |
+IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreCaseInsensitiveTwo) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
// U+0130 == LATIN CAPITAL LETTER I WITH DOT ABOVE |
- EXPECT_TRUE(ExecuteScript("suggestion = [ { value: '\\u0130NSTANT' } ]")); |
- |
- omnibox()->RevertAll(); |
- SetOmniboxTextAndWaitForInstantToShow("i"); |
- EXPECT_EQ(WideToUTF16(L"i\u0307nstant"), omnibox()->GetText()); |
- |
- omnibox()->RevertAll(); |
- SetOmniboxTextAndWaitForInstantToShow("I"); |
- EXPECT_EQ(WideToUTF16(L"I\u0307nstant"), omnibox()->GetText()); |
- |
- omnibox()->RevertAll(); |
- SetOmniboxTextAndWaitForInstantToShow(WideToUTF8(L"i\u0307")); |
- EXPECT_EQ(WideToUTF16(L"i\u0307nstant"), omnibox()->GetText()); |
- |
- omnibox()->RevertAll(); |
- SetOmniboxTextAndWaitForInstantToShow(WideToUTF8(L"I\u0307")); |
- EXPECT_EQ(WideToUTF16(L"I\u0307nstant"), omnibox()->GetText()); |
- |
- omnibox()->RevertAll(); |
- SetOmniboxTextAndWaitForInstantToShow(WideToUTF8(L"\u0130")); |
- EXPECT_EQ(WideToUTF16(L"\u0130NSTANT"), omnibox()->GetText()); |
- |
- omnibox()->RevertAll(); |
- SetOmniboxTextAndWaitForInstantToShow("in"); |
- EXPECT_EQ(ASCIIToUTF16("in"), omnibox()->GetText()); |
+ const std::string script = |
+ "suggestion = { suggestions: [ { value: '\\u0130NSTANT' } ] }"; |
+ |
+ const struct { |
+ const std::string user_text; |
+ const string16 omnibox_text; |
+ } kTestCases[] = { |
+ {std::string("i"), WideToUTF16(L"i\u0307nstant")}, |
+ {std::string("I"), WideToUTF16(L"I\u0307nstant")}, |
+ {WideToUTF8(L"i\u0307"), WideToUTF16(L"i\u0307nstant")}, |
+ {WideToUTF8(L"I\u0307"), WideToUTF16(L"I\u0307nstant")}, |
+ {WideToUTF8(L"\u0130"), WideToUTF16(L"\u0130NSTANT")}, |
+ {std::string("in"), ASCIIToUTF16("in")}, |
+ {std::string("IN"), ASCIIToUTF16("IN")}, |
+ }; |
+ |
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
+ FocusOmniboxAndWaitForInstantSupport(); |
+ EXPECT_TRUE(content::ExecuteScript(service()->loader()->contents(), |
+ script)); |
+ SetOmniboxTextAndWaitForOverlayToShow(kTestCases[i].user_text); |
+ EXPECT_EQ(kTestCases[i].omnibox_text, omnibox()->GetText()); |
+ omnibox()->RevertAll(); |
+ } |
+} |
- omnibox()->RevertAll(); |
- SetOmniboxTextAndWaitForInstantToShow("IN"); |
- EXPECT_EQ(ASCIIToUTF16("IN"), omnibox()->GetText()); |
+// Test that suggestions are case insensitive. http://crbug.com/150728 |
+IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreCaseInsensitiveThree) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
+ FocusOmniboxAndWaitForInstantSupport(); |
// Check that a d with a dot above and below it is completed regardless of |
// how that is encoded. |
// U+1E0D = LATIN SMALL LETTER D WITH DOT BELOW |
// U+1E0B = LATIN SMALL LETTER D WITH DOT ABOVE |
- EXPECT_TRUE(ExecuteScript("suggestion = [ { value: '\\u1e0d\\u0307oh' } ]")); |
- |
- omnibox()->RevertAll(); |
- SetOmniboxTextAndWaitForInstantToShow(WideToUTF8(L"\u1e0b\u0323")); |
+ EXPECT_TRUE(content::ExecuteScript(service()->loader()->contents(), |
+ "suggestion = { suggestions: [ { value: '\\u1e0d\\u0307oh' } ] }")); |
+ SetOmniboxTextAndWaitForOverlayToShow(WideToUTF8(L"\u1e0b\u0323")); |
EXPECT_EQ(WideToUTF16(L"\u1e0b\u0323oh"), omnibox()->GetText()); |
} |
-// Flakes on Windows and Mac: http://crbug.com/170677 |
-#if defined(OS_WIN) || defined(OS_MACOSX) |
-#define MAYBE_CommitInNewTab DISABLED_CommitInNewTab |
-#else |
-#define MAYBE_CommitInNewTab CommitInNewTab |
-#endif |
-// Test that the preview can be committed onto a new tab. |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_CommitInNewTab) { |
+// Test that the overlay can be committed onto a new tab. |
+IN_PROC_BROWSER_TEST_F(InstantTest, CommitInNewTab) { |
ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
FocusOmniboxAndWaitForInstantSupport(); |
// Use the Instant page as the active tab, so we can exploit its visibility |
// handler to check visibility transitions. |
- ui_test_utils::NavigateToURL(browser(), instant_url_); |
+ EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
+ ui_test_utils::NavigateToURL(browser(), instant_url()); |
content::WebContents* active_tab = |
browser()->tab_strip_model()->GetActiveWebContents(); |
@@ -871,23 +821,23 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_CommitInNewTab) { |
&active_tab_onvisibilitycalls)); |
EXPECT_EQ(0, active_tab_onvisibilitycalls); |
- SetOmniboxTextAndWaitForInstantToShow("search"); |
+ SetOmniboxTextAndWaitForOverlayToShow("search"); |
- // Stash a reference to the preview, so we can refer to it after commit. |
- content::WebContents* preview_tab = instant()->GetPreviewContents(); |
- EXPECT_TRUE(preview_tab); |
+ // Stash a reference to the overlay, so we can refer to it after commit. |
+ content::WebContents* overlay = instant()->GetOverlayContents(); |
+ EXPECT_TRUE(overlay); |
// The state of the searchbox before the commit. |
- EXPECT_TRUE(UpdateSearchState(preview_tab)); |
+ EXPECT_TRUE(UpdateSearchState(overlay)); |
EXPECT_EQ("search", value_); |
EXPECT_FALSE(verbatim_); |
EXPECT_EQ(0, onsubmitcalls_); |
EXPECT_EQ(1, onvisibilitycalls_); |
// The state of the active tab before the commit. |
- EXPECT_NE(preview_tab, active_tab); |
+ EXPECT_NE(overlay, active_tab); |
EXPECT_EQ(2, active_tab->GetController().GetEntryCount()); |
- EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); |
+ EXPECT_EQ(instant_url(), omnibox()->model()->PermanentURL()); |
active_tab_onvisibilitycalls = -1; |
EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls", |
&active_tab_onvisibilitycalls)); |
@@ -897,113 +847,90 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_CommitInNewTab) { |
omnibox()->model()->AcceptInput(NEW_FOREGROUND_TAB, false); |
// After the commit, Instant should not be showing. |
- EXPECT_FALSE(instant()->IsPreviewingSearchResults()); |
- EXPECT_TRUE(instant()->model()->mode().is_default()); |
- |
- // The old overlay is deleted and a new one is created. |
- EXPECT_TRUE(instant()->GetPreviewContents()); |
- EXPECT_NE(instant()->GetPreviewContents(), preview_tab); |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
// Check that we have two tabs and that the new active tab is indeed what was |
- // once the preview. The preview tab should have just one navigation entry, |
+ // once the overlay. The overlay tab should have just one navigation entry, |
// for the Instant search that was committed. |
EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
- EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveWebContents()); |
- EXPECT_EQ(1, preview_tab->GetController().GetEntryCount()); |
+ EXPECT_EQ(overlay, browser()->tab_strip_model()->GetActiveWebContents()); |
+ EXPECT_EQ(1, overlay->GetController().GetEntryCount()); |
// Check that the omnibox contains the Instant URL we loaded. |
- EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); |
+ EXPECT_EQ(instant_url(), omnibox()->model()->PermanentURL()); |
- // Check that the searchbox API values have been reset. |
- std::string value; |
- EXPECT_TRUE(GetStringFromJS(preview_tab, |
- "chrome.embeddedSearch.searchBox.value", &value)); |
- EXPECT_EQ("", value); |
- |
- // However, the page should've correctly received the committed query. |
- EXPECT_TRUE(UpdateSearchState(preview_tab)); |
+ // The page should've correctly received the committed query. |
+ EXPECT_TRUE(UpdateSearchState(overlay)); |
EXPECT_EQ("search", value_); |
EXPECT_TRUE(verbatim_); |
EXPECT_EQ(1, onsubmitcalls_); |
EXPECT_EQ(1, onvisibilitycalls_); |
// The ex-active tab should've gotten a visibility change marking it hidden. |
- EXPECT_NE(active_tab, preview_tab); |
+ EXPECT_NE(overlay, active_tab); |
EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls", |
&active_tab_onvisibilitycalls)); |
EXPECT_EQ(1, active_tab_onvisibilitycalls); |
} |
-// Test that suggestions are reusable. |
-IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreReusable) { |
+// Test that the Instant overlay is recreated if it gets destroyed. |
+IN_PROC_BROWSER_TEST_F(InstantTest, InstantRenderViewGone) { |
ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
- FocusOmniboxAndWaitForInstantSupport(); |
- |
- EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'instant' } ];" |
- "behavior = 'never';")); |
- SetOmniboxTextAndWaitForInstantToShow("in"); |
- EXPECT_EQ(ASCIIToUTF16("stant"), omnibox()->GetInstantSuggestion()); |
+ // Get the overlay to show. |
+ FocusOmniboxAndWaitForInstantSupport(); |
+ SetOmniboxTextAndWaitForOverlayToShow("search"); |
+ EXPECT_TRUE(instant()->IsOverlayingSearchResults()); |
- SetOmniboxText("ins"); |
- EXPECT_EQ(ASCIIToUTF16("tant"), omnibox()->GetInstantSuggestion()); |
+ InstantModel desired_model(service()); |
+ desired_model.SetOverlayState(NULL, 0, false); |
+ InstantTestModelObserver observer(instant(), &desired_model); |
- SetOmniboxText("in"); |
- EXPECT_EQ(ASCIIToUTF16("stant"), omnibox()->GetInstantSuggestion()); |
+ // Kill the overlay's renderer. |
+ KillOverlayRenderView(); |
- SetOmniboxText("insane"); |
- EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); |
-} |
- |
-// Test that instant overlay is recreated if it gets destroyed. |
-IN_PROC_BROWSER_TEST_F(InstantTest, InstantRenderViewGone) { |
- ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
- FocusOmniboxAndWaitForInstantSupport(); |
- |
- // Type partial query, get suggestion to show. |
- SetOmniboxTextAndWaitForInstantToShow("q"); |
- EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); |
+ // Wait for the overlay to disappear. |
+ observer.WaitForDesiredOverlayState(); |
+ EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
+ EXPECT_FALSE(instant()->GetOverlayContents()); |
- // Kill the instant renderer and wait for instant support again. |
- KillInstantRenderView(); |
+ // Tickle the loader into recreating an overlay. |
FocusOmniboxAndWaitForInstantSupport(); |
- SetOmniboxTextAndWaitForInstantToShow("qu"); |
+ // Continue typing. The overlay should show again, and set suggestions. |
+ SetOmniboxTextAndWaitForOverlayToShow("query"); |
+ EXPECT_TRUE(instant()->IsOverlayingSearchResults()); |
EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); |
} |
IN_PROC_BROWSER_TEST_F(InstantTest, ProcessIsolation) { |
// Prior to setup no render process is dedicated to Instant. |
- InstantService* instant_service = |
- InstantServiceFactory::GetForProfile(browser()->profile()); |
- ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); |
- EXPECT_EQ(0, instant_service->GetInstantProcessCount()); |
+ EXPECT_EQ(0, service()->GetInstantProcessCount()); |
// Setup Instant. |
ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
FocusOmniboxAndWaitForInstantSupport(); |
// Now there should be a registered Instant render process. |
- EXPECT_LT(0, instant_service->GetInstantProcessCount()); |
+ EXPECT_EQ(1, service()->GetInstantProcessCount()); |
- // And the Instant preview should live inside it. |
- content::WebContents* preview = instant()->GetPreviewContents(); |
- EXPECT_TRUE(instant_service->IsInstantProcess( |
- preview->GetRenderProcessHost()->GetID())); |
+ // And the Instant overlay should live inside it. |
+ content::WebContents* overlay = service()->loader()->contents(); |
+ EXPECT_TRUE( |
+ service()->IsInstantProcess(overlay->GetRenderProcessHost()->GetID())); |
// Search and commit the search by pressing Alt-Enter. |
- SetOmniboxTextAndWaitForInstantToShow("tractor"); |
+ SetOmniboxTextAndWaitForOverlayToShow("tractor"); |
omnibox()->model()->AcceptInput(NEW_FOREGROUND_TAB, false); |
- // The committed search results page should also live inside the |
- // Instant process. |
+ // The committed results page should also live inside the Instant process. |
content::WebContents* active_tab = |
browser()->tab_strip_model()->GetActiveWebContents(); |
- EXPECT_TRUE(instant_service->IsInstantProcess( |
- active_tab->GetRenderProcessHost()->GetID())); |
+ EXPECT_TRUE( |
+ service()->IsInstantProcess(active_tab->GetRenderProcessHost()->GetID())); |
// Navigating away should change the process. |
ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); |
- EXPECT_FALSE(instant_service->IsInstantProcess( |
- active_tab->GetRenderProcessHost()->GetID())); |
+ EXPECT_FALSE( |
+ service()->IsInstantProcess(active_tab->GetRenderProcessHost()->GetID())); |
} |