| 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" |
| 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 24 matching lines...) Expand all Loading... |
| 75 host_content_settings_map->SetContentSettingDefaultScope( | 77 host_content_settings_map->SetContentSettingDefaultScope( |
| 76 insecure_url, insecure_url, setting, std::string(), value); | 78 insecure_url, insecure_url, setting, std::string(), value); |
| 77 } | 79 } |
| 78 }; | 80 }; |
| 79 | 81 |
| 80 } // namespace | 82 } // namespace |
| 81 | 83 |
| 82 TEST_F(PushMessagingPermissionContextTest, HasPermissionPrompt) { | 84 TEST_F(PushMessagingPermissionContextTest, HasPermissionPrompt) { |
| 83 TestingProfile profile; | 85 TestingProfile profile; |
| 84 PushMessagingPermissionContext context(&profile); | 86 PushMessagingPermissionContext context(&profile); |
| 87 const GURL url_a(kOriginA); |
| 88 const url::Origin origin_a(url_a); |
| 85 EXPECT_EQ(CONTENT_SETTING_ASK, | 89 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 86 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); | 90 context.GetPermissionStatus(origin_a, origin_a)); |
| 87 | 91 |
| 88 // Just granting notifications should still prompt | 92 // Just granting notifications should still prompt |
| 89 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 93 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 90 CONTENT_SETTING_ALLOW); | 94 CONTENT_SETTING_ALLOW); |
| 91 | 95 |
| 92 EXPECT_EQ(CONTENT_SETTING_ASK, | 96 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 93 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); | 97 context.GetPermissionStatus(origin_a, origin_a)); |
| 94 | 98 |
| 95 // Just granting push should still prompt | 99 // Just granting push should still prompt |
| 96 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 100 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 97 CONTENT_SETTING_ASK); | 101 CONTENT_SETTING_ASK); |
| 98 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 102 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 99 CONTENT_SETTING_ALLOW); | 103 CONTENT_SETTING_ALLOW); |
| 100 | 104 |
| 101 EXPECT_EQ(CONTENT_SETTING_ASK, | 105 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 102 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); | 106 context.GetPermissionStatus(origin_a, origin_a)); |
| 103 } | 107 } |
| 104 | 108 |
| 105 TEST_F(PushMessagingPermissionContextTest, HasPermissionDenySettingsMismatch) { | 109 TEST_F(PushMessagingPermissionContextTest, HasPermissionDenySettingsMismatch) { |
| 106 TestingProfile profile; | 110 TestingProfile profile; |
| 107 PushMessagingPermissionContext context(&profile); | 111 PushMessagingPermissionContext context(&profile); |
| 108 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 112 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 109 CONTENT_SETTING_BLOCK); | 113 CONTENT_SETTING_BLOCK); |
| 114 const GURL url_a(kOriginA); |
| 115 const url::Origin origin_a(url_a); |
| 110 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 116 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 111 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); | 117 context.GetPermissionStatus(origin_a, origin_a)); |
| 112 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 118 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 113 CONTENT_SETTING_ASK); | 119 CONTENT_SETTING_ASK); |
| 114 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 120 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 115 CONTENT_SETTING_BLOCK); | 121 CONTENT_SETTING_BLOCK); |
| 116 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 122 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 117 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); | 123 context.GetPermissionStatus(origin_a, origin_a)); |
| 118 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 124 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 119 CONTENT_SETTING_ALLOW); | 125 CONTENT_SETTING_ALLOW); |
| 120 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 126 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 121 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); | 127 context.GetPermissionStatus(origin_a, origin_a)); |
| 122 | 128 |
| 123 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 129 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 124 CONTENT_SETTING_ASK); | 130 CONTENT_SETTING_ASK); |
| 125 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 131 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 126 CONTENT_SETTING_BLOCK); | 132 CONTENT_SETTING_BLOCK); |
| 127 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 133 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 128 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); | 134 context.GetPermissionStatus(origin_a, origin_a)); |
| 129 } | 135 } |
| 130 | 136 |
| 131 TEST_F(PushMessagingPermissionContextTest, HasPermissionDenyDifferentOrigins) { | 137 TEST_F(PushMessagingPermissionContextTest, HasPermissionDenyDifferentOrigins) { |
| 132 TestingProfile profile; | 138 TestingProfile profile; |
| 133 PushMessagingPermissionContext context(&profile); | 139 PushMessagingPermissionContext context(&profile); |
| 134 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 140 const GURL url_a(kOriginA); |
| 135 context.GetPermissionStatus(GURL(kOriginB), GURL(kOriginA))); | 141 const GURL url_b(kOriginB); |
| 142 EXPECT_EQ(CONTENT_SETTING_BLOCK, context.GetPermissionStatus( |
| 143 url::Origin(url_a), url::Origin(url_b))); |
| 136 } | 144 } |
| 137 | 145 |
| 138 TEST_F(PushMessagingPermissionContextTest, HasPermissionAccept) { | 146 TEST_F(PushMessagingPermissionContextTest, HasPermissionAccept) { |
| 139 TestingProfile profile; | 147 TestingProfile profile; |
| 140 PushMessagingPermissionContext context(&profile); | 148 PushMessagingPermissionContext context(&profile); |
| 141 | 149 |
| 142 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 150 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 143 CONTENT_SETTING_ALLOW); | 151 CONTENT_SETTING_ALLOW); |
| 144 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 152 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 145 CONTENT_SETTING_ALLOW); | 153 CONTENT_SETTING_ALLOW); |
| 146 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 154 const GURL url_a(kOriginA); |
| 147 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); | 155 const GURL url_b(kOriginB); |
| 156 EXPECT_EQ(CONTENT_SETTING_ALLOW, context.GetPermissionStatus( |
| 157 url::Origin(url_a), url::Origin(url_b))); |
| 148 } | 158 } |
| 149 | 159 |
| 150 TEST_F(PushMessagingPermissionContextTest, DecidePushPermission) { | 160 TEST_F(PushMessagingPermissionContextTest, DecidePushPermission) { |
| 151 TestingProfile profile; | 161 TestingProfile profile; |
| 152 TestPushMessagingPermissionContext context(&profile); | 162 TestPushMessagingPermissionContext context(&profile); |
| 153 PermissionRequestID request_id(-1, -1, -1); | 163 PermissionRequestID request_id(-1, -1, -1); |
| 154 BrowserPermissionCallback callback = base::Bind(DoNothing); | 164 BrowserPermissionCallback callback = base::Bind(DoNothing); |
| 155 | 165 |
| 156 context.DecidePushPermission(request_id, GURL(kOriginA), GURL(kOriginA), | 166 const GURL url_a(kOriginA); |
| 157 callback, CONTENT_SETTING_DEFAULT); | 167 const url::Origin origin_a(url_a); |
| 168 context.DecidePushPermission(request_id, origin_a, origin_a, callback, |
| 169 CONTENT_SETTING_DEFAULT); |
| 158 EXPECT_FALSE(context.was_persisted()); | 170 EXPECT_FALSE(context.was_persisted()); |
| 159 EXPECT_FALSE(context.was_granted()); | 171 EXPECT_FALSE(context.was_granted()); |
| 160 | 172 |
| 161 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 173 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 162 CONTENT_SETTING_ALLOW); | 174 CONTENT_SETTING_ALLOW); |
| 163 context.DecidePushPermission(request_id, GURL(kOriginA), GURL(kOriginA), | 175 context.DecidePushPermission(request_id, origin_a, origin_a, callback, |
| 164 callback, CONTENT_SETTING_ALLOW); | 176 CONTENT_SETTING_ALLOW); |
| 165 EXPECT_TRUE(context.was_persisted()); | 177 EXPECT_TRUE(context.was_persisted()); |
| 166 EXPECT_TRUE(context.was_granted()); | 178 EXPECT_TRUE(context.was_granted()); |
| 167 | 179 |
| 168 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 180 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 169 CONTENT_SETTING_BLOCK); | 181 CONTENT_SETTING_BLOCK); |
| 170 context.DecidePushPermission(request_id, GURL(kOriginA), GURL(kOriginA), | 182 context.DecidePushPermission(request_id, origin_a, origin_a, callback, |
| 171 callback, CONTENT_SETTING_ALLOW); | 183 CONTENT_SETTING_ALLOW); |
| 172 EXPECT_TRUE(context.was_persisted()); | 184 EXPECT_TRUE(context.was_persisted()); |
| 173 EXPECT_FALSE(context.was_granted()); | 185 EXPECT_FALSE(context.was_granted()); |
| 174 | 186 |
| 175 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 187 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 176 CONTENT_SETTING_ASK); | 188 CONTENT_SETTING_ASK); |
| 177 context.DecidePushPermission(request_id, GURL(kOriginA), GURL(kOriginA), | 189 context.DecidePushPermission(request_id, origin_a, origin_a, callback, |
| 178 callback, CONTENT_SETTING_ALLOW); | 190 CONTENT_SETTING_ALLOW); |
| 179 EXPECT_TRUE(context.was_persisted()); | 191 EXPECT_TRUE(context.was_persisted()); |
| 180 EXPECT_TRUE(context.was_granted()); | 192 EXPECT_TRUE(context.was_granted()); |
| 181 } | 193 } |
| 182 | 194 |
| 183 TEST_F(PushMessagingPermissionContextTest, DecidePermission) { | 195 TEST_F(PushMessagingPermissionContextTest, DecidePermission) { |
| 184 TestingProfile profile; | 196 TestingProfile profile; |
| 185 TestPushMessagingPermissionContext context(&profile); | 197 TestPushMessagingPermissionContext context(&profile); |
| 186 PermissionRequestID request_id(-1, -1, -1); | 198 PermissionRequestID request_id(-1, -1, -1); |
| 187 BrowserPermissionCallback callback = base::Bind(DoNothing); | 199 BrowserPermissionCallback callback = base::Bind(DoNothing); |
| 188 | 200 |
| 201 const GURL url_a(kOriginA); |
| 202 const GURL url_b(kOriginB); |
| 203 const url::Origin origin_a(url_a); |
| 204 const url::Origin origin_b(url_b); |
| 205 |
| 189 // Requesting and embedding origin are different. | 206 // Requesting and embedding origin are different. |
| 190 context.DecidePermission(NULL, request_id, GURL(kOriginA), GURL(kOriginB), | 207 context.DecidePermission(NULL, request_id, origin_a, origin_b, callback); |
| 191 callback); | |
| 192 EXPECT_FALSE(context.was_persisted()); | 208 EXPECT_FALSE(context.was_persisted()); |
| 193 EXPECT_FALSE(context.was_granted()); | 209 EXPECT_FALSE(context.was_granted()); |
| 194 | 210 |
| 195 // Insecure origin | 211 // Insecure origin |
| 196 NavigateAndCommit(GURL(kInsecureOrigin)); | 212 const GURL insecure_url(kInsecureOrigin); |
| 197 context.RequestPermission(web_contents(), request_id, GURL(kInsecureOrigin), | 213 const url::Origin insecure_origin(insecure_url); |
| 214 NavigateAndCommit(insecure_url); |
| 215 context.RequestPermission(web_contents(), request_id, insecure_origin, |
| 198 callback); | 216 callback); |
| 199 EXPECT_FALSE(context.was_persisted()); | 217 EXPECT_FALSE(context.was_persisted()); |
| 200 EXPECT_FALSE(context.was_granted()); | 218 EXPECT_FALSE(context.was_granted()); |
| 201 } | 219 } |
| 202 | 220 |
| 203 TEST_F(PushMessagingPermissionContextTest, RequestPermission) { | 221 TEST_F(PushMessagingPermissionContextTest, RequestPermission) { |
| 204 TestingProfile profile; | 222 TestingProfile profile; |
| 205 TestPushMessagingPermissionContext context(&profile); | 223 TestPushMessagingPermissionContext context(&profile); |
| 206 PermissionRequestID request_id(-1, -1, -1); | 224 PermissionRequestID request_id(-1, -1, -1); |
| 207 BrowserPermissionCallback callback = base::Bind(DoNothing); | 225 BrowserPermissionCallback callback = base::Bind(DoNothing); |
| 208 | 226 |
| 209 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 227 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 210 CONTENT_SETTING_ALLOW); | 228 CONTENT_SETTING_ALLOW); |
| 211 | 229 |
| 230 const GURL url_a(kOriginA); |
| 231 const url::Origin origin_a(url_a); |
| 232 |
| 212 EXPECT_EQ( | 233 EXPECT_EQ( |
| 213 CONTENT_SETTING_ASK, | 234 CONTENT_SETTING_ASK, |
| 214 HostContentSettingsMapFactory::GetForProfile(&profile)->GetContentSetting( | 235 HostContentSettingsMapFactory::GetForProfile(&profile)->GetContentSetting( |
| 215 GURL(kOriginA), GURL(kOriginA), CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 236 url_a, url_a, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string())); |
| 216 std::string())); | |
| 217 EXPECT_EQ(CONTENT_SETTING_ASK, | 237 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 218 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); | 238 context.GetPermissionStatus(origin_a, origin_a)); |
| 219 | 239 |
| 220 // If a website already has notifications permission, push permission is | 240 // If a website already has notifications permission, push permission is |
| 221 // silently granted once the website requests it. | 241 // silently granted once the website requests it. |
| 222 NavigateAndCommit(GURL(kOriginA)); | 242 NavigateAndCommit(url_a); |
| 223 context.RequestPermission(web_contents(), request_id, GURL(kOriginA), | 243 context.RequestPermission(web_contents(), request_id, origin_a, callback); |
| 224 callback); | |
| 225 | 244 |
| 226 EXPECT_TRUE(context.was_persisted()); | 245 EXPECT_TRUE(context.was_persisted()); |
| 227 EXPECT_TRUE(context.was_granted()); | 246 EXPECT_TRUE(context.was_granted()); |
| 228 EXPECT_EQ( | 247 EXPECT_EQ( |
| 229 CONTENT_SETTING_ALLOW, | 248 CONTENT_SETTING_ALLOW, |
| 230 HostContentSettingsMapFactory::GetForProfile(&profile)->GetContentSetting( | 249 HostContentSettingsMapFactory::GetForProfile(&profile)->GetContentSetting( |
| 231 GURL(kOriginA), GURL(kOriginA), CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 250 url_a, url_a, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string())); |
| 232 std::string())); | |
| 233 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 251 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 234 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); | 252 context.GetPermissionStatus(origin_a, origin_a)); |
| 235 } | 253 } |
| 236 | 254 |
| 237 TEST_F(PushMessagingPermissionContextTest, RequestAfterRevokingNotifications) { | 255 TEST_F(PushMessagingPermissionContextTest, RequestAfterRevokingNotifications) { |
| 238 TestingProfile profile; | 256 TestingProfile profile; |
| 239 TestPushMessagingPermissionContext context(&profile); | 257 TestPushMessagingPermissionContext context(&profile); |
| 240 PermissionRequestID request_id(-1, -1, -1); | 258 PermissionRequestID request_id(-1, -1, -1); |
| 241 BrowserPermissionCallback callback = base::Bind(DoNothing); | 259 BrowserPermissionCallback callback = base::Bind(DoNothing); |
| 242 | 260 |
| 243 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 261 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 244 CONTENT_SETTING_ALLOW); | 262 CONTENT_SETTING_ALLOW); |
| 245 | 263 |
| 246 NavigateAndCommit(GURL(kOriginA)); | 264 const GURL url_a(kOriginA); |
| 247 context.RequestPermission(web_contents(), request_id, GURL(kOriginA), | 265 NavigateAndCommit(url_a); |
| 248 callback); | 266 const url::Origin origin_a(url_a); |
| 267 context.RequestPermission(web_contents(), request_id, origin_a, callback); |
| 249 EXPECT_TRUE(context.was_persisted()); | 268 EXPECT_TRUE(context.was_persisted()); |
| 250 EXPECT_TRUE(context.was_granted()); | 269 EXPECT_TRUE(context.was_granted()); |
| 251 | 270 |
| 252 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 271 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 253 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); | 272 context.GetPermissionStatus(origin_a, origin_a)); |
| 254 | 273 |
| 255 // Revoke notifications permission. This should revoke push, and prevent | 274 // Revoke notifications permission. This should revoke push, and prevent |
| 256 // future requests for push from succeeding. | 275 // future requests for push from succeeding. |
| 257 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 276 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 258 CONTENT_SETTING_BLOCK); | 277 CONTENT_SETTING_BLOCK); |
| 259 | 278 |
| 260 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 279 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 261 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); | 280 context.GetPermissionStatus(origin_a, origin_a)); |
| 262 | 281 |
| 263 context.RequestPermission(web_contents(), request_id, GURL(kOriginA), | 282 context.RequestPermission(web_contents(), request_id, origin_a, callback); |
| 264 callback); | |
| 265 EXPECT_FALSE(context.was_persisted()); | 283 EXPECT_FALSE(context.was_persisted()); |
| 266 EXPECT_FALSE(context.was_granted()); | 284 EXPECT_FALSE(context.was_granted()); |
| 267 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 285 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 268 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); | 286 context.GetPermissionStatus(origin_a, origin_a)); |
| 269 } | 287 } |
| 270 | 288 |
| 271 TEST_F(PushMessagingPermissionContextTest, GetPermissionStatusInsecureOrigin) { | 289 TEST_F(PushMessagingPermissionContextTest, GetPermissionStatusInsecureOrigin) { |
| 272 TestingProfile profile; | 290 TestingProfile profile; |
| 273 TestPushMessagingPermissionContext context(&profile); | 291 TestPushMessagingPermissionContext context(&profile); |
| 274 | 292 |
| 293 const GURL insecure_url(kInsecureOrigin); |
| 294 const url::Origin insecure_origin(insecure_url); |
| 295 |
| 275 // The status should be blocked for an insecure origin, regardless of the | 296 // The status should be blocked for an insecure origin, regardless of the |
| 276 // content setting value. | 297 // content setting value. |
| 277 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 298 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 278 context.GetPermissionStatus(GURL(kInsecureOrigin), | 299 context.GetPermissionStatus(insecure_origin, insecure_origin)); |
| 279 GURL(kInsecureOrigin))); | |
| 280 | 300 |
| 281 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 301 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 282 CONTENT_SETTING_ALLOW); | 302 CONTENT_SETTING_ALLOW); |
| 283 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 303 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 284 CONTENT_SETTING_ALLOW); | 304 CONTENT_SETTING_ALLOW); |
| 285 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 305 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 286 context.GetPermissionStatus(GURL(kInsecureOrigin), | 306 context.GetPermissionStatus(insecure_origin, insecure_origin)); |
| 287 GURL(kInsecureOrigin))); | |
| 288 | 307 |
| 289 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 308 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 290 CONTENT_SETTING_BLOCK); | 309 CONTENT_SETTING_BLOCK); |
| 291 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 310 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 292 context.GetPermissionStatus(GURL(kInsecureOrigin), | 311 context.GetPermissionStatus(insecure_origin, insecure_origin)); |
| 293 GURL(kInsecureOrigin))); | |
| 294 | 312 |
| 295 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 313 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 296 CONTENT_SETTING_ASK); | 314 CONTENT_SETTING_ASK); |
| 297 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 315 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 298 context.GetPermissionStatus(GURL(kInsecureOrigin), | 316 context.GetPermissionStatus(insecure_origin, insecure_origin)); |
| 299 GURL(kInsecureOrigin))); | |
| 300 } | 317 } |
| OLD | NEW |