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-04-08 00:04:27 +0000
committerhuanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-08 00:04:27 +0000
commit4e41709d76504c389bb8c29b61a71773b5db6239 (patch)
treee26b7327785ff0afcba4126f2ea45276e4ca7e63 /chrome/browser/automation/automation_provider.cc
parent0cbd8e66a343e15f144d88f6f984082936499b6f (diff)
downloadchromium_src-4e41709d76504c389bb8c29b61a71773b5db6239.zip
chromium_src-4e41709d76504c389bb8c29b61a71773b5db6239.tar.gz
chromium_src-4e41709d76504c389bb8c29b61a71773b5db6239.tar.bz2
Skeleton setup for new Automated UI test framework.
- Add automated_ui_test_base.{cc,h} that defines an AutomatedUITestBase class. This class can be used for both UI test suites and automated UI test running on ChromeBot. - Add automated_ui_test_test and include it in UI test suite so we can individually test all commands provided in AutomatedUITestBase. - Change AutomatedUITest to be a subclass of AutomatedUITestBase. Move RunCommandAsync(), RunCommand(), and NewTab() from AutomatedUITest to AutomatedUITestBase. The plan is moving all individual UI command functions (after they are converted to sync mode) to AutomatedUITestBase so they can be shared by UI test suites and automated UI test. - In automation_provider.cc, add a mapping mechanism from command to notification type. This will make it easy to add more command types. Review URL: http://codereview.chromium.org/56190 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13312 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation/automation_provider.cc')
-rw-r--r--chrome/browser/automation/automation_provider.cc56
1 files changed, 44 insertions, 12 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index c8292ec..8a9aa98 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -453,22 +453,39 @@ class BrowserClosedNotificationObserver : public NotificationObserver {
IPC::Message* reply_message_;
};
+namespace {
+
+// Define mapping from command to notification
+struct CommandNotification {
+ int command;
+ NotificationType::Type notification_type;
+};
+
+const struct CommandNotification command_notifications[] = {
+ {IDC_NEW_TAB, NotificationType::TAB_PARENTED}
+};
+
+} // namespace
+
class ExecuteBrowserCommandObserver : public NotificationObserver {
public:
- ExecuteBrowserCommandObserver(
- AutomationProvider* automation,
- NotificationType::Type notification_type,
- IPC::Message* reply_message)
+ ExecuteBrowserCommandObserver(AutomationProvider* automation,
+ IPC::Message* reply_message)
: automation_(automation),
- notification_type_(notification_type),
reply_message_(reply_message) {
- registrar_.Add(this, notification_type,
- NotificationService::AllSources());
}
~ExecuteBrowserCommandObserver() {
}
+ bool Register(int command) {
+ if (!GetNotificationType(command, &notification_type_))
+ return false;
+ registrar_.Add(this, notification_type_,
+ NotificationService::AllSources());
+ return true;
+ }
+
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
@@ -483,6 +500,20 @@ class ExecuteBrowserCommandObserver : public NotificationObserver {
}
private:
+ bool GetNotificationType(int command, NotificationType::Type* type) {
+ if (!type)
+ return false;
+ bool found = false;
+ for (unsigned int i = 0; i < arraysize(command_notifications); i++) {
+ if (command_notifications[i].command == command) {
+ *type = command_notifications[i].notification_type;
+ found = true;
+ break;
+ }
+ }
+ return found;
+ }
+
AutomationProvider* automation_;
NotificationType::Type notification_type_;
IPC::Message* reply_message_;
@@ -1326,11 +1357,12 @@ void AutomationProvider::ExecuteBrowserCommandWithNotification(
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);
+ ExecuteBrowserCommandObserver* observer =
+ new ExecuteBrowserCommandObserver(this, reply_message);
+ if (observer->Register(command))
+ browser->ExecuteCommand(command);
+ else
+ delete observer;
return;
}
}