| 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 "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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } | 195 } |
| 196 | 196 |
| 197 TEST_F(PushMessagingPermissionContextTest, DecidePermission) { | 197 TEST_F(PushMessagingPermissionContextTest, DecidePermission) { |
| 198 TestingProfile profile; | 198 TestingProfile profile; |
| 199 TestPushMessagingPermissionContext context(&profile); | 199 TestPushMessagingPermissionContext context(&profile); |
| 200 PermissionRequestID request_id(-1, -1, -1); | 200 PermissionRequestID request_id(-1, -1, -1); |
| 201 BrowserPermissionCallback callback = base::Bind(DoNothing); | 201 BrowserPermissionCallback callback = base::Bind(DoNothing); |
| 202 | 202 |
| 203 // Requesting and embedding origin are different. | 203 // Requesting and embedding origin are different. |
| 204 context.DecidePermission(NULL, request_id, GURL(kOriginA), GURL(kOriginB), | 204 context.DecidePermission(NULL, request_id, GURL(kOriginA), GURL(kOriginB), |
| 205 callback); | 205 true /* user_gesture */, callback); |
| 206 EXPECT_FALSE(context.was_persisted()); | 206 EXPECT_FALSE(context.was_persisted()); |
| 207 EXPECT_FALSE(context.was_granted()); | 207 EXPECT_FALSE(context.was_granted()); |
| 208 | 208 |
| 209 // Insecure origin | 209 // Insecure origin |
| 210 NavigateAndCommit(GURL(kInsecureOrigin)); | 210 NavigateAndCommit(GURL(kInsecureOrigin)); |
| 211 context.RequestPermission(web_contents(), request_id, GURL(kInsecureOrigin), | 211 context.RequestPermission(web_contents(), request_id, GURL(kInsecureOrigin), |
| 212 callback); | 212 true /* user_gesture */, callback); |
| 213 EXPECT_FALSE(context.was_persisted()); | 213 EXPECT_FALSE(context.was_persisted()); |
| 214 EXPECT_FALSE(context.was_granted()); | 214 EXPECT_FALSE(context.was_granted()); |
| 215 } | 215 } |
| 216 | 216 |
| 217 TEST_F(PushMessagingPermissionContextTest, RequestPermission) { | 217 TEST_F(PushMessagingPermissionContextTest, RequestPermission) { |
| 218 TestingProfile profile; | 218 TestingProfile profile; |
| 219 TestPushMessagingPermissionContext context(&profile); | 219 TestPushMessagingPermissionContext context(&profile); |
| 220 PermissionRequestID request_id(-1, -1, -1); | 220 PermissionRequestID request_id(-1, -1, -1); |
| 221 BrowserPermissionCallback callback = base::Bind(DoNothing); | 221 BrowserPermissionCallback callback = base::Bind(DoNothing); |
| 222 | 222 |
| 223 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 223 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 224 CONTENT_SETTING_ALLOW); | 224 CONTENT_SETTING_ALLOW); |
| 225 | 225 |
| 226 EXPECT_EQ( | 226 EXPECT_EQ( |
| 227 CONTENT_SETTING_ASK, | 227 CONTENT_SETTING_ASK, |
| 228 HostContentSettingsMapFactory::GetForProfile(&profile)->GetContentSetting( | 228 HostContentSettingsMapFactory::GetForProfile(&profile)->GetContentSetting( |
| 229 GURL(kOriginA), GURL(kOriginA), CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 229 GURL(kOriginA), GURL(kOriginA), CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 230 std::string())); | 230 std::string())); |
| 231 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 231 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 232 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); | 232 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); |
| 233 | 233 |
| 234 // If a website already has notifications permission, push permission is | 234 // If a website already has notifications permission, push permission is |
| 235 // silently assumed to be granted. | 235 // silently assumed to be granted. |
| 236 NavigateAndCommit(GURL(kOriginA)); | 236 NavigateAndCommit(GURL(kOriginA)); |
| 237 context.RequestPermission(web_contents(), request_id, GURL(kOriginA), | 237 context.RequestPermission(web_contents(), request_id, GURL(kOriginA), |
| 238 callback); | 238 true /* user_gesture */, callback); |
| 239 | 239 |
| 240 // Although the permission check goes through, the push message permission | 240 // Although the permission check goes through, the push message permission |
| 241 // isn't actually updated. | 241 // isn't actually updated. |
| 242 EXPECT_TRUE(context.was_granted()); | 242 EXPECT_TRUE(context.was_granted()); |
| 243 EXPECT_EQ( | 243 EXPECT_EQ( |
| 244 CONTENT_SETTING_ASK, | 244 CONTENT_SETTING_ASK, |
| 245 HostContentSettingsMapFactory::GetForProfile(&profile)->GetContentSetting( | 245 HostContentSettingsMapFactory::GetForProfile(&profile)->GetContentSetting( |
| 246 GURL(kOriginA), GURL(kOriginA), CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 246 GURL(kOriginA), GURL(kOriginA), CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 247 std::string())); | 247 std::string())); |
| 248 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 248 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 249 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); | 249 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); |
| 250 } | 250 } |
| 251 | 251 |
| 252 TEST_F(PushMessagingPermissionContextTest, RequestAfterRevokingNotifications) { | 252 TEST_F(PushMessagingPermissionContextTest, RequestAfterRevokingNotifications) { |
| 253 TestingProfile profile; | 253 TestingProfile profile; |
| 254 TestPushMessagingPermissionContext context(&profile); | 254 TestPushMessagingPermissionContext context(&profile); |
| 255 PermissionRequestID request_id(-1, -1, -1); | 255 PermissionRequestID request_id(-1, -1, -1); |
| 256 BrowserPermissionCallback callback = base::Bind(DoNothing); | 256 BrowserPermissionCallback callback = base::Bind(DoNothing); |
| 257 | 257 |
| 258 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 258 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 259 CONTENT_SETTING_ALLOW); | 259 CONTENT_SETTING_ALLOW); |
| 260 | 260 |
| 261 NavigateAndCommit(GURL(kOriginA)); | 261 NavigateAndCommit(GURL(kOriginA)); |
| 262 context.RequestPermission(web_contents(), request_id, GURL(kOriginA), | 262 context.RequestPermission(web_contents(), request_id, GURL(kOriginA), |
| 263 callback); | 263 true /* user_gesture */, callback); |
| 264 EXPECT_TRUE(context.was_granted()); | 264 EXPECT_TRUE(context.was_granted()); |
| 265 | 265 |
| 266 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 266 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 267 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); | 267 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); |
| 268 | 268 |
| 269 // Revoke notifications permission. This should revoke push, and prevent | 269 // Revoke notifications permission. This should revoke push, and prevent |
| 270 // future requests for push from succeeding. | 270 // future requests for push from succeeding. |
| 271 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 271 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 272 CONTENT_SETTING_BLOCK); | 272 CONTENT_SETTING_BLOCK); |
| 273 | 273 |
| 274 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 274 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 275 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); | 275 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); |
| 276 | 276 |
| 277 context.RequestPermission(web_contents(), request_id, GURL(kOriginA), | 277 context.RequestPermission(web_contents(), request_id, GURL(kOriginA), |
| 278 callback); | 278 true /* user_gesture */, callback); |
| 279 EXPECT_FALSE(context.was_persisted()); | 279 EXPECT_FALSE(context.was_persisted()); |
| 280 EXPECT_FALSE(context.was_granted()); | 280 EXPECT_FALSE(context.was_granted()); |
| 281 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 281 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 282 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); | 282 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); |
| 283 } | 283 } |
| 284 | 284 |
| 285 TEST_F(PushMessagingPermissionContextTest, GetPermissionStatusInsecureOrigin) { | 285 TEST_F(PushMessagingPermissionContextTest, GetPermissionStatusInsecureOrigin) { |
| 286 TestingProfile profile; | 286 TestingProfile profile; |
| 287 TestPushMessagingPermissionContext context(&profile); | 287 TestPushMessagingPermissionContext context(&profile); |
| 288 | 288 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 305 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 305 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 306 context.GetPermissionStatus(GURL(kInsecureOrigin), | 306 context.GetPermissionStatus(GURL(kInsecureOrigin), |
| 307 GURL(kInsecureOrigin))); | 307 GURL(kInsecureOrigin))); |
| 308 | 308 |
| 309 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 309 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 310 CONTENT_SETTING_ASK); | 310 CONTENT_SETTING_ASK); |
| 311 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 311 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 312 context.GetPermissionStatus(GURL(kInsecureOrigin), | 312 context.GetPermissionStatus(GURL(kInsecureOrigin), |
| 313 GURL(kInsecureOrigin))); | 313 GURL(kInsecureOrigin))); |
| 314 } | 314 } |
| OLD | NEW |