summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/automation/automation_provider_observers.cc133
-rw-r--r--chrome/browser/automation/automation_provider_observers.h26
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc122
-rw-r--r--chrome/browser/automation/testing_automation_provider.h31
-rwxr-xr-xchrome/test/functional/policy.py15
-rwxr-xr-xchrome/test/pyautolib/pyauto.py69
-rw-r--r--chrome/test/pyautolib/pyautolib.cc22
-rw-r--r--chrome/test/pyautolib/pyautolib.h12
-rw-r--r--chrome/test/pyautolib/pyautolib.i16
9 files changed, 332 insertions, 114 deletions
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc
index 8ae57de..b67e29d 100644
--- a/chrome/browser/automation/automation_provider_observers.cc
+++ b/chrome/browser/automation/automation_provider_observers.cc
@@ -351,10 +351,16 @@ void NavigationNotificationObserver::ConditionMet(
AutomationMsg_NavigationResponseValues navigation_result) {
if (automation_) {
if (use_json_interface_) {
- DictionaryValue dict;
- dict.SetInteger("result", navigation_result);
- AutomationJSONReply(automation_, reply_message_.release())
- .SendSuccess(&dict);
+ if (navigation_result == AUTOMATION_MSG_NAVIGATION_SUCCESS) {
+ DictionaryValue dict;
+ dict.SetInteger("result", navigation_result);
+ AutomationJSONReply(automation_, reply_message_.release()).SendSuccess(
+ &dict);
+ } else {
+ AutomationJSONReply(automation_, reply_message_.release()).SendError(
+ StringPrintf("Navigation failed with error code=%d.",
+ navigation_result));
+ }
} else {
IPC::ParamTraits<int>::Write(
reply_message_.get(), navigation_result);
@@ -431,14 +437,17 @@ IPC::Message* TabAppendedNotificationObserver::ReleaseReply() {
}
TabClosedNotificationObserver::TabClosedNotificationObserver(
- AutomationProvider* automation, bool wait_until_closed,
- IPC::Message* reply_message)
+ AutomationProvider* automation,
+ bool wait_until_closed,
+ IPC::Message* reply_message,
+ bool use_json_interface)
: TabStripNotificationObserver(
wait_until_closed
? static_cast<int>(content::NOTIFICATION_WEB_CONTENTS_DESTROYED)
: static_cast<int>(chrome::NOTIFICATION_TAB_CLOSING),
automation),
reply_message_(reply_message),
+ use_json_interface_(use_json_interface),
for_browser_command_(false) {
}
@@ -449,13 +458,18 @@ void TabClosedNotificationObserver::ObserveTab(
if (!automation_)
return;
- if (for_browser_command_) {
- AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(),
- true);
+ if (use_json_interface_) {
+ AutomationJSONReply(automation_,
+ reply_message_.release()).SendSuccess(NULL);
} else {
- AutomationMsg_CloseTab::WriteReplyParams(reply_message_.get(), true);
+ if (for_browser_command_) {
+ AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(),
+ true);
+ } else {
+ AutomationMsg_CloseTab::WriteReplyParams(reply_message_.get(), true);
+ }
+ automation_->Send(reply_message_.release());
}
- automation_->Send(reply_message_.release());
}
void TabClosedNotificationObserver::set_for_browser_command(
@@ -778,10 +792,12 @@ void ExtensionsUpdatedObserver::Observe(
BrowserOpenedNotificationObserver::BrowserOpenedNotificationObserver(
AutomationProvider* automation,
- IPC::Message* reply_message)
+ IPC::Message* reply_message,
+ bool use_json_interface)
: automation_(automation->AsWeakPtr()),
reply_message_(reply_message),
new_window_id_(extension_misc::kUnknownWindowId),
+ use_json_interface_(use_json_interface),
for_browser_command_(false) {
registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED,
content::NotificationService::AllBrowserContextsAndSources());
@@ -813,11 +829,16 @@ void BrowserOpenedNotificationObserver::Observe(
TabContents::FromWebContents(controller->GetWebContents());
int window_id = tab ? tab->restore_tab_helper()->window_id().id() : -1;
if (window_id == new_window_id_) {
- if (for_browser_command_) {
- AutomationMsg_WindowExecuteCommand::WriteReplyParams(
- reply_message_.get(), true);
+ if (use_json_interface_) {
+ AutomationJSONReply(automation_,
+ reply_message_.release()).SendSuccess(NULL);
+ } else {
+ if (for_browser_command_) {
+ AutomationMsg_WindowExecuteCommand::WriteReplyParams(
+ reply_message_.get(), true);
+ }
+ automation_->Send(reply_message_.release());
}
- automation_->Send(reply_message_.release());
delete this;
return;
}
@@ -834,9 +855,11 @@ void BrowserOpenedNotificationObserver::set_for_browser_command(
BrowserClosedNotificationObserver::BrowserClosedNotificationObserver(
Browser* browser,
AutomationProvider* automation,
- IPC::Message* reply_message)
+ IPC::Message* reply_message,
+ bool use_json_interface)
: automation_(automation->AsWeakPtr()),
reply_message_(reply_message),
+ use_json_interface_(use_json_interface),
for_browser_command_(false) {
registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSED,
content::Source<Browser>(browser));
@@ -856,14 +879,19 @@ void BrowserClosedNotificationObserver::Observe(
content::Details<bool> close_app(details);
- if (for_browser_command_) {
- AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(),
- true);
+ if (use_json_interface_) {
+ AutomationJSONReply(automation_,
+ reply_message_.release()).SendSuccess(NULL);
} else {
- AutomationMsg_CloseBrowser::WriteReplyParams(reply_message_.get(), true,
- *(close_app.ptr()));
+ if (for_browser_command_) {
+ AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(),
+ true);
+ } else {
+ AutomationMsg_CloseBrowser::WriteReplyParams(reply_message_.get(), true,
+ *(close_app.ptr()));
+ }
+ automation_->Send(reply_message_.release());
}
- automation_->Send(reply_message_.release());
delete this;
}
@@ -946,31 +974,37 @@ ExecuteBrowserCommandObserver::~ExecuteBrowserCommandObserver() {
// static
bool ExecuteBrowserCommandObserver::CreateAndRegisterObserver(
- AutomationProvider* automation, Browser* browser, int command,
- IPC::Message* reply_message) {
+ AutomationProvider* automation,
+ Browser* browser,
+ int command,
+ IPC::Message* reply_message,
+ bool use_json_interface) {
bool result = true;
switch (command) {
case IDC_NEW_TAB: {
- new NewTabObserver(automation, reply_message);
+ new NewTabObserver(automation, reply_message, use_json_interface);
break;
}
case IDC_NEW_WINDOW:
case IDC_NEW_INCOGNITO_WINDOW: {
BrowserOpenedNotificationObserver* observer =
- new BrowserOpenedNotificationObserver(automation, reply_message);
+ new BrowserOpenedNotificationObserver(automation, reply_message,
+ use_json_interface);
observer->set_for_browser_command(true);
break;
}
case IDC_CLOSE_WINDOW: {
BrowserClosedNotificationObserver* observer =
new BrowserClosedNotificationObserver(browser, automation,
- reply_message);
+ reply_message,
+ use_json_interface);
observer->set_for_browser_command(true);
break;
}
case IDC_CLOSE_TAB: {
TabClosedNotificationObserver* observer =
- new TabClosedNotificationObserver(automation, true, reply_message);
+ new TabClosedNotificationObserver(automation, true, reply_message,
+ use_json_interface);
observer->set_for_browser_command(true);
break;
}
@@ -979,13 +1013,15 @@ bool ExecuteBrowserCommandObserver::CreateAndRegisterObserver(
case IDC_RELOAD: {
new NavigationNotificationObserver(
&chrome::GetActiveWebContents(browser)->GetController(),
- automation, reply_message, 1, false, false);
+ automation, reply_message, 1, false, use_json_interface);
break;
}
default: {
ExecuteBrowserCommandObserver* observer =
- new ExecuteBrowserCommandObserver(automation, reply_message);
+ new ExecuteBrowserCommandObserver(automation, reply_message,
+ use_json_interface);
if (!observer->Register(command)) {
+ observer->ReleaseReply();
delete observer;
result = false;
}
@@ -1000,9 +1036,14 @@ void ExecuteBrowserCommandObserver::Observe(
const content::NotificationDetails& details) {
if (type == notification_type_) {
if (automation_) {
- AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(),
- true);
- automation_->Send(reply_message_.release());
+ if (use_json_interface_) {
+ AutomationJSONReply(automation_,
+ reply_message_.release()).SendSuccess(NULL);
+ } else {
+ AutomationMsg_WindowExecuteCommand::WriteReplyParams(
+ reply_message_.get(), true);
+ automation_->Send(reply_message_.release());
+ }
}
delete this;
} else {
@@ -1011,10 +1052,13 @@ void ExecuteBrowserCommandObserver::Observe(
}
ExecuteBrowserCommandObserver::ExecuteBrowserCommandObserver(
- AutomationProvider* automation, IPC::Message* reply_message)
+ AutomationProvider* automation,
+ IPC::Message* reply_message,
+ bool use_json_interface)
: automation_(automation->AsWeakPtr()),
notification_type_(content::NOTIFICATION_ALL),
- reply_message_(reply_message) {
+ reply_message_(reply_message),
+ use_json_interface_(use_json_interface) {
}
bool ExecuteBrowserCommandObserver::Register(int command) {
@@ -1040,6 +1084,10 @@ bool ExecuteBrowserCommandObserver::Getint(
return found;
}
+IPC::Message* ExecuteBrowserCommandObserver::ReleaseReply() {
+ return reply_message_.release();
+}
+
FindInPageNotificationObserver::FindInPageNotificationObserver(
AutomationProvider* automation, WebContents* parent_tab,
bool reply_with_json, IPC::Message* reply_message)
@@ -2657,9 +2705,11 @@ void AllViewsStoppedLoadingObserver::CheckIfNoMorePendingLoads() {
}
NewTabObserver::NewTabObserver(AutomationProvider* automation,
- IPC::Message* reply_message)
+ IPC::Message* reply_message,
+ bool use_json_interface)
: automation_(automation->AsWeakPtr()),
- reply_message_(reply_message) {
+ reply_message_(reply_message),
+ use_json_interface_(use_json_interface) {
// Use TAB_PARENTED to detect the new tab.
registrar_.Add(this,
chrome::NOTIFICATION_TAB_PARENTED,
@@ -2678,11 +2728,12 @@ void NewTabObserver::Observe(int type,
// here, but don't send the message. NavigationNotificationObserver
// will wait properly for the load to finish, and send the message,
// but it will also append its own return value at the end of the reply.
- AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(),
- true);
+ if (!use_json_interface_)
+ AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(),
+ true);
new NavigationNotificationObserver(controller, automation_,
reply_message_.release(),
- 1, false, false);
+ 1, false, use_json_interface_);
}
delete this;
}
diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h
index 749c5de..3c607a9 100644
--- a/chrome/browser/automation/automation_provider_observers.h
+++ b/chrome/browser/automation/automation_provider_observers.h
@@ -294,7 +294,8 @@ class TabClosedNotificationObserver : public TabStripNotificationObserver {
public:
TabClosedNotificationObserver(AutomationProvider* automation,
bool wait_until_closed,
- IPC::Message* reply_message);
+ IPC::Message* reply_message,
+ bool use_json_interface);
virtual ~TabClosedNotificationObserver();
virtual void ObserveTab(content::NavigationController* controller);
@@ -303,6 +304,7 @@ class TabClosedNotificationObserver : public TabStripNotificationObserver {
protected:
scoped_ptr<IPC::Message> reply_message_;
+ bool use_json_interface_;
bool for_browser_command_;
private:
@@ -446,7 +448,8 @@ class ExtensionsUpdatedObserver : public content::NotificationObserver {
class BrowserOpenedNotificationObserver : public content::NotificationObserver {
public:
BrowserOpenedNotificationObserver(AutomationProvider* automation,
- IPC::Message* reply_message);
+ IPC::Message* reply_message,
+ bool use_json_interface);
virtual ~BrowserOpenedNotificationObserver();
// Overridden from content::NotificationObserver:
@@ -461,6 +464,7 @@ class BrowserOpenedNotificationObserver : public content::NotificationObserver {
base::WeakPtr<AutomationProvider> automation_;
scoped_ptr<IPC::Message> reply_message_;
int new_window_id_;
+ bool use_json_interface_;
bool for_browser_command_;
DISALLOW_COPY_AND_ASSIGN(BrowserOpenedNotificationObserver);
@@ -470,7 +474,8 @@ class BrowserClosedNotificationObserver : public content::NotificationObserver {
public:
BrowserClosedNotificationObserver(Browser* browser,
AutomationProvider* automation,
- IPC::Message* reply_message);
+ IPC::Message* reply_message,
+ bool use_json_interface);
virtual ~BrowserClosedNotificationObserver();
// Overridden from content::NotificationObserver:
@@ -484,6 +489,7 @@ class BrowserClosedNotificationObserver : public content::NotificationObserver {
content::NotificationRegistrar registrar_;
base::WeakPtr<AutomationProvider> automation_;
scoped_ptr<IPC::Message> reply_message_;
+ bool use_json_interface_;
bool for_browser_command_;
DISALLOW_COPY_AND_ASSIGN(BrowserClosedNotificationObserver);
@@ -518,7 +524,8 @@ class ExecuteBrowserCommandObserver : public content::NotificationObserver {
static bool CreateAndRegisterObserver(AutomationProvider* automation,
Browser* browser,
int command,
- IPC::Message* reply_message);
+ IPC::Message* reply_message,
+ bool use_json_interface);
// Overridden from content::NotificationObserver:
virtual void Observe(int type,
@@ -527,16 +534,20 @@ class ExecuteBrowserCommandObserver : public content::NotificationObserver {
private:
ExecuteBrowserCommandObserver(AutomationProvider* automation,
- IPC::Message* reply_message);
+ IPC::Message* reply_message,
+ bool use_json_interface);
bool Register(int command);
bool Getint(int command, int* type);
+ IPC::Message* ReleaseReply();
+
content::NotificationRegistrar registrar_;
base::WeakPtr<AutomationProvider> automation_;
int notification_type_;
scoped_ptr<IPC::Message> reply_message_;
+ bool use_json_interface_;
DISALLOW_COPY_AND_ASSIGN(ExecuteBrowserCommandObserver);
};
@@ -1742,7 +1753,9 @@ class AllViewsStoppedLoadingObserver : public TabEventObserver,
// Observer used to listen for new tab creation to complete.
class NewTabObserver : public content::NotificationObserver {
public:
- NewTabObserver(AutomationProvider* automation, IPC::Message* reply_message);
+ NewTabObserver(AutomationProvider* automation,
+ IPC::Message* reply_message,
+ bool use_json_interface);
// Overridden from content::NotificationObserver:
virtual void Observe(int type,
@@ -1755,6 +1768,7 @@ class NewTabObserver : public content::NotificationObserver {
content::NotificationRegistrar registrar_;
base::WeakPtr<AutomationProvider> automation_;
scoped_ptr<IPC::Message> reply_message_;
+ bool use_json_interface_;
DISALLOW_COPY_AND_ASSIGN(NewTabObserver);
};
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 36ed1a7..629c0ab 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -254,6 +254,13 @@ class AutomationInterstitialPage : public content::InterstitialPageDelegate {
} // namespace
+const int TestingAutomationProvider::kSynchronousCommands[] = {
+ IDC_HOME,
+ IDC_SELECT_NEXT_TAB,
+ IDC_SELECT_PREVIOUS_TAB,
+ IDC_SHOW_BOOKMARK_MANAGER,
+};
+
TestingAutomationProvider::TestingAutomationProvider(Profile* profile)
: AutomationProvider(profile)
#if defined(OS_CHROMEOS)
@@ -477,7 +484,7 @@ void TestingAutomationProvider::CloseBrowser(int browser_handle,
return;
Browser* browser = browser_tracker_->GetResource(browser_handle);
- new BrowserClosedNotificationObserver(browser, this, reply_message);
+ new BrowserClosedNotificationObserver(browser, this, reply_message, false);
browser->window()->Close();
}
@@ -550,7 +557,8 @@ void TestingAutomationProvider::CloseTab(int tab_handle,
Browser* browser = browser::FindBrowserWithWebContents(
controller->GetWebContents());
DCHECK(browser);
- new TabClosedNotificationObserver(this, wait_until_closed, reply_message);
+ new TabClosedNotificationObserver(this, wait_until_closed, reply_message,
+ false);
chrome::CloseWebContents(browser, controller->GetWebContents());
return;
}
@@ -690,14 +698,6 @@ void TestingAutomationProvider::ExecuteBrowserCommandAsync(int handle,
void TestingAutomationProvider::ExecuteBrowserCommand(
int handle, int command, IPC::Message* reply_message) {
- // List of commands which just finish synchronously and don't require
- // setting up an observer.
- static const int kSynchronousCommands[] = {
- IDC_HOME,
- IDC_SELECT_NEXT_TAB,
- IDC_SELECT_PREVIOUS_TAB,
- IDC_SHOW_BOOKMARK_MANAGER,
- };
if (browser_tracker_->ContainsHandle(handle)) {
Browser* browser = browser_tracker_->GetResource(handle);
if (chrome::SupportsCommand(browser, command) &&
@@ -715,7 +715,7 @@ void TestingAutomationProvider::ExecuteBrowserCommand(
// Use an observer if we have one, otherwise fail.
if (ExecuteBrowserCommandObserver::CreateAndRegisterObserver(
- this, browser, command, reply_message)) {
+ this, browser, command, reply_message, false)) {
chrome::ExecuteCommand(browser, command);
return;
}
@@ -1191,7 +1191,7 @@ void TestingAutomationProvider::GetMultiProfileInfo(
void TestingAutomationProvider::OpenNewBrowserWindowOfType(
int type, bool show, IPC::Message* reply_message) {
- new BrowserOpenedNotificationObserver(this, reply_message);
+ new BrowserOpenedNotificationObserver(this, reply_message, false);
// We may have no current browser windows open so don't rely on
// asking an existing browser to execute the IDC_NEWWINDOW command
Browser* browser = new Browser(static_cast<Browser::Type>(type), profile_);
@@ -1653,6 +1653,12 @@ void TestingAutomationProvider::SetShelfVisibility(int handle, bool visible) {
void TestingAutomationProvider::BuildJSONHandlerMaps() {
// Map json commands to their handlers.
+ handler_map_["ApplyAccelerator"] =
+ &TestingAutomationProvider::ExecuteBrowserCommandAsyncJSON;
+ handler_map_["RunCommand"] =
+ &TestingAutomationProvider::ExecuteBrowserCommandJSON;
+ handler_map_["IsMenuCommandEnabled"] =
+ &TestingAutomationProvider::IsMenuCommandEnabledJSON;
handler_map_["WaitForAllTabsToStopLoading"] =
&TestingAutomationProvider::WaitForAllViewsToStopLoading;
handler_map_["GetIndicesFromTab"] =
@@ -6385,6 +6391,98 @@ void TestingAutomationProvider::GoForward(
controller.GoForward();
}
+void TestingAutomationProvider::ExecuteBrowserCommandAsyncJSON(
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+ int command;
+ Browser* browser;
+ std::string error;
+ if (!GetBrowserFromJSONArgs(args, &browser, &error)) {
+ reply.SendError(error);
+ return;
+ }
+ if (!args->GetInteger("accelerator", &command)) {
+ reply.SendError("'accelerator' missing or invalid.");
+ return;
+ }
+ if (!chrome::SupportsCommand(browser, command)) {
+ reply.SendError(StringPrintf("Browser does not support command=%d.",
+ command));
+ return;
+ }
+ if (!chrome::IsCommandEnabled(browser, command)) {
+ reply.SendError(StringPrintf("Browser command=%d not enabled.", command));
+ return;
+ }
+ chrome::ExecuteCommand(browser, command);
+ reply.SendSuccess(NULL);
+}
+
+void TestingAutomationProvider::ExecuteBrowserCommandJSON(
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ int command;
+ Browser* browser;
+ std::string error;
+ if (!GetBrowserFromJSONArgs(args, &browser, &error)) {
+ AutomationJSONReply(this, reply_message).SendError(error);
+ return;
+ }
+ if (!args->GetInteger("accelerator", &command)) {
+ AutomationJSONReply(this, reply_message).SendError(
+ "'accelerator' missing or invalid.");
+ return;
+ }
+ if (!chrome::SupportsCommand(browser, command)) {
+ AutomationJSONReply(this, reply_message).SendError(
+ StringPrintf("Browser does not support command=%d.", command));
+ return;
+ }
+ if (!chrome::IsCommandEnabled(browser, command)) {
+ AutomationJSONReply(this, reply_message).SendError(
+ StringPrintf("Browser command=%d not enabled.", command));
+ return;
+ }
+ // First check if we can handle the command without using an observer.
+ for (size_t i = 0; i < arraysize(kSynchronousCommands); i++) {
+ if (command == kSynchronousCommands[i]) {
+ chrome::ExecuteCommand(browser, command);
+ AutomationJSONReply(this, reply_message).SendSuccess(NULL);
+ return;
+ }
+ }
+ // Use an observer if we have one, otherwise fail.
+ if (ExecuteBrowserCommandObserver::CreateAndRegisterObserver(
+ this, browser, command, reply_message, true)) {
+ chrome::ExecuteCommand(browser, command);
+ return;
+ }
+ AutomationJSONReply(this, reply_message).SendError(
+ StringPrintf("Unable to register observer for browser command=%d.",
+ command));
+}
+
+void TestingAutomationProvider::IsMenuCommandEnabledJSON(
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ int command;
+ Browser* browser;
+ std::string error;
+ if (!GetBrowserFromJSONArgs(args, &browser, &error)) {
+ AutomationJSONReply(this, reply_message).SendError(error);
+ return;
+ }
+ if (!args->GetInteger("accelerator", &command)) {
+ AutomationJSONReply(this, reply_message).SendError(
+ "'accelerator' missing or invalid.");
+ return;
+ }
+ DictionaryValue dict;
+ dict.SetBoolean("enabled", chrome::IsCommandEnabled(browser, command));
+ AutomationJSONReply(this, reply_message).SendSuccess(&dict);
+}
+
void TestingAutomationProvider::GoBack(
DictionaryValue* args,
IPC::Message* reply_message) {
diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h
index 2081705..3f374ee 100644
--- a/chrome/browser/automation/testing_automation_provider.h
+++ b/chrome/browser/automation/testing_automation_provider.h
@@ -848,6 +848,33 @@ class TestingAutomationProvider : public AutomationProvider,
void GetIndicesFromTab(base::DictionaryValue* args,
IPC::Message* reply_message);
+ // Executes a browser command on the given browser window. Does not wait for
+ // the command to complete.
+ // Example:
+ // input: { "accelerator": 1,
+ // "windex": 1
+ // }
+ void ExecuteBrowserCommandAsyncJSON(DictionaryValue* args,
+ IPC::Message* reply_message);
+
+ // Executes a browser command on the given browser window. Waits for the
+ // command to complete before returning.
+ // Example:
+ // input: { "accelerator": 1,
+ // "windex": 1
+ // }
+ void ExecuteBrowserCommandJSON(DictionaryValue* args,
+ IPC::Message* reply_message);
+
+ // Checks if a browser command is enabled on the given browser window.
+ // Example:
+ // input: { "accelerator": 1,
+ // "windex": 1
+ // }
+ // output: { "enabled": true }
+ void IsMenuCommandEnabledJSON(DictionaryValue* args,
+ IPC::Message* reply_message);
+
// Navigates to the given URL. Uses the JSON interface.
// The pair |windex| and |tab_index| or the single |auto_id| must be given
// to specify the tab.
@@ -1602,6 +1629,10 @@ class TestingAutomationProvider : public AutomationProvider,
// is added to avoid overhead when not needed.
scoped_ptr<AutomationEventQueue> automation_event_queue_;
+ // List of commands which just finish synchronously and don't require
+ // setting up an observer.
+ static const int kSynchronousCommands[];
+
DISALLOW_COPY_AND_ASSIGN(TestingAutomationProvider);
};
diff --git a/chrome/test/functional/policy.py b/chrome/test/functional/policy.py
index 5908a17..875bee6 100755
--- a/chrome/test/functional/policy.py
+++ b/chrome/test/functional/policy.py
@@ -176,7 +176,9 @@ class PolicyTest(policy_base.PolicyTestBase):
self.assertTrue(self.GetBookmarkBarVisibility())
self.assertFalse(self.IsBookmarkBarDetached())
# The accelerator should be disabled by the policy.
- self.ApplyAccelerator(pyauto.IDC_SHOW_BOOKMARK_BAR)
+ self.assertRaises(
+ pyauto_errors.JSONInterfaceError,
+ lambda: self.ApplyAccelerator(pyauto.IDC_SHOW_BOOKMARK_BAR))
self.assertTrue(self.WaitForBookmarkBarVisibilityChange(True))
self.assertTrue(self.GetBookmarkBarVisibility())
self.assertFalse(self.IsBookmarkBarDetached())
@@ -186,7 +188,9 @@ class PolicyTest(policy_base.PolicyTestBase):
self.assertTrue(self.WaitForBookmarkBarVisibilityChange(False))
self.assertFalse(self.GetBookmarkBarVisibility())
- self.ApplyAccelerator(pyauto.IDC_SHOW_BOOKMARK_BAR)
+ self.assertRaises(
+ pyauto_errors.JSONInterfaceError,
+ lambda: self.ApplyAccelerator(pyauto.IDC_SHOW_BOOKMARK_BAR))
self.assertTrue(self.WaitForBookmarkBarVisibilityChange(False))
self.assertFalse(self.GetBookmarkBarVisibility())
# When disabled by policy, it should never be displayed at all,
@@ -341,7 +345,8 @@ class PolicyTest(policy_base.PolicyTestBase):
policy = {'DeveloperToolsDisabled': True}
self.SetUserPolicy(policy)
self.SetPrefs(pyauto.kDevToolsOpenDocked, False)
- self.ApplyAccelerator(pyauto.IDC_DEV_TOOLS)
+ self.assertRaises(pyauto_errors.JSONInterfaceError,
+ lambda: self.ApplyAccelerator(pyauto.IDC_DEV_TOOLS))
self.assertEquals(1, len(self.GetBrowserInfo()['windows']),
msg='Devtools window launched.')
policy = {'DeveloperToolsDisabled': False}
@@ -451,7 +456,9 @@ class PolicyTest(policy_base.PolicyTestBase):
"""Verify that incognito window can be launched."""
policy = {'IncognitoEnabled': False}
self.SetUserPolicy(policy)
- self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW)
+ self.assertRaises(
+ pyauto_errors.JSONInterfaceError,
+ lambda: self.ApplyAccelerator(pyauto.IDC_NEW_INCOGNITO_WINDOW))
self.assertEquals(1, self.GetBrowserWindowCount())
policy = {'IncognitoEnabled': True}
self.SetUserPolicy(policy)
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index bad4a7c..1bef6ba 100755
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -1091,6 +1091,73 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
}
self._GetResultFromJSONRequest(cmd_dict, windex=None)
+ def ApplyAccelerator(self, accelerator, windex=0):
+ """Apply the accelerator with the given id.
+
+ Note that this method schedules the accelerator, but does not wait for it to
+ actually finish doing anything.
+
+ Args:
+ accelerator: The accelerator id, IDC_BACK, IDC_NEWTAB, etc. The list of
+ ids can be found at chrome/app/chrome_command_ids.h.
+ windex: The index of the browser window to work on. Defaults to the first
+ window.
+
+ Raises:
+ pyauto_errors.JSONInterfaceError if the automation call returns an error.
+ """
+
+ cmd_dict = {
+ 'command': 'ApplyAccelerator',
+ 'accelerator': accelerator,
+ 'windex': windex,
+ }
+ self._GetResultFromJSONRequest(cmd_dict, windex=None)
+
+ def RunCommand(self, accelerator, windex=0):
+ """Apply the accelerator with the given id and wait for it to finish.
+
+ This is like ApplyAccelerator except that it waits for the command to finish
+ executing.
+
+ Args:
+ accelerator: The accelerator id. The list of ids can be found at
+ chrome/app/chrome_command_ids.h.
+ windex: The index of the browser window to work on. Defaults to the first
+ window.
+
+ Raises:
+ pyauto_errors.JSONInterfaceError if the automation call returns an error.
+ """
+ cmd_dict = {
+ 'command': 'RunCommand',
+ 'accelerator': accelerator,
+ 'windex': windex,
+ }
+ self._GetResultFromJSONRequest(cmd_dict, windex=None)
+
+ def IsMenuCommandEnabled(self, accelerator, windex=0):
+ """Check if a command is enabled for a window.
+
+ Returns true if the command with the given accelerator id is enabled on the
+ given window.
+
+ Args:
+ accelerator: The accelerator id. The list of ids can be found at
+ chrome/app/chrome_command_ids.h.
+ windex: The index of the browser window to work on. Defaults to the first
+ window.
+
+ Returns:
+ True if the command is enabled for the given window.
+ """
+ cmd_dict = {
+ 'command': 'IsMenuCommandEnabled',
+ 'accelerator': accelerator,
+ 'windex': windex,
+ }
+ return self._GetResultFromJSONRequest(cmd_dict, windex=None).get('enabled')
+
def ReloadTab(self, tab_index=0, windex=0):
"""Reload the given tab.
@@ -1124,7 +1191,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
Raises:
pyauto_errors.JSONInterfaceError if the automation call returns an error.
"""
- self.ReloadTab(windex, self.GetActiveTabIndex(windex))
+ self.ReloadTab(self.GetActiveTabIndex(windex), windex)
def GetActiveTabIndex(self, windex=0):
"""Get the index of the currently active tab in the given browser window.
diff --git a/chrome/test/pyautolib/pyautolib.cc b/chrome/test/pyautolib/pyautolib.cc
index 55855fe..91da779 100644
--- a/chrome/test/pyautolib/pyautolib.cc
+++ b/chrome/test/pyautolib/pyautolib.cc
@@ -101,28 +101,6 @@ void PyUITestBase::SetLaunchSwitches() {
launch_arguments_.AppendSwitchASCII(switches::kHomePage, homepage_);
}
-bool PyUITestBase::ApplyAccelerator(int id, int window_index) {
- scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
- return browser_proxy->ApplyAccelerator(id);
-}
-
-bool PyUITestBase::RunCommand(int browser_command, int window_index) {
- scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
- EXPECT_TRUE(browser_proxy.get());
- if (!browser_proxy.get())
- return false;
- return browser_proxy->RunCommand(browser_command);
-}
-
-bool PyUITestBase::IsMenuCommandEnabled(int id, int window_index) {
- scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
- EXPECT_TRUE(browser_proxy.get());
- bool enabled = false;
- if (browser_proxy.get())
- EXPECT_TRUE(browser_proxy->IsMenuCommandEnabled(id, &enabled));
- return enabled;
-}
-
bool PyUITestBase::ActivateTab(int tab_index, int window_index) {
scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
return browser_proxy->BringToFront() && browser_proxy->ActivateTab(tab_index);
diff --git a/chrome/test/pyautolib/pyautolib.h b/chrome/test/pyautolib/pyautolib.h
index 91beeb3..3de0596 100644
--- a/chrome/test/pyautolib/pyautolib.h
+++ b/chrome/test/pyautolib/pyautolib.h
@@ -78,18 +78,6 @@ class PyUITestBase : public UITestBase {
// browser window. Also brings the window to front.
bool ActivateTab(int tab_index, int window_index = 0);
- // Apply the accelerator with given id (IDC_BACK, IDC_NEWTAB ...) to the
- // browser window at the given or first index.
- // The list can be found at chrome/app/chrome_command_ids.h
- // Returns true if the call was successful.
- bool ApplyAccelerator(int id, int window_index = 0);
-
- // Like ApplyAccelerator except that it waits for the command to execute.
- bool RunCommand(int browser_command, int window_index = 0);
-
- // Returns true if the given command id is enabled on the given window.
- bool IsMenuCommandEnabled(int browser_command, int window_index = 0);
-
// Shows or hides the download shelf.
void SetDownloadShelfVisible(bool is_visible, int window_index = 0);
diff --git a/chrome/test/pyautolib/pyautolib.i b/chrome/test/pyautolib/pyautolib.i
index 0ee4bea..1e9b388 100644
--- a/chrome/test/pyautolib/pyautolib.i
+++ b/chrome/test/pyautolib/pyautolib.i
@@ -275,22 +275,6 @@ class PyUITestBase {
set_clear_profile;
void set_clear_profile(bool clear_profile);
- // BrowserProxy methods
- %feature("docstring", "Apply the accelerator with given id "
- "(IDC_BACK, IDC_NEWTAB ...) to the given or first window. "
- "The list can be found at chrome/app/chrome_dll_resource.h. "
- "Note that this method just schedules the accelerator, but does "
- "not wait for it to actually finish doing anything."
- "Returns True on success.")
- ApplyAccelerator;
- bool ApplyAccelerator(int id, int window_index=0);
- %feature("docstring", "Like ApplyAccelerator, except that it waits for "
- "the command to execute.") RunCommand;
- bool RunCommand(int browser_command, int window_index = 0);
- %feature("docstring", "Returns true if the given command id is enabled on "
- "the given window.") IsMenuCommandEnabled;
- bool IsMenuCommandEnabled(int browser_command, int window_index = 0);
-
// Get/fetch properties
%feature("docstring",
"Get the path to download directory.") GetDownloadDirectory;