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_observers.cc43
-rw-r--r--chrome/browser/automation/automation_provider_observers.h32
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc19
-rw-r--r--chrome/browser/automation/testing_automation_provider.h4
4 files changed, 98 insertions, 0 deletions
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc
index 0107708..a30e801 100644
--- a/chrome/browser/automation/automation_provider_observers.cc
+++ b/chrome/browser/automation/automation_provider_observers.cc
@@ -340,6 +340,49 @@ void TabClosedNotificationObserver::set_for_browser_command(
for_browser_command_ = for_browser_command;
}
+TabCountChangeObserver::TabCountChangeObserver(AutomationProvider* automation,
+ Browser* browser,
+ IPC::Message* reply_message,
+ int target_tab_count)
+ : automation_(automation),
+ reply_message_(reply_message),
+ tab_strip_model_(browser->tabstrip_model()),
+ target_tab_count_(target_tab_count) {
+ tab_strip_model_->AddObserver(this);
+ CheckTabCount();
+}
+
+TabCountChangeObserver::~TabCountChangeObserver() {
+ tab_strip_model_->RemoveObserver(this);
+}
+
+void TabCountChangeObserver::TabInsertedAt(TabContents* contents,
+ int index,
+ bool foreground) {
+ CheckTabCount();
+}
+
+void TabCountChangeObserver::TabClosingAt(TabContents* contents, int index) {
+ CheckTabCount();
+}
+
+void TabCountChangeObserver::TabStripModelDeleted() {
+ AutomationMsg_WaitForTabCountToBecome::WriteReplyParams(reply_message_,
+ false);
+ automation_->Send(reply_message_);
+ delete this;
+}
+
+void TabCountChangeObserver::CheckTabCount() {
+ if (tab_strip_model_->count() != target_tab_count_)
+ return;
+
+ AutomationMsg_WaitForTabCountToBecome::WriteReplyParams(reply_message_,
+ true);
+ automation_->Send(reply_message_);
+ delete this;
+}
+
bool DidExtensionHostsStopLoading(ExtensionProcessManager* manager) {
for (ExtensionProcessManager::const_iterator iter = manager->begin();
iter != manager->end(); ++iter) {
diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h
index e55fec8..c9e3afd 100644
--- a/chrome/browser/automation/automation_provider_observers.h
+++ b/chrome/browser/automation/automation_provider_observers.h
@@ -19,6 +19,7 @@
#include "chrome/browser/importer/importer_data_types.h"
#include "chrome/browser/password_manager/password_store.h"
#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
#include "chrome/common/notification_type.h"
@@ -191,6 +192,37 @@ class TabClosedNotificationObserver : public TabStripNotificationObserver {
DISALLOW_COPY_AND_ASSIGN(TabClosedNotificationObserver);
};
+// Notifies when the tab count reaches the target number.
+class TabCountChangeObserver : public TabStripModelObserver {
+ public:
+ TabCountChangeObserver(AutomationProvider* automation,
+ Browser* browser,
+ IPC::Message* reply_message,
+ int target_tab_count);
+ // Implementation of TabStripModelObserver.
+ virtual void TabInsertedAt(TabContents* contents,
+ int index,
+ bool foreground);
+ virtual void TabClosingAt(TabContents* contents, int index);
+ virtual void TabStripModelDeleted();
+
+ private:
+ ~TabCountChangeObserver();
+
+ // Checks if the current tab count matches our target, and if so,
+ // sends the reply message and deletes self.
+ void CheckTabCount();
+
+ AutomationProvider* automation_;
+ IPC::Message* reply_message_;
+
+ TabStripModel* tab_strip_model_;
+
+ const int target_tab_count_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabCountChangeObserver);
+};
+
// Observes when an extension has finished installing or possible install
// errors. This does not guarantee that the extension is ready for use.
class ExtensionInstallNotificationObserver : public NotificationObserver {
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 62e98a9..1a0afca 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -403,6 +403,8 @@ void TestingAutomationProvider::OnMessageReceived(
IPC_MESSAGE_HANDLER(AutomationMsg_BlockedPopupCount, GetBlockedPopupCount)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SendJSONRequest,
SendJSONRequest)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabCountToBecome,
+ WaitForTabCountToBecome)
IPC_MESSAGE_UNHANDLED(AutomationProvider::OnMessageReceived(message));
IPC_END_MESSAGE_MAP()
@@ -3689,6 +3691,23 @@ std::map<AutoFillFieldType, std::wstring>
return credit_card_type_to_string;
}
+void TestingAutomationProvider::WaitForTabCountToBecome(
+ int browser_handle,
+ int target_tab_count,
+ IPC::Message* reply_message) {
+ if (!browser_tracker_->ContainsHandle(browser_handle)) {
+ AutomationMsg_WaitForTabCountToBecome::WriteReplyParams(reply_message,
+ false);
+ Send(reply_message);
+ return;
+ }
+
+ Browser* browser = browser_tracker_->GetResource(browser_handle);
+
+ // The observer will delete itself.
+ new TabCountChangeObserver(this, browser, reply_message, target_tab_count);
+}
+
// 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 10fe387..565bd8c 100644
--- a/chrome/browser/automation/testing_automation_provider.h
+++ b/chrome/browser/automation/testing_automation_provider.h
@@ -596,6 +596,10 @@ class TestingAutomationProvider : public AutomationProvider,
static std::map<AutoFillFieldType, std::wstring>
GetCreditCardFieldToStringMap();
+ void WaitForTabCountToBecome(int browser_handle,
+ int target_tab_count,
+ IPC::Message* reply_message);
+
// Callback for history redirect queries.
virtual void OnRedirectQueryComplete(
HistoryService::Handle request_handle,