| 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 242db0b05bff31c20faf248c7d7058342eb7b484..01de31c91480a72b60ecedfebc8805bd6bbe4611 100644
|
| --- a/chrome/browser/instant/instant_test_utils.cc
|
| +++ b/chrome/browser/instant/instant_test_utils.cc
|
| @@ -9,9 +9,13 @@
|
| #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/ui/omnibox/omnibox_view.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/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"
|
| @@ -51,9 +55,10 @@ void InstantTestModelObserver::OverlayStateChanged(
|
|
|
| // InstantTestBase -----------------------------------------------------------
|
|
|
| -void InstantTestBase::SetupInstant() {
|
| +void InstantTestBase::SetupInstant(Browser* browser) {
|
| + browser_ = browser;
|
| TemplateURLService* service =
|
| - TemplateURLServiceFactory::GetForProfile(browser()->profile());
|
| + TemplateURLServiceFactory::GetForProfile(browser_->profile());
|
| ui_test_utils::WaitForTemplateURLServiceToLoad(service);
|
|
|
| TemplateURLData data;
|
| @@ -64,17 +69,21 @@ void InstantTestBase::SetupInstant() {
|
| 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(), data);
|
| service->Add(template_url); // Takes ownership of |template_url|.
|
| service->SetDefaultSearchProvider(template_url);
|
|
|
| - browser()->profile()->GetPrefs()->SetBoolean(prefs::kInstantEnabled, true);
|
| + browser_->profile()->GetPrefs()->SetBoolean(prefs::kInstantEnabled, true);
|
|
|
| // TODO(shishir): Fix this ugly hack.
|
| instant()->SetInstantEnabled(false, true);
|
| instant()->SetInstantEnabled(true, false);
|
| }
|
|
|
| +void InstantTestBase::Init(const GURL& instant_url) {
|
| + instant_url_ = instant_url;
|
| +}
|
| +
|
| void InstantTestBase::KillInstantRenderView() {
|
| base::KillProcess(
|
| instant()->GetOverlayContents()->GetRenderProcessHost()->GetHandle(),
|
| @@ -88,10 +97,30 @@ 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() {
|
| + 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,
|
| + content::NotificationService::AllSources());
|
| + FocusOmnibox();
|
| + ntp_observer.Wait();
|
| + overlay_observer.Wait();
|
| +}
|
| +
|
| void InstantTestBase::SetOmniboxText(const std::string& text) {
|
| FocusOmnibox();
|
| omnibox()->SetUserText(UTF8ToUTF16(text));
|
| @@ -146,3 +175,14 @@ bool InstantTestBase::HasUserInputInProgress() {
|
| bool InstantTestBase::HasTemporaryText() {
|
| return omnibox()->model()->has_temporary_text_;
|
| }
|
| +
|
| +bool InstantTestBase::LoadImage(content::RenderViewHost* rvh,
|
| + const std::string& image,
|
| + bool* loaded) {
|
| + std::string js_chrome =
|
| + "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);
|
| +}
|
|
|