summaryrefslogtreecommitdiffstats
path: root/chrome/browser/automation
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/automation')
-rw-r--r--chrome/browser/automation/automation_provider.h1
-rw-r--r--chrome/browser/automation/automation_provider_observers.cc65
-rw-r--r--chrome/browser/automation/automation_provider_observers.h42
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc12
-rw-r--r--chrome/browser/automation/testing_automation_provider.h2
5 files changed, 121 insertions, 1 deletions
diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h
index a8d531a..d558c45 100644
--- a/chrome/browser/automation/automation_provider.h
+++ b/chrome/browser/automation/automation_provider.h
@@ -29,6 +29,7 @@
#include "chrome/common/notification_observer.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_channel.h"
+
#if defined(OS_WIN)
#include "gfx/native_widget_types.h"
#include "views/event.h"
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc
index 111c220..3d1f780 100644
--- a/chrome/browser/automation/automation_provider_observers.cc
+++ b/chrome/browser/automation/automation_provider_observers.cc
@@ -204,6 +204,7 @@ bool NavigationControllerRestoredObserver::FinishedRestoring() {
void NavigationControllerRestoredObserver::SendDone() {
DCHECK(reply_message_ != NULL);
+ AutomationMsg_WaitForTabToBeRestored::WriteReplyParams(reply_message_, true);
automation_->Send(reply_message_);
}
@@ -750,7 +751,6 @@ struct CommandNotification {
const struct CommandNotification command_notifications[] = {
{IDC_DUPLICATE_TAB, NotificationType::TAB_PARENTED},
- {IDC_NEW_TAB, NotificationType::INITIAL_NEW_TAB_UI_LOAD},
// Returns as soon as the restored tab is created. To further wait until
// the content page is loaded, use WaitForTabToBeRestored.
@@ -776,6 +776,10 @@ bool ExecuteBrowserCommandObserver::CreateAndRegisterObserver(
IPC::Message* reply_message) {
bool result = true;
switch (command) {
+ case IDC_NEW_TAB: {
+ new NewTabObserver(automation, reply_message);
+ break;
+ }
case IDC_NEW_WINDOW:
case IDC_NEW_INCOGNITO_WINDOW: {
BrowserOpenedNotificationObserver* observer =
@@ -1639,3 +1643,62 @@ void RendererProcessClosedObserver::Observe(
AutomationJSONReply(automation_, reply_message_).SendSuccess(NULL);
delete this;
}
+
+NewTabObserver::NewTabObserver(AutomationProvider* automation,
+ IPC::Message* reply_message)
+ : automation_(automation),
+ reply_message_(reply_message) {
+ // Use TAB_PARENTED to detect the new tab.
+ registrar_.Add(this,
+ NotificationType::TAB_PARENTED,
+ NotificationService::AllSources());
+}
+
+void NewTabObserver::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ DCHECK_EQ(NotificationType::TAB_PARENTED, type.value);
+ // We found the new tab. Now wait for it to load.
+ NavigationController* controller = Source<NavigationController>(source).ptr();
+ AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_, true);
+ automation_->AddNavigationStatusListener(
+ controller, reply_message_, 1, false);
+ delete this;
+}
+
+NewTabObserver::~NewTabObserver() {
+}
+
+WaitForProcessLauncherThreadToGoIdleObserver::
+WaitForProcessLauncherThreadToGoIdleObserver(
+ AutomationProvider* automation, IPC::Message* reply_message)
+ : automation_(automation),
+ reply_message_(reply_message) {
+ // Balanced in RunOnUIThread.
+ AddRef();
+ BrowserThread::PostTask(
+ BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
+ NewRunnableMethod(
+ this,
+ &WaitForProcessLauncherThreadToGoIdleObserver::
+ RunOnProcessLauncherThread));
+}
+
+WaitForProcessLauncherThreadToGoIdleObserver::
+~WaitForProcessLauncherThreadToGoIdleObserver() {
+}
+
+void WaitForProcessLauncherThreadToGoIdleObserver::
+RunOnProcessLauncherThread() {
+ BrowserThread::PostTask(
+ BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
+ NewRunnableMethod(
+ this,
+ &WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread));
+}
+
+void WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread() {
+ automation_->Send(reply_message_);
+ Release();
+}
+
diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h
index 6cbe1bd..d7a0c5e 100644
--- a/chrome/browser/automation/automation_provider_observers.h
+++ b/chrome/browser/automation/automation_provider_observers.h
@@ -1028,5 +1028,47 @@ class RendererProcessClosedObserver : public NotificationObserver {
DISALLOW_COPY_AND_ASSIGN(RendererProcessClosedObserver);
};
+// Observer used to listen for new tab creation to complete.
+class NewTabObserver : public NotificationObserver {
+ public:
+ NewTabObserver(AutomationProvider* automation, IPC::Message* reply_message);
+
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) OVERRIDE;
+
+ private:
+ ~NewTabObserver();
+
+ NotificationRegistrar registrar_;
+ scoped_refptr<AutomationProvider> automation_;
+ IPC::Message* reply_message_;
+
+ DISALLOW_COPY_AND_ASSIGN(NewTabObserver);
+};
+
+// Posts a task to the PROCESS_LAUNCHER thread, once processed posts a task
+// back to the UI thread that notifies the provider we're done.
+class WaitForProcessLauncherThreadToGoIdleObserver
+ : public base::RefCountedThreadSafe<
+ WaitForProcessLauncherThreadToGoIdleObserver> {
+ public:
+ WaitForProcessLauncherThreadToGoIdleObserver(
+ AutomationProvider* automation, IPC::Message* reply_message);
+
+ private:
+ friend class base::RefCountedThreadSafe<
+ WaitForProcessLauncherThreadToGoIdleObserver>;
+
+ ~WaitForProcessLauncherThreadToGoIdleObserver();
+
+ void RunOnProcessLauncherThread();
+ void RunOnUIThread();
+
+ scoped_refptr<AutomationProvider> automation_;
+ IPC::Message* reply_message_;
+
+ DISALLOW_COPY_AND_ASSIGN(WaitForProcessLauncherThreadToGoIdleObserver);
+};
#endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 088a23a..d4c946b 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -393,6 +393,9 @@ bool TestingAutomationProvider::OnMessageReceived(
IPC_MESSAGE_HANDLER(AutomationMsg_SetContentSetting, SetContentSetting)
IPC_MESSAGE_HANDLER(AutomationMsg_LoadBlockedPlugins, LoadBlockedPlugins)
IPC_MESSAGE_HANDLER(AutomationMsg_ResetToDefaultTheme, ResetToDefaultTheme)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(
+ AutomationMsg_WaitForProcessLauncherThreadToGoIdle,
+ WaitForProcessLauncherThreadToGoIdle)
IPC_MESSAGE_UNHANDLED(
handled = AutomationProvider::OnMessageReceived(message))
@@ -1262,6 +1265,10 @@ void TestingAutomationProvider::WaitForTabToBeRestored(
NavigationController* tab = tab_tracker_->GetResource(tab_handle);
restore_tracker_.reset(
new NavigationControllerRestoredObserver(this, tab, reply_message));
+ } else {
+ AutomationMsg_WaitForTabToBeRestored::WriteReplyParams(
+ reply_message, false);
+ Send(reply_message);
}
}
@@ -4469,6 +4476,11 @@ void TestingAutomationProvider::ResetToDefaultTheme() {
profile_->ClearTheme();
}
+void TestingAutomationProvider::WaitForProcessLauncherThreadToGoIdle(
+ IPC::Message* reply_message) {
+ new WaitForProcessLauncherThreadToGoIdleObserver(this, reply_message);
+}
+
// TODO(brettw) change this to accept GURLs when history supports it
void TestingAutomationProvider::OnRedirectQueryComplete(
HistoryService::Handle request_handle,
diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h
index 9c8d471c..27252ef 100644
--- a/chrome/browser/automation/testing_automation_provider.h
+++ b/chrome/browser/automation/testing_automation_provider.h
@@ -775,6 +775,8 @@ class TestingAutomationProvider : public AutomationProvider,
// Resets to the default theme.
void ResetToDefaultTheme();
+ void WaitForProcessLauncherThreadToGoIdle(IPC::Message* reply_message);
+
// Callback for history redirect queries.
virtual void OnRedirectQueryComplete(
HistoryService::Handle request_handle,