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 | |
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
9 files changed, 108 insertions, 21 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, diff --git a/chrome/browser/notifications/notifications_interactive_uitest.cc b/chrome/browser/notifications/notifications_interactive_uitest.cc index 97bb1e2..afd44d7 100644 --- a/chrome/browser/notifications/notifications_interactive_uitest.cc +++ b/chrome/browser/notifications/notifications_interactive_uitest.cc @@ -40,7 +40,7 @@ TEST_F(NotificationsPermissionTest, TestUserGestureInfobar) { &result)); EXPECT_TRUE(result); - EXPECT_TRUE(tab->WaitForInfoBarCount(1, action_max_timeout_ms())); + EXPECT_TRUE(tab->WaitForInfoBarCount(1)); } TEST_F(NotificationsPermissionTest, TestNoUserGestureInfobar) { diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h index 196fe0f..2f413d7 100644 --- a/chrome/test/automation/automation_messages_internal.h +++ b/chrome/test/automation/automation_messages_internal.h @@ -1434,4 +1434,10 @@ IPC_BEGIN_MESSAGES(Automation) int /* target tab count */, bool /* success */) + // Waits for the infobar count to reach given number. + IPC_SYNC_MESSAGE_ROUTED2_1(AutomationMsg_WaitForInfoBarCount, + int /* tab handle */, + int /* target count */, + bool /* success */) + IPC_END_MESSAGES(Automation) diff --git a/chrome/test/automation/tab_proxy.cc b/chrome/test/automation/tab_proxy.cc index cf37561..3888c79 100644 --- a/chrome/test/automation/tab_proxy.cc +++ b/chrome/test/automation/tab_proxy.cc @@ -658,17 +658,13 @@ bool TabProxy::GetInfoBarCount(int* count) { return sender_->Send(new AutomationMsg_GetInfoBarCount(0, handle_, count)); } -bool TabProxy::WaitForInfoBarCount(int target_count, int wait_timeout) { - int intervals = std::max(wait_timeout / automation::kSleepTime, 1); - for (int i = 0; i < intervals; ++i) { - PlatformThread::Sleep(automation::kSleepTime); - int new_count = -1; - if (!GetInfoBarCount(&new_count)) - return false; - if (target_count == new_count) - return true; - } - return false; +bool TabProxy::WaitForInfoBarCount(int target_count) { + if (!is_valid()) + return false; + + bool success = false; + return sender_->Send(new AutomationMsg_WaitForInfoBarCount( + 0, handle_, target_count, &success)) && success; } bool TabProxy::ClickInfoBarAccept(int info_bar_index, diff --git a/chrome/test/automation/tab_proxy.h b/chrome/test/automation/tab_proxy.h index dd97f26..b360b84 100644 --- a/chrome/test/automation/tab_proxy.h +++ b/chrome/test/automation/tab_proxy.h @@ -346,10 +346,9 @@ class TabProxy : public AutomationResourceProxy, // Retrieves the number of info-bars currently showing in |count|. bool GetInfoBarCount(int* count) WARN_UNUSED_RESULT; - // Waits for up to |wait_timeout| ms until the infobar count is |count|. - // Returns false if a timeout occurred before the count matched, or an - // error occurred retrieving the count. - bool WaitForInfoBarCount(int count, int wait_timeout) WARN_UNUSED_RESULT; + // Waits until the infobar count is |count|. + // Returns true on success. + bool WaitForInfoBarCount(int count) WARN_UNUSED_RESULT; // Causes a click on the "accept" button of the info-bar at |info_bar_index|. // If |wait_for_navigation| is true, this call does not return until a diff --git a/chrome/test/interactive_ui/infobars_uitest.cc b/chrome/test/interactive_ui/infobars_uitest.cc index 34d1bda..def82d5 100644 --- a/chrome/test/interactive_ui/infobars_uitest.cc +++ b/chrome/test/interactive_ui/infobars_uitest.cc @@ -31,7 +31,7 @@ TEST_F(InfoBarsUITest, TestInfoBarsCloseOnNewTheme) { test_data_directory_.AppendASCII("extensions").AppendASCII("theme.crx"), true); ASSERT_TRUE(theme != NULL); - EXPECT_TRUE(tab_1->WaitForInfoBarCount(1, action_max_timeout_ms())); + EXPECT_TRUE(tab_1->WaitForInfoBarCount(1)); EXPECT_TRUE(browser->AppendTab( test_server.GetURL("files/simple.html"))); @@ -42,9 +42,9 @@ TEST_F(InfoBarsUITest, TestInfoBarsCloseOnNewTheme) { test_data_directory_.AppendASCII("extensions").AppendASCII("theme2.crx"), true); ASSERT_TRUE(theme != NULL); - EXPECT_TRUE(tab_2->WaitForInfoBarCount(1, action_max_timeout_ms())); - EXPECT_TRUE(tab_1->WaitForInfoBarCount(0, action_max_timeout_ms())); + EXPECT_TRUE(tab_2->WaitForInfoBarCount(1)); + EXPECT_TRUE(tab_1->WaitForInfoBarCount(0)); EXPECT_TRUE(automation()->ResetToDefaultTheme()); - EXPECT_TRUE(tab_2->WaitForInfoBarCount(0, action_max_timeout_ms())); + EXPECT_TRUE(tab_2->WaitForInfoBarCount(0)); } |