summaryrefslogtreecommitdiffstats
path: root/chrome/browser/automation/automation_provider.cc
diff options
context:
space:
mode:
authorhuanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-27 03:05:56 +0000
committerhuanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-27 03:05:56 +0000
commit56e71b7c8d857ed8c05336c370fe4cf95d10f973 (patch)
tree4c4748da6b2780b6d26443b78b3bd53dc577b13c /chrome/browser/automation/automation_provider.cc
parent768336c46a3740caa5716e4a6edcf6e7c03d1d9b (diff)
downloadchromium_src-56e71b7c8d857ed8c05336c370fe4cf95d10f973.zip
chromium_src-56e71b7c8d857ed8c05336c370fe4cf95d10f973.tar.gz
chromium_src-56e71b7c8d857ed8c05336c370fe4cf95d10f973.tar.bz2
This check in is the initial step to try improve UI
automation framework. Currently we are not consistent in UI automation. After receiving the automation message, the automation provider in browser does not always execute UI commands synchronously. In many cases, it simply sends back an acknowledgement and dispatches the command. On the test client side, it waits and polls the result after sending the message. I think this causes lots of UI test flakeyness and makes the test slow. I plan to convert all asynchronous execution to synchronous. It may take some time to get them all done. I CC'ed a few people so they are aware of this ongoing work. Feel free to comment on whether and how to address the issue. This check in adds an UI automation message AutomationMsg_WindowExecuteCommandSync that executes accelerators synchronously. The existing automation message AutomationMsg_WindowExecuteCommand only dispatches the accelerator. There are many UI accelerators using the existing async version. In this check in I only made the conversion for IDC_NEW_TAB to try out the new mechanism. Review URL: http://codereview.chromium.org/53108 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12632 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation/automation_provider.cc')
-rw-r--r--chrome/browser/automation/automation_provider.cc57
1 files changed, 57 insertions, 0 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index ccdb32d..954db43 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -451,6 +451,42 @@ class BrowserClosedNotificationObserver : public NotificationObserver {
IPC::Message* reply_message_;
};
+class ExecuteBrowserCommandObserver : public NotificationObserver {
+ public:
+ ExecuteBrowserCommandObserver(
+ AutomationProvider* automation,
+ NotificationType::Type notification_type,
+ IPC::Message* reply_message)
+ : automation_(automation),
+ notification_type_(notification_type),
+ reply_message_(reply_message) {
+ registrar_.Add(this, notification_type,
+ NotificationService::AllSources());
+ }
+
+ ~ExecuteBrowserCommandObserver() {
+ }
+
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == notification_type_) {
+ AutomationMsg_WindowExecuteCommandSync::WriteReplyParams(reply_message_,
+ true);
+ automation_->Send(reply_message_);
+ delete this;
+ } else {
+ NOTREACHED();
+ }
+ }
+
+ private:
+ AutomationProvider* automation_;
+ NotificationType::Type notification_type_;
+ IPC::Message* reply_message_;
+ NotificationRegistrar registrar_;
+};
+
class FindInPageNotificationObserver : public NotificationObserver {
public:
FindInPageNotificationObserver(AutomationProvider* automation,
@@ -803,6 +839,8 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
#endif // defined(OS_WIN)
IPC_MESSAGE_HANDLER(AutomationMsg_WindowExecuteCommand,
ExecuteBrowserCommand)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowExecuteCommandSync,
+ ExecuteBrowserCommandWithNotification)
IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBounds,
WindowGetViewBounds)
IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible,
@@ -1283,6 +1321,25 @@ void AutomationProvider::ExecuteBrowserCommand(int handle, int command,
}
}
+void AutomationProvider::ExecuteBrowserCommandWithNotification(
+ int handle, int command, IPC::Message* reply_message) {
+ if (browser_tracker_->ContainsHandle(handle)) {
+ Browser* browser = browser_tracker_->GetResource(handle);
+ if (browser->command_updater()->SupportsCommand(command) &&
+ browser->command_updater()->IsCommandEnabled(command)) {
+ // TODO(huanr): mapping command to notification type.
+ // For now only IDC_NEW_TAB uses this code path.
+ NotificationType::Type type = NotificationType::TAB_PARENTED;
+ new ExecuteBrowserCommandObserver(this, type, reply_message);
+ browser->ExecuteCommand(command);
+ return;
+ }
+ }
+ AutomationMsg_WindowExecuteCommandSync::WriteReplyParams(reply_message,
+ false);
+ Send(reply_message);
+}
+
void AutomationProvider::WindowGetViewBounds(int handle, int view_id,
bool screen_coordinates,
bool* success,