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/services/gcm/push_messaging_permission_context.h" | 5 #include "chrome/browser/services/gcm/push_messaging_permission_context.h" |
6 #include "chrome/test/base/testing_profile.h" | 6 #include "chrome/test/base/testing_profile.h" |
7 #include "components/content_settings/core/browser/host_content_settings_map.h" | 7 #include "components/content_settings/core/browser/host_content_settings_map.h" |
8 #include "components/content_settings/core/common/content_settings.h" | 8 #include "components/content_settings/core/common/content_settings.h" |
9 #include "components/content_settings/core/common/content_settings_types.h" | 9 #include "components/content_settings/core/common/content_settings_types.h" |
10 #include "components/content_settings/core/common/permission_request_id.h" | 10 #include "components/content_settings/core/common/permission_request_id.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 bool was_persisted() const { return was_persisted_; } | 27 bool was_persisted() const { return was_persisted_; } |
28 bool was_granted() const { return permission_granted_; } | 28 bool was_granted() const { return permission_granted_; } |
29 | 29 |
30 private: | 30 private: |
31 // PushMessagingPermissionContext: | 31 // PushMessagingPermissionContext: |
32 void NotifyPermissionSet(const PermissionRequestID& id, | 32 void NotifyPermissionSet(const PermissionRequestID& id, |
33 const GURL& requesting_origin, | 33 const GURL& requesting_origin, |
34 const GURL& embedder_origin, | 34 const GURL& embedder_origin, |
35 const BrowserPermissionCallback& callback, | 35 const BrowserPermissionCallback& callback, |
36 bool persist, | 36 bool persist, |
37 bool allowed) override { | 37 ContentSetting content_setting) override { |
38 was_persisted_ = persist; | 38 was_persisted_ = persist; |
39 permission_granted_ = allowed; | 39 permission_granted_ = content_setting == CONTENT_SETTING_ALLOW; |
40 } | 40 } |
41 | 41 |
42 bool was_persisted_; | 42 bool was_persisted_; |
43 bool permission_granted_; | 43 bool permission_granted_; |
44 }; | 44 }; |
45 | 45 |
46 class PushMessagingPermissionContextTest : public testing::Test { | 46 class PushMessagingPermissionContextTest : public testing::Test { |
47 public: | 47 public: |
48 PushMessagingPermissionContextTest() {} | 48 PushMessagingPermissionContextTest() {} |
49 | 49 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); | 130 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); |
131 } | 131 } |
132 | 132 |
133 TEST_F(PushMessagingPermissionContextTest, DecidePushPermission) { | 133 TEST_F(PushMessagingPermissionContextTest, DecidePushPermission) { |
134 TestingProfile profile; | 134 TestingProfile profile; |
135 TestPushMessagingPermissionContext context(&profile); | 135 TestPushMessagingPermissionContext context(&profile); |
136 PermissionRequestID request_id(-1, -1, -1, GURL(kOriginA)); | 136 PermissionRequestID request_id(-1, -1, -1, GURL(kOriginA)); |
137 BrowserPermissionCallback callback; | 137 BrowserPermissionCallback callback; |
138 | 138 |
139 context.DecidePushPermission(request_id, GURL(kOriginA), GURL(kOriginA), | 139 context.DecidePushPermission(request_id, GURL(kOriginA), GURL(kOriginA), |
140 callback, false); | 140 callback, CONTENT_SETTING_DEFAULT); |
141 EXPECT_FALSE(context.was_persisted()); | 141 EXPECT_FALSE(context.was_persisted()); |
142 EXPECT_FALSE(context.was_granted()); | 142 EXPECT_FALSE(context.was_granted()); |
143 | 143 |
144 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 144 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
145 CONTENT_SETTING_ALLOW); | 145 CONTENT_SETTING_ALLOW); |
146 context.DecidePushPermission(request_id, GURL(kOriginA), GURL(kOriginA), | 146 context.DecidePushPermission(request_id, GURL(kOriginA), GURL(kOriginA), |
147 callback, true); | 147 callback, CONTENT_SETTING_ALLOW); |
148 EXPECT_TRUE(context.was_persisted()); | 148 EXPECT_TRUE(context.was_persisted()); |
149 EXPECT_TRUE(context.was_granted()); | 149 EXPECT_TRUE(context.was_granted()); |
150 | 150 |
151 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 151 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
152 CONTENT_SETTING_BLOCK); | 152 CONTENT_SETTING_BLOCK); |
153 context.DecidePushPermission(request_id, GURL(kOriginA), GURL(kOriginA), | 153 context.DecidePushPermission(request_id, GURL(kOriginA), GURL(kOriginA), |
154 callback, true); | 154 callback, CONTENT_SETTING_ALLOW); |
155 EXPECT_TRUE(context.was_persisted()); | 155 EXPECT_TRUE(context.was_persisted()); |
156 EXPECT_FALSE(context.was_granted()); | 156 EXPECT_FALSE(context.was_granted()); |
157 | 157 |
158 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 158 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
159 CONTENT_SETTING_ASK); | 159 CONTENT_SETTING_ASK); |
160 context.DecidePushPermission(request_id, GURL(kOriginA), GURL(kOriginA), | 160 context.DecidePushPermission(request_id, GURL(kOriginA), GURL(kOriginA), |
161 callback, true); | 161 callback, CONTENT_SETTING_ALLOW); |
162 EXPECT_TRUE(context.was_persisted()); | 162 EXPECT_TRUE(context.was_persisted()); |
163 EXPECT_TRUE(context.was_granted()); | 163 EXPECT_TRUE(context.was_granted()); |
164 } | 164 } |
165 | 165 |
166 } // namespace gcm | 166 } // namespace gcm |
OLD | NEW |