diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-08 22:04:40 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-08 22:04:40 +0000 |
commit | e04c7eacaa5092fa740c5ac330f4b8f01755fc2d (patch) | |
tree | 1cfd82a2b49c98aa26ab83767f821726ed8ad687 /chrome/browser/automation | |
parent | a233a64c05fa151f0a9d1eff6839962d23d82b17 (diff) | |
download | chromium_src-e04c7eacaa5092fa740c5ac330f4b8f01755fc2d.zip chromium_src-e04c7eacaa5092fa740c5ac330f4b8f01755fc2d.tar.gz chromium_src-e04c7eacaa5092fa740c5ac330f4b8f01755fc2d.tar.bz2 |
GTTF: Make WaitForInfoBarCount not Sleep.
Use an observer instead, to wait more reliably.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3344006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58880 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation')
4 files changed, 87 insertions, 1 deletions
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index a30e801..d0ef3de 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -1054,6 +1054,37 @@ void TabLanguageDeterminedObserver::Observe( delete this; } +InfoBarCountObserver::InfoBarCountObserver(AutomationProvider* automation, + IPC::Message* reply_message, + TabContents* tab_contents, + int target_count) + : automation_(automation), + reply_message_(reply_message), + tab_contents_(tab_contents), + target_count_(target_count) { + Source<TabContents> source(tab_contents); + registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED, source); + registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, source); + CheckCount(); +} + +void InfoBarCountObserver::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + DCHECK(type == NotificationType::TAB_CONTENTS_INFOBAR_ADDED || + type == NotificationType::TAB_CONTENTS_INFOBAR_REMOVED); + CheckCount(); +} + +void InfoBarCountObserver::CheckCount() { + if (tab_contents_->infobar_delegate_count() != target_count_) + return; + + AutomationMsg_WaitForInfoBarCount::WriteReplyParams(reply_message_, true); + automation_->Send(reply_message_); + delete this; +} + #if defined(OS_CHROMEOS) LoginManagerObserver::LoginManagerObserver( AutomationProvider* automation, diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h index c9e3afd..78dc586 100644 --- a/chrome/browser/automation/automation_provider_observers.h +++ b/chrome/browser/automation/automation_provider_observers.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -562,6 +562,33 @@ class TabLanguageDeterminedObserver : public NotificationObserver { DISALLOW_COPY_AND_ASSIGN(TabLanguageDeterminedObserver); }; +class InfoBarCountObserver : public NotificationObserver { + public: + InfoBarCountObserver(AutomationProvider* automation, + IPC::Message* reply_message, + TabContents* tab_contents, + int target_count); + + // NotificationObserver interface. + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + private: + // Checks whether the infobar count matches our target, and if so + // sends the reply message and deletes itself. + void CheckCount(); + + NotificationRegistrar registrar_; + AutomationProvider* automation_; + IPC::Message* reply_message_; + TabContents* tab_contents_; + + const int target_count_; + + DISALLOW_COPY_AND_ASSIGN(InfoBarCountObserver); +}; + #if defined(OS_CHROMEOS) // Collects LOGIN_AUTHENTICATION notifications and returns // whether authentication succeeded to the automation provider. diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 1a0afca..4f937b6 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -405,6 +405,8 @@ void TestingAutomationProvider::OnMessageReceived( SendJSONRequest) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabCountToBecome, WaitForTabCountToBecome) + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForInfoBarCount, + WaitForInfoBarCount) IPC_MESSAGE_UNHANDLED(AutomationProvider::OnMessageReceived(message)); IPC_END_MESSAGE_MAP() @@ -3708,6 +3710,28 @@ void TestingAutomationProvider::WaitForTabCountToBecome( new TabCountChangeObserver(this, browser, reply_message, target_tab_count); } +void TestingAutomationProvider::WaitForInfoBarCount( + int tab_handle, + int target_count, + IPC::Message* reply_message) { + if (!tab_tracker_->ContainsHandle(tab_handle)) { + AutomationMsg_WaitForInfoBarCount::WriteReplyParams(reply_message_, false); + Send(reply_message_); + return; + } + + NavigationController* controller = tab_tracker_->GetResource(tab_handle); + if (!controller) { + AutomationMsg_WaitForInfoBarCount::WriteReplyParams(reply_message_, false); + Send(reply_message_); + return; + } + + // The delegate will delete itself. + new InfoBarCountObserver(this, reply_message, controller->tab_contents(), + target_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 565bd8c..3f0930d 100644 --- a/chrome/browser/automation/testing_automation_provider.h +++ b/chrome/browser/automation/testing_automation_provider.h @@ -600,6 +600,10 @@ class TestingAutomationProvider : public AutomationProvider, int target_tab_count, IPC::Message* reply_message); + void WaitForInfoBarCount(int tab_handle, + int target_count, + IPC::Message* reply_message); + // Callback for history redirect queries. virtual void OnRedirectQueryComplete( HistoryService::Handle request_handle, |