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

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

Issue 1816123002: Add testing for subscription from service workers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix asan errors Created 4 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 "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"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 }; 78 };
79 79
80 } // namespace 80 } // namespace
81 81
82 TEST_F(PushMessagingPermissionContextTest, HasPermissionPrompt) { 82 TEST_F(PushMessagingPermissionContextTest, HasPermissionPrompt) {
83 TestingProfile profile; 83 TestingProfile profile;
84 PushMessagingPermissionContext context(&profile); 84 PushMessagingPermissionContext context(&profile);
85 EXPECT_EQ(CONTENT_SETTING_ASK, 85 EXPECT_EQ(CONTENT_SETTING_ASK,
86 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 86 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA)));
87 87
88 // Just granting notifications should still prompt 88 // Just granting push messaging permission should still prompt.
89 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 89 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
90 CONTENT_SETTING_ALLOW); 90 CONTENT_SETTING_ALLOW);
91 91
92 EXPECT_EQ(CONTENT_SETTING_ASK, 92 EXPECT_EQ(CONTENT_SETTING_ASK,
93 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 93 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA)));
94 94
95 // Just granting push should still prompt 95 // Just granting notifications should allow if push messaging is not blocked.
96 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 96 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
97 CONTENT_SETTING_ASK); 97 CONTENT_SETTING_ASK);
98 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 98 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
99 CONTENT_SETTING_ALLOW); 99 CONTENT_SETTING_ALLOW);
100 100
101 EXPECT_EQ(CONTENT_SETTING_ASK, 101 EXPECT_EQ(CONTENT_SETTING_ASK,
102 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 102 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA)));
103
104 // Granting allow notifications but explicitly denying push messaging should
105 // block.
106 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
107 CONTENT_SETTING_ALLOW);
108 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
109 CONTENT_SETTING_BLOCK);
110
111 EXPECT_EQ(CONTENT_SETTING_BLOCK,
112 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA)));
103 } 113 }
104 114
105 TEST_F(PushMessagingPermissionContextTest, HasPermissionDenySettingsMismatch) { 115 TEST_F(PushMessagingPermissionContextTest, HasPermissionDenySettingsMismatch) {
106 TestingProfile profile; 116 TestingProfile profile;
107 PushMessagingPermissionContext context(&profile); 117 PushMessagingPermissionContext context(&profile);
108 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 118 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
109 CONTENT_SETTING_BLOCK); 119 CONTENT_SETTING_BLOCK);
110 EXPECT_EQ(CONTENT_SETTING_BLOCK, 120 EXPECT_EQ(CONTENT_SETTING_BLOCK,
111 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 121 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA)));
112 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 122 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 BrowserPermissionCallback callback = base::Bind(DoNothing); 217 BrowserPermissionCallback callback = base::Bind(DoNothing);
208 218
209 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 219 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
210 CONTENT_SETTING_ALLOW); 220 CONTENT_SETTING_ALLOW);
211 221
212 EXPECT_EQ( 222 EXPECT_EQ(
213 CONTENT_SETTING_ASK, 223 CONTENT_SETTING_ASK,
214 HostContentSettingsMapFactory::GetForProfile(&profile)->GetContentSetting( 224 HostContentSettingsMapFactory::GetForProfile(&profile)->GetContentSetting(
215 GURL(kOriginA), GURL(kOriginA), CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 225 GURL(kOriginA), GURL(kOriginA), CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
216 std::string())); 226 std::string()));
217 EXPECT_EQ(CONTENT_SETTING_ASK, 227 EXPECT_EQ(CONTENT_SETTING_ALLOW,
218 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 228 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA)));
219 229
220 // If a website already has notifications permission, push permission is 230 // If a website already has notifications permission, push permission is
221 // silently granted once the website requests it. 231 // silently assumed to be granted.
222 NavigateAndCommit(GURL(kOriginA)); 232 NavigateAndCommit(GURL(kOriginA));
223 context.RequestPermission(web_contents(), request_id, GURL(kOriginA), 233 context.RequestPermission(web_contents(), request_id, GURL(kOriginA),
224 callback); 234 callback);
225 235
226 EXPECT_TRUE(context.was_persisted()); 236 // Although the permission check goes through, the push message permission
237 // isn't actually updated.
227 EXPECT_TRUE(context.was_granted()); 238 EXPECT_TRUE(context.was_granted());
228 EXPECT_EQ( 239 EXPECT_EQ(
229 CONTENT_SETTING_ALLOW, 240 CONTENT_SETTING_ASK,
230 HostContentSettingsMapFactory::GetForProfile(&profile)->GetContentSetting( 241 HostContentSettingsMapFactory::GetForProfile(&profile)->GetContentSetting(
231 GURL(kOriginA), GURL(kOriginA), CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 242 GURL(kOriginA), GURL(kOriginA), CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
232 std::string())); 243 std::string()));
233 EXPECT_EQ(CONTENT_SETTING_ALLOW, 244 EXPECT_EQ(CONTENT_SETTING_ALLOW,
234 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 245 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA)));
235 } 246 }
236 247
237 TEST_F(PushMessagingPermissionContextTest, RequestAfterRevokingNotifications) { 248 TEST_F(PushMessagingPermissionContextTest, RequestAfterRevokingNotifications) {
238 TestingProfile profile; 249 TestingProfile profile;
239 TestPushMessagingPermissionContext context(&profile); 250 TestPushMessagingPermissionContext context(&profile);
240 PermissionRequestID request_id(-1, -1, -1); 251 PermissionRequestID request_id(-1, -1, -1);
241 BrowserPermissionCallback callback = base::Bind(DoNothing); 252 BrowserPermissionCallback callback = base::Bind(DoNothing);
242 253
243 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 254 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
244 CONTENT_SETTING_ALLOW); 255 CONTENT_SETTING_ALLOW);
245 256
246 NavigateAndCommit(GURL(kOriginA)); 257 NavigateAndCommit(GURL(kOriginA));
247 context.RequestPermission(web_contents(), request_id, GURL(kOriginA), 258 context.RequestPermission(web_contents(), request_id, GURL(kOriginA),
248 callback); 259 callback);
249 EXPECT_TRUE(context.was_persisted());
250 EXPECT_TRUE(context.was_granted()); 260 EXPECT_TRUE(context.was_granted());
251 261
252 EXPECT_EQ(CONTENT_SETTING_ALLOW, 262 EXPECT_EQ(CONTENT_SETTING_ALLOW,
253 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 263 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA)));
254 264
255 // Revoke notifications permission. This should revoke push, and prevent 265 // Revoke notifications permission. This should revoke push, and prevent
256 // future requests for push from succeeding. 266 // future requests for push from succeeding.
257 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 267 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
258 CONTENT_SETTING_BLOCK); 268 CONTENT_SETTING_BLOCK);
259 269
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 EXPECT_EQ(CONTENT_SETTING_BLOCK, 301 EXPECT_EQ(CONTENT_SETTING_BLOCK,
292 context.GetPermissionStatus(GURL(kInsecureOrigin), 302 context.GetPermissionStatus(GURL(kInsecureOrigin),
293 GURL(kInsecureOrigin))); 303 GURL(kInsecureOrigin)));
294 304
295 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 305 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
296 CONTENT_SETTING_ASK); 306 CONTENT_SETTING_ASK);
297 EXPECT_EQ(CONTENT_SETTING_BLOCK, 307 EXPECT_EQ(CONTENT_SETTING_BLOCK,
298 context.GetPermissionStatus(GURL(kInsecureOrigin), 308 context.GetPermissionStatus(GURL(kInsecureOrigin),
299 GURL(kInsecureOrigin))); 309 GURL(kInsecureOrigin)));
300 } 310 }
OLDNEW
« no previous file with comments | « chrome/browser/push_messaging/push_messaging_permission_context.cc ('k') | chrome/test/data/push_messaging/push_constants.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698