Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: content/shell/browser/layout_test/layout_test_notification_manager.cc

Issue 1026853002: Integrate the notification database with the normal code path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-db-ConfirmShow
Patch Set: fix layout tests Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/desktop_notification_delegate.h" 10 #include "content/public/browser/desktop_notification_delegate.h"
11 #include "content/public/browser/notification_event_dispatcher.h" 11 #include "content/public/browser/notification_event_dispatcher.h"
12 #include "content/public/common/persistent_notification_status.h" 12 #include "content/public/common/persistent_notification_status.h"
13 #include "content/public/common/platform_notification_data.h" 13 #include "content/public/common/platform_notification_data.h"
14 14
15 namespace content { 15 namespace content {
16 namespace { 16 namespace {
17 17
18 // The Web Notification layout tests don't care about the lifetime of the 18 // The Web Notification layout tests don't care about the lifetime of the
19 // Service Worker when a notificationclick event has been dispatched. 19 // Service Worker when a notificationclick event has been dispatched.
20 void OnEventDispatchComplete(PersistentNotificationStatus status) {} 20 void OnEventDispatchComplete(PersistentNotificationStatus status) {}
21 21
22 } // namespace 22 } // namespace
23 23
24 LayoutTestNotificationManager::LayoutTestNotificationManager() 24 LayoutTestNotificationManager::LayoutTestNotificationManager()
25 : weak_factory_(this) {} 25 : weak_factory_(this) {}
26 26
27 LayoutTestNotificationManager::PersistentNotification::PersistentNotification()
28 : browser_context(nullptr),
29 service_worker_registration_id(0) {}
30
31 LayoutTestNotificationManager::~LayoutTestNotificationManager() {} 27 LayoutTestNotificationManager::~LayoutTestNotificationManager() {}
32 28
33 PermissionStatus LayoutTestNotificationManager::RequestPermission( 29 PermissionStatus LayoutTestNotificationManager::RequestPermission(
34 const GURL& origin) { 30 const GURL& origin) {
35 return GetPermissionStatus(origin); 31 return GetPermissionStatus(origin);
36 } 32 }
37 33
38 blink::WebNotificationPermission 34 blink::WebNotificationPermission
39 LayoutTestNotificationManager::CheckPermission(const GURL& origin) { 35 LayoutTestNotificationManager::CheckPermission(const GURL& origin) {
40 base::AutoLock lock(permission_lock_); 36 base::AutoLock lock(permission_lock_);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 title); 73 title);
78 74
79 ReplaceNotificationIfNeeded(notification_data); 75 ReplaceNotificationIfNeeded(notification_data);
80 76
81 page_notifications_[title] = delegate.release(); 77 page_notifications_[title] = delegate.release();
82 page_notifications_[title]->NotificationDisplayed(); 78 page_notifications_[title]->NotificationDisplayed();
83 } 79 }
84 80
85 void LayoutTestNotificationManager::DisplayPersistentNotification( 81 void LayoutTestNotificationManager::DisplayPersistentNotification(
86 BrowserContext* browser_context, 82 BrowserContext* browser_context,
87 int64 service_worker_registration_id, 83 int64_t persistent_notification_id,
88 const GURL& origin, 84 const GURL& origin,
89 const SkBitmap& icon, 85 const SkBitmap& icon,
90 const PlatformNotificationData& notification_data) { 86 const PlatformNotificationData& notification_data) {
91 DCHECK_CURRENTLY_ON(BrowserThread::UI); 87 DCHECK_CURRENTLY_ON(BrowserThread::UI);
92 std::string title = base::UTF16ToUTF8(notification_data.title); 88 std::string title = base::UTF16ToUTF8(notification_data.title);
93 89
94 ReplaceNotificationIfNeeded(notification_data); 90 ReplaceNotificationIfNeeded(notification_data);
95 91
96 PersistentNotification notification; 92 PersistentNotification notification;
97 notification.browser_context = browser_context; 93 notification.browser_context = browser_context;
98 notification.origin = origin; 94 notification.origin = origin;
99 notification.notification_data = notification_data; 95 notification.persistent_id = persistent_notification_id;
100 notification.service_worker_registration_id = service_worker_registration_id;
101 notification.persistent_id = base::GenerateGUID();
102 96
103 persistent_notifications_[title] = notification; 97 persistent_notifications_[title] = notification;
104 } 98 }
105 99
106 void LayoutTestNotificationManager::ClosePersistentNotification( 100 void LayoutTestNotificationManager::ClosePersistentNotification(
107 BrowserContext* browser_context, 101 BrowserContext* browser_context,
108 const std::string& persistent_notification_id) { 102 int64_t persistent_notification_id) {
109 for (const auto& iter : persistent_notifications_) { 103 for (const auto& iter : persistent_notifications_) {
110 if (iter.second.persistent_id != persistent_notification_id) 104 if (iter.second.persistent_id != persistent_notification_id)
111 continue; 105 continue;
112 106
113 persistent_notifications_.erase(iter.first); 107 persistent_notifications_.erase(iter.first);
114 return; 108 return;
115 } 109 }
116 } 110 }
117 111
118 void LayoutTestNotificationManager::SimulateClick(const std::string& title) { 112 void LayoutTestNotificationManager::SimulateClick(const std::string& title) {
119 DCHECK_CURRENTLY_ON(BrowserThread::UI); 113 DCHECK_CURRENTLY_ON(BrowserThread::UI);
120 114
121 // First check for page-notifications with the given title. 115 // First check for page-notifications with the given title.
122 const auto& page_iterator = page_notifications_.find(title); 116 const auto& page_iterator = page_notifications_.find(title);
123 if (page_iterator != page_notifications_.end()) { 117 if (page_iterator != page_notifications_.end()) {
124 page_iterator->second->NotificationClick(); 118 page_iterator->second->NotificationClick();
125 return; 119 return;
126 } 120 }
127 121
128 // Then check for persistent notifications with the given title. 122 // Then check for persistent notifications with the given title.
129 const auto& persistent_iterator = persistent_notifications_.find(title); 123 const auto& persistent_iterator = persistent_notifications_.find(title);
130 if (persistent_iterator == persistent_notifications_.end()) 124 if (persistent_iterator == persistent_notifications_.end())
131 return; 125 return;
132 126
133 const PersistentNotification& notification = persistent_iterator->second; 127 const PersistentNotification& notification = persistent_iterator->second;
134 content::NotificationEventDispatcher::GetInstance() 128 content::NotificationEventDispatcher::GetInstance()
135 ->DispatchNotificationClickEvent( 129 ->DispatchNotificationClickEvent(
136 notification.browser_context, 130 notification.browser_context,
131 notification.persistent_id,
137 notification.origin, 132 notification.origin,
138 notification.service_worker_registration_id,
139 notification.persistent_id,
140 notification.notification_data,
141 base::Bind(&OnEventDispatchComplete)); 133 base::Bind(&OnEventDispatchComplete));
142 } 134 }
143 135
144 PermissionStatus LayoutTestNotificationManager::GetPermissionStatus( 136 PermissionStatus LayoutTestNotificationManager::GetPermissionStatus(
145 const GURL& origin) { 137 const GURL& origin) {
146 switch (CheckPermission(origin)) { 138 switch (CheckPermission(origin)) {
147 case blink::WebNotificationPermissionAllowed: 139 case blink::WebNotificationPermissionAllowed:
148 return PERMISSION_STATUS_GRANTED; 140 return PERMISSION_STATUS_GRANTED;
149 case blink::WebNotificationPermissionDenied: 141 case blink::WebNotificationPermissionDenied:
150 return PERMISSION_STATUS_DENIED; 142 return PERMISSION_STATUS_DENIED;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 const auto& persistent_notification_iter = 200 const auto& persistent_notification_iter =
209 persistent_notifications_.find(previous_title); 201 persistent_notifications_.find(previous_title);
210 if (persistent_notification_iter != persistent_notifications_.end()) 202 if (persistent_notification_iter != persistent_notifications_.end())
211 persistent_notifications_.erase(persistent_notification_iter); 203 persistent_notifications_.erase(persistent_notification_iter);
212 } 204 }
213 205
214 replacements_[tag] = base::UTF16ToUTF8(notification_data.title); 206 replacements_[tag] = base::UTF16ToUTF8(notification_data.title);
215 } 207 }
216 208
217 } // namespace content 209 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698