Index: chrome/browser/instant/instant_browsertest.cc |
diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc |
index 58b6207143810a0c58b0852309e4e0abcff1be82..1c210afd3a9e469918418c15c1176d6cdcfb6b5b 100644 |
--- a/chrome/browser/instant/instant_browsertest.cc |
+++ b/chrome/browser/instant/instant_browsertest.cc |
@@ -3,20 +3,18 @@ |
// found in the LICENSE file. |
#include "base/command_line.h" |
-#include "base/string_util.h" |
#include "base/stringprintf.h" |
-#include "base/utf_string_conversions.h" |
#include "chrome/browser/content_settings/host_content_settings_map.h" |
+#include "chrome/browser/history/history.h" |
+#include "chrome/browser/history/history_service_factory.h" |
#include "chrome/browser/instant/instant_controller.h" |
#include "chrome/browser/instant/instant_loader.h" |
#include "chrome/browser/prefs/pref_service.h" |
-#include "chrome/browser/profiles/profile.h" |
-#include "chrome/browser/search_engines/template_url.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/browser_instant_controller.h" |
#include "chrome/browser/ui/browser_tabstrip.h" |
#include "chrome/browser/ui/browser_window.h" |
@@ -27,819 +25,803 @@ |
#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 "chrome/test/base/in_process_browser_test.h" |
#include "chrome/test/base/ui_test_utils.h" |
-#include "content/public/browser/navigation_controller.h" |
#include "content/public/browser/notification_service.h" |
-#include "content/public/browser/render_view_host.h" |
-#include "content/public/browser/render_widget_host_view.h" |
#include "content/public/browser/web_contents.h" |
-#include "content/public/common/content_switches.h" |
#include "content/public/test/browser_test_utils.h" |
#include "grit/generated_resources.h" |
#include "ui/base/l10n/l10n_util.h" |
-using content::WebContents; |
- |
-// Tests are flaky on Linux because of http://crbug.com/80118. |
-#if defined(OS_LINUX) && !defined(USE_ASH) |
-#define MAYBE(TestName) DISABLED_ ## TestName |
-#elif defined(OS_WIN) |
-#define MAYBE(TestName) FLAKY_ ## TestName |
-#else |
-#define MAYBE(TestName) TestName |
-#endif |
- |
class InstantTest : public InProcessBrowserTest { |
- public: |
- InstantTest() {} |
- |
- void EnableInstant() { |
- InstantController::Enable(browser()->profile()); |
+ protected: |
+ virtual void SetUpCommandLine(CommandLine* command_line) { |
+ // Do not prelaunch the GPU process because it will show up in the task |
+ // manager, but whether it appears before or after the Instant tab is not |
+ // well defined. This affects the TaskManagerPrefix test below. |
+ command_line->AppendSwitch(switches::kDisableGpuProcessPrelaunch); |
} |
- void SetupInstantProvider(const std::string& page) { |
- Profile* profile = browser()->profile(); |
- TemplateURLService* model = |
- TemplateURLServiceFactory::GetForProfile(profile); |
+ void SetupInstant(const std::string& page) { |
+ ASSERT_TRUE(test_server()->Start()); |
- content::WindowedNotificationObserver observer( |
- chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, |
- content::NotificationService::AllSources()); |
- if (!model->loaded()) { |
- model->Load(); |
- observer.Wait(); |
- } |
+ TemplateURLService* service = |
+ TemplateURLServiceFactory::GetForProfile(browser()->profile()); |
+ ui_test_utils::WaitForTemplateURLServiceToLoad(service); |
TemplateURLData data; |
- data.short_name = ASCIIToUTF16("foo"); |
- data.SetKeyword(ASCIIToUTF16("foo")); |
data.SetURL(base::StringPrintf("http://%s:%d/files/%s?q={searchTerms}", |
test_server()->host_port_pair().host().c_str(), |
test_server()->host_port_pair().port(), page.c_str())); |
data.instant_url = data.url(); |
- // TemplateURLService takes ownership of this. |
- TemplateURL* template_url = new TemplateURL(profile, data); |
- model->Add(template_url); |
- model->SetDefaultSearchProvider(template_url); |
- } |
- // Type a character to get instant to trigger and determine instant support. |
- void DetermineInstantSupport() { |
- content::WindowedNotificationObserver observer( |
- chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
- content::NotificationService::AllSources()); |
- // "a" triggers the "about:" provider. "b" begins the "bing.com" keyword. |
- // "c" might someday trigger a "chrome:" provider. |
- omnibox()->SetUserText(ASCIIToUTF16("d")); |
- observer.Wait(); |
- } |
- |
- // Types "def" into the omnibox and waits for the preview to be shown. |
- void SearchAndWaitForPreviewToShow() { |
- content::WindowedNotificationObserver observer( |
- chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN, |
- content::NotificationService::AllSources()); |
- omnibox()->SetUserText(ASCIIToUTF16("def")); |
- observer.Wait(); |
- } |
- |
- // Sends a message to the renderer and waits for the response to come back to |
- // the browser. Returns true on success. |
- bool WaitForMessageToBeProcessedByRenderer() { |
- bool result = false; |
- return GetBoolFromJavascript(preview()->web_contents(), "true", &result) && |
- result; |
- } |
+ TemplateURL* template_url = new TemplateURL(browser()->profile(), data); |
+ service->Add(template_url); // Takes ownership of |template_url|. |
+ service->SetDefaultSearchProvider(template_url); |
- InstantController* instant() const { |
- return browser()->instant_controller()->instant(); |
+ browser()->profile()->GetPrefs()->SetBoolean(prefs::kInstantEnabled, true); |
} |
OmniboxView* omnibox() const { |
return browser()->window()->GetLocationBar()->GetLocationEntry(); |
} |
- TabContents* preview() const { |
- return instant()->GetPreviewContents(); |
- } |
- |
- InstantLoader* loader() const { |
- return instant()->loader_.get(); |
+ InstantController* instant() const { |
+ return browser()->instant_controller()->instant(); |
} |
- std::string GetSuggestion() const { |
- return UTF16ToUTF8(loader()->complete_suggested_text_); |
+ void WaitFor(chrome::NotificationType notification_type) const { |
+ content::WindowedNotificationObserver observer( |
+ notification_type, content::NotificationService::AllSources()); |
+ observer.Wait(); |
} |
- bool PressEnter() { |
- return ui_test_utils::SendKeyPressSync( |
- browser(), ui::VKEY_RETURN, false, false, false, false); |
+ std::wstring WrapScript(const std::string& script) const { |
+ return UTF8ToWide("domAutomationController.send(" + script + ")"); |
} |
- bool SetSuggestionsJavascriptArgument(const std::string& argument) { |
- std::wstring script = UTF8ToWide(base::StringPrintf( |
- "window.setSuggestionsArgument = %s;", argument.c_str())); |
- content::RenderViewHost* rvh = |
- preview()->web_contents()->GetRenderViewHost(); |
- return content::ExecuteJavaScript(rvh, std::wstring(), script); |
+ bool GetBoolFromJS(content::RenderViewHost* rvh, |
+ const std::string& script, |
+ bool* result) const WARN_UNUSED_RESULT { |
+ return content::ExecuteJavaScriptAndExtractBool( |
+ rvh, std::wstring(), WrapScript(script), result); |
} |
- std::wstring WrapScript(const std::string& script) { |
- return UTF8ToWide(base::StringPrintf( |
- "window.domAutomationController.send(%s)", script.c_str())); |
+ bool GetIntFromJS(content::RenderViewHost* rvh, |
+ const std::string& script, |
+ int* result) const WARN_UNUSED_RESULT { |
+ return content::ExecuteJavaScriptAndExtractInt( |
+ rvh, std::wstring(), WrapScript(script), result); |
} |
- bool GetStringFromJavascript(WebContents* tab, |
- const std::string& script, |
- std::string* result) { |
+ bool GetStringFromJS(content::RenderViewHost* rvh, |
+ const std::string& script, |
+ std::string* result) const WARN_UNUSED_RESULT { |
return content::ExecuteJavaScriptAndExtractString( |
- tab->GetRenderViewHost(), std::wstring(), WrapScript(script), result); |
+ rvh, std::wstring(), WrapScript(script), result); |
} |
- bool GetIntFromJavascript(WebContents* tab, |
- const std::string& script, |
- int* result) { |
- return content::ExecuteJavaScriptAndExtractInt( |
- tab->GetRenderViewHost(), std::wstring(), WrapScript(script), result); |
+ bool UpdateSearchState(TabContents* tab) WARN_UNUSED_RESULT { |
+ content::RenderViewHost* rvh = tab->web_contents()->GetRenderViewHost(); |
+ return GetIntFromJS(rvh, "onchangecalls", &onchangecalls_) && |
+ GetIntFromJS(rvh, "onsubmitcalls", &onsubmitcalls_) && |
+ GetIntFromJS(rvh, "oncancelcalls", &oncancelcalls_) && |
+ GetIntFromJS(rvh, "onresizecalls", &onresizecalls_) && |
+ GetStringFromJS(rvh, "value", &value_) && |
+ GetBoolFromJS(rvh, "verbatim", &verbatim_) && |
+ GetIntFromJS(rvh, "height", &height_); |
} |
- bool GetBoolFromJavascript(WebContents* tab, |
- const std::string& script, |
- bool* result) { |
- return content::ExecuteJavaScriptAndExtractBool( |
- tab->GetRenderViewHost(), std::wstring(), WrapScript(script), result); |
+ bool ExecuteScript(const std::string& script) const WARN_UNUSED_RESULT { |
+ return content::ExecuteJavaScript( |
+ instant()->GetPreviewContents()->web_contents()->GetRenderViewHost(), |
+ std::wstring(), ASCIIToWide(script)); |
} |
- bool CheckVisibilityIs(WebContents* tab, bool visible) { |
- bool hidden = visible; |
- return GetBoolFromJavascript(tab, "document.webkitHidden", &hidden) && |
- hidden != visible; |
+ void SetOmniboxText(const std::string& text) const { |
+ omnibox()->SetUserText(ASCIIToUTF16(text)); |
} |
- // Returns the state of the search box as a string. This consists of the |
- // following: |
- // window.chrome.sv |
- // window.onsubmitcalls |
- // window.oncancelcalls |
- // window.onchangecalls |
- // 'true' if any window.onresize call has been sent, otherwise false. |
- // window.beforeLoadSearchBox.value |
- // window.beforeLoadSearchBox.verbatim |
- // window.chrome.searchBox.value |
- // window.chrome.searchBox.verbatim |
- // window.chrome.searchBox.selectionStart |
- // window.chrome.searchBox.selectionEnd |
- // If determining any of the values fails, the value is 'fail'. |
- // |
- // If |use_last| is true, then the last searchBox values are used instead of |
- // the current. Set |use_last| to true when testing OnSubmit/OnCancel. |
- std::string GetSearchStateAsString(WebContents* tab, bool use_last) { |
- bool sv = false; |
- int onsubmitcalls = 0; |
- int oncancelcalls = 0; |
- int onchangecalls = 0; |
- int onresizecalls = 0; |
- int selection_start = 0; |
- int selection_end = 0; |
- std::string before_load_value; |
- bool before_load_verbatim = false; |
- std::string value; |
- bool verbatim = false; |
- |
- if (!GetBoolFromJavascript(tab, "window.chrome.sv", &sv) || |
- !GetIntFromJavascript(tab, "window.onsubmitcalls", &onsubmitcalls) || |
- !GetIntFromJavascript(tab, "window.oncancelcalls", &oncancelcalls) || |
- !GetIntFromJavascript(tab, "window.onchangecalls", &onchangecalls) || |
- !GetIntFromJavascript(tab, "window.onresizecalls", &onresizecalls) || |
- !GetStringFromJavascript(tab, "window.beforeLoadSearchBox.value", |
- &before_load_value) || |
- !GetBoolFromJavascript(tab, "window.beforeLoadSearchBox.verbatim", |
- &before_load_verbatim)) { |
- return "fail"; |
- } |
- |
- if (use_last && |
- (!GetStringFromJavascript(tab, "window.lastSearchBox.value", &value) || |
- !GetBoolFromJavascript(tab, "window.lastSearchBox.verbatim", |
- &verbatim) || |
- !GetIntFromJavascript(tab, "window.lastSearchBox.selectionStart", |
- &selection_start) || |
- !GetIntFromJavascript(tab, "window.lastSearchBox.selectionEnd", |
- &selection_end))) { |
- return "fail"; |
- } |
- |
- if (!use_last && |
- (!GetStringFromJavascript(tab, "window.chrome.searchBox.value", |
- &value) || |
- !GetBoolFromJavascript(tab, "window.chrome.searchBox.verbatim", |
- &verbatim) || |
- !GetIntFromJavascript(tab, "window.chrome.searchBox.selectionStart", |
- &selection_start) || |
- !GetIntFromJavascript(tab, "window.chrome.searchBox.selectionEnd", |
- &selection_end))) { |
- return "fail"; |
- } |
- |
- return base::StringPrintf("%s %d %d %d %s %s %s %s %s %d %d", |
- sv ? "true" : "false", |
- onsubmitcalls, |
- oncancelcalls, |
- onchangecalls, |
- onresizecalls ? "true" : "false", |
- before_load_value.c_str(), |
- before_load_verbatim ? "true" : "false", |
- value.c_str(), |
- verbatim ? "true" : "false", |
- selection_start, |
- selection_end); |
+ bool CheckVisibilityIs(TabContents* tab, |
+ bool expected) const WARN_UNUSED_RESULT { |
+ bool actual = !expected; // Purposely start with a mis-match. |
+ // We can only use ASSERT_*() in a method that returns void, hence this |
+ // convoluted check. |
+ return GetBoolFromJS(tab->web_contents()->GetRenderViewHost(), |
+ "!document.webkitHidden", &actual) && |
+ actual == expected; |
} |
- protected: |
- virtual void SetUpCommandLine(CommandLine* command_line) { |
- // Do not prelaunch the GPU process for these tests because it will show |
- // up in task manager but whether it appears before or after the new tab |
- // renderer process is not well defined. |
- command_line->AppendSwitch(switches::kDisableGpuProcessPrelaunch); |
- } |
-}; |
+ int onchangecalls_; |
+ int onsubmitcalls_; |
+ int oncancelcalls_; |
+ int onresizecalls_; |
-// TODO(tonyg): Add the following tests: |
-// - Test that the search box API is not populated for pages other than the |
-// default search provider. |
-// - Test resize events. |
- |
-// Verify that the onchange event is dispatched upon typing in the box. |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(OnChangeEvent)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
- DetermineInstantSupport(); |
- SearchAndWaitForPreviewToShow(); |
- |
- EXPECT_TRUE(preview()); |
- EXPECT_TRUE(instant()->is_displayable()); |
- EXPECT_TRUE(instant()->IsCurrent()); |
- EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText())); |
- |
- // Make sure the URL that will get committed when we press <Enter> matches |
- // that of the default search provider. |
- const TemplateURL* default_turl = |
- TemplateURLServiceFactory::GetForProfile(browser()->profile())-> |
- GetDefaultSearchProvider(); |
- EXPECT_TRUE(default_turl); |
- EXPECT_EQ(default_turl->url_ref().ReplaceSearchTerms( |
- TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("defghi"))), |
- loader()->url().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()->web_contents(), false)); |
-} |
+ std::string value_; |
+ bool verbatim_; |
+ int height_; |
+}; |
-// Verify that the onsubmit event is dispatched upon pressing <Enter>. |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(OnSubmitEvent)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
- DetermineInstantSupport(); |
- SearchAndWaitForPreviewToShow(); |
+// Test that Instant is preloaded when the omnibox is focused. |
+IN_PROC_BROWSER_TEST_F(InstantTest, OmniboxFocusLoadsInstant) { |
+ // The omnibox gets focus before the test begins. At this time, there's no |
+ // InstantController (which is only created in SetupInstant() below), so no |
+ // preloading has happened yet. |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
+ EXPECT_FALSE(instant()->GetPreviewContents()); |
+ |
+ // Explicitly unfocus and refocus the omnibox. Since an InstantController now |
+ // exists, it will preload Instant. |
+ EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
+ ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
+ EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
- EXPECT_TRUE(preview()); |
- EXPECT_TRUE(instant()->is_displayable()); |
- EXPECT_TRUE(instant()->IsCurrent()); |
- EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText())); |
+ browser()->window()->GetLocationBar()->FocusLocation(false); |
+ EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
- WebContents* preview_tab = preview()->web_contents(); |
+ TabContents* preview_tab = instant()->GetPreviewContents(); |
EXPECT_TRUE(preview_tab); |
- ASSERT_TRUE(PressEnter()); |
- |
- // Check that the preview has been committed. |
- EXPECT_FALSE(preview()); |
- EXPECT_FALSE(instant()->is_displayable()); |
+ // Check that the page supports Instant, but it isn't showing. |
+ WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED); |
+ EXPECT_TRUE(instant()->loader()->supports_instant()); |
EXPECT_FALSE(instant()->IsCurrent()); |
- EXPECT_EQ(preview_tab, chrome::GetActiveWebContents(browser())); |
+ EXPECT_FALSE(instant()->is_showing()); |
+ |
+ // Adding a new tab shouldn't delete or recreate the TabContents; otherwise, |
+ // what's the point of preloading? |
+ AddBlankTabAndShow(browser()); |
+ EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); |
+ |
+ // Unfocusing and refocusing the omnibox should also preserve the preview. |
+ ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
+ EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
- // We should have two entries. One corresponding to the page the user was |
- // first on, and one for the search page. |
- EXPECT_EQ(2, preview_tab->GetController().GetEntryCount()); |
+ browser()->window()->GetLocationBar()->FocusLocation(false); |
+ EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
- // Check that the value is reflected and onsubmit is called. |
- EXPECT_EQ("true 1 0 1 true d false defghi true 3 3", |
- GetSearchStateAsString(preview_tab, true)); |
+ EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); |
- // Make sure the searchbox values were reset. |
- EXPECT_EQ("true 1 0 1 true d false false 0 0", |
- GetSearchStateAsString(preview_tab, false)); |
+ // Doing a search should also use the same preloaded page. |
+ SetOmniboxText("query"); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); |
+ EXPECT_TRUE(instant()->is_showing()); |
+ EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); |
} |
-// Verify that the oncancel event is dispatched upon losing focus. |
-IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_OnCancelEvent) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
- DetermineInstantSupport(); |
- SearchAndWaitForPreviewToShow(); |
+// Test that the onchange event is dispatched upon typing in the omnibox. |
+IN_PROC_BROWSER_TEST_F(InstantTest, OnChangeEvent) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
+ |
+ // Typing "query" into the omnibox causes the first onchange event. |
+ SetOmniboxText("query"); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); |
+ |
+ // The page suggested "query suggestion" is inline autocompleted into the |
+ // omnibox, causing the second onchange event. |
+ EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); |
+ EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
+ EXPECT_EQ(2, onchangecalls_); |
+ |
+ // Change the query and confirm that another onchange is sent. Since the new |
+ // query is not a prefix of the hardcoded "query suggestion", no inline |
+ // autocompletion happens, and thus, no fourth onchange event. |
+ SetOmniboxText("search"); |
+ EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
+ EXPECT_EQ(3, onchangecalls_); |
+} |
- EXPECT_TRUE(preview()); |
- EXPECT_TRUE(instant()->is_displayable()); |
- EXPECT_TRUE(instant()->IsCurrent()); |
- EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText())); |
+// Test that the onsubmit event is dispatched upon pressing Enter. |
+IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
+ SetOmniboxText("search"); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); |
- WebContents* preview_tab = preview()->web_contents(); |
+ // Stash a reference to the preview, so we can refer to it after commit. |
+ TabContents* preview_tab = instant()->GetPreviewContents(); |
EXPECT_TRUE(preview_tab); |
- ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
- ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
+ // The state of the searchbox before the commit. |
+ EXPECT_TRUE(UpdateSearchState(preview_tab)); |
+ EXPECT_EQ("search", value_); |
+ EXPECT_FALSE(verbatim_); |
+ EXPECT_EQ(0, onsubmitcalls_); |
- // Check that the preview has been committed. |
- EXPECT_FALSE(preview()); |
- EXPECT_FALSE(instant()->is_displayable()); |
- EXPECT_FALSE(instant()->IsCurrent()); |
- EXPECT_EQ(preview_tab, chrome::GetActiveWebContents(browser())); |
+ // Before the commit, the active tab is the NTP (i.e., not Instant). |
+ TabContents* active_tab = chrome::GetActiveTabContents(browser()); |
+ EXPECT_NE(preview_tab, active_tab); |
+ EXPECT_EQ(1, active_tab->web_contents()->GetController().GetEntryCount()); |
+ EXPECT_EQ(std::string(chrome::kAboutBlankURL), |
+ omnibox()->model()->PermanentURL().spec()); |
- // Check that the value is reflected and oncancel is called. |
- EXPECT_EQ("true 0 1 1 true d false def false 3 3", |
- GetSearchStateAsString(preview_tab, true)); |
+ // Commit the search by pressing Enter. |
+ browser()->window()->GetLocationBar()->AcceptInput(); |
- // Make sure the searchbox values were reset. |
- EXPECT_EQ("true 0 1 1 true d false false 0 0", |
- GetSearchStateAsString(preview_tab, false)); |
-} |
+ // After the commit, Instant should not be showing, or even have a preview. |
+ EXPECT_FALSE(instant()->GetPreviewContents()); |
+ EXPECT_FALSE(instant()->IsCurrent()); |
+ EXPECT_FALSE(instant()->is_showing()); |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsArrayOfStrings)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
- DetermineInstantSupport(); |
+ // Check that the current active tab is indeed what was once the preview. |
+ EXPECT_EQ(preview_tab, chrome::GetActiveTabContents(browser())); |
- ASSERT_TRUE(SetSuggestionsJavascriptArgument("['defg', 'unused']")); |
- SearchAndWaitForPreviewToShow(); |
- EXPECT_EQ("defg", GetSuggestion()); |
-} |
+ // We should have two navigation entries, one for the NTP, and one for the |
+ // Instant search that was committed. |
+ EXPECT_EQ(2, preview_tab->web_contents()->GetController().GetEntryCount()); |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsEmptyArray)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
- DetermineInstantSupport(); |
+ // Check that the omnibox contains the Instant URL we loaded. |
+ std::string instant_url = TemplateURLServiceFactory::GetForProfile( |
+ browser()->profile())->GetDefaultSearchProvider()->instant_url_ref(). |
+ ReplaceSearchTerms(TemplateURLRef::SearchTermsArgs(string16())); |
+ EXPECT_EQ(instant_url, omnibox()->model()->PermanentURL().spec()); |
- ASSERT_TRUE(SetSuggestionsJavascriptArgument("[]")); |
- SearchAndWaitForPreviewToShow(); |
- EXPECT_EQ("", GetSuggestion()); |
+ // Check that the searchbox API values have been reset. |
+ std::string value; |
+ EXPECT_TRUE(GetStringFromJS(preview_tab->web_contents()->GetRenderViewHost(), |
+ "chrome.searchBox.value", &value)); |
+ EXPECT_EQ("", value); |
+ |
+ // However, the page should've correctly received the committed query. |
+ EXPECT_TRUE(UpdateSearchState(preview_tab)); |
+ EXPECT_EQ("search", value_); |
+ EXPECT_TRUE(verbatim_); |
+ EXPECT_EQ(1, onsubmitcalls_); |
} |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsValidJson)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
- DetermineInstantSupport(); |
+// Test that the oncancel event is dispatched upon clicking on the preview. |
+IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
+ SetOmniboxText("search"); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); |
- ASSERT_TRUE(SetSuggestionsJavascriptArgument( |
- "{suggestions:[{value:'defg'},{value:'unused'}]}")); |
- SearchAndWaitForPreviewToShow(); |
- EXPECT_EQ("defg", GetSuggestion()); |
-} |
+ // Stash a reference to the preview, so we can refer to it after commit. |
+ TabContents* preview_tab = instant()->GetPreviewContents(); |
+ EXPECT_TRUE(preview_tab); |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsInvalidSuggestions)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
- DetermineInstantSupport(); |
+ // The state of the searchbox before the commit. |
+ EXPECT_TRUE(UpdateSearchState(preview_tab)); |
+ EXPECT_EQ("search", value_); |
+ EXPECT_FALSE(verbatim_); |
+ EXPECT_EQ(0, oncancelcalls_); |
+ |
+ // Before the commit, the active tab is the NTP (i.e., not Instant). |
+ TabContents* active_tab = chrome::GetActiveTabContents(browser()); |
+ EXPECT_NE(preview_tab, active_tab); |
+ EXPECT_EQ(1, active_tab->web_contents()->GetController().GetEntryCount()); |
+ EXPECT_EQ(std::string(chrome::kAboutBlankURL), |
+ omnibox()->model()->PermanentURL().spec()); |
+ |
+ // Commit the search by clicking on the preview. |
+ EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
+ ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
- ASSERT_TRUE(SetSuggestionsJavascriptArgument("{suggestions:{value:'defg'}}")); |
- SearchAndWaitForPreviewToShow(); |
- EXPECT_EQ("", GetSuggestion()); |
-} |
+ // After the commit, Instant should not be showing, or even have a preview. |
+ EXPECT_FALSE(instant()->GetPreviewContents()); |
+ EXPECT_FALSE(instant()->IsCurrent()); |
+ EXPECT_FALSE(instant()->is_showing()); |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsEmptyJson)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
- DetermineInstantSupport(); |
+ // Check that the current active tab is indeed what was once the preview. |
+ EXPECT_EQ(preview_tab, chrome::GetActiveTabContents(browser())); |
- ASSERT_TRUE(SetSuggestionsJavascriptArgument("{}")); |
- SearchAndWaitForPreviewToShow(); |
- EXPECT_EQ("", GetSuggestion()); |
-} |
+ // We should have two navigation entries, one for the NTP, and one for the |
+ // Instant search that was committed. |
+ EXPECT_EQ(2, preview_tab->web_contents()->GetController().GetEntryCount()); |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsEmptySuggestions)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
- DetermineInstantSupport(); |
+ // Check that the omnibox contains the Instant URL we loaded. |
+ std::string instant_url = TemplateURLServiceFactory::GetForProfile( |
+ browser()->profile())->GetDefaultSearchProvider()->instant_url_ref(). |
+ ReplaceSearchTerms(TemplateURLRef::SearchTermsArgs(string16())); |
+ EXPECT_EQ(instant_url, omnibox()->model()->PermanentURL().spec()); |
- ASSERT_TRUE(SetSuggestionsJavascriptArgument("{suggestions:[]}")); |
- SearchAndWaitForPreviewToShow(); |
- EXPECT_EQ("", GetSuggestion()); |
+ // Check that the searchbox API values have been reset. |
+ std::string value; |
+ EXPECT_TRUE(GetStringFromJS(preview_tab->web_contents()->GetRenderViewHost(), |
+ "chrome.searchBox.value", &value)); |
+ EXPECT_EQ("", value); |
+ |
+ // However, the page should've correctly received the committed query. |
+ EXPECT_TRUE(UpdateSearchState(preview_tab)); |
+ EXPECT_EQ("search", value_); |
+ EXPECT_TRUE(verbatim_); |
+ EXPECT_EQ(1, oncancelcalls_); |
} |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsEmptySuggestion)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
- DetermineInstantSupport(); |
+// Test that the onreisze event is dispatched upon typing in the omnibox. |
+IN_PROC_BROWSER_TEST_F(InstantTest, OnResizeEvent) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
- ASSERT_TRUE(SetSuggestionsJavascriptArgument("{suggestions:[{}]}")); |
- SearchAndWaitForPreviewToShow(); |
- EXPECT_EQ("", GetSuggestion()); |
-} |
+ // This makes Instant load the preview, along with an initial onresize() (see |
+ // SearchBoxExtension::PageSupportsInstant() for why). |
+ instant()->OnAutocompleteGotFocus(); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED); |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(InstantCompleteNever)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
- DetermineInstantSupport(); |
+ EXPECT_TRUE(instant()->GetPreviewContents()); |
+ EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
+ EXPECT_EQ(1, onresizecalls_); |
+ EXPECT_EQ(0, height_); |
- ASSERT_TRUE(SetSuggestionsJavascriptArgument( |
- "{suggestions:[{value:'defg'}],complete_behavior:'never'}")); |
- SearchAndWaitForPreviewToShow(); |
- EXPECT_EQ("defg", GetSuggestion()); |
+ // Type a query into the omnibox. This should cause an onresize() event, with |
+ // a valid (non-zero) height. |
+ SetOmniboxText("search"); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); |
- EXPECT_EQ(INSTANT_COMPLETE_NEVER, |
- omnibox()->model()->instant_complete_behavior()); |
- EXPECT_EQ("def", UTF16ToUTF8(omnibox()->GetText())); |
+ EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
+ EXPECT_EQ(2, onresizecalls_); |
+ EXPECT_LT(0, height_); |
} |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(InstantCompleteDelayed)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
- DetermineInstantSupport(); |
+// Test that the INSTANT_COMPLETE_NOW behavior works as expected. |
+IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNow) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
+ instant()->OnAutocompleteGotFocus(); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED); |
- ASSERT_TRUE(SetSuggestionsJavascriptArgument( |
- "{suggestions:[{value:'defg'}],complete_behavior:'delayed'}")); |
- SearchAndWaitForPreviewToShow(); |
- EXPECT_EQ("defg", GetSuggestion()); |
+ // Tell the JS to request for the given behavior. |
+ EXPECT_TRUE(ExecuteScript("behavior = 'now'")); |
- EXPECT_EQ(INSTANT_COMPLETE_DELAYED, |
- omnibox()->model()->instant_complete_behavior()); |
- EXPECT_EQ("def", UTF16ToUTF8(omnibox()->GetText())); |
-} |
+ SetOmniboxText("query"); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(InstantCompleteNow)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
- DetermineInstantSupport(); |
+ // 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); |
- ASSERT_TRUE(SetSuggestionsJavascriptArgument( |
- "{suggestions:[{value:'defg'}],complete_behavior:'now'}")); |
- SearchAndWaitForPreviewToShow(); |
- EXPECT_EQ("defg", GetSuggestion()); |
+ EXPECT_EQ(ASCIIToUTF16("query suggestion"), text); |
+ EXPECT_EQ(ASCIIToUTF16(" suggestion"), text.substr(start, end - start)); |
+ EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); |
+} |
- EXPECT_EQ(INSTANT_COMPLETE_NOW, |
- omnibox()->model()->instant_complete_behavior()); |
- EXPECT_EQ("defg", UTF16ToUTF8(omnibox()->GetText())); |
+// The "delayed" completion behavior is not implemented on the Mac. Strange. |
+#if !defined(OS_MACOSX) |
+// Test that the INSTANT_COMPLETE_DELAYED behavior works as expected. |
+IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedDelayed) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
+ instant()->OnAutocompleteGotFocus(); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED); |
+ |
+ // Tell the JS to request for the given behavior. |
+ EXPECT_TRUE(ExecuteScript("behavior = 'delayed'")); |
+ |
+ SetOmniboxText("query"); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); |
+ |
+ // 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()); |
+ |
+ // Wait for the animation to complete, which causes the omnibox to update. |
+ WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED); |
+ |
+ text = omnibox()->GetText(); |
+ omnibox()->GetSelectionBounds(&start, &end); |
+ if (start > end) |
+ std::swap(start, end); |
+ |
+ EXPECT_EQ(ASCIIToUTF16("query suggestion"), text); |
+ EXPECT_EQ(ASCIIToUTF16(" suggestion"), text.substr(start, end - start)); |
+ EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); |
} |
+#endif |
-// Verifies that instant previews aren't shown for crash URLs. |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(CrashUrlCancelsInstant)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
+// Test that the INSTANT_COMPLETE_NEVER behavior works as expected. |
+IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNever) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
+ instant()->OnAutocompleteGotFocus(); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED); |
- omnibox()->SetUserText(ASCIIToUTF16(chrome::kChromeUICrashURL)); |
- EXPECT_FALSE(preview()); |
-} |
+ // Tell the JS to request for the given behavior. |
+ EXPECT_TRUE(ExecuteScript("behavior = 'never'")); |
-// Tests that instant doesn't fire for intranet paths that look like searches. |
-// http://crbug.com/99836 |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(IntranetPathLooksLikeSearch)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
+ SetOmniboxText("query"); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); |
- // Unfocus the omnibox. This should delete any existing preview contents. |
- ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
- ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
- EXPECT_FALSE(preview()); |
+ // 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); |
- // Navigate to a URL that looks like a search (when the scheme is stripped). |
- // It's okay if the host is bogus or the navigation fails, since we only care |
- // that instant doesn't act on it. |
- ui_test_utils::NavigateToURL(browser(), GURL("http://baby/beluga")); |
- EXPECT_EQ("baby/beluga", UTF16ToUTF8(omnibox()->GetText())); |
- EXPECT_FALSE(preview()); |
+ EXPECT_EQ(ASCIIToUTF16("query"), text); |
+ EXPECT_EQ(ASCIIToUTF16(""), text.substr(start, end - start)); |
+ EXPECT_EQ(ASCIIToUTF16(" suggestion"), omnibox()->GetInstantSuggestion()); |
} |
-// Verifies that instant previews aren't shown for non-search URLs. |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(ShowPreviewNonSearch)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
+// Test that a valid suggestion is accepted. |
+IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsValidObject) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
+ instant()->OnAutocompleteGotFocus(); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED); |
- GURL url(test_server()->GetURL("files/empty.html")); |
- omnibox()->SetUserText(UTF8ToUTF16(url.spec())); |
- EXPECT_FALSE(preview()); |
+ // Tell the JS to use the given suggestion. |
+ EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'query completion' } ]")); |
+ |
+ SetOmniboxText("query"); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); |
+ |
+ EXPECT_EQ(ASCIIToUTF16("query completion"), omnibox()->GetText()); |
} |
-// Transition from non-search to search and make sure everything works. |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(NonSearchToSearch)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
- |
- // Load a non-search URL. |
- GURL url(test_server()->GetURL("files/empty.html")); |
- omnibox()->SetUserText(UTF8ToUTF16(url.spec())); |
- EXPECT_FALSE(preview()); |
- |
- // Now type in some search text. |
- DetermineInstantSupport(); |
- |
- // We should now have a preview, but it shouldn't be showing yet, because we |
- // haven't gotten back suggestions. |
- EXPECT_TRUE(preview()); |
- EXPECT_FALSE(loader()->ready()); |
- EXPECT_FALSE(instant()->is_displayable()); |
- EXPECT_FALSE(instant()->IsCurrent()); |
+// Test that an invalid suggestion is rejected. |
+IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsInvalidObject) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
+ instant()->OnAutocompleteGotFocus(); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED); |
- // Reset the user text so that the page is told the text changed. |
- // |
- // Typing into the omnibox sends onchange() to the page, which responds with |
- // suggestions, which causes the preview to be shown. However, when we called |
- // DetermineInstantSupport(), the resulting onchange was dropped on the floor |
- // because the page wasn't loaded yet. This is fine (the user may type before |
- // the page loads too). To handle this, we explicitly call onchange after the |
- // page loads (see initScript in searchbox_extension.cc). The search provider |
- // used in this test (instant.html) doesn't support initScript, so we have to |
- // trigger an onchange ourselves. |
- SearchAndWaitForPreviewToShow(); |
- |
- // We should now be showing the preview. |
- EXPECT_TRUE(preview()); |
- EXPECT_TRUE(loader()->ready()); |
- EXPECT_TRUE(instant()->is_displayable()); |
- EXPECT_TRUE(instant()->IsCurrent()); |
+ // Tell the JS to use the given suggestion. |
+ EXPECT_TRUE(ExecuteScript("suggestion = { value: 'query completion' }")); |
- content::RenderWidgetHostView* rwhv = |
- preview()->web_contents()->GetRenderWidgetHostView(); |
- EXPECT_TRUE(rwhv); |
- EXPECT_TRUE(rwhv->IsShowing()); |
+ SetOmniboxText("query"); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); |
+ |
+ EXPECT_EQ(ASCIIToUTF16("query"), omnibox()->GetText()); |
} |
-// Transition from search to non-search and make sure instant isn't displayable. |
-// See bug http://crbug.com/100368 for details. |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SearchToNonSearch)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
+// Test that various forms of empty suggestions are rejected. |
+IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsEmpty) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
+ instant()->OnAutocompleteGotFocus(); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED); |
- content::WindowedNotificationObserver instant_support_observer( |
- chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
- content::NotificationService::AllSources()); |
+ EXPECT_TRUE(ExecuteScript("suggestion = {}")); |
+ SetOmniboxText("query1"); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); |
+ EXPECT_EQ(ASCIIToUTF16("query1"), omnibox()->GetText()); |
+ |
+ instant()->Hide(); |
- // Type in some search text. |
- omnibox()->SetUserText(ASCIIToUTF16("def")); |
+ EXPECT_TRUE(ExecuteScript("suggestion = []")); |
+ SetOmniboxText("query2"); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); |
+ EXPECT_EQ(ASCIIToUTF16("query2"), omnibox()->GetText()); |
- // Load a non search URL. Don't wait for the preview to navigate. It'll still |
- // end up loading in the background. |
- GURL url(test_server()->GetURL("files/empty.html")); |
- omnibox()->SetUserText(UTF8ToUTF16(url.spec())); |
+ instant()->Hide(); |
+ |
+ EXPECT_TRUE(ExecuteScript("suggestion = [{}]")); |
+ SetOmniboxText("query3"); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); |
+ EXPECT_EQ(ASCIIToUTF16("query3"), omnibox()->GetText()); |
+} |
- instant_support_observer.Wait(); |
+// Test that Instant doesn't process URLs. |
+IN_PROC_BROWSER_TEST_F(InstantTest, RejectsURLs) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
- // We should now have a preview, but it shouldn't be showing yet. |
- EXPECT_TRUE(preview()); |
- EXPECT_FALSE(loader()->ready()); |
- EXPECT_FALSE(instant()->is_displayable()); |
+ // Note that we are not actually navigating to these URLs yet. We are just |
+ // typing them into the omnibox (without pressing Enter) and checking that |
+ // Instant doesn't try to process them. |
+ SetOmniboxText(chrome::kChromeUICrashURL); |
+ EXPECT_FALSE(instant()->GetPreviewContents()); |
EXPECT_FALSE(instant()->IsCurrent()); |
+ EXPECT_FALSE(instant()->is_showing()); |
- // Send onchange so that the page sends up suggestions. See the comments in |
- // NonSearchToSearch for why this is needed. |
- ASSERT_TRUE(content::ExecuteJavaScript( |
- preview()->web_contents()->GetRenderViewHost(), std::wstring(), |
- L"window.chrome.searchBox.onchange();")); |
- ASSERT_TRUE(WaitForMessageToBeProcessedByRenderer()); |
- |
- // Instant should be active, but not displaying. |
- EXPECT_TRUE(preview()); |
- EXPECT_TRUE(loader()->ready()); |
- EXPECT_FALSE(instant()->is_displayable()); |
+ // Let's try again after creating the preview. |
+ instant()->OnAutocompleteGotFocus(); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED); |
+ |
+ SetOmniboxText(chrome::kChromeUIHangURL); |
+ EXPECT_TRUE(instant()->GetPreviewContents()); |
EXPECT_FALSE(instant()->IsCurrent()); |
-} |
+ EXPECT_FALSE(instant()->is_showing()); |
-// Makes sure that if the server doesn't support the instant API we don't show |
-// anything. |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SearchServerDoesntSupportInstant)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("empty.html"); |
+ SetOmniboxText(chrome::kChromeUIKillURL); |
+ EXPECT_TRUE(instant()->GetPreviewContents()); |
+ EXPECT_FALSE(instant()->IsCurrent()); |
+ EXPECT_FALSE(instant()->is_showing()); |
- content::WindowedNotificationObserver tab_closed_observer( |
- content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
- content::NotificationService::AllSources()); |
+ // Make sure that the URLs were never sent to the preview page. |
+ EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
+ EXPECT_EQ(0, onchangecalls_); |
+ EXPECT_EQ("", value_); |
+} |
- omnibox()->SetUserText(ASCIIToUTF16("d")); |
- EXPECT_TRUE(preview()); |
+// Test that Instant doesn't fire for intranet paths that look like searches. |
+// http://crbug.com/99836 |
+IN_PROC_BROWSER_TEST_F(InstantTest, IntranetPathLooksLikeSearch) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
- // When the response comes back that the page doesn't support instant the tab |
- // should be closed. |
- tab_closed_observer.Wait(); |
- EXPECT_FALSE(preview()); |
+ // Navigate to a URL that looks like a search (when the scheme is stripped). |
+ // It's okay if the host is bogus or the navigation fails, since we only care |
+ // that Instant doesn't act on it. |
+ ui_test_utils::NavigateToURL(browser(), GURL("http://baby/beluga")); |
+ EXPECT_EQ(ASCIIToUTF16("baby/beluga"), omnibox()->GetText()); |
+ EXPECT_FALSE(instant()->GetPreviewContents()); |
} |
-// 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). |
-IN_PROC_BROWSER_TEST_F(InstantTest, |
- MAYBE(NonSearchToSearchDoesntSupportInstant)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("empty.html"); |
- |
- GURL url(test_server()->GetURL("files/empty.html")); |
- omnibox()->SetUserText(UTF8ToUTF16(url.spec())); |
- EXPECT_FALSE(preview()); |
- |
- content::WindowedNotificationObserver tab_closed_observer( |
- content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
- content::NotificationService::AllSources()); |
+// Test that transitions between searches and non-searches work as expected. |
+IN_PROC_BROWSER_TEST_F(InstantTest, TransitionsBetweenSearchAndURL) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
- // Now type in some search text. |
- omnibox()->SetUserText(ASCIIToUTF16("d")); |
- EXPECT_TRUE(preview()); |
+ // Type a search, but without waiting for the page to load, type a URL. |
+ SetOmniboxText("query"); |
+ SetOmniboxText("http://monstrous/nightmare"); |
- // When the response comes back that the page doesn't support instant the tab |
- // should be closed. |
- tab_closed_observer.Wait(); |
- EXPECT_FALSE(preview()); |
-} |
+ // Wait for the page to load. |
+ WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED); |
+ EXPECT_TRUE(instant()->GetPreviewContents()); |
+ EXPECT_FALSE(instant()->IsCurrent()); |
+ EXPECT_FALSE(instant()->is_showing()); |
+ EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
+ EXPECT_EQ(1, onchangecalls_); |
+ EXPECT_EQ("query", value_); |
+ |
+ // Type a search. Instant should show. |
+ SetOmniboxText("search"); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); |
+ EXPECT_TRUE(instant()->GetPreviewContents()); |
+ EXPECT_TRUE(instant()->IsCurrent()); |
+ EXPECT_TRUE(instant()->is_showing()); |
+ EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
+ EXPECT_EQ(2, onchangecalls_); |
-// Verifies the page was told a non-zero height. |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(ValidHeight)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
- DetermineInstantSupport(); |
- SearchAndWaitForPreviewToShow(); |
- |
- int height = -1; |
- |
- // searchBox height is not yet set during initial load. |
- ASSERT_TRUE(GetIntFromJavascript(preview()->web_contents(), |
- "window.beforeLoadSearchBox.height", &height)); |
- EXPECT_EQ(0, height); |
- |
- // searchBox height is available by the time the page loads. |
- ASSERT_TRUE(GetIntFromJavascript(preview()->web_contents(), |
- "window.chrome.searchBox.height", &height)); |
- EXPECT_GT(height, 0); |
+ // Type another URL. The preview should be hidden. |
+ SetOmniboxText("http://terrible/terror"); |
+ EXPECT_TRUE(instant()->GetPreviewContents()); |
+ EXPECT_FALSE(instant()->IsCurrent()); |
+ EXPECT_FALSE(instant()->is_showing()); |
+ EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
+ EXPECT_EQ(2, onchangecalls_); |
+ |
+ // Type the same search as before. The preview should show, but no onchange() |
+ // is sent, since query hasn't changed. |
+ SetOmniboxText("search"); |
+ EXPECT_TRUE(instant()->GetPreviewContents()); |
+ EXPECT_TRUE(instant()->IsCurrent()); |
+ EXPECT_TRUE(instant()->is_showing()); |
+ EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
+ EXPECT_EQ(2, onchangecalls_); |
} |
-// Make sure the renderer doesn't crash if javascript is blocked. |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(DontCrashOnBlockedJS)) { |
- browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
- CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
+// Test that Instant can't be fooled into committing a URL. |
+IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLs) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
+ EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
- // 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). |
- DetermineInstantSupport(); |
-} |
+ // Type a URL. No Instant. |
+ SetOmniboxText("http://deadly/nadder"); |
+ EXPECT_FALSE(instant()->GetPreviewContents()); |
-// Makes sure window.chrome.searchbox doesn't persist when a new page is loaded. |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(DontPersistSearchbox)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
- DetermineInstantSupport(); |
- SearchAndWaitForPreviewToShow(); |
+ // 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)); |
+ browser()->window()->GetLocationBar()->FocusLocation(false); |
- std::string value; |
- ASSERT_TRUE(GetStringFromJavascript(preview()->web_contents(), |
- "window.chrome.searchBox.value", &value)); |
- EXPECT_EQ("def", value); |
+ // The omnibox text hasn't changed, but the preview should've preloaded due |
+ // to the omnibox getting focus. It still shouldn't be showing. |
+ EXPECT_EQ(ASCIIToUTF16("http://deadly/nadder"), omnibox()->GetText()); |
+ TabContents* preview_tab = instant()->GetPreviewContents(); |
+ EXPECT_TRUE(preview_tab); |
+ EXPECT_FALSE(instant()->IsCurrent()); |
+ EXPECT_FALSE(instant()->is_showing()); |
- // Commit the preview. |
- ASSERT_TRUE(PressEnter()); |
- EXPECT_FALSE(preview()); |
+ // Commit the URL. The omnibox should reflect the URL minus the scheme. |
+ browser()->window()->GetLocationBar()->AcceptInput(); |
+ TabContents* active_tab = chrome::GetActiveTabContents(browser()); |
+ EXPECT_NE(preview_tab, active_tab); |
+ EXPECT_EQ(ASCIIToUTF16("deadly/nadder"), omnibox()->GetText()); |
- // The searchBox actually gets cleared on commit. |
- ASSERT_TRUE(GetStringFromJavascript(chrome::GetActiveWebContents(browser()), |
- "window.chrome.searchBox.value", &value)); |
- EXPECT_EQ("", value); |
+ // Instant shouldn't have done anything. |
+ EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); |
+ EXPECT_FALSE(instant()->IsCurrent()); |
+ EXPECT_FALSE(instant()->is_showing()); |
- // Navigate to a new URL. The searchBox values should stay cleared. |
- ui_test_utils::NavigateToURL( |
- browser(), test_server()->GetURL("files/empty.html")); |
+ // Let's try again, using a slightly different approach. |
- ASSERT_TRUE(GetStringFromJavascript(chrome::GetActiveWebContents(browser()), |
- "window.chrome.searchBox.value", &value)); |
- EXPECT_EQ("", value); |
-} |
+ // Type a query. This causes the preview to be shown. |
+ browser()->window()->GetLocationBar()->FocusLocation(false); |
+ SetOmniboxText("query"); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); |
-// Tests that instant search is preloaded whenever the omnibox gets focus. |
-// PreloadsInstant fails on linux_chromeos trybots all the time, possibly |
-// because of http://crbug.com/80118. |
-#if defined(OS_CHROMEOS) || defined(OS_MACOSX) |
-IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_PreloadsInstant) { |
-#else |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(PreloadsInstant)) { |
-#endif |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
- |
- // The omnibox gets focus before the test begins. At that time, there was no |
- // instant controller (which was only created after EnableInstant()), so no |
- // preloading happened. Unfocus the omnibox with ClickOnView(), so that when |
- // we focus it again, the controller will preload instant search. |
- ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
- ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
+ // Type a URL. This causes the preview to be hidden. |
+ SetOmniboxText("http://hideous/zippleback"); |
+ EXPECT_FALSE(instant()->is_showing()); |
- // Verify that there is no preview. |
- EXPECT_FALSE(preview()); |
+ // Pretend the omnibox got focus. It already had focus, so we are just trying |
+ // to tickle a different code path. |
+ instant()->OnAutocompleteGotFocus(); |
- // Focusing the omnibox should cause instant to be preloaded. |
- content::WindowedNotificationObserver instant_support_observer( |
- chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
- content::NotificationService::AllSources()); |
- browser()->window()->GetLocationBar()->FocusLocation(false); |
- instant_support_observer.Wait(); |
+ // Commit the URL. As before, check that Instant wasn't committed. |
+ browser()->window()->GetLocationBar()->AcceptInput(); |
+ EXPECT_EQ(active_tab, chrome::GetActiveTabContents(browser())); |
+ EXPECT_NE(preview_tab, active_tab); |
+ EXPECT_EQ(ASCIIToUTF16("hideous/zippleback"), omnibox()->GetText()); |
- // Instant should have a preview, but not display it. |
- EXPECT_TRUE(preview()); |
- EXPECT_FALSE(instant()->is_displayable()); |
+ // As before, Instant shouldn't have done anything. |
+ EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); |
EXPECT_FALSE(instant()->IsCurrent()); |
- ASSERT_TRUE(CheckVisibilityIs(preview()->web_contents(), false)); |
+ EXPECT_FALSE(instant()->is_showing()); |
+} |
- // Adding a new tab shouldn't delete (or recreate) the TabContents. |
- TabContents* preview_tab = preview(); |
- AddBlankTabAndShow(browser()); |
- EXPECT_EQ(preview_tab, preview()); |
+// Test that a non-Instant search provider shows no previews. |
+IN_PROC_BROWSER_TEST_F(InstantTest, NonInstantSearchProvider) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("empty.html")); |
- // Doing a search should still use the same loader for the preview. |
- SearchAndWaitForPreviewToShow(); |
- EXPECT_EQ(preview_tab, preview()); |
+ // Type a query. Instant will load the search provider. |
+ SetOmniboxText("query"); |
+ EXPECT_TRUE(instant()->GetPreviewContents()); |
- // Verify that the preview is in fact showing instant search. |
- EXPECT_TRUE(instant()->is_displayable()); |
- EXPECT_TRUE(instant()->IsCurrent()); |
- ASSERT_TRUE(CheckVisibilityIs(preview()->web_contents(), true)); |
+ // When the response comes back, Instant will destroy the non-Instant page. |
+ WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED); |
+ EXPECT_FALSE(instant()->GetPreviewContents()); |
} |
-// Tests that the instant search page's visibility is set correctly. |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(PageVisibilityTest)) { |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
+// Test that the renderer doesn't crash if JavaScript is blocked. |
+IN_PROC_BROWSER_TEST_F(InstantTest, NoCrashOnBlockedJS) { |
+ browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
+ CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
- // Initially navigate to the empty page which should be visible. |
- ui_test_utils::NavigateToURL(browser(), test_server()->GetURL("")); |
- WebContents* initial_contents = chrome::GetActiveWebContents(browser()); |
+ // 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). |
+ instant()->OnAutocompleteGotFocus(); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED); |
+} |
- ASSERT_TRUE(CheckVisibilityIs(initial_contents, true)); |
+// Test that the preview and active tab's visibility states are set correctly. |
+IN_PROC_BROWSER_TEST_F(InstantTest, PageVisibility) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
+ instant()->OnAutocompleteGotFocus(); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED); |
- // Type a search term and wait for the preview to appear. |
- browser()->window()->GetLocationBar()->FocusLocation(false); |
- DetermineInstantSupport(); |
- SearchAndWaitForPreviewToShow(); |
- WebContents* preview_contents = preview()->web_contents(); |
+ TabContents* active_tab = chrome::GetActiveTabContents(browser()); |
+ TabContents* preview_tab = instant()->GetPreviewContents(); |
- ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); |
- ASSERT_TRUE(CheckVisibilityIs(initial_contents, false)); |
+ // Inititally, the active tab is showing; the preview is not. |
+ EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); |
+ EXPECT_TRUE(CheckVisibilityIs(preview_tab, false)); |
- // Deleting the user text should hide the preview. |
- omnibox()->SetUserText(string16()); |
- ASSERT_TRUE(CheckVisibilityIs(preview_contents, false)); |
- ASSERT_TRUE(CheckVisibilityIs(initial_contents, true)); |
+ // Type a query and wait for Instant to show. |
+ SetOmniboxText("search"); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); |
+ EXPECT_TRUE(CheckVisibilityIs(active_tab, false)); |
+ EXPECT_TRUE(CheckVisibilityIs(preview_tab, true)); |
- // Set the user text back and we should see the preview again. |
- omnibox()->SetUserText(ASCIIToUTF16("def")); |
- ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); |
- ASSERT_TRUE(CheckVisibilityIs(initial_contents, false)); |
+ // Deleting the omnibox text should hide the preview. |
+ SetOmniboxText(""); |
+ EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); |
+ EXPECT_TRUE(CheckVisibilityIs(preview_tab, false)); |
+ |
+ // Typing a query should show the preview again. |
+ SetOmniboxText("search"); |
+ EXPECT_TRUE(CheckVisibilityIs(active_tab, false)); |
+ EXPECT_TRUE(CheckVisibilityIs(preview_tab, true)); |
// Commit the preview. |
- ASSERT_TRUE(PressEnter()); |
- EXPECT_EQ(preview_contents, chrome::GetActiveWebContents(browser())); |
- ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); |
+ browser()->window()->GetLocationBar()->AcceptInput(); |
+ EXPECT_EQ(preview_tab, chrome::GetActiveTabContents(browser())); |
+ EXPECT_TRUE(CheckVisibilityIs(preview_tab, true)); |
} |
-// Tests that the task manager identifies instant's preview tab correctly. |
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(TaskManagerPrefix)) { |
+// Test that the task manager identifies Instant's preview tab correctly. |
+IN_PROC_BROWSER_TEST_F(InstantTest, TaskManagerPrefix) { |
// The browser starts with one new tab, so the task manager should have two |
// rows initially, one for the browser process and one for tab's renderer. |
TaskManagerModel* task_manager = TaskManager::GetInstance()->model(); |
task_manager->StartUpdating(); |
TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
- ASSERT_TRUE(test_server()->Start()); |
- EnableInstant(); |
- SetupInstantProvider("instant.html"); |
- DetermineInstantSupport(); |
- SearchAndWaitForPreviewToShow(); |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
+ instant()->OnAutocompleteGotFocus(); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED); |
- // Now there should be three rows, the third being the instant preview. |
+ // Now there should be three rows, the third being the Instant preview. |
TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
string16 prefix = l10n_util::GetStringFUTF16( |
IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX, string16()); |
string16 title = task_manager->GetResourceTitle(2); |
EXPECT_TRUE(StartsWith(title, prefix, true)) << title << " vs " << prefix; |
} |
+ |
+void HistoryQueryDone(base::RunLoop* run_loop, |
+ bool* result, |
+ HistoryService::Handle /* handle */, |
+ bool success, |
+ const history::URLRow* /* urlrow */, |
+ history::VisitVector* /* visitvector */) { |
+ *result = success; |
+ run_loop->Quit(); |
+} |
+ |
+void KeywordQueryDone(base::RunLoop* run_loop, |
+ std::vector<string16>* result, |
+ HistoryService::Handle /* handle */, |
+ std::vector<history::KeywordSearchTermVisit>* terms) { |
+ for (size_t i = 0; i < terms->size(); ++i) |
+ result->push_back((*terms)[i].term); |
+ run_loop->Quit(); |
+} |
+ |
+// Test that the Instant page load is not added to history. |
+IN_PROC_BROWSER_TEST_F(InstantTest, History) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
+ instant()->OnAutocompleteGotFocus(); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED); |
+ |
+ const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( |
+ browser()->profile())->GetDefaultSearchProvider(); |
+ |
+ // |instant_url| is the URL Instant loads. |search_url| is the fake URL we |
+ // enter into history for search terms extraction to work correctly. |
+ std::string search_url = template_url->url_ref().ReplaceSearchTerms( |
+ TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("search"))); |
+ std::string instant_url = template_url->instant_url_ref().ReplaceSearchTerms( |
+ TemplateURLRef::SearchTermsArgs(string16())); |
+ |
+ HistoryService* history = HistoryServiceFactory::GetForProfile( |
+ browser()->profile(), Profile::EXPLICIT_ACCESS); |
+ ui_test_utils::WaitForHistoryToLoad(history); |
+ |
+ // Perform a search. |
+ SetOmniboxText("search"); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); |
+ EXPECT_EQ(instant_url, instant()->loader()->instant_url()); |
+ |
+ // Commit the search. |
+ browser()->window()->GetLocationBar()->AcceptInput(); |
+ |
+ bool found = false; |
+ CancelableRequestConsumer consumer; |
+ |
+ // The fake search URL should be in history. |
+ base::RunLoop run_loop1; |
+ history->QueryURL(GURL(search_url), false, &consumer, |
+ base::Bind(&HistoryQueryDone, &run_loop1, &found)); |
+ run_loop1.Run(); |
+ EXPECT_TRUE(found); |
+ |
+ // The Instant URL should not be in history. |
+ base::RunLoop run_loop2; |
+ history->QueryURL(GURL(instant_url), false, &consumer, |
+ base::Bind(&HistoryQueryDone, &run_loop2, &found)); |
+ run_loop2.Run(); |
+ EXPECT_FALSE(found); |
+ |
+ // The search terms should have been extracted into history. |
+ base::RunLoop run_loop3; |
+ std::vector<string16> queries; |
+ history->GetMostRecentKeywordSearchTerms(template_url->id(), |
+ ASCIIToUTF16("s"), 1, &consumer, |
+ base::Bind(&KeywordQueryDone, &run_loop3, &queries)); |
+ run_loop3.Run(); |
+ ASSERT_TRUE(queries.size()); |
+ EXPECT_EQ(ASCIIToUTF16("search"), queries[0]); |
+} |
+ |
+// On Windows, the call to NewEmptyWindow() fails the "GetBackingStore called |
+// while hidden" DCHECK(). It's not clear why; maybe because the active tab is |
+// in a hidden state when the Instant preview is showing, and somebody's trying |
+// to get its backing store? |
+#if !defined(OS_WIN) |
+// Test that creating a new window hides any currently showing Instant preview. |
+IN_PROC_BROWSER_TEST_F(InstantTest, NewWindowDismissesInstant) { |
+ ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); |
+ instant()->OnAutocompleteGotFocus(); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED); |
+ |
+ EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
+ SetOmniboxText("search"); |
+ WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); |
+ EXPECT_TRUE(instant()->GetPreviewContents()); |
+ EXPECT_TRUE(instant()->IsCurrent()); |
+ EXPECT_TRUE(instant()->is_showing()); |
+ |
+ content::WindowedNotificationObserver observer( |
+ chrome::NOTIFICATION_INSTANT_CONTROLLER_HIDDEN, |
+ content::NotificationService::AllSources()); |
+ chrome::NewEmptyWindow(browser()->profile()); |
+ observer.Wait(); |
+ EXPECT_TRUE(instant()->GetPreviewContents()); |
+ EXPECT_FALSE(instant()->IsCurrent()); |
+ EXPECT_FALSE(instant()->is_showing()); |
+} |
+#endif |