Index: content/shell/browser/layout_test/layout_test_notification_manager.cc |
diff --git a/content/shell/browser/layout_test/layout_test_notification_manager.cc b/content/shell/browser/layout_test/layout_test_notification_manager.cc |
index a30c719b0f54904c8657db984816c327a083841c..6748a3ed39ecb2495ca1dc797005e5ada7f405f7 100644 |
--- a/content/shell/browser/layout_test/layout_test_notification_manager.cc |
+++ b/content/shell/browser/layout_test/layout_test_notification_manager.cc |
@@ -16,13 +16,11 @@ |
#include "content/shell/browser/layout_test/layout_test_content_browser_client.h" |
#include "content/shell/browser/layout_test/layout_test_permission_manager.h" |
+using message_center::Notification; |
+ |
namespace content { |
namespace { |
-// The Web Notification layout tests don't care about the lifetime of the |
-// Service Worker when a notificationclick event has been dispatched. |
-void OnEventDispatchComplete(PersistentNotificationStatus status) {} |
- |
blink::WebNotificationPermission ToWebNotificationPermission( |
PermissionStatus status) { |
switch (status) { |
@@ -40,85 +38,55 @@ blink::WebNotificationPermission ToWebNotificationPermission( |
} // namespace |
-LayoutTestNotificationManager::LayoutTestNotificationManager() |
- : weak_factory_(this) {} |
+LayoutTestNotificationManager::LayoutTestNotificationManager() {} |
LayoutTestNotificationManager::~LayoutTestNotificationManager() {} |
void LayoutTestNotificationManager::DisplayNotification( |
BrowserContext* browser_context, |
- const GURL& origin, |
- const SkBitmap& icon, |
- const PlatformNotificationData& notification_data, |
- scoped_ptr<DesktopNotificationDelegate> delegate, |
- base::Closure* cancel_callback) { |
+ const Notification& notification) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
- std::string title = base::UTF16ToUTF8(notification_data.title); |
- |
- DCHECK(cancel_callback); |
- *cancel_callback = base::Bind(&LayoutTestNotificationManager::Close, |
- weak_factory_.GetWeakPtr(), |
- title); |
- |
- ReplaceNotificationIfNeeded(notification_data); |
- page_notifications_[title] = delegate.release(); |
- page_notifications_[title]->NotificationDisplayed(); |
-} |
- |
-void LayoutTestNotificationManager::DisplayPersistentNotification( |
- BrowserContext* browser_context, |
- int64_t persistent_notification_id, |
- const GURL& origin, |
- const SkBitmap& icon, |
- const PlatformNotificationData& notification_data) { |
- DCHECK_CURRENTLY_ON(BrowserThread::UI); |
- std::string title = base::UTF16ToUTF8(notification_data.title); |
+ const std::string& notification_id = notification.id(); |
- ReplaceNotificationIfNeeded(notification_data); |
+ // Deterministic notification id generation allows us to simply check for |
+ // notifications sharing an id with |notification| rather than having to |
+ // consider the tag when closing to-be-replaced notifications. |
+ if (notifications_.contains(notification_id)) |
+ CloseNotification(browser_context, notification_id); |
- PersistentNotification notification; |
- notification.browser_context = browser_context; |
- notification.origin = origin; |
- notification.persistent_id = persistent_notification_id; |
+ // Makes sure that the |onshow| event fires for non-persistent notifications. |
+ notification.delegate()->Display(); |
- persistent_notifications_[title] = notification; |
+ notifications_.add(notification_id, |
+ make_scoped_ptr(new Notification(notification))); |
} |
-void LayoutTestNotificationManager::ClosePersistentNotification( |
+void LayoutTestNotificationManager::CloseNotification( |
BrowserContext* browser_context, |
- int64_t persistent_notification_id) { |
- for (const auto& iter : persistent_notifications_) { |
- if (iter.second.persistent_id != persistent_notification_id) |
- continue; |
- |
- persistent_notifications_.erase(iter.first); |
+ const std::string& notification_id) { |
+ Notification* notification = notifications_.get(notification_id); |
+ if (!notification) |
return; |
- } |
+ |
+ // Makes sure that the |onclose| event fires for non-persistent notifications. |
+ notification->delegate()->Close(false /* by_user */); |
+ |
+ notifications_.erase(notification_id); |
} |
void LayoutTestNotificationManager::SimulateClick(const std::string& title) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
- // First check for page-notifications with the given title. |
- const auto& page_iterator = page_notifications_.find(title); |
- if (page_iterator != page_notifications_.end()) { |
- page_iterator->second->NotificationClick(); |
- return; |
- } |
- |
- // Then check for persistent notifications with the given title. |
- const auto& persistent_iterator = persistent_notifications_.find(title); |
- if (persistent_iterator == persistent_notifications_.end()) |
- return; |
+ base::string16 title16 = base::UTF8ToUTF16(title); |
+ for (const auto& iter : notifications_) { |
+ if (iter.second->title() != title16) |
+ continue; |
- const PersistentNotification& notification = persistent_iterator->second; |
- content::NotificationEventDispatcher::GetInstance() |
- ->DispatchNotificationClickEvent( |
- notification.browser_context, |
- notification.persistent_id, |
- notification.origin, |
- base::Bind(&OnEventDispatchComplete)); |
+ // Makes sure that the |onclick| event fires for non-persistent |
+ // notifications, or the |onnotificationclick| event for persistent ones. |
+ iter.second->delegate()->Click(); |
+ } |
} |
blink::WebNotificationPermission |
@@ -139,46 +107,6 @@ LayoutTestNotificationManager::CheckPermissionOnIOThread( |
return CheckPermission(origin); |
} |
-void LayoutTestNotificationManager::Close(const std::string& title) { |
- DCHECK_CURRENTLY_ON(BrowserThread::UI); |
- auto iterator = page_notifications_.find(title); |
- if (iterator == page_notifications_.end()) |
- return; |
- |
- iterator->second->NotificationClosed(); |
-} |
- |
-void LayoutTestNotificationManager::ReplaceNotificationIfNeeded( |
- const PlatformNotificationData& notification_data) { |
- if (!notification_data.tag.length()) |
- return; |
- |
- std::string tag = notification_data.tag; |
- const auto& replace_iter = replacements_.find(tag); |
- if (replace_iter != replacements_.end()) { |
- const std::string& previous_title = replace_iter->second; |
- |
- const auto& page_notification_iter = |
- page_notifications_.find(previous_title); |
- if (page_notification_iter != page_notifications_.end()) { |
- DesktopNotificationDelegate* previous_delegate = |
- page_notification_iter->second; |
- |
- previous_delegate->NotificationClosed(); |
- |
- page_notifications_.erase(page_notification_iter); |
- delete previous_delegate; |
- } |
- |
- const auto& persistent_notification_iter = |
- persistent_notifications_.find(previous_title); |
- if (persistent_notification_iter != persistent_notifications_.end()) |
- persistent_notifications_.erase(persistent_notification_iter); |
- } |
- |
- replacements_[tag] = base::UTF16ToUTF8(notification_data.title); |
-} |
- |
blink::WebNotificationPermission |
LayoutTestNotificationManager::CheckPermission(const GURL& origin) { |
return ToWebNotificationPermission(LayoutTestContentBrowserClient::Get() |