| Index: chrome/browser/instant/instant_test_utils.cc
|
| diff --git a/chrome/browser/instant/instant_test_utils.cc b/chrome/browser/instant/instant_test_utils.cc
|
| index 01de31c91480a72b60ecedfebc8805bd6bbe4611..299e001714dbd67d58226fb8c0b30da03660c7e8 100644
|
| --- a/chrome/browser/instant/instant_test_utils.cc
|
| +++ b/chrome/browser/instant/instant_test_utils.cc
|
| @@ -4,18 +4,24 @@
|
|
|
| #include "chrome/browser/instant/instant_test_utils.h"
|
|
|
| -#include "base/command_line.h"
|
| -#include "base/prefs/pref_service.h"
|
| -#include "chrome/browser/profiles/profile.h"
|
| +#include "base/path_service.h"
|
| +#include "chrome/browser/instant/instant_controller.h"
|
| +#include "chrome/browser/instant/instant_overlay_model.h"
|
| +#include "chrome/browser/instant/instant_preloader.h"
|
| +#include "chrome/browser/instant/instant_service.h"
|
| +#include "chrome/browser/instant/instant_service_factory.h"
|
| #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_instant_controller.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/common/chrome_constants.h"
|
| #include "chrome/common/chrome_notification_types.h"
|
| -#include "chrome/common/chrome_switches.h"
|
| -#include "chrome/common/pref_names.h"
|
| -#include "chrome/test/base/interactive_test_utils.h"
|
| +#include "chrome/common/chrome_paths.h"
|
| +#include "chrome/test/base/testing_profile.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"
|
| @@ -29,66 +35,94 @@ std::string WrapScript(const std::string& script) {
|
|
|
| } // namespace
|
|
|
| -// InstantTestModelObserver --------------------------------------------------
|
| +// InstantTestOverlayModelObserver --------------------------------------------
|
|
|
| -InstantTestModelObserver::InstantTestModelObserver(
|
| - InstantOverlayModel* model,
|
| - chrome::search::Mode::Type desired_mode_type)
|
| - : model_(model),
|
| - desired_mode_type_(desired_mode_type) {
|
| - model_->AddObserver(this);
|
| +InstantTestOverlayModelObserver::InstantTestOverlayModelObserver(
|
| + InstantController* controller,
|
| + bool expected_to_show)
|
| + : controller_(controller),
|
| + expected_to_show_(expected_to_show) {
|
| + controller_->AddOverlayModelObserver(this);
|
| }
|
|
|
| -InstantTestModelObserver::~InstantTestModelObserver() {
|
| - model_->RemoveObserver(this);
|
| +InstantTestOverlayModelObserver::~InstantTestOverlayModelObserver() {
|
| + controller_->RemoveOverlayModelObserver(this);
|
| }
|
|
|
| -void InstantTestModelObserver::WaitForDesiredOverlayState() {
|
| +void InstantTestOverlayModelObserver::WaitForDesiredOverlayState() {
|
| run_loop_.Run();
|
| }
|
|
|
| -void InstantTestModelObserver::OverlayStateChanged(
|
| +void InstantTestOverlayModelObserver::OverlayStateChanged(
|
| const InstantOverlayModel& model) {
|
| - if (model.mode().mode == desired_mode_type_)
|
| + if (expected_to_show_ == (model.contents() != NULL))
|
| run_loop_.Quit();
|
| }
|
|
|
| -// InstantTestBase -----------------------------------------------------------
|
| +// InstantTestBase ------------------------------------------------------------
|
|
|
| -void InstantTestBase::SetupInstant(Browser* browser) {
|
| - browser_ = browser;
|
| +InstantTestBase::InstantTestBase()
|
| + : https_test_server_(
|
| + net::TestServer::TYPE_HTTPS,
|
| + net::BaseTestServer::SSLOptions(),
|
| + base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))),
|
| + browser_(NULL) {
|
| +}
|
| +
|
| +InstantTestBase::~InstantTestBase() {
|
| +}
|
| +
|
| +// Set up the profile dir to explicitly null out any Instant URL. Without this,
|
| +// the dir ends up with a default "google.com" Instant URL which we might try
|
| +// to load at startup.
|
| +bool InstantTestBase::DisableInstantOnStartup() {
|
| + base::FilePath profile_dir;
|
| + if (!PathService::Get(chrome::DIR_USER_DATA, &profile_dir))
|
| + return false;
|
| +
|
| + profile_dir = profile_dir.AppendASCII(TestingProfile::kTestUserProfileDir);
|
| + if (!file_util::CreateDirectory(profile_dir))
|
| + return false;
|
| +
|
| + base::FilePath source_dir;
|
| + if (!PathService::Get(chrome::DIR_TEST_DATA, &source_dir))
|
| + return false;
|
| +
|
| + source_dir = source_dir.AppendASCII("profiles").AppendASCII("instant");
|
| +
|
| + if (!file_util::CopyFile(source_dir.AppendASCII("Preferences"),
|
| + profile_dir.Append(chrome::kPreferencesFilename)))
|
| + return false;
|
| +
|
| + if (!file_util::CopyFile(source_dir.AppendASCII("Web Data"),
|
| + profile_dir.Append(chrome::kWebDataFilename)))
|
| + return false;
|
| +
|
| + return true;
|
| +}
|
| +
|
| +void InstantTestBase::SetupDefaultSearchProvider(
|
| + const TemplateURLData& template_data) {
|
| TemplateURLService* service =
|
| TemplateURLServiceFactory::GetForProfile(browser_->profile());
|
| ui_test_utils::WaitForTemplateURLServiceToLoad(service);
|
|
|
| - TemplateURLData data;
|
| - // Necessary to use exact URL for both the main URL and the alternate URL for
|
| - // search term extraction to work in InstantExtended.
|
| - data.SetURL(instant_url_.spec() + "q={searchTerms}");
|
| - data.instant_url = instant_url_.spec();
|
| - data.alternate_urls.push_back(instant_url_.spec() + "#q={searchTerms}");
|
| - data.search_terms_replacement_key = "strk";
|
| -
|
| - TemplateURL* template_url = new TemplateURL(browser_->profile(), data);
|
| + TemplateURL* template_url =
|
| + new TemplateURL(browser_->profile(), template_data);
|
| service->Add(template_url); // Takes ownership of |template_url|.
|
| service->SetDefaultSearchProvider(template_url);
|
| +}
|
|
|
| - browser_->profile()->GetPrefs()->SetBoolean(prefs::kInstantEnabled, true);
|
| -
|
| - // TODO(shishir): Fix this ugly hack.
|
| - instant()->SetInstantEnabled(false, true);
|
| - instant()->SetInstantEnabled(true, false);
|
| +InstantService* InstantTestBase::service() const {
|
| + return InstantServiceFactory::GetForProfile(browser_->profile());
|
| }
|
|
|
| -void InstantTestBase::Init(const GURL& instant_url) {
|
| - instant_url_ = instant_url;
|
| +InstantController* InstantTestBase::instant() const {
|
| + return browser_->instant_controller()->instant();
|
| }
|
|
|
| -void InstantTestBase::KillInstantRenderView() {
|
| - base::KillProcess(
|
| - instant()->GetOverlayContents()->GetRenderProcessHost()->GetHandle(),
|
| - content::RESULT_CODE_KILLED,
|
| - false);
|
| +OmniboxView* InstantTestBase::omnibox() const {
|
| + return browser_->window()->GetLocationBar()->GetLocationEntry();
|
| }
|
|
|
| void InstantTestBase::FocusOmnibox() {
|
| @@ -103,22 +137,11 @@ void InstantTestBase::FocusOmnibox() {
|
|
|
| void InstantTestBase::FocusOmniboxAndWaitForInstantSupport() {
|
| content::WindowedNotificationObserver observer(
|
| - chrome::NOTIFICATION_INSTANT_OVERLAY_SUPPORT_DETERMINED,
|
| - content::NotificationService::AllSources());
|
| - FocusOmnibox();
|
| - observer.Wait();
|
| -}
|
| -
|
| -void InstantTestBase::FocusOmniboxAndWaitForInstantExtendedSupport() {
|
| - content::WindowedNotificationObserver ntp_observer(
|
| - chrome::NOTIFICATION_INSTANT_NTP_SUPPORT_DETERMINED,
|
| - content::NotificationService::AllSources());
|
| - content::WindowedNotificationObserver overlay_observer(
|
| - chrome::NOTIFICATION_INSTANT_OVERLAY_SUPPORT_DETERMINED,
|
| + chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED,
|
| content::NotificationService::AllSources());
|
| FocusOmnibox();
|
| - ntp_observer.Wait();
|
| - overlay_observer.Wait();
|
| + if (!service()->preloader()->supports_instant())
|
| + observer.Wait();
|
| }
|
|
|
| void InstantTestBase::SetOmniboxText(const std::string& text) {
|
| @@ -128,8 +151,7 @@ void InstantTestBase::SetOmniboxText(const std::string& text) {
|
|
|
| void InstantTestBase::SetOmniboxTextAndWaitForOverlayToShow(
|
| const std::string& text) {
|
| - InstantTestModelObserver observer(
|
| - instant()->model(), chrome::search::Mode::MODE_SEARCH_SUGGESTIONS);
|
| + InstantTestOverlayModelObserver observer(instant(), true);
|
| SetOmniboxText(text);
|
| observer.WaitForDesiredOverlayState();
|
| }
|
| @@ -155,10 +177,6 @@ bool InstantTestBase::GetStringFromJS(content::WebContents* contents,
|
| contents, WrapScript(script), result);
|
| }
|
|
|
| -bool InstantTestBase::ExecuteScript(const std::string& script) {
|
| - return content::ExecuteScript(instant()->GetOverlayContents(), script);
|
| -}
|
| -
|
| bool InstantTestBase::CheckVisibilityIs(content::WebContents* contents,
|
| bool expected) {
|
| bool actual = !expected; // Purposely start with a mis-match.
|
| @@ -168,21 +186,20 @@ bool InstantTestBase::CheckVisibilityIs(content::WebContents* contents,
|
| actual == expected;
|
| }
|
|
|
| -bool InstantTestBase::HasUserInputInProgress() {
|
| - return omnibox()->model()->user_input_in_progress_;
|
| -}
|
| -
|
| -bool InstantTestBase::HasTemporaryText() {
|
| - return omnibox()->model()->has_temporary_text_;
|
| +void InstantTestBase::KillOverlayRenderView() {
|
| + base::KillProcess(
|
| + instant()->GetOverlayContents()->GetRenderProcessHost()->GetHandle(),
|
| + content::RESULT_CODE_KILLED,
|
| + false);
|
| }
|
|
|
| -bool InstantTestBase::LoadImage(content::RenderViewHost* rvh,
|
| - const std::string& image,
|
| +bool InstantTestBase::LoadImage(content::WebContents* contents,
|
| + const std::string& image_url,
|
| bool* loaded) {
|
| - std::string js_chrome =
|
| + std::string script =
|
| "var img = document.createElement('img');"
|
| "img.onerror = function() { domAutomationController.send(false); };"
|
| "img.onload = function() { domAutomationController.send(true); };"
|
| - "img.src = '" + image + "';";
|
| - return content::ExecuteScriptAndExtractBool(rvh, js_chrome, loaded);
|
| + "img.src = '" + image_url + "';";
|
| + return content::ExecuteScriptAndExtractBool(contents, script, loaded);
|
| }
|
|
|