summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsreeram@chromium.org <sreeram@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-03 23:52:16 +0000
committersreeram@chromium.org <sreeram@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-03 23:52:16 +0000
commiteadbf953ed4c20049793a0672c62ecb90a28e9ac (patch)
tree59372e54befd976fbcadce9cb23c82e492327889
parenta77f68d645f00b878cfe59a4883cc483016a0847 (diff)
downloadchromium_src-eadbf953ed4c20049793a0672c62ecb90a28e9ac.zip
chromium_src-eadbf953ed4c20049793a0672c62ecb90a28e9ac.tar.gz
chromium_src-eadbf953ed4c20049793a0672c62ecb90a28e9ac.tar.bz2
Refactor Instant tests.
BUG=none TEST=interactive_ui_tests --gtest_filter=Instant* Review URL: http://codereview.chromium.org/8409005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108580 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc2
-rw-r--r--chrome/browser/instant/instant_browsertest.cc1268
-rw-r--r--chrome/browser/instant/instant_controller.cc4
-rw-r--r--chrome/browser/instant/instant_controller.h4
-rw-r--r--chrome/test/data/instant.html (renamed from chrome/test/data/instant/search.html)28
5 files changed, 541 insertions, 765 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 82e2b7c..fef9c88 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -3513,8 +3513,6 @@ void TestingAutomationProvider::GetInstantInfo(Browser* browser,
if (browser->instant()) {
InstantController* instant = browser->instant();
info->SetBoolean("enabled", true);
- info->SetBoolean("showing", instant->is_displayable());
- // TODO: can we remove this?
info->SetBoolean("active", (instant->GetPreviewContents() != NULL));
info->SetBoolean("current", instant->IsCurrent());
if (instant->GetPreviewContents() &&
diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc
index 73203c5..7780699 100644
--- a/chrome/browser/instant/instant_browsertest.cc
+++ b/chrome/browser/instant/instant_browsertest.cc
@@ -15,7 +15,6 @@
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
@@ -26,88 +25,21 @@
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
-#include "chrome/test/test_navigation_observer.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/renderer_host/render_widget_host_view.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/public/browser/notification_service.h"
-#define EXPECT_STR_EQ(ascii, utf16) \
- EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16))
-
+// Tests are flaky on Linux because of http://crbug.com/80118.
#if defined(OS_LINUX)
-// These tests are disabled on linux because of http://crbug.com/80118 .
-#define MAYBE_OnChangeEvent DISABLED_OnChangeEvent
-#define MAYBE_SetSuggestionsArrayOfStrings DISABLED_SetSuggestionsArrayOfStrings
-#define MAYBE_SetSuggestionsEmptyArray DISABLED_SetSuggestionsEmptyArray
-#define MAYBE_SetSuggestionsValidJson DISABLED_SetSuggestionsValidJson
-#define MAYBE_SetSuggestionsInvalidSuggestions \
- DISABLED_SetSuggestionsInvalidSuggestions
-#define MAYBE_SetSuggestionsEmptyJson DISABLED_SetSuggestionsEmptyJson
-#define MAYBE_SetSuggestionsEmptySuggestions \
- DISABLED_SetSuggestionsEmptySuggestions
-#define MAYBE_SetSuggestionsEmptySuggestion \
- DISABLED_SetSuggestionsEmptySuggestion
-#define MAYBE_ShowPreviewNonSearch DISABLED_ShowPreviewNonSearch
-#define MAYBE_NonSearchToSearch DISABLED_NonSearchToSearch
-#define MAYBE_SearchToNonSearch DISABLED_SearchToNonSearch
-#define MAYBE_ValidHeight DISABLED_ValidHeight
-#define MAYBE_OnSubmitEvent DISABLED_OnSubmitEvent
-#define MAYBE_OnCancelEvent DISABLED_OnCancelEvent
-#define MAYBE_InstantCompleteNever DISABLED_InstantCompleteNever
-#define MAYBE_InstantCompleteDelayed DISABLED_InstantCompleteDelayed
-#define MAYBE_DontCrashOnBlockedJS DISABLED_DontCrashOnBlockedJS
-#define MAYBE_DontPersistSearchbox DISABLED_DontPersistSearchbox
-#define MAYBE_PreloadsInstant DISABLED_PreloadsInstant
-#define MAYBE_PageVisibilityTest DISABLED_PageVisibilityTest
-#define MAYBE_ExperimentEnabled DISABLED_ExperimentEnabled
-#define MAYBE_IntranetPathLooksLikeSearch DISABLED_IntranetPathLooksLikeSearch
-#else
-#define MAYBE_OnChangeEvent OnChangeEvent
-#define MAYBE_SetSuggestionsArrayOfStrings SetSuggestionsArrayOfStrings
-#define MAYBE_SetSuggestionsEmptyArray SetSuggestionsEmptyArray
-#define MAYBE_SetSuggestionsValidJson SetSuggestionsValidJson
-#define MAYBE_SetSuggestionsInvalidSuggestions SetSuggestionsInvalidSuggestions
-#define MAYBE_SetSuggestionsEmptyJson SetSuggestionsEmptyJson
-#define MAYBE_SetSuggestionsEmptySuggestions SetSuggestionsEmptySuggestions
-#define MAYBE_SetSuggestionsEmptySuggestion SetSuggestionsEmptySuggestion
-#define MAYBE_ShowPreviewNonSearch ShowPreviewNonSearch
-#define MAYBE_NonSearchToSearch NonSearchToSearch
-#define MAYBE_SearchToNonSearch SearchToNonSearch
-#define MAYBE_ValidHeight ValidHeight
-#define MAYBE_OnSubmitEvent OnSubmitEvent
-#define MAYBE_OnCancelEvent OnCancelEvent
-#define MAYBE_InstantCompleteNever InstantCompleteNever
-#define MAYBE_InstantCompleteDelayed InstantCompleteDelayed
-#define MAYBE_DontCrashOnBlockedJS DontCrashOnBlockedJS
-#define MAYBE_DontPersistSearchbox DontPersistSearchbox
-#define MAYBE_PreloadsInstant PreloadsInstant
-#define MAYBE_PageVisibilityTest PageVisibilityTest
-#define MAYBE_ExperimentEnabled ExperimentEnabled
-#define MAYBE_IntranetPathLooksLikeSearch IntranetPathLooksLikeSearch
-#endif
-
-#if defined(OS_MACOSX) || defined(OS_LINUX)
-// Showing as flaky on Mac and Linux.
-// http://crbug.com/70860
-#define MAYBE_SearchServerDoesntSupportInstant \
- DISABLED_SearchServerDoesntSupportInstant
-#define MAYBE_NonSearchToSearchDoesntSupportInstant \
- DISABLED_NonSearchToSearchDoesntSupportInstant
+#define MAYBE(TestName) DISABLED_ ## TestName
#else
-#define MAYBE_SearchServerDoesntSupportInstant \
- SearchServerDoesntSupportInstant
-#define MAYBE_NonSearchToSearchDoesntSupportInstant \
- NonSearchToSearchDoesntSupportInstant
+#define MAYBE(TestName) TestName
#endif
-
class InstantTest : public InProcessBrowserTest {
public:
- InstantTest()
- : location_bar_(NULL),
- preview_(NULL),
- template_url_id_(0) {
+ InstantTest() {
set_show_window(true);
EnableDOMAutomation();
}
@@ -119,22 +51,20 @@ class InstantTest : public InProcessBrowserTest {
void SetupInstantProvider(const std::string& page) {
TemplateURLService* model =
TemplateURLServiceFactory::GetForProfile(browser()->profile());
- ASSERT_TRUE(model);
- ui_test_utils::WindowedNotificationObserver service_loaded_observer(
+ ui_test_utils::WindowedNotificationObserver observer(
chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED,
content::NotificationService::AllSources());
if (!model->loaded()) {
model->Load();
- service_loaded_observer.Wait();
+ observer.Wait();
}
- ASSERT_TRUE(model->loaded());
// TemplateURLService takes ownership of this.
TemplateURL* template_url = new TemplateURL();
- std::string url = StringPrintf(
- "http://%s:%d/files/instant/%s?q={searchTerms}",
+ std::string url = 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());
@@ -145,134 +75,98 @@ class InstantTest : public InProcessBrowserTest {
model->Add(template_url);
model->SetDefaultSearchProvider(template_url);
- template_url_id_ = template_url->id();
- }
-
- void FindLocationBar() {
- if (location_bar_)
- return;
- location_bar_ = browser()->window()->GetLocationBar();
- ASSERT_TRUE(location_bar_);
}
- // Type a character to get instant to trigger.
- void SetupLocationBar() {
- FindLocationBar();
- // "a" triggers the "about:" provider. "b" begins the "bing.com" keyword.
+ // Type a character to get instant to trigger and determine instant support.
+ void DetermineInstantSupport() {
+ ui_test_utils::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.
- location_bar_->location_entry()->SetUserText(ASCIIToUTF16("d"));
+ omnibox()->SetUserText(ASCIIToUTF16("d"));
+ observer.Wait();
}
- // Waits for preview to be shown.
- void WaitForPreviewToNavigate() {
- InstantController* instant = browser()->instant();
- ASSERT_TRUE(instant);
- TabContentsWrapper* tab = instant->GetPreviewContents();
- ASSERT_TRUE(tab);
- preview_ = tab->tab_contents();
- ASSERT_TRUE(preview_);
- // TODO(gbillock): This should really be moved into calling code. It is
- // still race-prone here.
- TestNavigationObserver observer(content::Source<NavigationController>(
- &preview_->controller()), NULL, 1);
- observer.WaitForObservation();
+ // Types "def" into the omnibox and waits for the preview to be shown.
+ void SearchAndWaitForPreviewToShow() {
+ ui_test_utils::WindowedNotificationObserver observer(
+ chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN,
+ content::NotificationService::AllSources());
+ omnibox()->SetUserText(ASCIIToUTF16("def"));
+ observer.Wait();
}
- // Wait for instant to load and ensure it is in the state we expect.
- void SetupPreview() {
- // Wait for the preview to navigate.
- WaitForPreviewToNavigate();
-
- ASSERT_FALSE(browser()->instant()->is_displayable());
- ASSERT_TRUE(HasPreview());
+ // 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()->tab_contents(), "true", &result) &&
+ result;
+ }
- // When the page loads, the initial searchBox values are set and only a
- // resize will have been sent.
- ASSERT_EQ("true 0 0 0 true d false d false 1 1",
- GetSearchStateAsString(preview_, false));
+ InstantController* instant() const {
+ return browser()->instant();
}
- void SetLocationBarText(const std::string& text) {
- ASSERT_NO_FATAL_FAILURE(FindLocationBar());
- ui_test_utils::WindowedNotificationObserver controller_shown_observer(
- chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN,
- content::NotificationService::AllSources());
- location_bar_->location_entry()->SetUserText(UTF8ToUTF16(text));
- controller_shown_observer.Wait();
+ OmniboxView* omnibox() const {
+ return browser()->window()->GetLocationBar()->location_entry();
}
- const string16& GetSuggestion() const {
- return browser()->instant()->loader_->complete_suggested_text_;
+ TabContentsWrapper* preview() const {
+ return instant()->GetPreviewContents();
}
- GURL GetCurrentURL() {
- return browser()->instant()->loader_.get() ?
- browser()->instant()->loader_.get()->url() : GURL();
+ InstantLoader* loader() const {
+ return instant()->loader_.get();
}
- bool LoaderIsReady() const {
- return browser()->instant()->loader_->ready();
+ std::string GetSuggestion() const {
+ return UTF16ToUTF8(loader()->complete_suggested_text_);
}
- const string16& GetUserText() const {
- return browser()->instant()->loader_->user_text();
+ bool PressEnter() {
+ return ui_test_utils::SendKeyPressSync(
+ browser(), ui::VKEY_RETURN, false, false, false, false);
}
- void SendKey(ui::KeyboardCode key) {
- ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
- browser(), key, false, false, false, false));
+ bool SetSuggestionsJavascriptArgument(const std::string& argument) {
+ std::wstring script = UTF8ToWide(base::StringPrintf(
+ "window.setSuggestionsArgument = %s;", argument.c_str()));
+ RenderViewHost* rvh = preview()->tab_contents()->render_view_host();
+ return ui_test_utils::ExecuteJavaScript(rvh, std::wstring(), script);
}
- void SetSuggestionsJavascriptArgument(TabContents* tab_contents,
- const std::string& argument) {
- std::string script = StringPrintf(
- "window.setSuggestionsArgument = %s;", argument.c_str());
- ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
- tab_contents->render_view_host(),
- std::wstring(),
- UTF8ToWide(script)));
+ std::wstring WrapScript(const std::string& script) {
+ return UTF8ToWide(base::StringPrintf(
+ "window.domAutomationController.send(%s)", script.c_str()));
}
- bool GetStringFromJavascript(TabContents* tab_contents,
- const std::string& function,
+ bool GetStringFromJavascript(TabContents* tab,
+ const std::string& script,
std::string* result) {
- std::string script = StringPrintf(
- "window.domAutomationController.send(%s)", function.c_str());
return ui_test_utils::ExecuteJavaScriptAndExtractString(
- tab_contents->render_view_host(),
- std::wstring(), UTF8ToWide(script), result);
+ tab->render_view_host(), std::wstring(), WrapScript(script), result);
}
- bool GetIntFromJavascript(TabContents* tab_contents,
- const std::string& function,
+ bool GetIntFromJavascript(TabContents* tab,
+ const std::string& script,
int* result) {
- std::string script = StringPrintf(
- "window.domAutomationController.send(%s)", function.c_str());
return ui_test_utils::ExecuteJavaScriptAndExtractInt(
- tab_contents->render_view_host(),
- std::wstring(), UTF8ToWide(script), result);
+ tab->render_view_host(), std::wstring(), WrapScript(script), result);
}
- bool GetBoolFromJavascript(TabContents* tab_contents,
- const std::string& function,
+ bool GetBoolFromJavascript(TabContents* tab,
+ const std::string& script,
bool* result) {
- std::string script = StringPrintf(
- "window.domAutomationController.send(%s)", function.c_str());
return ui_test_utils::ExecuteJavaScriptAndExtractBool(
- tab_contents->render_view_host(),
- std::wstring(), UTF8ToWide(script), result);
+ tab->render_view_host(), std::wstring(), WrapScript(script), result);
}
- bool HasPreview() {
- return browser()->instant()->GetPreviewContents() != NULL;
- }
-
- bool IsVisible(TabContents* tab_contents) {
- std::string visibility;
- if (!GetStringFromJavascript(tab_contents, "document.webkitVisibilityState",
- &visibility))
- return false;
- return visibility == "visible";
+ bool CheckVisibilityIs(TabContents* tab, bool visible) {
+ bool hidden = visible;
+ return GetBoolFromJavascript(tab, "document.webkitHidden", &hidden) &&
+ hidden != visible;
}
// Returns the state of the search box as a string. This consists of the
@@ -281,7 +175,7 @@ class InstantTest : public InProcessBrowserTest {
// window.onsubmitcalls
// window.oncancelcalls
// window.onchangecalls
- // 'true' if window.onresizecalls has been sent, otherwise false.
+ // 'true' if any window.onresize call has been sent, otherwise false.
// window.beforeLoadSearchBox.value
// window.beforeLoadSearchBox.verbatim
// window.chrome.searchBox.value
@@ -292,8 +186,7 @@ class InstantTest : public InProcessBrowserTest {
//
// 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(TabContents* tab_contents,
- bool use_last) {
+ std::string GetSearchStateAsString(TabContents* tab, bool use_last) {
bool sv = false;
int onsubmitcalls = 0;
int oncancelcalls = 0;
@@ -306,106 +199,54 @@ class InstantTest : public InProcessBrowserTest {
std::string value;
bool verbatim = false;
- if (!GetBoolFromJavascript(tab_contents, "window.chrome.sv", &sv) ||
- !GetIntFromJavascript(tab_contents, "window.onsubmitcalls",
- &onsubmitcalls) ||
- !GetIntFromJavascript(tab_contents, "window.oncancelcalls",
- &oncancelcalls) ||
- !GetIntFromJavascript(tab_contents, "window.onchangecalls",
- &onchangecalls) ||
- !GetIntFromJavascript(tab_contents, "window.onresizecalls",
- &onresizecalls) ||
- !GetStringFromJavascript(
- tab_contents, "window.beforeLoadSearchBox.value",
- &before_load_value) ||
- !GetBoolFromJavascript(
- tab_contents, "window.beforeLoadSearchBox.verbatim",
- &before_load_verbatim)) {
+ 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_contents, "window.lastSearchBox.value",
- &value) ||
- !GetBoolFromJavascript(tab_contents, "window.lastSearchBox.verbatim",
+ (!GetStringFromJavascript(tab, "window.lastSearchBox.value", &value) ||
+ !GetBoolFromJavascript(tab, "window.lastSearchBox.verbatim",
&verbatim) ||
- !GetIntFromJavascript(tab_contents,
- "window.lastSearchBox.selectionStart",
+ !GetIntFromJavascript(tab, "window.lastSearchBox.selectionStart",
&selection_start) ||
- !GetIntFromJavascript(tab_contents,
- "window.lastSearchBox.selectionEnd",
+ !GetIntFromJavascript(tab, "window.lastSearchBox.selectionEnd",
&selection_end))) {
return "fail";
}
if (!use_last &&
- (!GetStringFromJavascript(tab_contents, "window.searchBox.value",
+ (!GetStringFromJavascript(tab, "window.chrome.searchBox.value",
&value) ||
- !GetBoolFromJavascript(tab_contents, "window.searchBox.verbatim",
+ !GetBoolFromJavascript(tab, "window.chrome.searchBox.verbatim",
&verbatim) ||
- !GetIntFromJavascript(tab_contents,
- "window.searchBox.selectionStart",
+ !GetIntFromJavascript(tab, "window.chrome.searchBox.selectionStart",
&selection_start) ||
- !GetIntFromJavascript(tab_contents,
- "window.searchBox.selectionEnd",
+ !GetIntFromJavascript(tab, "window.chrome.searchBox.selectionEnd",
&selection_end))) {
return "fail";
}
- return 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);
- }
-
- void CheckStringValueFromJavascript(
- const std::string& expected,
- const std::string& function,
- TabContents* tab_contents) {
- std::string result;
- ASSERT_TRUE(GetStringFromJavascript(tab_contents, function, &result));
- ASSERT_EQ(expected, result);
- }
-
- void CheckBoolValueFromJavascript(
- bool expected,
- const std::string& function,
- TabContents* tab_contents) {
- bool result;
- ASSERT_TRUE(GetBoolFromJavascript(tab_contents, function, &result));
- ASSERT_EQ(expected, result);
+ 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);
}
-
- void CheckIntValueFromJavascript(
- int expected,
- const std::string& function,
- TabContents* tab_contents) {
- int result;
- ASSERT_TRUE(GetIntFromJavascript(tab_contents, function, &result));
- ASSERT_EQ(expected, result);
- }
-
- // Sends a message to the renderer and waits for the response to come back to
- // the browser.
- void WaitForMessageToBeProcessedByRenderer(TabContentsWrapper* tab) {
- ASSERT_NO_FATAL_FAILURE(
- CheckBoolValueFromJavascript(true, "true", tab->tab_contents()));
- }
-
- protected:
- LocationBar* location_bar_;
- TabContents* preview_;
-
- // ID of the default search engine's template_url (in the installed model).
- TemplateURLID template_url_id_;
};
// TODO(tonyg): Add the following tests:
@@ -414,577 +255,553 @@ class InstantTest : public InProcessBrowserTest {
// - Test resize events.
// Verify that the onchange event is dispatched upon typing in the box.
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnChangeEvent) {
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(OnChangeEvent)) {
ASSERT_TRUE(test_server()->Start());
EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
- ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
- ASSERT_NO_FATAL_FAILURE(SetupPreview());
+ SetupInstantProvider("instant.html");
+ DetermineInstantSupport();
+ SearchAndWaitForPreviewToShow();
- ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
+ EXPECT_TRUE(preview());
+ EXPECT_TRUE(instant()->is_displayable());
+ EXPECT_TRUE(instant()->IsCurrent());
+ EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText()));
- ASSERT_EQ(ASCIIToUTF16("defghi"), location_bar_->location_entry()->GetText());
-
- // Make sure the url that will get committed when we press enter matches that
- // of the default search provider.
+ // 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();
- ASSERT_TRUE(default_turl);
- ASSERT_TRUE(default_turl->url());
+ EXPECT_TRUE(default_turl);
+ EXPECT_TRUE(default_turl->url());
EXPECT_EQ(default_turl->url()->ReplaceSearchTerms(
*default_turl, ASCIIToUTF16("defghi"), 0, string16()),
- GetCurrentURL().spec());
+ 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_, true));
+ GetSearchStateAsString(preview()->tab_contents(), false));
}
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsArrayOfStrings) {
+// Verify that the onsubmit event is dispatched upon pressing <Enter>.
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(OnSubmitEvent)) {
ASSERT_TRUE(test_server()->Start());
EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
- ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
- ASSERT_NO_FATAL_FAILURE(SetupPreview());
+ SetupInstantProvider("instant.html");
+ DetermineInstantSupport();
+ SearchAndWaitForPreviewToShow();
+
+ EXPECT_TRUE(preview());
+ EXPECT_TRUE(instant()->is_displayable());
+ EXPECT_TRUE(instant()->IsCurrent());
+ EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText()));
+
+ TabContents* preview_tab = preview()->tab_contents();
+ EXPECT_TRUE(preview_tab);
+
+ ASSERT_TRUE(PressEnter());
+
+ // Check that the preview has been committed.
+ EXPECT_FALSE(preview());
+ EXPECT_FALSE(instant()->is_displayable());
+ EXPECT_FALSE(instant()->IsCurrent());
+ EXPECT_EQ(preview_tab, browser()->GetSelectedTabContents());
+
+ // 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->controller().entry_count());
- SetSuggestionsJavascriptArgument(preview_, "['defgh', 'unused']");
- ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
- EXPECT_STR_EQ("defgh", GetSuggestion());
+ // 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));
+
+ // Make sure the searchbox values were reset.
+ EXPECT_EQ("true 1 0 1 true d false false 0 0",
+ GetSearchStateAsString(preview_tab, false));
}
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsEmptyArray) {
+// Verify that the oncancel event is dispatched upon losing focus.
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(OnCancelEvent)) {
ASSERT_TRUE(test_server()->Start());
EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
- ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
- ASSERT_NO_FATAL_FAILURE(SetupPreview());
+ SetupInstantProvider("instant.html");
+ DetermineInstantSupport();
+ SearchAndWaitForPreviewToShow();
+
+ EXPECT_TRUE(preview());
+ EXPECT_TRUE(instant()->is_displayable());
+ EXPECT_TRUE(instant()->IsCurrent());
+ EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText()));
- SetSuggestionsJavascriptArgument(preview_, "[]");
- ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
- EXPECT_STR_EQ("", GetSuggestion());
+ TabContents* preview_tab = preview()->tab_contents();
+ EXPECT_TRUE(preview_tab);
+
+ ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
+ ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
+
+ // Check that the preview has been committed.
+ EXPECT_FALSE(preview());
+ EXPECT_FALSE(instant()->is_displayable());
+ EXPECT_FALSE(instant()->IsCurrent());
+ EXPECT_EQ(preview_tab, browser()->GetSelectedTabContents());
+
+ // 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));
+
+ // Make sure the searchbox values were reset.
+ EXPECT_EQ("true 0 1 1 true d false false 0 0",
+ GetSearchStateAsString(preview_tab, false));
}
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsValidJson) {
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsArrayOfStrings)) {
ASSERT_TRUE(test_server()->Start());
EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
- ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
- ASSERT_NO_FATAL_FAILURE(SetupPreview());
-
- SetSuggestionsJavascriptArgument(
- preview_,
- "{suggestions:[{value:'defghij'},{value:'unused'}]}");
- ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
- EXPECT_STR_EQ("defghij", GetSuggestion());
+ SetupInstantProvider("instant.html");
+ DetermineInstantSupport();
+
+ ASSERT_TRUE(SetSuggestionsJavascriptArgument("['defg', 'unused']"));
+ SearchAndWaitForPreviewToShow();
+ EXPECT_EQ("defg", GetSuggestion());
}
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsInvalidSuggestions) {
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsEmptyArray)) {
ASSERT_TRUE(test_server()->Start());
EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
- ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
- ASSERT_NO_FATAL_FAILURE(SetupPreview());
-
- SetSuggestionsJavascriptArgument(
- preview_,
- "{suggestions:{value:'defghi'}}");
- ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
- EXPECT_STR_EQ("", GetSuggestion());
+ SetupInstantProvider("instant.html");
+ DetermineInstantSupport();
+
+ ASSERT_TRUE(SetSuggestionsJavascriptArgument("[]"));
+ SearchAndWaitForPreviewToShow();
+ EXPECT_EQ("", GetSuggestion());
}
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsEmptyJson) {
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsValidJson)) {
ASSERT_TRUE(test_server()->Start());
EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
- ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
- ASSERT_NO_FATAL_FAILURE(SetupPreview());
+ SetupInstantProvider("instant.html");
+ DetermineInstantSupport();
- SetSuggestionsJavascriptArgument(preview_, "{}");
- ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
- EXPECT_STR_EQ("", GetSuggestion());
+ ASSERT_TRUE(SetSuggestionsJavascriptArgument(
+ "{suggestions:[{value:'defg'},{value:'unused'}]}"));
+ SearchAndWaitForPreviewToShow();
+ EXPECT_EQ("defg", GetSuggestion());
}
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsEmptySuggestions) {
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsInvalidSuggestions)) {
ASSERT_TRUE(test_server()->Start());
EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
- ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
- ASSERT_NO_FATAL_FAILURE(SetupPreview());
+ SetupInstantProvider("instant.html");
+ DetermineInstantSupport();
- SetSuggestionsJavascriptArgument(preview_, "{suggestions:[]}");
- ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
- EXPECT_STR_EQ("", GetSuggestion());
+ ASSERT_TRUE(SetSuggestionsJavascriptArgument("{suggestions:{value:'defg'}}"));
+ SearchAndWaitForPreviewToShow();
+ EXPECT_EQ("", GetSuggestion());
}
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsEmptySuggestion) {
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsEmptyJson)) {
ASSERT_TRUE(test_server()->Start());
EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
- ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
- ASSERT_NO_FATAL_FAILURE(SetupPreview());
+ SetupInstantProvider("instant.html");
+ DetermineInstantSupport();
- SetSuggestionsJavascriptArgument(preview_, "{suggestions:[{}]}");
- ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
- EXPECT_STR_EQ("", GetSuggestion());
+ ASSERT_TRUE(SetSuggestionsJavascriptArgument("{}"));
+ SearchAndWaitForPreviewToShow();
+ EXPECT_EQ("", GetSuggestion());
}
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_ShowPreviewNonSearch) {
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsEmptySuggestions)) {
ASSERT_TRUE(test_server()->Start());
EnableInstant();
- GURL url(test_server()->GetURL("files/instant/empty.html"));
- ASSERT_NO_FATAL_FAILURE(FindLocationBar());
- location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec()));
-
- // The preview should not be active or showing.
- ASSERT_FALSE(HasPreview());
- ASSERT_FALSE(browser()->instant()->is_displayable());
- ASSERT_FALSE(browser()->instant()->IsCurrent());
- ASSERT_EQ(NULL, browser()->instant()->GetPreviewContents());
+ SetupInstantProvider("instant.html");
+ DetermineInstantSupport();
+
+ ASSERT_TRUE(SetSuggestionsJavascriptArgument("{suggestions:[]}"));
+ SearchAndWaitForPreviewToShow();
+ EXPECT_EQ("", GetSuggestion());
}
-// Transition from non-search to search and make sure everything is shown
-// correctly.
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_NonSearchToSearch) {
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SetSuggestionsEmptySuggestion)) {
ASSERT_TRUE(test_server()->Start());
EnableInstant();
- GURL url(test_server()->GetURL("files/instant/empty.html"));
- ASSERT_NO_FATAL_FAILURE(FindLocationBar());
- location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec()));
- // The preview not should be active and not showing.
- ASSERT_FALSE(HasPreview());
- ASSERT_FALSE(browser()->instant()->is_displayable());
- ASSERT_EQ(NULL, browser()->instant()->GetPreviewContents());
+ SetupInstantProvider("instant.html");
+ DetermineInstantSupport();
+
+ ASSERT_TRUE(SetSuggestionsJavascriptArgument("{suggestions:[{}]}"));
+ SearchAndWaitForPreviewToShow();
+ EXPECT_EQ("", GetSuggestion());
+}
+
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(InstantCompleteNever)) {
+ ASSERT_TRUE(test_server()->Start());
+ EnableInstant();
+ SetupInstantProvider("instant.html");
+ DetermineInstantSupport();
+
+ ASSERT_TRUE(SetSuggestionsJavascriptArgument(
+ "{suggestions:[{value:'defg'}],complete_behavior:'never'}"));
+ SearchAndWaitForPreviewToShow();
+ EXPECT_EQ("defg", GetSuggestion());
+
+ EXPECT_EQ(INSTANT_COMPLETE_NEVER,
+ omnibox()->model()->instant_complete_behavior());
+ EXPECT_EQ("def", UTF16ToUTF8(omnibox()->GetText()));
+}
+
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(InstantCompleteDelayed)) {
+ ASSERT_TRUE(test_server()->Start());
+ EnableInstant();
+ SetupInstantProvider("instant.html");
+ DetermineInstantSupport();
+
+ ASSERT_TRUE(SetSuggestionsJavascriptArgument(
+ "{suggestions:[{value:'defg'}],complete_behavior:'delayed'}"));
+ SearchAndWaitForPreviewToShow();
+ EXPECT_EQ("defg", GetSuggestion());
+
+ EXPECT_EQ(INSTANT_COMPLETE_DELAYED,
+ omnibox()->model()->instant_complete_behavior());
+ EXPECT_EQ("def", UTF16ToUTF8(omnibox()->GetText()));
+}
+
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(InstantCompleteNow)) {
+ ASSERT_TRUE(test_server()->Start());
+ EnableInstant();
+ SetupInstantProvider("instant.html");
+ DetermineInstantSupport();
+
+ ASSERT_TRUE(SetSuggestionsJavascriptArgument(
+ "{suggestions:[{value:'defg'}],complete_behavior:'now'}"));
+ SearchAndWaitForPreviewToShow();
+ EXPECT_EQ("defg", GetSuggestion());
+
+ EXPECT_EQ(INSTANT_COMPLETE_NOW,
+ omnibox()->model()->instant_complete_behavior());
+ EXPECT_EQ("defg", UTF16ToUTF8(omnibox()->GetText()));
+}
+
+// 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");
+
+ omnibox()->SetUserText(ASCIIToUTF16(chrome::kChromeUICrashURL));
+ EXPECT_FALSE(preview());
+}
+
+// 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");
+
+ // 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());
+
+ // 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());
+}
+
+// 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");
+
+ GURL url(test_server()->GetURL("files/empty.html"));
+ omnibox()->SetUserText(UTF8ToUTF16(url.spec()));
+ EXPECT_FALSE(preview());
+}
+
+// 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.
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
- location_bar_->location_entry()->SetUserText(ASCIIToUTF16("def"));
-
- // Wait for the preview to navigate.
- ASSERT_NO_FATAL_FAILURE(WaitForPreviewToNavigate());
-
- // The controller is still determining if the provider really supports
- // instant.
- TabContentsWrapper* current_tab = browser()->instant()->GetPreviewContents();
- ASSERT_TRUE(current_tab);
-
- // Instant should be active.
- EXPECT_TRUE(HasPreview());
- EXPECT_FALSE(browser()->instant()->is_displayable());
-
- // Because we're waiting on the page, instant isn't current.
- ASSERT_FALSE(browser()->instant()->IsCurrent());
-
- // Bounce a message to the renderer so that we know the instant has gotten a
- // response back from the renderer as to whether the page supports instant.
- ASSERT_NO_FATAL_FAILURE(WaitForMessageToBeProcessedByRenderer(current_tab));
-
- // Reset the user text so that the page is told the text changed. We should be
- // able to nuke this once 66104 is fixed.
- location_bar_->location_entry()->SetUserText(ASCIIToUTF16("defg"));
-
- // Wait for the renderer to process it.
- ASSERT_NO_FATAL_FAILURE(WaitForMessageToBeProcessedByRenderer(current_tab));
-
- // We should have gotten a response back from the renderer that resulted in
- // committing.
- ASSERT_TRUE(HasPreview());
- ASSERT_TRUE(browser()->instant()->is_displayable());
- TabContentsWrapper* new_tab = browser()->instant()->GetPreviewContents();
- ASSERT_TRUE(new_tab);
- RenderWidgetHostView* new_rwhv =
- new_tab->tab_contents()->GetRenderWidgetHostView();
- ASSERT_TRUE(new_rwhv);
- ASSERT_TRUE(new_rwhv->IsShowing());
+ 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());
+
+ // 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());
+
+ RenderWidgetHostView* rwhv =
+ preview()->tab_contents()->GetRenderWidgetHostView();
+ EXPECT_TRUE(rwhv);
+ EXPECT_TRUE(rwhv->IsShowing());
}
// 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) {
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SearchToNonSearch)) {
ASSERT_TRUE(test_server()->Start());
EnableInstant();
- GURL url(test_server()->GetURL("files/instant/empty.html"));
- ASSERT_NO_FATAL_FAILURE(FindLocationBar());
+ SetupInstantProvider("instant.html");
+
+ ui_test_utils::WindowedNotificationObserver instant_support_observer(
+ chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED,
+ content::NotificationService::AllSources());
// Type in some search text.
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
- location_bar_->location_entry()->SetUserText(ASCIIToUTF16("def"));
+ omnibox()->SetUserText(ASCIIToUTF16("def"));
- // Load a non search url. Don't wait for the preview to navigate. It'll still
+ // Load a non search URL. Don't wait for the preview to navigate. It'll still
// end up loading in the background.
- location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec()));
+ GURL url(test_server()->GetURL("files/empty.html"));
+ omnibox()->SetUserText(UTF8ToUTF16(url.spec()));
- // Wait for the preview to navigate.
- ASSERT_NO_FATAL_FAILURE(WaitForPreviewToNavigate());
+ instant_support_observer.Wait();
+
+ // 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());
+ EXPECT_FALSE(instant()->IsCurrent());
- // Send onchange so that the page sends up suggestions.
- TabContentsWrapper* current_tab = browser()->instant()->GetPreviewContents();
+ // Send onchange so that the page sends up suggestions. See the comments in
+ // NonSearchToSearch for why this is needed.
ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
- current_tab->tab_contents()->render_view_host(), std::wstring(),
+ preview()->tab_contents()->render_view_host(), std::wstring(),
L"window.chrome.searchBox.onchange();"));
- ASSERT_NO_FATAL_FAILURE(WaitForMessageToBeProcessedByRenderer(current_tab));
+ ASSERT_TRUE(WaitForMessageToBeProcessedByRenderer());
- // Instant should be active, but not displaying
- EXPECT_TRUE(HasPreview());
- EXPECT_FALSE(browser()->instant()->is_displayable());
+ // Instant should be active, but not displaying.
+ EXPECT_TRUE(preview());
+ EXPECT_TRUE(loader()->ready());
+ EXPECT_FALSE(instant()->is_displayable());
+ EXPECT_FALSE(instant()->IsCurrent());
}
// 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) {
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SearchServerDoesntSupportInstant)) {
ASSERT_TRUE(test_server()->Start());
EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html"));
- ASSERT_NO_FATAL_FAILURE(FindLocationBar());
+ SetupInstantProvider("empty.html");
ui_test_utils::WindowedNotificationObserver tab_closed_observer(
content::NOTIFICATION_TAB_CLOSED,
content::NotificationService::AllSources());
- location_bar_->location_entry()->SetUserText(ASCIIToUTF16("d"));
- ASSERT_TRUE(browser()->instant());
- // But because we're waiting to determine if the page really supports instant
- // we shouldn't be showing the preview.
- EXPECT_FALSE(browser()->instant()->is_displayable());
- // But instant should still be active.
- EXPECT_TRUE(HasPreview());
+ omnibox()->SetUserText(ASCIIToUTF16("d"));
+ EXPECT_TRUE(preview());
// When the response comes back that the page doesn't support instant the tab
// should be closed.
tab_closed_observer.Wait();
- EXPECT_FALSE(browser()->instant()->is_displayable());
- EXPECT_FALSE(HasPreview());
- EXPECT_FALSE(browser()->instant()->IsCurrent());
-}
-
-// Verifies that Instant previews aren't shown for crash URLs.
-IN_PROC_BROWSER_TEST_F(InstantTest, CrashUrlCancelsInstant) {
- ASSERT_TRUE(test_server()->Start());
- EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html"));
- ASSERT_NO_FATAL_FAILURE(FindLocationBar());
- location_bar_->location_entry()->SetUserText(ASCIIToUTF16("chrome://crash"));
- ASSERT_TRUE(browser()->instant());
- EXPECT_FALSE(browser()->instant()->is_displayable());
+ EXPECT_FALSE(preview());
}
// 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) {
+ MAYBE(NonSearchToSearchDoesntSupportInstant)) {
ASSERT_TRUE(test_server()->Start());
EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html"));
- GURL url(test_server()->GetURL("files/instant/empty.html"));
- ASSERT_NO_FATAL_FAILURE(FindLocationBar());
- location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec()));
- // The preview should not be showing or active.
- EXPECT_FALSE(browser()->instant()->is_displayable());
- EXPECT_FALSE(HasPreview());
+ SetupInstantProvider("empty.html");
+
+ GURL url(test_server()->GetURL("files/empty.html"));
+ omnibox()->SetUserText(UTF8ToUTF16(url.spec()));
+ EXPECT_FALSE(preview());
ui_test_utils::WindowedNotificationObserver tab_closed_observer(
content::NOTIFICATION_TAB_CLOSED,
content::NotificationService::AllSources());
// Now type in some search text.
- location_bar_->location_entry()->SetUserText(ASCIIToUTF16("d"));
-
- // Instant should be active.
- ASSERT_TRUE(HasPreview());
- // Instant should not be current (it's still loading).
- EXPECT_FALSE(browser()->instant()->IsCurrent());
+ omnibox()->SetUserText(ASCIIToUTF16("d"));
+ EXPECT_TRUE(preview());
// When the response comes back that the page doesn't support instant the tab
// should be closed.
tab_closed_observer.Wait();
- EXPECT_FALSE(browser()->instant()->is_displayable());
- EXPECT_FALSE(HasPreview());
- EXPECT_FALSE(browser()->instant()->IsCurrent());
- EXPECT_EQ(NULL, browser()->instant()->GetPreviewContents());
+ EXPECT_FALSE(preview());
}
// Verifies the page was told a non-zero height.
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_ValidHeight) {
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(ValidHeight)) {
ASSERT_TRUE(test_server()->Start());
EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
- ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
- ASSERT_NO_FATAL_FAILURE(SetupPreview());
-
- ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
+ SetupInstantProvider("instant.html");
+ DetermineInstantSupport();
+ SearchAndWaitForPreviewToShow();
- int height;
+ int height = -1;
// searchBox height is not yet set during initial load.
- ASSERT_TRUE(GetIntFromJavascript(preview_,
- "window.beforeLoadSearchBox.height",
- &height));
+ ASSERT_TRUE(GetIntFromJavascript(preview()->tab_contents(),
+ "window.beforeLoadSearchBox.height", &height));
EXPECT_EQ(0, height);
// searchBox height is available by the time the page loads.
- ASSERT_TRUE(GetIntFromJavascript(preview_,
- "window.chrome.searchBox.height",
- &height));
+ ASSERT_TRUE(GetIntFromJavascript(preview()->tab_contents(),
+ "window.chrome.searchBox.height", &height));
EXPECT_GT(height, 0);
}
-// Verify that the onsubmit event is dispatched upon pressing enter.
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnSubmitEvent) {
- ASSERT_TRUE(test_server()->Start());
- EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
-
- ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
- ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
- ASSERT_NO_FATAL_FAILURE(SetupPreview());
-
- ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
- ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN));
-
- // Check that the preview contents have been committed.
- ASSERT_FALSE(browser()->instant()->GetPreviewContents());
- ASSERT_FALSE(HasPreview());
- TabContents* contents = browser()->GetSelectedTabContents();
- ASSERT_TRUE(contents);
-
- // We should have two entries. One corresponding to the page the user was
- // first on, and one for the search page.
- ASSERT_EQ(2, contents->controller().entry_count());
-
- // 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_, true));
-
- // Make sure the searchbox values were reset.
- EXPECT_EQ("true 1 0 1 true d false false 0 0",
- GetSearchStateAsString(preview_, false));
-}
-
-// Verify that the oncancel event is dispatched upon losing focus.
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnCancelEvent) {
- ASSERT_TRUE(test_server()->Start());
- EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
-
- ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
- ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
- ASSERT_NO_FATAL_FAILURE(SetupPreview());
-
- ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
- ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(),
- VIEW_ID_TAB_CONTAINER));
-
- // Check that the preview contents has been committed.
- ASSERT_FALSE(browser()->instant()->GetPreviewContents());
- ASSERT_FALSE(HasPreview());
- TabContents* contents = browser()->GetSelectedTabContents();
- ASSERT_TRUE(contents);
-
- // 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_, true));
-
- // Make sure the searchbox values were reset.
- EXPECT_EQ("true 0 1 1 true d false false 0 0",
- GetSearchStateAsString(preview_, false));
-}
-
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_InstantCompleteNever) {
- ASSERT_TRUE(test_server()->Start());
- EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
- ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
- ASSERT_NO_FATAL_FAILURE(SetupPreview());
-
- SetSuggestionsJavascriptArgument(
- preview_,
- "{suggestions:[{value:'defghij'}],complete_behavior:'never'}");
- ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
- EXPECT_STR_EQ("defghij", GetSuggestion());
- AutocompleteEditModel* edit_model = location_bar_->location_entry()->model();
- EXPECT_EQ(INSTANT_COMPLETE_NEVER, edit_model->instant_complete_behavior());
- ASSERT_EQ(ASCIIToUTF16("def"), location_bar_->location_entry()->GetText());
-}
-
-// DISABLED http://crbug.com/80118
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_InstantCompleteDelayed) {
- ASSERT_TRUE(test_server()->Start());
- EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
- ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
- ASSERT_NO_FATAL_FAILURE(SetupPreview());
-
- SetSuggestionsJavascriptArgument(
- preview_,
- "{suggestions:[{value:'defghij'}],complete_behavior:'delayed'}");
- ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
- EXPECT_STR_EQ("defghij", GetSuggestion());
- AutocompleteEditModel* edit_model = location_bar_->location_entry()->model();
- EXPECT_EQ(INSTANT_COMPLETE_DELAYED, edit_model->instant_complete_behavior());
- ASSERT_EQ(ASCIIToUTF16("def"), location_bar_->location_entry()->GetText());
-}
-
// Make sure the renderer doesn't crash if javascript is blocked.
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_DontCrashOnBlockedJS) {
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(DontCrashOnBlockedJS)) {
browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
ASSERT_TRUE(test_server()->Start());
-
- ui_test_utils::WindowedNotificationObserver instant_support_observer(
- chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED,
- content::NotificationService::AllSources());
-
EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
- ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
- // Wait for notification that the instant API has been determined.
- instant_support_observer.Wait();
- // As long as we get the notification we're good (the renderer didn't crash).
+ SetupInstantProvider("instant.html");
+
+ // 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();
}
// Makes sure window.chrome.searchbox doesn't persist when a new page is loaded.
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_DontPersistSearchbox) {
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(DontPersistSearchbox)) {
ASSERT_TRUE(test_server()->Start());
EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
-
- ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
- ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
- ASSERT_NO_FATAL_FAILURE(SetupPreview());
+ SetupInstantProvider("instant.html");
+ DetermineInstantSupport();
+ SearchAndWaitForPreviewToShow();
- ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
- ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN));
+ std::string value;
+ ASSERT_TRUE(GetStringFromJavascript(preview()->tab_contents(),
+ "window.chrome.searchBox.value", &value));
+ EXPECT_EQ("def", value);
- // Check that the preview contents have been committed.
- ASSERT_FALSE(browser()->instant()->GetPreviewContents());
- ASSERT_FALSE(HasPreview());
+ // Commit the preview.
+ ASSERT_TRUE(PressEnter());
+ EXPECT_FALSE(preview());
- TabContents* contents = browser()->GetSelectedTabContents();
- ASSERT_TRUE(contents);
+ // The searchBox actually gets cleared on commit.
+ ASSERT_TRUE(GetStringFromJavascript(browser()->GetSelectedTabContents(),
+ "window.chrome.searchBox.value", &value));
+ EXPECT_EQ("", value);
- // Navigate to a new URL. This should reset the searchbox values.
+ // Navigate to a new URL. The searchBox values should stay cleared.
ui_test_utils::NavigateToURL(
- browser(),
- GURL(test_server()->GetURL("files/instant/empty.html")));
- bool result;
- ASSERT_TRUE(GetBoolFromJavascript(
- browser()->GetSelectedTabContents(),
- "window.chrome.searchBox.value.length == 0",
- &result));
- EXPECT_TRUE(result);
+ browser(), test_server()->GetURL("files/empty.html"));
+
+ ASSERT_TRUE(GetStringFromJavascript(browser()->GetSelectedTabContents(),
+ "window.chrome.searchBox.value", &value));
+ EXPECT_EQ("", value);
}
// Tests that instant search is preloaded whenever the omnibox gets focus.
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_PreloadsInstant) {
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(PreloadsInstant)) {
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kPreloadInstantSearch);
-
- // The omnibox gets focus before the test begins. At that time, there's no
- // instant controller (which is only created after EnableInstant()), so no
- // preloading happens. Unfocus the omnibox with ClickOnView(), so that when
- // we focus it again, the controller will preload instant search.
ASSERT_TRUE(test_server()->Start());
EnableInstant();
- SetupInstantProvider("search.html");
+ 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);
- // Verify that there is no previews contents.
- EXPECT_EQ(NULL, browser()->instant()->GetPreviewContents());
+ // Verify that there is no preview.
+ EXPECT_FALSE(preview());
+ // Focusing the omnibox should cause instant to be preloaded.
ui_test_utils::WindowedNotificationObserver instant_support_observer(
chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED,
content::NotificationService::AllSources());
-
- // Focusing the omnibox should cause instant to be preloaded.
- FindLocationBar();
- location_bar_->FocusLocation(false);
- TabContentsWrapper* tab_contents = browser()->instant()->GetPreviewContents();
- EXPECT_TRUE(tab_contents);
-
+ browser()->window()->GetLocationBar()->FocusLocation(false);
instant_support_observer.Wait();
// Instant should have a preview, but not display it.
- EXPECT_TRUE(HasPreview());
- EXPECT_FALSE(browser()->instant()->is_displayable());
- EXPECT_FALSE(IsVisible(tab_contents->tab_contents()));
+ EXPECT_TRUE(preview());
+ EXPECT_FALSE(instant()->is_displayable());
+ EXPECT_FALSE(instant()->IsCurrent());
+ ASSERT_TRUE(CheckVisibilityIs(preview()->tab_contents(), false));
// Adding a new tab shouldn't delete (or recreate) the TabContentsWrapper.
+ TabContentsWrapper* preview_tab = preview();
AddBlankTabAndShow(browser());
- EXPECT_EQ(tab_contents, browser()->instant()->GetPreviewContents());
+ EXPECT_EQ(preview_tab, preview());
// Doing a search should still use the same loader for the preview.
- SetLocationBarText("def");
- EXPECT_EQ(tab_contents, browser()->instant()->GetPreviewContents());
+ SearchAndWaitForPreviewToShow();
+ EXPECT_EQ(preview_tab, preview());
// Verify that the preview is in fact showing instant search.
- EXPECT_TRUE(HasPreview());
- EXPECT_TRUE(browser()->instant()->is_displayable());
- EXPECT_TRUE(browser()->instant()->IsCurrent());
-}
-
-// Tests that instant doesn't fire for intranet paths that look like searches.
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_IntranetPathLooksLikeSearch) {
- ASSERT_TRUE(test_server()->Start());
- EnableInstant();
- SetupInstantProvider("search.html");
-
- // 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_TRUE(browser()->instant());
- EXPECT_FALSE(HasPreview());
-
- // 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"));
-
- // Instant should not have tried to load a preview for this "search".
- EXPECT_FALSE(HasPreview());
+ EXPECT_TRUE(instant()->is_displayable());
+ EXPECT_TRUE(instant()->IsCurrent());
+ ASSERT_TRUE(CheckVisibilityIs(preview()->tab_contents(), true));
}
// Tests that the instant search page's visibility is set correctly.
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_PageVisibilityTest) {
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(PageVisibilityTest)) {
ASSERT_TRUE(test_server()->Start());
EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
+ SetupInstantProvider("instant.html");
// Initially navigate to the empty page which should be visible.
ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(""));
TabContents* initial_contents = browser()->GetSelectedTabContents();
- EXPECT_TRUE(IsVisible(initial_contents));
-
- // Type something for instant to trigger and wait for preview to navigate.
- ASSERT_NO_FATAL_FAILURE(FindLocationBar());
- location_bar_->FocusLocation(false);
- SetupLocationBar();
- SetupPreview();
- SetLocationBarText("def");
- TabContents* preview_contents =
- browser()->instant()->GetPreviewContents()->tab_contents();
- EXPECT_TRUE(IsVisible(preview_contents));
- EXPECT_FALSE(IsVisible(initial_contents));
-
- // Delete the user text we should show the previous page.
- location_bar_->location_entry()->SetUserText(UTF8ToUTF16(""));
- EXPECT_FALSE(IsVisible(preview_contents));
- EXPECT_TRUE(IsVisible(initial_contents));
+
+ ASSERT_TRUE(CheckVisibilityIs(initial_contents, true));
+
+ // Type a search term and wait for the preview to appear.
+ browser()->window()->GetLocationBar()->FocusLocation(false);
+ DetermineInstantSupport();
+ SearchAndWaitForPreviewToShow();
+ TabContents* preview_contents = preview()->tab_contents();
+
+ ASSERT_TRUE(CheckVisibilityIs(preview_contents, true));
+ ASSERT_TRUE(CheckVisibilityIs(initial_contents, false));
+
+ // Deleting the user text should hide the preview.
+ omnibox()->SetUserText(string16());
+ ASSERT_TRUE(CheckVisibilityIs(preview_contents, false));
+ ASSERT_TRUE(CheckVisibilityIs(initial_contents, true));
// Set the user text back and we should see the preview again.
- location_bar_->location_entry()->SetUserText(UTF8ToUTF16("def"));
- EXPECT_TRUE(IsVisible(preview_contents));
- EXPECT_FALSE(IsVisible(initial_contents));
+ omnibox()->SetUserText(ASCIIToUTF16("def"));
+ ASSERT_TRUE(CheckVisibilityIs(preview_contents, true));
+ ASSERT_TRUE(CheckVisibilityIs(initial_contents, false));
// Commit the preview.
- SendKey(ui::VKEY_RETURN);
+ ASSERT_TRUE(PressEnter());
EXPECT_EQ(preview_contents, browser()->GetSelectedTabContents());
- EXPECT_TRUE(IsVisible(preview_contents));
+ ASSERT_TRUE(CheckVisibilityIs(preview_contents, true));
}
-
// Tests the INSTANT experiment of the field trial.
class InstantFieldTrialInstantTest : public InstantTest {
public:
@@ -995,22 +812,36 @@ class InstantFieldTrialInstantTest : public InstantTest {
};
// Tests that instant is active, even without calling EnableInstant().
-IN_PROC_BROWSER_TEST_F(InstantFieldTrialInstantTest, MAYBE_ExperimentEnabled) {
+IN_PROC_BROWSER_TEST_F(InstantFieldTrialInstantTest, MAYBE(ExperimentEnabled)) {
// Check that instant is enabled, despite not setting the preference.
Profile* profile = browser()->profile();
EXPECT_FALSE(profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled));
EXPECT_TRUE(InstantController::IsEnabled(profile));
ASSERT_TRUE(test_server()->Start());
- SetupInstantProvider("search.html");
- SetupLocationBar();
- SetupPreview();
- SetLocationBarText("def");
+ SetupInstantProvider("instant.html");
+ DetermineInstantSupport();
+ SearchAndWaitForPreviewToShow();
// Check that instant is active and showing a preview.
- EXPECT_TRUE(HasPreview());
- EXPECT_TRUE(browser()->instant()->is_displayable());
- EXPECT_TRUE(browser()->instant()->IsCurrent());
+ EXPECT_TRUE(preview());
+ EXPECT_TRUE(loader()->ready());
+ EXPECT_TRUE(instant()->is_displayable());
+ EXPECT_TRUE(instant()->IsCurrent());
+
+ // Check that the suggested text has been set in the omnibox.
+ EXPECT_EQ("defghi", GetSuggestion());
+ EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText()));
+
+ // Press <Enter> in the omnibox, causing the preview to be committed.
+ TabContents* preview_tab = preview()->tab_contents();
+ ASSERT_TRUE(PressEnter());
+
+ // The preview contents should now be the active tab contents.
+ EXPECT_FALSE(preview());
+ EXPECT_FALSE(instant()->is_displayable());
+ EXPECT_FALSE(instant()->IsCurrent());
+ EXPECT_EQ(preview_tab, browser()->GetSelectedTabContents());
}
// Tests the HIDDEN experiment of the field trial.
@@ -1023,48 +854,39 @@ class InstantFieldTrialHiddenTest : public InstantTest {
};
// Tests that instant is active, even without calling EnableInstant().
-IN_PROC_BROWSER_TEST_F(InstantFieldTrialHiddenTest, MAYBE_ExperimentEnabled) {
+IN_PROC_BROWSER_TEST_F(InstantFieldTrialHiddenTest, MAYBE(ExperimentEnabled)) {
// Check that instant is enabled, despite not setting the preference.
Profile* profile = browser()->profile();
EXPECT_FALSE(profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled));
EXPECT_TRUE(InstantController::IsEnabled(profile));
ASSERT_TRUE(test_server()->Start());
- SetupInstantProvider("search.html");
- ui_test_utils::WindowedNotificationObserver instant_support_observer(
- chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED,
- content::NotificationService::AllSources());
- SetupLocationBar();
- WaitForPreviewToNavigate();
- instant_support_observer.Wait();
+ SetupInstantProvider("instant.html");
+ DetermineInstantSupport();
// Type into the omnibox, but don't press <Enter> yet.
- location_bar_->location_entry()->SetUserText(UTF8ToUTF16("def"));
+ omnibox()->SetUserText(ASCIIToUTF16("def"));
+ ASSERT_TRUE(WaitForMessageToBeProcessedByRenderer());
// Check that instant is active, but the preview is not showing.
- EXPECT_TRUE(HasPreview());
- EXPECT_FALSE(browser()->instant()->is_displayable());
- EXPECT_FALSE(browser()->instant()->IsCurrent());
-
- TabContentsWrapper* tab_contents = browser()->instant()->GetPreviewContents();
- EXPECT_TRUE(tab_contents);
+ EXPECT_TRUE(preview());
+ EXPECT_TRUE(loader()->ready());
+ EXPECT_FALSE(instant()->is_displayable());
+ EXPECT_FALSE(instant()->IsCurrent());
- // Wait for the underlying loader to finish processing.
- WaitForMessageToBeProcessedByRenderer(tab_contents);
-
- EXPECT_STR_EQ("def", location_bar_->location_entry()->GetText());
- EXPECT_STR_EQ("defghi", GetUserText());
- EXPECT_TRUE(LoaderIsReady());
+ // Check that the suggested text hasn't actually been set in the omnibox.
+ EXPECT_EQ("defghi", GetSuggestion());
+ EXPECT_EQ("def", UTF16ToUTF8(omnibox()->GetText()));
// Press <Enter> in the omnibox, causing the preview to be committed.
- SendKey(ui::VKEY_RETURN);
+ TabContents* preview_tab = preview()->tab_contents();
+ ASSERT_TRUE(PressEnter());
// The preview contents should now be the active tab contents.
- EXPECT_FALSE(browser()->instant()->GetPreviewContents());
- EXPECT_FALSE(HasPreview());
- EXPECT_FALSE(browser()->instant()->is_displayable());
- EXPECT_FALSE(browser()->instant()->IsCurrent());
- EXPECT_EQ(tab_contents, browser()->GetSelectedTabContentsWrapper());
+ EXPECT_FALSE(preview());
+ EXPECT_FALSE(instant()->is_displayable());
+ EXPECT_FALSE(instant()->IsCurrent());
+ EXPECT_EQ(preview_tab, browser()->GetSelectedTabContents());
}
// Tests the SILENT experiment of the field trial.
@@ -1077,71 +899,37 @@ class InstantFieldTrialSilentTest : public InstantTest {
};
// Tests that instant is active, even without calling EnableInstant().
-IN_PROC_BROWSER_TEST_F(InstantFieldTrialSilentTest, MAYBE_ExperimentEnabled) {
+IN_PROC_BROWSER_TEST_F(InstantFieldTrialSilentTest, MAYBE(ExperimentEnabled)) {
// Check that instant is enabled, despite not setting the preference.
Profile* profile = browser()->profile();
EXPECT_FALSE(profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled));
EXPECT_TRUE(InstantController::IsEnabled(profile));
ASSERT_TRUE(test_server()->Start());
- SetupInstantProvider("search.html");
- ui_test_utils::WindowedNotificationObserver instant_support_observer(
- chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED,
- content::NotificationService::AllSources());
- SetupLocationBar();
- WaitForPreviewToNavigate();
- instant_support_observer.Wait();
+ SetupInstantProvider("instant.html");
+ DetermineInstantSupport();
// Type into the omnibox, but don't press <Enter> yet.
- location_bar_->location_entry()->SetUserText(UTF8ToUTF16("def"));
+ omnibox()->SetUserText(ASCIIToUTF16("def"));
+ ASSERT_TRUE(WaitForMessageToBeProcessedByRenderer());
// Check that instant is active, but the preview is not showing.
- EXPECT_TRUE(HasPreview());
- EXPECT_FALSE(browser()->instant()->is_displayable());
- EXPECT_FALSE(browser()->instant()->IsCurrent());
+ EXPECT_TRUE(preview());
+ EXPECT_FALSE(loader()->ready());
+ EXPECT_FALSE(instant()->is_displayable());
+ EXPECT_FALSE(instant()->IsCurrent());
- TabContentsWrapper* tab_contents = browser()->instant()->GetPreviewContents();
- EXPECT_TRUE(tab_contents);
-
- // Wait for the underlying loader to finish processing.
- WaitForMessageToBeProcessedByRenderer(tab_contents);
-
- EXPECT_STR_EQ("def", location_bar_->location_entry()->GetText());
- EXPECT_STR_EQ("", GetUserText());
- EXPECT_FALSE(LoaderIsReady());
+ // There are no suggestions, as the loader hasn't seen the query yet.
+ EXPECT_EQ("", GetSuggestion());
+ EXPECT_EQ("def", UTF16ToUTF8(omnibox()->GetText()));
// Press <Enter> in the omnibox, causing the preview to be committed.
- SendKey(ui::VKEY_RETURN);
+ TabContents* preview_tab = preview()->tab_contents();
+ ASSERT_TRUE(PressEnter());
// The preview contents should now be the active tab contents.
- EXPECT_FALSE(browser()->instant()->GetPreviewContents());
- EXPECT_FALSE(HasPreview());
- EXPECT_FALSE(browser()->instant()->is_displayable());
- EXPECT_FALSE(browser()->instant()->IsCurrent());
- EXPECT_EQ(tab_contents, browser()->GetSelectedTabContentsWrapper());
-}
-
-// Tests the SearchToNonSearch scenario under the SILENT field trial.
-IN_PROC_BROWSER_TEST_F(InstantFieldTrialSilentTest, MAYBE_SearchToNonSearch) {
- ASSERT_TRUE(test_server()->Start());
- ui_test_utils::WindowedNotificationObserver instant_support_observer(
- chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED,
- content::NotificationService::AllSources());
-
- // Type in some search text.
- SetupInstantProvider("search.html");
- SetupLocationBar();
-
- // Load a non-search URL; don't wait for the preview to navigate.
- GURL url(test_server()->GetURL("files/instant/empty.html"));
- location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec()));
-
- // Wait for the preview to navigate.
- WaitForPreviewToNavigate();
- instant_support_observer.Wait();
-
- // Instant should be active, but not displayable or committable.
- EXPECT_TRUE(HasPreview());
- EXPECT_FALSE(browser()->instant()->is_displayable());
- EXPECT_FALSE(browser()->instant()->PrepareForCommit());
+ EXPECT_FALSE(preview());
+ EXPECT_FALSE(instant()->is_displayable());
+ EXPECT_FALSE(instant()->IsCurrent());
+ EXPECT_EQ(preview_tab, browser()->GetSelectedTabContents());
}
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc
index 07fdc19..b1292b5 100644
--- a/chrome/browser/instant/instant_controller.cc
+++ b/chrome/browser/instant/instant_controller.cc
@@ -226,7 +226,7 @@ void InstantController::Hide() {
}
}
-bool InstantController::IsCurrent() {
+bool InstantController::IsCurrent() const {
// TODO(mmenke): See if we can do something more intelligent in the
// navigation pending case.
return is_displayable_ && !loader_->IsNavigationPending() &&
@@ -410,7 +410,7 @@ void InstantController::CompleteRelease(TabContentsWrapper* tab) {
tab->blocked_content_tab_helper()->SetAllContentsBlocked(false);
}
-TabContentsWrapper* InstantController::GetPreviewContents() {
+TabContentsWrapper* InstantController::GetPreviewContents() const {
return loader_.get() ? loader_->preview_contents() : NULL;
}
diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h
index 8e3c238..39e44a8 100644
--- a/chrome/browser/instant/instant_controller.h
+++ b/chrome/browser/instant/instant_controller.h
@@ -101,7 +101,7 @@ class InstantController : public InstantLoaderDelegate {
// false a commit does not result in committing the last url passed to update.
// A return value of false happens if we're in the process of determining if
// the page supports instant.
- bool IsCurrent();
+ bool IsCurrent() const;
// Returns true if the caller should proceed with committing the preview. A
// return value of false means that there is no valid preview to commit. This
@@ -149,7 +149,7 @@ class InstantController : public InstantLoaderDelegate {
TabContentsWrapper* tab_contents() const { return tab_contents_; }
// The preview TabContents; may be null.
- TabContentsWrapper* GetPreviewContents();
+ TabContentsWrapper* GetPreviewContents() const;
// Returns true if the preview TabContents is ready to be displayed. In some
// situations this may return false yet GetPreviewContents() returns non-NULL.
diff --git a/chrome/test/data/instant/search.html b/chrome/test/data/instant.html
index f6539f7..513a007 100644
--- a/chrome/test/data/instant/search.html
+++ b/chrome/test/data/instant.html
@@ -1,7 +1,6 @@
<html>
<body>
<h1>Instant</h1>
-<div id=log></div>
<script>
window.chrome.sv = true;
@@ -10,23 +9,14 @@ window.onchangecalls = 0;
window.oncancelcalls = 0;
window.onresizecalls = 0;
-var searchBox = window.chrome.searchBox || {};
-window.lastSearchBox = {};
-
Object.prototype.clone = function() {
- var copy = {}
+ var copy = {};
for (var prop in this) copy[prop] = this[prop];
return copy;
};
-var CloneSearchBox = function() {
- window.lastSearchBox = {};
- for (var key in searchBox)
- window.lastSearchBox[key] = searchBox[key];
-};
-
-window.beforeLoadSearchBox = searchBox.clone();
-window.lastSearchBox = searchBox.clone();
+window.beforeLoadSearchBox = window.chrome.searchBox.clone();
+window.lastSearchBox = window.chrome.searchBox.clone();
window.setSuggestionsArgument = {
suggestions: [
@@ -35,20 +25,20 @@ window.setSuggestionsArgument = {
};
window.chrome.searchBox.onsubmit = function() {
- searchBox.setSuggestions(setSuggestionsArgument);
- window.lastSearchBox = searchBox.clone();
+ window.chrome.searchBox.setSuggestions(setSuggestionsArgument);
+ window.lastSearchBox = window.chrome.searchBox.clone();
window.onsubmitcalls++;
};
window.chrome.searchBox.onchange = function() {
- searchBox.setSuggestions(setSuggestionsArgument);
- window.lastSearchBox = searchBox.clone();
+ window.chrome.searchBox.setSuggestions(setSuggestionsArgument);
+ window.lastSearchBox = window.chrome.searchBox.clone();
window.onchangecalls++;
};
window.chrome.searchBox.oncancel = function() {
- searchBox.setSuggestions(setSuggestionsArgument);
- window.lastSearchBox = searchBox.clone();
+ window.chrome.searchBox.setSuggestions(setSuggestionsArgument);
+ window.lastSearchBox = window.chrome.searchBox.clone();
window.oncancelcalls++;
};