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

Side by Side Diff: content/shell/renderer/test_runner/notification_presenter.cc

Issue 183663021: Notification.permission's default value of "default" should be testable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « content/shell/renderer/test_runner/notification_presenter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/renderer/test_runner/notification_presenter.h" 5 #include "content/shell/renderer/test_runner/notification_presenter.h"
6 6
7 #include "content/shell/renderer/test_runner/WebTestDelegate.h" 7 #include "content/shell/renderer/test_runner/WebTestDelegate.h"
8 #include "third_party/WebKit/public/platform/Platform.h" 8 #include "third_party/WebKit/public/platform/Platform.h"
9 #include "third_party/WebKit/public/platform/WebString.h" 9 #include "third_party/WebKit/public/platform/WebString.h"
10 #include "third_party/WebKit/public/platform/WebURL.h" 10 #include "third_party/WebKit/public/platform/WebURL.h"
(...skipping 19 matching lines...) Expand all
30 30
31 delete notification; 31 delete notification;
32 } 32 }
33 33
34 } // namespace 34 } // namespace
35 35
36 NotificationPresenter::NotificationPresenter() : delegate_(0) {} 36 NotificationPresenter::NotificationPresenter() : delegate_(0) {}
37 37
38 NotificationPresenter::~NotificationPresenter() {} 38 NotificationPresenter::~NotificationPresenter() {}
39 39
40 void NotificationPresenter::GrantPermission(const std::string& origin) { 40 void NotificationPresenter::GrantPermission(const std::string& origin,
41 allowed_origins_.insert(origin); 41 bool permission_granted) {
42 known_origins_[origin] = permission_granted;
42 } 43 }
43 44
44 bool NotificationPresenter::SimulateClick(const std::string& title) { 45 bool NotificationPresenter::SimulateClick(const std::string& title) {
45 ActiveNotificationMap::iterator iter = active_notifications_.find(title); 46 ActiveNotificationMap::iterator iter = active_notifications_.find(title);
46 if (iter == active_notifications_.end()) 47 if (iter == active_notifications_.end())
47 return false; 48 return false;
48 49
49 const WebNotification& notification = iter->second; 50 const WebNotification& notification = iter->second;
50 51
51 WebNotification event_target(notification); 52 WebNotification event_target(notification);
52 event_target.dispatchClickEvent(); 53 event_target.dispatchClickEvent();
53 54
54 return true; 55 return true;
55 } 56 }
56 57
57 void NotificationPresenter::CancelAllActiveNotifications() { 58 void NotificationPresenter::CancelAllActiveNotifications() {
58 while (!active_notifications_.empty()) { 59 while (!active_notifications_.empty()) {
59 const WebNotification& notification = active_notifications_.begin()->second; 60 const WebNotification& notification = active_notifications_.begin()->second;
60 cancel(notification); 61 cancel(notification);
61 } 62 }
62 } 63 }
63 64
64 void NotificationPresenter::Reset() { 65 void NotificationPresenter::Reset() {
65 // TODO(peter): Ensure that |active_notifications_| is empty as well. 66 // TODO(peter): Ensure that |active_notifications_| is empty as well.
66 allowed_origins_.clear(); 67 known_origins_.clear();
67 } 68 }
68 69
69 bool NotificationPresenter::show(const WebNotification& notification) { 70 bool NotificationPresenter::show(const WebNotification& notification) {
70 if (!notification.replaceId().isEmpty()) { 71 if (!notification.replaceId().isEmpty()) {
71 std::string replaceId(notification.replaceId().utf8()); 72 std::string replaceId(notification.replaceId().utf8());
72 if (replacements_.find(replaceId) != replacements_.end()) { 73 if (replacements_.find(replaceId) != replacements_.end()) {
73 delegate_->printMessage(std::string("REPLACING NOTIFICATION ") + 74 delegate_->printMessage(std::string("REPLACING NOTIFICATION ") +
74 replacements_.find(replaceId)->second + "\n"); 75 replacements_.find(replaceId)->second + "\n");
75 } 76 }
76 replacements_[replaceId] = notification.title().utf8(); 77 replacements_[replaceId] = notification.title().utf8();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 115
115 void NotificationPresenter::objectDestroyed( 116 void NotificationPresenter::objectDestroyed(
116 const WebNotification& notification) { 117 const WebNotification& notification) {
117 std::string title = notification.title().utf8(); 118 std::string title = notification.title().utf8();
118 active_notifications_.erase(title); 119 active_notifications_.erase(title);
119 } 120 }
120 121
121 WebNotificationPresenter::Permission NotificationPresenter::checkPermission( 122 WebNotificationPresenter::Permission NotificationPresenter::checkPermission(
122 const WebSecurityOrigin& security_origin) { 123 const WebSecurityOrigin& security_origin) {
123 const std::string origin = security_origin.toString().utf8(); 124 const std::string origin = security_origin.toString().utf8();
124 if (allowed_origins_.find(origin) != allowed_origins_.end()) 125 const KnownOriginMap::iterator it = known_origins_.find(origin);
126 if (it == known_origins_.end())
127 return WebNotificationPresenter::PermissionNotAllowed;
128
129 // Values in |known_origins_| indicate whether permission has been granted.
130 if (it->second)
125 return WebNotificationPresenter::PermissionAllowed; 131 return WebNotificationPresenter::PermissionAllowed;
126 132
127 return WebNotificationPresenter::PermissionDenied; 133 return WebNotificationPresenter::PermissionDenied;
128 } 134 }
129 135
130 void NotificationPresenter::requestPermission( 136 void NotificationPresenter::requestPermission(
131 const WebSecurityOrigin& security_origin, 137 const WebSecurityOrigin& security_origin,
132 WebNotificationPermissionCallback* callback) { 138 WebNotificationPermissionCallback* callback) {
133 std::string origin = security_origin.toString().utf8(); 139 std::string origin = security_origin.toString().utf8();
134 delegate_->printMessage("DESKTOP NOTIFICATION PERMISSION REQUESTED: " + 140 delegate_->printMessage("DESKTOP NOTIFICATION PERMISSION REQUESTED: " +
135 origin + "\n"); 141 origin + "\n");
136 callback->permissionRequestComplete(); 142 callback->permissionRequestComplete();
137 } 143 }
138 144
139 } // namespace content 145 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/renderer/test_runner/notification_presenter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698