| Index: chrome/browser/instant/instant_browsertest.cc
|
| diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc
|
| index 3813c54e95b2cb52c74faffa03dd560e8dcfd302..00f667416aa4466efed9813769e63d916d4c599b 100644
|
| --- a/chrome/browser/instant/instant_browsertest.cc
|
| +++ b/chrome/browser/instant/instant_browsertest.cc
|
| @@ -5,157 +5,28 @@
|
| #include "chrome/browser/content_settings/host_content_settings_map.h"
|
| #include "chrome/browser/history/history_service_factory.h"
|
| #include "chrome/browser/instant/instant_loader.h"
|
| -#include "chrome/browser/instant/instant_model_observer.h"
|
| -#include "chrome/browser/prefs/pref_service.h"
|
| +#include "chrome/browser/instant/instant_test_utils.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/search_engines/template_url_service.h"
|
| #include "chrome/browser/search_engines/template_url_service_factory.h"
|
| #include "chrome/browser/task_manager/task_manager.h"
|
| #include "chrome/browser/task_manager/task_manager_browsertest_util.h"
|
| #include "chrome/browser/ui/browser_commands.h"
|
| -#include "chrome/browser/ui/browser_instant_controller.h"
|
| #include "chrome/browser/ui/browser_tabstrip.h"
|
| -#include "chrome/browser/ui/browser_window.h"
|
| -#include "chrome/browser/ui/omnibox/location_bar.h"
|
| -#include "chrome/browser/ui/omnibox/omnibox_view.h"
|
| #include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| -#include "chrome/common/chrome_notification_types.h"
|
| -#include "chrome/common/pref_names.h"
|
| #include "chrome/test/base/interactive_test_utils.h"
|
| -#include "chrome/test/base/in_process_browser_test.h"
|
| #include "chrome/test/base/ui_test_utils.h"
|
| -#include "content/public/browser/notification_service.h"
|
| -#include "content/public/browser/render_process_host.h"
|
| #include "content/public/browser/web_contents.h"
|
| -#include "content/public/common/result_codes.h"
|
| -#include "content/public/test/browser_test_utils.h"
|
| #include "grit/generated_resources.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
|
|
| -class InstantTestModelObserver : public InstantModelObserver {
|
| - public:
|
| - InstantTestModelObserver(const InstantModel* model,
|
| - chrome::search::Mode::Type desired_mode_type)
|
| - : model_(model),
|
| - desired_mode_type_(desired_mode_type) {
|
| - model_->AddObserver(this);
|
| - }
|
| -
|
| - ~InstantTestModelObserver() {
|
| - model_->RemoveObserver(this);
|
| - }
|
| -
|
| - void WaitUntilDesiredPreviewState() {
|
| - run_loop_.Run();
|
| - }
|
| -
|
| - // Overridden from InstantModelObserver:
|
| - virtual void PreviewStateChanged(const InstantModel& model) OVERRIDE {
|
| - if (model.mode().mode == desired_mode_type_)
|
| - run_loop_.Quit();
|
| - }
|
| -
|
| - private:
|
| - const InstantModel* const model_;
|
| - const chrome::search::Mode::Type desired_mode_type_;
|
| - base::RunLoop run_loop_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(InstantTestModelObserver);
|
| -};
|
| -
|
| -class InstantTest : public InProcessBrowserTest {
|
| +class InstantTest : public InstantTestBase {
|
| protected:
|
| virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
|
| ASSERT_TRUE(test_server()->Start());
|
| instant_url_ = test_server()->GetURL("files/instant.html");
|
| }
|
|
|
| - void SetupInstant() {
|
| - TemplateURLService* service =
|
| - TemplateURLServiceFactory::GetForProfile(browser()->profile());
|
| - ui_test_utils::WaitForTemplateURLServiceToLoad(service);
|
| -
|
| - TemplateURLData data;
|
| - data.SetURL("http://does/not/exist?q={searchTerms}");
|
| - data.instant_url = instant_url_.spec();
|
| - data.safe_for_autoreplace = true;
|
| -
|
| - TemplateURL* template_url = new TemplateURL(browser()->profile(), data);
|
| - service->Add(template_url); // Takes ownership of |template_url|.
|
| - service->SetDefaultSearchProvider(template_url);
|
| -
|
| - browser()->profile()->GetPrefs()->SetBoolean(prefs::kInstantEnabled, true);
|
| - }
|
| -
|
| - InstantController* instant() {
|
| - return browser()->instant_controller()->instant();
|
| - }
|
| -
|
| - OmniboxView* omnibox() {
|
| - return browser()->window()->GetLocationBar()->GetLocationEntry();
|
| - }
|
| -
|
| - void KillInstantRenderView() {
|
| - base::KillProcess(
|
| - instant()->GetPreviewContents()->GetRenderProcessHost()->GetHandle(),
|
| - content::RESULT_CODE_KILLED,
|
| - false);
|
| - }
|
| -
|
| - void FocusOmnibox() {
|
| - // If the omnibox already has focus, just notify Instant.
|
| - if (omnibox()->model()->has_focus()) {
|
| - instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_VISIBLE,
|
| - OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL);
|
| - } else {
|
| - browser()->window()->GetLocationBar()->FocusLocation(false);
|
| - }
|
| - }
|
| -
|
| - void FocusOmniboxAndWaitForInstantSupport() {
|
| - content::WindowedNotificationObserver observer(
|
| - chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED,
|
| - content::NotificationService::AllSources());
|
| - FocusOmnibox();
|
| - observer.Wait();
|
| - }
|
| -
|
| - void SetOmniboxText(const std::string& text) {
|
| - FocusOmnibox();
|
| - omnibox()->SetUserText(UTF8ToUTF16(text));
|
| - }
|
| -
|
| - void SetOmniboxTextAndWaitForInstantToShow(const std::string& text) {
|
| - InstantTestModelObserver observer(
|
| - instant()->model(), chrome::search::Mode::MODE_SEARCH_SUGGESTIONS);
|
| - SetOmniboxText(text);
|
| - observer.WaitUntilDesiredPreviewState();
|
| - }
|
| -
|
| - std::string WrapScript(const std::string& script) const {
|
| - return "domAutomationController.send(" + script + ")";
|
| - }
|
| -
|
| - bool GetBoolFromJS(content::WebContents* contents,
|
| - const std::string& script,
|
| - bool* result) WARN_UNUSED_RESULT {
|
| - return content::ExecuteScriptAndExtractBool(contents, WrapScript(script),
|
| - result);
|
| - }
|
| -
|
| - bool GetIntFromJS(content::WebContents* contents,
|
| - const std::string& script,
|
| - int* result) WARN_UNUSED_RESULT {
|
| - return content::ExecuteScriptAndExtractInt(contents, WrapScript(script),
|
| - result);
|
| - }
|
| -
|
| - bool GetStringFromJS(content::WebContents* contents,
|
| - const std::string& script,
|
| - std::string* result) WARN_UNUSED_RESULT {
|
| - return content::ExecuteScriptAndExtractString(contents, WrapScript(script),
|
| - result);
|
| - }
|
| -
|
| bool UpdateSearchState(content::WebContents* contents) WARN_UNUSED_RESULT {
|
| return GetIntFromJS(contents, "onvisibilitycalls", &onvisibilitycalls_) &&
|
| GetIntFromJS(contents, "onchangecalls", &onchangecalls_) &&
|
| @@ -167,21 +38,6 @@ class InstantTest : public InProcessBrowserTest {
|
| GetIntFromJS(contents, "height", &height_);
|
| }
|
|
|
| - bool ExecuteScript(const std::string& script) WARN_UNUSED_RESULT {
|
| - return content::ExecuteScript(instant()->GetPreviewContents(), script);
|
| - }
|
| -
|
| - bool CheckVisibilityIs(content::WebContents* contents,
|
| - bool expected) 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(contents, "!document.webkitHidden", &actual) &&
|
| - actual == expected;
|
| - }
|
| -
|
| - GURL instant_url_;
|
| -
|
| int onvisibilitycalls_;
|
| int onchangecalls_;
|
| int onsubmitcalls_;
|
| @@ -242,6 +98,37 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OmniboxFocusLoadsInstant) {
|
| EXPECT_EQ(preview_tab, instant()->GetPreviewContents());
|
| }
|
|
|
| +// Test that Instant works when the URL is set via a TemplateURL (as opposed to
|
| +// --instant-url).
|
| +IN_PROC_BROWSER_TEST_F(InstantTest, SetWithTemplateURL) {
|
| + ASSERT_NO_FATAL_FAILURE(SetupInstantUsingTemplateURL());
|
| +
|
| + // Explicitly unfocus the omnibox.
|
| + 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_FALSE(omnibox()->model()->has_focus());
|
| +
|
| + // Delete any existing preview.
|
| + instant()->loader_.reset();
|
| + EXPECT_FALSE(instant()->GetPreviewContents());
|
| +
|
| + // Refocus the omnibox. The InstantController should've preloaded Instant.
|
| + FocusOmniboxAndWaitForInstantSupport();
|
| +
|
| + EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
|
| + EXPECT_TRUE(omnibox()->model()->has_focus());
|
| +
|
| + content::WebContents* preview_tab = instant()->GetPreviewContents();
|
| + EXPECT_TRUE(preview_tab);
|
| +
|
| + // Check that the page supports Instant, but it isn't showing.
|
| + EXPECT_TRUE(instant()->loader_->supports_instant());
|
| + EXPECT_FALSE(instant()->IsPreviewingSearchResults());
|
| + EXPECT_TRUE(instant()->model()->mode().is_default());
|
| +}
|
| +
|
| // Flakes on Windows: http://crbug.com/170677
|
| #if defined(OS_WIN)
|
| #define MAYBE_OnChangeEvent DISABLED_OnChangeEvent
|
|
|