| 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 eb288bcef31f7bdcfab38934211325c931b6ccc0..83f4a0d1497e7400ec1f83e0635cfc6c16007ff4 100644
 | 
| --- a/chrome/browser/instant/instant_test_utils.cc
 | 
| +++ b/chrome/browser/instant/instant_test_utils.cc
 | 
| @@ -4,13 +4,22 @@
 | 
|  
 | 
|  #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_loader.h"
 | 
| +#include "chrome/browser/instant/instant_model.h"
 | 
| +#include "chrome/browser/instant/instant_service.h"
 | 
| +#include "chrome/browser/instant/instant_service_factory.h"
 | 
|  #include "chrome/browser/search_engines/template_url_service.h"
 | 
|  #include "chrome/browser/search_engines/template_url_service_factory.h"
 | 
| -#include "chrome/common/pref_names.h"
 | 
| -#include "chrome/test/base/interactive_test_utils.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_paths.h"
 | 
| +#include "chrome/test/base/testing_profile.h"
 | 
|  #include "chrome/test/base/ui_test_utils.h"
 | 
|  #include "content/public/browser/render_process_host.h"
 | 
|  #include "content/public/browser/web_contents.h"
 | 
| @@ -23,62 +32,127 @@ std::string WrapScript(const std::string& script) {
 | 
|    return "domAutomationController.send(" + script + ")";
 | 
|  }
 | 
|  
 | 
| +class InstantTestServiceObserver : public InstantServiceObserver {
 | 
| + public:
 | 
| +  explicit InstantTestServiceObserver(InstantService* service)
 | 
| +      : service_(service) {
 | 
| +    service_->AddObserver(this);
 | 
| +  }
 | 
| +
 | 
| +  virtual ~InstantTestServiceObserver() {
 | 
| +    service_->RemoveObserver(this);
 | 
| +  }
 | 
| +
 | 
| +  void WaitForInstantSupport() {
 | 
| +    run_loop_.Run();
 | 
| +  }
 | 
| +
 | 
| + private:
 | 
| +  // Overridden from InstantServiceObserver:
 | 
| +  virtual void InstantStatusChanged() OVERRIDE {}
 | 
| +  virtual void ThemeInfoChanged() OVERRIDE {}
 | 
| +  virtual void MostVisitedItemsChanged() OVERRIDE {}
 | 
| +  virtual void InstantSupportDecided() OVERRIDE {
 | 
| +    run_loop_.Quit();
 | 
| +  }
 | 
| +
 | 
| +  InstantService* const service_;
 | 
| +  base::RunLoop run_loop_;
 | 
| +
 | 
| +  DISALLOW_COPY_AND_ASSIGN(InstantTestServiceObserver);
 | 
| +};
 | 
| +
 | 
|  }  // namespace
 | 
|  
 | 
| -// InstantTestModelObserver --------------------------------------------------
 | 
| +// InstantTestModelObserver ---------------------------------------------------
 | 
|  
 | 
|  InstantTestModelObserver::InstantTestModelObserver(
 | 
| -    InstantModel* model,
 | 
| -    chrome::search::Mode::Type desired_mode_type)
 | 
| -    : model_(model),
 | 
| -      desired_mode_type_(desired_mode_type) {
 | 
| -  model_->AddObserver(this);
 | 
| +    InstantController* controller,
 | 
| +    const InstantModel* desired_model)
 | 
| +    : controller_(controller),
 | 
| +      desired_model_(desired_model) {
 | 
| +  controller_->AddModelObserver(this);
 | 
|  }
 | 
|  
 | 
|  InstantTestModelObserver::~InstantTestModelObserver() {
 | 
| -  model_->RemoveObserver(this);
 | 
| +  controller_->RemoveModelObserver(this);
 | 
|  }
 | 
|  
 | 
| -void InstantTestModelObserver::WaitUntilDesiredPreviewState() {
 | 
| +void InstantTestModelObserver::WaitForDesiredOverlayState() {
 | 
|    run_loop_.Run();
 | 
|  }
 | 
|  
 | 
| -void InstantTestModelObserver::PreviewStateChanged(const InstantModel& model) {
 | 
| -  if (model.mode().mode == desired_mode_type_)
 | 
| +void InstantTestModelObserver::OverlayStateChanged(const InstantModel& model) {
 | 
| +  if (model.overlay() == desired_model_->overlay() &&
 | 
| +      model.height() == desired_model_->height() &&
 | 
| +      model.is_height_in_pixels() == desired_model_->is_height_in_pixels())
 | 
|      run_loop_.Quit();
 | 
|  }
 | 
|  
 | 
| -// InstantTestBase -----------------------------------------------------------
 | 
| +// InstantTestBase ------------------------------------------------------------
 | 
| +
 | 
| +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;
 | 
|  
 | 
| -void InstantTestBase::SetupInstant() {
 | 
| +  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());
 | 
| +      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);
 | 
| +InstantService* InstantTestBase::service() const {
 | 
| +  return InstantServiceFactory::GetForProfile(browser_->profile());
 | 
| +}
 | 
|  
 | 
| -  // TODO(shishir): Fix this ugly hack.
 | 
| -  instant()->SetInstantEnabled(false, true);
 | 
| -  instant()->SetInstantEnabled(true, false);
 | 
| +InstantController* InstantTestBase::instant() const {
 | 
| +  return browser_->instant_controller()->instant();
 | 
|  }
 | 
|  
 | 
| -void InstantTestBase::KillInstantRenderView() {
 | 
| -  base::KillProcess(
 | 
| -      instant()->GetPreviewContents()->GetRenderProcessHost()->GetHandle(),
 | 
| -      content::RESULT_CODE_KILLED,
 | 
| -      false);
 | 
| +OmniboxView* InstantTestBase::omnibox() const {
 | 
| +  return browser_->window()->GetLocationBar()->GetLocationEntry();
 | 
|  }
 | 
|  
 | 
|  void InstantTestBase::FocusOmnibox() {
 | 
| @@ -87,21 +161,29 @@ void InstantTestBase::FocusOmnibox() {
 | 
|      instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_VISIBLE,
 | 
|                                     OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL);
 | 
|    } else {
 | 
| -    browser()->window()->GetLocationBar()->FocusLocation(false);
 | 
| +    browser_->window()->GetLocationBar()->FocusLocation(false);
 | 
|    }
 | 
|  }
 | 
|  
 | 
| +void InstantTestBase::FocusOmniboxAndWaitForInstantSupport() {
 | 
| +  InstantTestServiceObserver observer(service());
 | 
| +  FocusOmnibox();
 | 
| +  if (!service()->loader()->supports_instant())
 | 
| +    observer.WaitForInstantSupport();
 | 
| +}
 | 
| +
 | 
|  void InstantTestBase::SetOmniboxText(const std::string& text) {
 | 
|    FocusOmnibox();
 | 
|    omnibox()->SetUserText(UTF8ToUTF16(text));
 | 
|  }
 | 
|  
 | 
| -void InstantTestBase::SetOmniboxTextAndWaitForInstantToShow(
 | 
| +void InstantTestBase::SetOmniboxTextAndWaitForOverlayToShow(
 | 
|      const std::string& text) {
 | 
| -  InstantTestModelObserver observer(
 | 
| -      instant()->model(), chrome::search::Mode::MODE_SEARCH_SUGGESTIONS);
 | 
| +  InstantModel desired_model(service());
 | 
| +  desired_model.SetOverlayState(service()->loader()->contents(), 100, false);
 | 
| +  InstantTestModelObserver observer(instant(), &desired_model);
 | 
|    SetOmniboxText(text);
 | 
| -  observer.WaitUntilDesiredPreviewState();
 | 
| +  observer.WaitForDesiredOverlayState();
 | 
|  }
 | 
|  
 | 
|  bool InstantTestBase::GetBoolFromJS(content::WebContents* contents,
 | 
| @@ -125,10 +207,6 @@ bool InstantTestBase::GetStringFromJS(content::WebContents* contents,
 | 
|        contents, WrapScript(script), result);
 | 
|  }
 | 
|  
 | 
| -bool InstantTestBase::ExecuteScript(const std::string& script) {
 | 
| -  return content::ExecuteScript(instant()->GetPreviewContents(), script);
 | 
| -}
 | 
| -
 | 
|  bool InstantTestBase::CheckVisibilityIs(content::WebContents* contents,
 | 
|                                          bool expected) {
 | 
|    bool actual = !expected;  // Purposely start with a mis-match.
 | 
| @@ -138,10 +216,9 @@ 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);
 | 
|  }
 | 
| 
 |