| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(const std::string& title, |
| 97 int action_index) { | 97 int action_index, |
| 98 const std::string& reply) { |
| 98 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 99 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 99 | 100 |
| 100 const auto notification_id_iter = notification_id_map_.find(title); | 101 const auto notification_id_iter = notification_id_map_.find(title); |
| 101 if (notification_id_iter == notification_id_map_.end()) | 102 if (notification_id_iter == notification_id_map_.end()) |
| 102 return; | 103 return; |
| 103 | 104 |
| 104 const std::string& notification_id = notification_id_iter->second; | 105 const std::string& notification_id = notification_id_iter->second; |
| 105 | 106 |
| 106 const auto persistent_iter = persistent_notifications_.find(notification_id); | 107 const auto persistent_iter = persistent_notifications_.find(notification_id); |
| 107 const auto non_persistent_iter = | 108 const auto non_persistent_iter = |
| 108 non_persistent_notifications_.find(notification_id); | 109 non_persistent_notifications_.find(notification_id); |
| 109 | 110 |
| 110 if (persistent_iter != persistent_notifications_.end()) { | 111 if (persistent_iter != persistent_notifications_.end()) { |
| 111 DCHECK(non_persistent_iter == non_persistent_notifications_.end()); | 112 DCHECK(non_persistent_iter == non_persistent_notifications_.end()); |
| 112 | 113 |
| 113 const PersistentNotification& notification = persistent_iter->second; | 114 const PersistentNotification& notification = persistent_iter->second; |
| 114 content::NotificationEventDispatcher::GetInstance() | 115 content::NotificationEventDispatcher::GetInstance() |
| 115 ->DispatchNotificationClickEvent(notification.browser_context, | 116 ->DispatchNotificationClickEvent( |
| 116 notification_id, notification.origin, | 117 notification.browser_context, notification_id, notification.origin, |
| 117 action_index, base::NullableString16(), | 118 action_index, base::NullableString16(base::UTF8ToUTF16(reply), |
| 118 base::Bind(&OnEventDispatchComplete)); | 119 false /* is_null */), |
| 120 base::Bind(&OnEventDispatchComplete)); |
| 119 } else if (non_persistent_iter != non_persistent_notifications_.end()) { | 121 } else if (non_persistent_iter != non_persistent_notifications_.end()) { |
| 120 DCHECK_EQ(action_index, -1) << "Action buttons are only supported for " | 122 DCHECK_EQ(action_index, -1) << "Action buttons are only supported for " |
| 121 "persistent notifications"; | 123 "persistent notifications"; |
| 122 | 124 |
| 123 non_persistent_iter->second->NotificationClick(); | 125 non_persistent_iter->second->NotificationClick(); |
| 124 } | 126 } |
| 125 } | 127 } |
| 126 | 128 |
| 127 void LayoutTestNotificationManager::SimulateClose(const std::string& title, | 129 void LayoutTestNotificationManager::SimulateClose(const std::string& title, |
| 128 bool by_user) { | 130 bool by_user) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 LayoutTestNotificationManager::CheckPermission(const GURL& origin) { | 193 LayoutTestNotificationManager::CheckPermission(const GURL& origin) { |
| 192 return LayoutTestContentBrowserClient::Get() | 194 return LayoutTestContentBrowserClient::Get() |
| 193 ->GetLayoutTestBrowserContext() | 195 ->GetLayoutTestBrowserContext() |
| 194 ->GetLayoutTestPermissionManager() | 196 ->GetLayoutTestPermissionManager() |
| 195 ->GetPermissionStatus(PermissionType::NOTIFICATIONS, | 197 ->GetPermissionStatus(PermissionType::NOTIFICATIONS, |
| 196 origin, | 198 origin, |
| 197 origin); | 199 origin); |
| 198 } | 200 } |
| 199 | 201 |
| 200 } // namespace content | 202 } // namespace content |
| OLD | NEW |