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

Side by Side Diff: chrome/browser/push_messaging/push_messaging_permission_context_unittest.cc

Issue 1726323002: Have Permission{Manager,Service} use Origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clarify and test Origin.empty_. Created 4 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
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 "chrome/browser/push_messaging/push_messaging_permission_context.h" 5 #include "chrome/browser/push_messaging/push_messaging_permission_context.h"
6 6
7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
8 #include "chrome/browser/permissions/permission_request_id.h" 8 #include "chrome/browser/permissions/permission_request_id.h"
9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
10 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
11 #include "components/content_settings/core/browser/host_content_settings_map.h" 11 #include "components/content_settings/core/browser/host_content_settings_map.h"
12 #include "components/content_settings/core/common/content_settings.h" 12 #include "components/content_settings/core/common/content_settings.h"
13 #include "components/content_settings/core/common/content_settings_types.h" 13 #include "components/content_settings/core/common/content_settings_types.h"
14 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "url/gurl.h"
17 #include "url/origin.h"
16 18
17 namespace { 19 namespace {
18 20
19 const char kOriginA[] = "https://origina.org"; 21 const char kOriginA[] = "https://origina.org";
20 const char kOriginB[] = "https://originb.org"; 22 const char kOriginB[] = "https://originb.org";
21 const char kInsecureOrigin[] = "http://insecureorigin.org"; 23 const char kInsecureOrigin[] = "http://insecureorigin.org";
22 24
23 void DoNothing(ContentSetting content_setting) {} 25 void DoNothing(ContentSetting content_setting) {}
24 26
25 class TestPushMessagingPermissionContext 27 class TestPushMessagingPermissionContext
26 : public PushMessagingPermissionContext { 28 : public PushMessagingPermissionContext {
27 public: 29 public:
28 explicit TestPushMessagingPermissionContext(Profile* profile) 30 explicit TestPushMessagingPermissionContext(Profile* profile)
29 : PushMessagingPermissionContext(profile), 31 : PushMessagingPermissionContext(profile),
30 was_persisted_(false), 32 was_persisted_(false),
31 permission_granted_(false) {} 33 permission_granted_(false) {}
32 34
33 bool was_persisted() const { return was_persisted_; } 35 bool was_persisted() const { return was_persisted_; }
34 bool was_granted() const { return permission_granted_; } 36 bool was_granted() const { return permission_granted_; }
35 37
36 private: 38 private:
37 // PushMessagingPermissionContext: 39 // PushMessagingPermissionContext:
38 void NotifyPermissionSet(const PermissionRequestID& id, 40 void NotifyPermissionSet(const PermissionRequestID& id,
39 const GURL& requesting_origin, 41 const url::Origin& requesting_origin,
40 const GURL& embedder_origin, 42 const url::Origin& embedder_origin,
41 const BrowserPermissionCallback& callback, 43 const BrowserPermissionCallback& callback,
42 bool persist, 44 bool persist,
43 ContentSetting content_setting) override { 45 ContentSetting content_setting) override {
44 was_persisted_ = persist; 46 was_persisted_ = persist;
45 permission_granted_ = content_setting == CONTENT_SETTING_ALLOW; 47 permission_granted_ = content_setting == CONTENT_SETTING_ALLOW;
46 PushMessagingPermissionContext::NotifyPermissionSet( 48 PushMessagingPermissionContext::NotifyPermissionSet(
47 id, requesting_origin, embedder_origin, callback, persist, 49 id, requesting_origin, embedder_origin, callback, persist,
48 content_setting); 50 content_setting);
49 } 51 }
50 52
(...skipping 25 matching lines...) Expand all
76 host_content_settings_map->SetContentSetting( 78 host_content_settings_map->SetContentSetting(
77 insecure_pattern, insecure_pattern, setting, std::string(), value); 79 insecure_pattern, insecure_pattern, setting, std::string(), value);
78 } 80 }
79 }; 81 };
80 82
81 } // namespace 83 } // namespace
82 84
83 TEST_F(PushMessagingPermissionContextTest, HasPermissionPrompt) { 85 TEST_F(PushMessagingPermissionContextTest, HasPermissionPrompt) {
84 TestingProfile profile; 86 TestingProfile profile;
85 PushMessagingPermissionContext context(&profile); 87 PushMessagingPermissionContext context(&profile);
88 const GURL url_a(kOriginA);
89 const url::Origin origin_a(url_a);
86 EXPECT_EQ(CONTENT_SETTING_ASK, 90 EXPECT_EQ(CONTENT_SETTING_ASK,
87 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 91 context.GetPermissionStatus(origin_a, origin_a));
88 92
89 // Just granting notifications should still prompt 93 // Just granting notifications should still prompt
90 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 94 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
91 CONTENT_SETTING_ALLOW); 95 CONTENT_SETTING_ALLOW);
92 96
93 EXPECT_EQ(CONTENT_SETTING_ASK, 97 EXPECT_EQ(CONTENT_SETTING_ASK,
94 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 98 context.GetPermissionStatus(origin_a, origin_a));
95 99
96 // Just granting push should still prompt 100 // Just granting push should still prompt
97 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 101 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
98 CONTENT_SETTING_ASK); 102 CONTENT_SETTING_ASK);
99 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 103 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
100 CONTENT_SETTING_ALLOW); 104 CONTENT_SETTING_ALLOW);
101 105
102 EXPECT_EQ(CONTENT_SETTING_ASK, 106 EXPECT_EQ(CONTENT_SETTING_ASK,
103 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 107 context.GetPermissionStatus(origin_a, origin_a));
104 } 108 }
105 109
106 TEST_F(PushMessagingPermissionContextTest, HasPermissionDenySettingsMismatch) { 110 TEST_F(PushMessagingPermissionContextTest, HasPermissionDenySettingsMismatch) {
107 TestingProfile profile; 111 TestingProfile profile;
108 PushMessagingPermissionContext context(&profile); 112 PushMessagingPermissionContext context(&profile);
109 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 113 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
110 CONTENT_SETTING_BLOCK); 114 CONTENT_SETTING_BLOCK);
115 const GURL url_a(kOriginA);
116 const url::Origin origin_a(url_a);
111 EXPECT_EQ(CONTENT_SETTING_BLOCK, 117 EXPECT_EQ(CONTENT_SETTING_BLOCK,
112 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 118 context.GetPermissionStatus(origin_a, origin_a));
113 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 119 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
114 CONTENT_SETTING_ASK); 120 CONTENT_SETTING_ASK);
115 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 121 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
116 CONTENT_SETTING_BLOCK); 122 CONTENT_SETTING_BLOCK);
117 EXPECT_EQ(CONTENT_SETTING_BLOCK, 123 EXPECT_EQ(CONTENT_SETTING_BLOCK,
118 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 124 context.GetPermissionStatus(origin_a, origin_a));
119 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 125 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
120 CONTENT_SETTING_ALLOW); 126 CONTENT_SETTING_ALLOW);
121 EXPECT_EQ(CONTENT_SETTING_BLOCK, 127 EXPECT_EQ(CONTENT_SETTING_BLOCK,
122 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 128 context.GetPermissionStatus(origin_a, origin_a));
123 129
124 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 130 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
125 CONTENT_SETTING_ASK); 131 CONTENT_SETTING_ASK);
126 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 132 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
127 CONTENT_SETTING_BLOCK); 133 CONTENT_SETTING_BLOCK);
128 EXPECT_EQ(CONTENT_SETTING_BLOCK, 134 EXPECT_EQ(CONTENT_SETTING_BLOCK,
129 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 135 context.GetPermissionStatus(origin_a, origin_a));
130 } 136 }
131 137
132 TEST_F(PushMessagingPermissionContextTest, HasPermissionDenyDifferentOrigins) { 138 TEST_F(PushMessagingPermissionContextTest, HasPermissionDenyDifferentOrigins) {
133 TestingProfile profile; 139 TestingProfile profile;
134 PushMessagingPermissionContext context(&profile); 140 PushMessagingPermissionContext context(&profile);
135 EXPECT_EQ(CONTENT_SETTING_BLOCK, 141 const GURL url_a(kOriginA);
136 context.GetPermissionStatus(GURL(kOriginB), GURL(kOriginA))); 142 const GURL url_b(kOriginB);
143 EXPECT_EQ(CONTENT_SETTING_BLOCK, context.GetPermissionStatus(
144 url::Origin(url_a), url::Origin(url_b)));
137 } 145 }
138 146
139 TEST_F(PushMessagingPermissionContextTest, HasPermissionAccept) { 147 TEST_F(PushMessagingPermissionContextTest, HasPermissionAccept) {
140 TestingProfile profile; 148 TestingProfile profile;
141 PushMessagingPermissionContext context(&profile); 149 PushMessagingPermissionContext context(&profile);
142 150
143 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 151 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
144 CONTENT_SETTING_ALLOW); 152 CONTENT_SETTING_ALLOW);
145 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 153 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
146 CONTENT_SETTING_ALLOW); 154 CONTENT_SETTING_ALLOW);
147 EXPECT_EQ(CONTENT_SETTING_ALLOW, 155 const GURL url_a(kOriginA);
148 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 156 const GURL url_b(kOriginB);
157 EXPECT_EQ(CONTENT_SETTING_ALLOW, context.GetPermissionStatus(
158 url::Origin(url_a), url::Origin(url_b)));
149 } 159 }
150 160
151 TEST_F(PushMessagingPermissionContextTest, DecidePushPermission) { 161 TEST_F(PushMessagingPermissionContextTest, DecidePushPermission) {
152 TestingProfile profile; 162 TestingProfile profile;
153 TestPushMessagingPermissionContext context(&profile); 163 TestPushMessagingPermissionContext context(&profile);
154 PermissionRequestID request_id(-1, -1, -1); 164 PermissionRequestID request_id(-1, -1, -1);
155 BrowserPermissionCallback callback = base::Bind(DoNothing); 165 BrowserPermissionCallback callback = base::Bind(DoNothing);
156 166
157 context.DecidePushPermission(request_id, GURL(kOriginA), GURL(kOriginA), 167 const GURL url_a(kOriginA);
158 callback, CONTENT_SETTING_DEFAULT); 168 const url::Origin origin_a(url_a);
169 context.DecidePushPermission(request_id, origin_a, origin_a, callback,
170 CONTENT_SETTING_DEFAULT);
159 EXPECT_FALSE(context.was_persisted()); 171 EXPECT_FALSE(context.was_persisted());
160 EXPECT_FALSE(context.was_granted()); 172 EXPECT_FALSE(context.was_granted());
161 173
162 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 174 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
163 CONTENT_SETTING_ALLOW); 175 CONTENT_SETTING_ALLOW);
164 context.DecidePushPermission(request_id, GURL(kOriginA), GURL(kOriginA), 176 context.DecidePushPermission(request_id, origin_a, origin_a, callback,
165 callback, CONTENT_SETTING_ALLOW); 177 CONTENT_SETTING_ALLOW);
166 EXPECT_TRUE(context.was_persisted()); 178 EXPECT_TRUE(context.was_persisted());
167 EXPECT_TRUE(context.was_granted()); 179 EXPECT_TRUE(context.was_granted());
168 180
169 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 181 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
170 CONTENT_SETTING_BLOCK); 182 CONTENT_SETTING_BLOCK);
171 context.DecidePushPermission(request_id, GURL(kOriginA), GURL(kOriginA), 183 context.DecidePushPermission(request_id, origin_a, origin_a, callback,
172 callback, CONTENT_SETTING_ALLOW); 184 CONTENT_SETTING_ALLOW);
173 EXPECT_TRUE(context.was_persisted()); 185 EXPECT_TRUE(context.was_persisted());
174 EXPECT_FALSE(context.was_granted()); 186 EXPECT_FALSE(context.was_granted());
175 187
176 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 188 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
177 CONTENT_SETTING_ASK); 189 CONTENT_SETTING_ASK);
178 context.DecidePushPermission(request_id, GURL(kOriginA), GURL(kOriginA), 190 context.DecidePushPermission(request_id, origin_a, origin_a, callback,
179 callback, CONTENT_SETTING_ALLOW); 191 CONTENT_SETTING_ALLOW);
180 EXPECT_TRUE(context.was_persisted()); 192 EXPECT_TRUE(context.was_persisted());
181 EXPECT_TRUE(context.was_granted()); 193 EXPECT_TRUE(context.was_granted());
182 } 194 }
183 195
184 TEST_F(PushMessagingPermissionContextTest, DecidePermission) { 196 TEST_F(PushMessagingPermissionContextTest, DecidePermission) {
185 TestingProfile profile; 197 TestingProfile profile;
186 TestPushMessagingPermissionContext context(&profile); 198 TestPushMessagingPermissionContext context(&profile);
187 PermissionRequestID request_id(-1, -1, -1); 199 PermissionRequestID request_id(-1, -1, -1);
188 BrowserPermissionCallback callback = base::Bind(DoNothing); 200 BrowserPermissionCallback callback = base::Bind(DoNothing);
189 201
202 const GURL url_a(kOriginA);
203 const GURL url_b(kOriginB);
204 const url::Origin origin_a(url_a);
205 const url::Origin origin_b(url_b);
206
190 // Requesting and embedding origin are different. 207 // Requesting and embedding origin are different.
191 context.DecidePermission(NULL, request_id, GURL(kOriginA), GURL(kOriginB), 208 context.DecidePermission(NULL, request_id, origin_a, origin_b, callback);
192 callback);
193 EXPECT_FALSE(context.was_persisted()); 209 EXPECT_FALSE(context.was_persisted());
194 EXPECT_FALSE(context.was_granted()); 210 EXPECT_FALSE(context.was_granted());
195 211
196 // Insecure origin 212 // Insecure origin
197 NavigateAndCommit(GURL(kInsecureOrigin)); 213 const GURL insecure_url(kInsecureOrigin);
198 context.RequestPermission(web_contents(), request_id, GURL(kInsecureOrigin), 214 const url::Origin insecure_origin(insecure_url);
215 NavigateAndCommit(insecure_url);
216 context.RequestPermission(web_contents(), request_id, insecure_origin,
199 callback); 217 callback);
200 EXPECT_FALSE(context.was_persisted()); 218 EXPECT_FALSE(context.was_persisted());
201 EXPECT_FALSE(context.was_granted()); 219 EXPECT_FALSE(context.was_granted());
202 } 220 }
203 221
204 TEST_F(PushMessagingPermissionContextTest, RequestPermission) { 222 TEST_F(PushMessagingPermissionContextTest, RequestPermission) {
205 TestingProfile profile; 223 TestingProfile profile;
206 TestPushMessagingPermissionContext context(&profile); 224 TestPushMessagingPermissionContext context(&profile);
207 PermissionRequestID request_id(-1, -1, -1); 225 PermissionRequestID request_id(-1, -1, -1);
208 BrowserPermissionCallback callback = base::Bind(DoNothing); 226 BrowserPermissionCallback callback = base::Bind(DoNothing);
209 227
210 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 228 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
211 CONTENT_SETTING_ALLOW); 229 CONTENT_SETTING_ALLOW);
212 230
231 const GURL url_a(kOriginA);
232 const url::Origin origin_a(url_a);
233
213 EXPECT_EQ( 234 EXPECT_EQ(
214 CONTENT_SETTING_ASK, 235 CONTENT_SETTING_ASK,
215 HostContentSettingsMapFactory::GetForProfile(&profile)->GetContentSetting( 236 HostContentSettingsMapFactory::GetForProfile(&profile)->GetContentSetting(
216 GURL(kOriginA), GURL(kOriginA), CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 237 url_a, url_a, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string()));
217 std::string()));
218 EXPECT_EQ(CONTENT_SETTING_ASK, 238 EXPECT_EQ(CONTENT_SETTING_ASK,
219 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 239 context.GetPermissionStatus(origin_a, origin_a));
220 240
221 // If a website already has notifications permission, push permission is 241 // If a website already has notifications permission, push permission is
222 // silently granted once the website requests it. 242 // silently granted once the website requests it.
223 NavigateAndCommit(GURL(kOriginA)); 243 NavigateAndCommit(url_a);
224 context.RequestPermission(web_contents(), request_id, GURL(kOriginA), 244 context.RequestPermission(web_contents(), request_id, origin_a, callback);
225 callback);
226 245
227 EXPECT_TRUE(context.was_persisted()); 246 EXPECT_TRUE(context.was_persisted());
228 EXPECT_TRUE(context.was_granted()); 247 EXPECT_TRUE(context.was_granted());
229 EXPECT_EQ( 248 EXPECT_EQ(
230 CONTENT_SETTING_ALLOW, 249 CONTENT_SETTING_ALLOW,
231 HostContentSettingsMapFactory::GetForProfile(&profile)->GetContentSetting( 250 HostContentSettingsMapFactory::GetForProfile(&profile)->GetContentSetting(
232 GURL(kOriginA), GURL(kOriginA), CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 251 url_a, url_a, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string()));
233 std::string()));
234 EXPECT_EQ(CONTENT_SETTING_ALLOW, 252 EXPECT_EQ(CONTENT_SETTING_ALLOW,
235 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 253 context.GetPermissionStatus(origin_a, origin_a));
236 } 254 }
237 255
238 TEST_F(PushMessagingPermissionContextTest, RequestAfterRevokingNotifications) { 256 TEST_F(PushMessagingPermissionContextTest, RequestAfterRevokingNotifications) {
239 TestingProfile profile; 257 TestingProfile profile;
240 TestPushMessagingPermissionContext context(&profile); 258 TestPushMessagingPermissionContext context(&profile);
241 PermissionRequestID request_id(-1, -1, -1); 259 PermissionRequestID request_id(-1, -1, -1);
242 BrowserPermissionCallback callback = base::Bind(DoNothing); 260 BrowserPermissionCallback callback = base::Bind(DoNothing);
243 261
244 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 262 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
245 CONTENT_SETTING_ALLOW); 263 CONTENT_SETTING_ALLOW);
246 264
247 NavigateAndCommit(GURL(kOriginA)); 265 const GURL url_a(kOriginA);
248 context.RequestPermission(web_contents(), request_id, GURL(kOriginA), 266 NavigateAndCommit(url_a);
249 callback); 267 const url::Origin origin_a(url_a);
268 context.RequestPermission(web_contents(), request_id, origin_a, callback);
250 EXPECT_TRUE(context.was_persisted()); 269 EXPECT_TRUE(context.was_persisted());
251 EXPECT_TRUE(context.was_granted()); 270 EXPECT_TRUE(context.was_granted());
252 271
253 EXPECT_EQ(CONTENT_SETTING_ALLOW, 272 EXPECT_EQ(CONTENT_SETTING_ALLOW,
254 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 273 context.GetPermissionStatus(origin_a, origin_a));
255 274
256 // Revoke notifications permission. This should revoke push, and prevent 275 // Revoke notifications permission. This should revoke push, and prevent
257 // future requests for push from succeeding. 276 // future requests for push from succeeding.
258 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 277 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
259 CONTENT_SETTING_BLOCK); 278 CONTENT_SETTING_BLOCK);
260 279
261 EXPECT_EQ(CONTENT_SETTING_BLOCK, 280 EXPECT_EQ(CONTENT_SETTING_BLOCK,
262 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 281 context.GetPermissionStatus(origin_a, origin_a));
263 282
264 context.RequestPermission(web_contents(), request_id, GURL(kOriginA), 283 context.RequestPermission(web_contents(), request_id, origin_a, callback);
265 callback);
266 EXPECT_FALSE(context.was_persisted()); 284 EXPECT_FALSE(context.was_persisted());
267 EXPECT_FALSE(context.was_granted()); 285 EXPECT_FALSE(context.was_granted());
268 EXPECT_EQ(CONTENT_SETTING_BLOCK, 286 EXPECT_EQ(CONTENT_SETTING_BLOCK,
269 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 287 context.GetPermissionStatus(origin_a, origin_a));
270 } 288 }
271 289
272 TEST_F(PushMessagingPermissionContextTest, GetPermissionStatusInsecureOrigin) { 290 TEST_F(PushMessagingPermissionContextTest, GetPermissionStatusInsecureOrigin) {
273 TestingProfile profile; 291 TestingProfile profile;
274 TestPushMessagingPermissionContext context(&profile); 292 TestPushMessagingPermissionContext context(&profile);
275 293
294 const GURL insecure_url(kInsecureOrigin);
295 const url::Origin insecure_origin(insecure_url);
296
276 // The status should be blocked for an insecure origin, regardless of the 297 // The status should be blocked for an insecure origin, regardless of the
277 // content setting value. 298 // content setting value.
278 EXPECT_EQ(CONTENT_SETTING_BLOCK, 299 EXPECT_EQ(CONTENT_SETTING_BLOCK,
279 context.GetPermissionStatus(GURL(kInsecureOrigin), 300 context.GetPermissionStatus(insecure_origin, insecure_origin));
280 GURL(kInsecureOrigin)));
281 301
282 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 302 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
283 CONTENT_SETTING_ALLOW); 303 CONTENT_SETTING_ALLOW);
284 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 304 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
285 CONTENT_SETTING_ALLOW); 305 CONTENT_SETTING_ALLOW);
286 EXPECT_EQ(CONTENT_SETTING_BLOCK, 306 EXPECT_EQ(CONTENT_SETTING_BLOCK,
287 context.GetPermissionStatus(GURL(kInsecureOrigin), 307 context.GetPermissionStatus(insecure_origin, insecure_origin));
288 GURL(kInsecureOrigin)));
289 308
290 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 309 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
291 CONTENT_SETTING_BLOCK); 310 CONTENT_SETTING_BLOCK);
292 EXPECT_EQ(CONTENT_SETTING_BLOCK, 311 EXPECT_EQ(CONTENT_SETTING_BLOCK,
293 context.GetPermissionStatus(GURL(kInsecureOrigin), 312 context.GetPermissionStatus(insecure_origin, insecure_origin));
294 GURL(kInsecureOrigin)));
295 313
296 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 314 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
297 CONTENT_SETTING_ASK); 315 CONTENT_SETTING_ASK);
298 EXPECT_EQ(CONTENT_SETTING_BLOCK, 316 EXPECT_EQ(CONTENT_SETTING_BLOCK,
299 context.GetPermissionStatus(GURL(kInsecureOrigin), 317 context.GetPermissionStatus(insecure_origin, insecure_origin));
300 GURL(kInsecureOrigin)));
301 } 318 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698