Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/notifications/notification_permission_context.h" | 5 #include "chrome/browser/notifications/notification_permission_context.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/test/test_mock_time_task_runner.h" | 9 #include "base/test/test_mock_time_task_runner.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 void DoNothing(ContentSetting content_setting) {} | 31 void DoNothing(ContentSetting content_setting) {} |
| 32 void DoNothing2(blink::mojom::PermissionStatus status) {} | 32 void DoNothing2(blink::mojom::PermissionStatus status) {} |
| 33 | 33 |
| 34 class TestNotificationPermissionContext : public NotificationPermissionContext { | 34 class TestNotificationPermissionContext : public NotificationPermissionContext { |
| 35 public: | 35 public: |
| 36 explicit TestNotificationPermissionContext(Profile* profile) | 36 explicit TestNotificationPermissionContext(Profile* profile) |
| 37 : NotificationPermissionContext(profile), | 37 : NotificationPermissionContext(profile, |
| 38 content::PermissionType::NOTIFICATIONS), | |
| 38 permission_set_count_(0), | 39 permission_set_count_(0), |
| 39 last_permission_set_persisted_(false), | 40 last_permission_set_persisted_(false), |
| 40 last_permission_set_setting_(CONTENT_SETTING_DEFAULT) {} | 41 last_permission_set_setting_(CONTENT_SETTING_DEFAULT) {} |
| 41 | 42 |
| 42 int permission_set_count() const { return permission_set_count_; } | 43 int permission_set_count() const { return permission_set_count_; } |
| 43 bool last_permission_set_persisted() const { | 44 bool last_permission_set_persisted() const { |
| 44 return last_permission_set_persisted_; | 45 return last_permission_set_persisted_; |
| 45 } | 46 } |
| 46 ContentSetting last_permission_set_setting() const { | 47 ContentSetting last_permission_set_setting() const { |
| 47 return last_permission_set_setting_; | 48 return last_permission_set_setting_; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 | 102 |
| 102 } // namespace | 103 } // namespace |
| 103 | 104 |
| 104 // Web Notification permission requests will completely ignore the embedder | 105 // Web Notification permission requests will completely ignore the embedder |
| 105 // origin. See https://crbug.com/416894. | 106 // origin. See https://crbug.com/416894. |
| 106 TEST_F(NotificationPermissionContextTest, IgnoresEmbedderOrigin) { | 107 TEST_F(NotificationPermissionContextTest, IgnoresEmbedderOrigin) { |
| 107 GURL requesting_origin("https://example.com"); | 108 GURL requesting_origin("https://example.com"); |
| 108 GURL embedding_origin("https://chrome.com"); | 109 GURL embedding_origin("https://chrome.com"); |
| 109 GURL different_origin("https://foobar.com"); | 110 GURL different_origin("https://foobar.com"); |
| 110 | 111 |
| 111 NotificationPermissionContext context(profile()); | 112 NotificationPermissionContext context(profile(), |
| 113 content::PermissionType::NOTIFICATIONS); | |
| 112 context.UpdateContentSetting(requesting_origin, | 114 context.UpdateContentSetting(requesting_origin, |
| 113 embedding_origin, | 115 embedding_origin, |
| 114 CONTENT_SETTING_ALLOW); | 116 CONTENT_SETTING_ALLOW); |
| 115 | 117 |
| 116 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 118 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 117 context.GetPermissionStatus(requesting_origin, embedding_origin)); | 119 context.GetPermissionStatus(requesting_origin, embedding_origin)); |
| 118 | 120 |
| 119 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 121 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 120 context.GetPermissionStatus(requesting_origin, different_origin)); | 122 context.GetPermissionStatus(requesting_origin, different_origin)); |
| 121 | 123 |
| 122 context.ResetPermission(requesting_origin, embedding_origin); | 124 context.ResetPermission(requesting_origin, embedding_origin); |
| 123 | 125 |
| 124 EXPECT_EQ(CONTENT_SETTING_ASK, | 126 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 125 context.GetPermissionStatus(requesting_origin, embedding_origin)); | 127 context.GetPermissionStatus(requesting_origin, embedding_origin)); |
| 126 | 128 |
| 127 EXPECT_EQ(CONTENT_SETTING_ASK, | 129 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 128 context.GetPermissionStatus(requesting_origin, different_origin)); | 130 context.GetPermissionStatus(requesting_origin, different_origin)); |
| 129 } | 131 } |
| 130 | 132 |
| 131 // Web Notifications do not require a secure origin when requesting permission. | 133 // Web Notifications do not require a secure origin when requesting permission. |
| 132 // See https://crbug.com/404095. | 134 // See https://crbug.com/404095. |
| 133 TEST_F(NotificationPermissionContextTest, NoSecureOriginRequirement) { | 135 TEST_F(NotificationPermissionContextTest, NoSecureOriginRequirement) { |
| 134 GURL origin("http://example.com"); | 136 GURL origin("http://example.com"); |
| 135 | 137 |
| 136 NotificationPermissionContext context(profile()); | 138 NotificationPermissionContext context(profile(), |
| 139 content::PermissionType::NOTIFICATIONS); | |
| 137 EXPECT_EQ(CONTENT_SETTING_ASK, | 140 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 138 context.GetPermissionStatus(origin, origin)); | 141 context.GetPermissionStatus(origin, origin)); |
| 139 | 142 |
| 140 context.UpdateContentSetting(origin, origin, CONTENT_SETTING_ALLOW); | 143 context.UpdateContentSetting(origin, origin, CONTENT_SETTING_ALLOW); |
| 141 | 144 |
| 142 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 145 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 143 context.GetPermissionStatus(origin, origin)); | 146 context.GetPermissionStatus(origin, origin)); |
| 144 } | 147 } |
| 145 | 148 |
| 146 // Tests auto-denial after a time delay in incognito. | 149 // Tests auto-denial after a time delay in incognito. |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 | 294 |
| 292 // After another 2.5 seconds, the second permission request should also have | 295 // After another 2.5 seconds, the second permission request should also have |
| 293 // received a response. | 296 // received a response. |
| 294 task_runner->FastForwardBy(base::TimeDelta::FromMilliseconds(2500)); | 297 task_runner->FastForwardBy(base::TimeDelta::FromMilliseconds(2500)); |
| 295 EXPECT_EQ(2, permission_context.permission_set_count()); | 298 EXPECT_EQ(2, permission_context.permission_set_count()); |
| 296 EXPECT_TRUE(permission_context.last_permission_set_persisted()); | 299 EXPECT_TRUE(permission_context.last_permission_set_persisted()); |
| 297 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 300 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 298 permission_context.last_permission_set_setting()); | 301 permission_context.last_permission_set_setting()); |
| 299 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 302 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 300 permission_context.GetContentSettingFromMap(url, url)); | 303 permission_context.GetContentSettingFromMap(url, url)); |
| 301 } | 304 } |
|
Peter Beverloo
2016/07/14 17:15:19
Would you mind adding some very simple tests for t
raymes
2016/07/18 07:04:51
Done.
| |
| OLD | NEW |