| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/shell/browser/layout_test/layout_test_notification_manager.h" | 5 #include "content/shell/browser/layout_test/layout_test_notification_manager.h" |
| 6 | 6 |
| 7 #include "base/guid.h" | 7 #include "base/guid.h" |
| 8 #include "base/strings/nullable_string16.h" | 8 #include "base/strings/nullable_string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 bool LayoutTestNotificationManager::GetDisplayedPersistentNotifications( | 86 bool LayoutTestNotificationManager::GetDisplayedPersistentNotifications( |
| 87 BrowserContext* browser_context, | 87 BrowserContext* browser_context, |
| 88 std::set<std::string>* displayed_notifications) { | 88 std::set<std::string>* displayed_notifications) { |
| 89 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 89 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 90 DCHECK(displayed_notifications); | 90 DCHECK(displayed_notifications); |
| 91 | 91 |
| 92 // Notifications will never outlive the lifetime of running layout tests. | 92 // Notifications will never outlive the lifetime of running layout tests. |
| 93 return false; | 93 return false; |
| 94 } | 94 } |
| 95 | 95 |
| 96 void LayoutTestNotificationManager::SimulateClick(const std::string& title, | 96 void LayoutTestNotificationManager::SimulateClick( |
| 97 int action_index) { | 97 const std::string& title, |
| 98 int action_index, |
| 99 const base::NullableString16& reply) { |
| 98 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 100 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 99 | 101 |
| 100 const auto notification_id_iter = notification_id_map_.find(title); | 102 const auto notification_id_iter = notification_id_map_.find(title); |
| 101 if (notification_id_iter == notification_id_map_.end()) | 103 if (notification_id_iter == notification_id_map_.end()) |
| 102 return; | 104 return; |
| 103 | 105 |
| 104 const std::string& notification_id = notification_id_iter->second; | 106 const std::string& notification_id = notification_id_iter->second; |
| 105 | 107 |
| 106 const auto persistent_iter = persistent_notifications_.find(notification_id); | 108 const auto persistent_iter = persistent_notifications_.find(notification_id); |
| 107 const auto non_persistent_iter = | 109 const auto non_persistent_iter = |
| 108 non_persistent_notifications_.find(notification_id); | 110 non_persistent_notifications_.find(notification_id); |
| 109 | 111 |
| 110 if (persistent_iter != persistent_notifications_.end()) { | 112 if (persistent_iter != persistent_notifications_.end()) { |
| 111 DCHECK(non_persistent_iter == non_persistent_notifications_.end()); | 113 DCHECK(non_persistent_iter == non_persistent_notifications_.end()); |
| 112 | 114 |
| 113 const PersistentNotification& notification = persistent_iter->second; | 115 const PersistentNotification& notification = persistent_iter->second; |
| 114 content::NotificationEventDispatcher::GetInstance() | 116 content::NotificationEventDispatcher::GetInstance() |
| 115 ->DispatchNotificationClickEvent(notification.browser_context, | 117 ->DispatchNotificationClickEvent( |
| 116 notification_id, notification.origin, | 118 notification.browser_context, notification_id, notification.origin, |
| 117 action_index, base::NullableString16(), | 119 action_index, reply, base::Bind(&OnEventDispatchComplete)); |
| 118 base::Bind(&OnEventDispatchComplete)); | |
| 119 } else if (non_persistent_iter != non_persistent_notifications_.end()) { | 120 } else if (non_persistent_iter != non_persistent_notifications_.end()) { |
| 120 DCHECK_EQ(action_index, -1) << "Action buttons are only supported for " | 121 DCHECK_EQ(action_index, -1) << "Action buttons are only supported for " |
| 121 "persistent notifications"; | 122 "persistent notifications"; |
| 122 | 123 |
| 123 non_persistent_iter->second->NotificationClick(); | 124 non_persistent_iter->second->NotificationClick(); |
| 124 } | 125 } |
| 125 } | 126 } |
| 126 | 127 |
| 127 void LayoutTestNotificationManager::SimulateClose(const std::string& title, | 128 void LayoutTestNotificationManager::SimulateClose(const std::string& title, |
| 128 bool by_user) { | 129 bool by_user) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 LayoutTestNotificationManager::CheckPermission(const GURL& origin) { | 192 LayoutTestNotificationManager::CheckPermission(const GURL& origin) { |
| 192 return LayoutTestContentBrowserClient::Get() | 193 return LayoutTestContentBrowserClient::Get() |
| 193 ->GetLayoutTestBrowserContext() | 194 ->GetLayoutTestBrowserContext() |
| 194 ->GetLayoutTestPermissionManager() | 195 ->GetLayoutTestPermissionManager() |
| 195 ->GetPermissionStatus(PermissionType::NOTIFICATIONS, | 196 ->GetPermissionStatus(PermissionType::NOTIFICATIONS, |
| 196 origin, | 197 origin, |
| 197 origin); | 198 origin); |
| 198 } | 199 } |
| 199 | 200 |
| 200 } // namespace content | 201 } // namespace content |
| OLD | NEW |