diff options
-rw-r--r-- | chrome/browser/automation/automation_provider_observers.cc | 73 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider_observers.h | 20 | ||||
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.cc | 23 | ||||
-rw-r--r-- | chrome/test/functional/PYAUTO_TESTS | 5 | ||||
-rw-r--r-- | chrome/test/functional/notifications.py | 8 |
5 files changed, 99 insertions, 30 deletions
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index 1cec458..505836c 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -34,9 +34,13 @@ #include "chrome/browser/history/top_sites.h" #include "chrome/browser/metrics/metric_event_duration_details.h" #include "chrome/browser/notifications/balloon.h" +#include "chrome/browser/notifications/balloon_host.h" #include "chrome/browser/notifications/balloon_collection.h" +#include "chrome/browser/notifications/notification.h" +#include "chrome/browser/notifications/notification_ui_manager.h" #include "chrome/browser/printing/print_job.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/sessions/tab_restore_service.h" @@ -1530,6 +1534,75 @@ void AutocompleteEditFocusedObserver::Observe( delete this; } +namespace { + +// Returns whether the notification's host has a non-null process handle. +bool IsNotificationProcessReady(Balloon* balloon) { + return balloon->view() && + balloon->view()->GetHost() && + balloon->view()->GetHost()->render_view_host() && + balloon->view()->GetHost()->render_view_host()->process()->GetHandle(); +} + +// Returns whether all active notifications have an associated process ID. +bool AreActiveNotificationProcessesReady() { + NotificationUIManager* manager = g_browser_process->notification_ui_manager(); + const BalloonCollection::Balloons& balloons = + manager->balloon_collection()->GetActiveBalloons(); + BalloonCollection::Balloons::const_iterator iter; + for (iter = balloons.begin(); iter != balloons.end(); ++iter) { + if (!IsNotificationProcessReady(*iter)) + return false; + } + return true; +} + +} // namespace + +GetActiveNotificationsObserver::GetActiveNotificationsObserver( + AutomationProvider* automation, + IPC::Message* reply_message) + : reply_(automation, reply_message) { + if (AreActiveNotificationProcessesReady()) { + SendMessage(); + } else { + registrar_.Add(this, NotificationType::RENDERER_PROCESS_CREATED, + NotificationService::AllSources()); + } +} + +void GetActiveNotificationsObserver::Observe( + NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + if (AreActiveNotificationProcessesReady()) + SendMessage(); +} + +void GetActiveNotificationsObserver::SendMessage() { + NotificationUIManager* manager = + g_browser_process->notification_ui_manager(); + const BalloonCollection::Balloons& balloons = + manager->balloon_collection()->GetActiveBalloons(); + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); + ListValue* list = new ListValue; + return_value->Set("notifications", list); + BalloonCollection::Balloons::const_iterator iter; + for (iter = balloons.begin(); iter != balloons.end(); ++iter) { + const Notification& notification = (*iter)->notification(); + DictionaryValue* balloon = new DictionaryValue; + balloon->SetString("content_url", notification.content_url().spec()); + balloon->SetString("origin_url", notification.origin_url().spec()); + balloon->SetString("display_source", notification.display_source()); + BalloonView* view = (*iter)->view(); + balloon->SetInteger("pid", base::GetProcId( + view->GetHost()->render_view_host()->process()->GetHandle())); + list->Append(balloon); + } + reply_.SendSuccess(return_value.get()); + delete this; +} + OnNotificationBalloonCountObserver::OnNotificationBalloonCountObserver( AutomationProvider* provider, IPC::Message* reply_message, diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h index dd49775..8868863 100644 --- a/chrome/browser/automation/automation_provider_observers.h +++ b/chrome/browser/automation/automation_provider_observers.h @@ -970,6 +970,26 @@ class AutocompleteEditFocusedObserver : public NotificationObserver { DISALLOW_COPY_AND_ASSIGN(AutocompleteEditFocusedObserver); }; +// Allows the automation provider to wait until all the notification +// processes are ready. +class GetActiveNotificationsObserver : public NotificationObserver { + public: + GetActiveNotificationsObserver(AutomationProvider* automation, + IPC::Message* reply_message); + + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + private: + void SendMessage(); + + AutomationJSONReply reply_; + NotificationRegistrar registrar_; + + DISALLOW_COPY_AND_ASSIGN(GetActiveNotificationsObserver); +}; + // Allows the automation provider to wait for a given number of // notification balloons. class OnNotificationBalloonCountObserver { diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 215a480..fcc609f 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -44,7 +44,6 @@ #include "chrome/browser/importer/importer.h" #include "chrome/browser/notifications/balloon.h" #include "chrome/browser/notifications/balloon_collection.h" -#include "chrome/browser/notifications/balloon_host.h" #include "chrome/browser/notifications/notification.h" #include "chrome/browser/notifications/notification_ui_manager.h" #include "chrome/browser/profiles/profile.h" @@ -4210,27 +4209,7 @@ void TestingAutomationProvider::GetActiveNotifications( Browser* browser, DictionaryValue* args, IPC::Message* reply_message) { - NotificationUIManager* manager = g_browser_process->notification_ui_manager(); - const BalloonCollection::Balloons& balloons = - manager->balloon_collection()->GetActiveBalloons(); - scoped_ptr<DictionaryValue> return_value(new DictionaryValue); - ListValue* list = new ListValue; - return_value->Set("notifications", list); - BalloonCollection::Balloons::const_iterator iter; - for (iter = balloons.begin(); iter != balloons.end(); ++iter) { - const Notification& notification = (*iter)->notification(); - DictionaryValue* balloon = new DictionaryValue; - balloon->SetString("content_url", notification.content_url().spec()); - balloon->SetString("origin_url", notification.origin_url().spec()); - balloon->SetString("display_source", notification.display_source()); - BalloonView* view = (*iter)->view(); - if (view && view->GetHost() && view->GetHost()->render_view_host()) { - balloon->SetInteger("pid", base::GetProcId( - view->GetHost()->render_view_host()->process()->GetHandle())); - } - list->Append(balloon); - } - AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); + new GetActiveNotificationsObserver(this, reply_message); } // Refer to CloseNotification() in chrome/test/pyautolib/pyauto.py for diff --git a/chrome/test/functional/PYAUTO_TESTS b/chrome/test/functional/PYAUTO_TESTS index 8db5f34..4280c39 100644 --- a/chrome/test/functional/PYAUTO_TESTS +++ b/chrome/test/functional/PYAUTO_TESTS @@ -43,11 +43,6 @@ 'infobars', 'navigation', 'notifications', - # Sometimes notification process hasn't been created yet, crbug.com/65408 - '-notifications.NotificationsTest.testKillNotificationProcess', - # crbug.com/66072 - '-notifications.NotificationsTest.testNotificationReplacement', - '-notifications.NotificationsTest.testNotificationOrderAfterClosingOne', 'ntp', 'omnibox', 'passwords', diff --git a/chrome/test/functional/notifications.py b/chrome/test/functional/notifications.py index 29bf31b..b15fbb2 100644 --- a/chrome/test/functional/notifications.py +++ b/chrome/test/functional/notifications.py @@ -527,12 +527,14 @@ class NotificationsTest(pyauto.PyUITest): """Test that we can replace a notification using the replaceId.""" self._AllowAllOrigins() self.NavigateToURL(self.TEST_PAGE_URL) - self._CreateHTMLNotification(self.NO_SUCH_URL, 'chat') + self._CreateSimpleNotification('', 'Title2', '', 'chat') self.WaitForNotificationCount(1) - self._CreateHTMLNotification(self.NO_SUCH_URL2, 'chat') + # Since this notification has the same replaceId, 'chat', it should replace + # the first notification. + self._CreateHTMLNotification(self.NO_SUCH_URL, 'chat') notifications = self.GetActiveNotifications() self.assertEquals(1, len(notifications)) - self.assertEquals(self.NO_SUCH_URL2, notifications[0]['content_url']) + self.assertEquals(self.NO_SUCH_URL, notifications[0]['content_url']) if __name__ == '__main__': |