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

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

Issue 1478433002: Permissions: Move common logic from DecidePermission to RequestPermission (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@innoinherit
Patch Set: Rebase / git cl format Created 5 years 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/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
10 #include "components/content_settings/core/browser/host_content_settings_map.h" 11 #include "components/content_settings/core/browser/host_content_settings_map.h"
11 #include "components/content_settings/core/common/content_settings.h" 12 #include "components/content_settings/core/common/content_settings.h"
12 #include "components/content_settings/core/common/content_settings_types.h" 13 #include "components/content_settings/core/common/content_settings_types.h"
13 #include "content/public/test/test_browser_thread_bundle.h" 14 #include "content/public/browser/web_contents.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 const char kOriginA[] = "https://origina.org"; 17 const char kOriginA[] = "https://origina.org";
17 const char kOriginB[] = "https://originb.org"; 18 const char kOriginB[] = "https://originb.org";
18 const char kInsecureOrigin[] = "http://insecureorigin.org"; 19 const char kInsecureOrigin[] = "http://insecureorigin.org";
19 20
20 class TestPushMessagingPermissionContext 21 class TestPushMessagingPermissionContext
21 : public PushMessagingPermissionContext { 22 : public PushMessagingPermissionContext {
22 public: 23 public:
23 explicit TestPushMessagingPermissionContext(Profile* profile) 24 explicit TestPushMessagingPermissionContext(Profile* profile)
(...skipping 13 matching lines...) Expand all
37 bool persist, 38 bool persist,
38 ContentSetting content_setting) override { 39 ContentSetting content_setting) override {
39 was_persisted_ = persist; 40 was_persisted_ = persist;
40 permission_granted_ = content_setting == CONTENT_SETTING_ALLOW; 41 permission_granted_ = content_setting == CONTENT_SETTING_ALLOW;
41 } 42 }
42 43
43 bool was_persisted_; 44 bool was_persisted_;
44 bool permission_granted_; 45 bool permission_granted_;
45 }; 46 };
46 47
47 class PushMessagingPermissionContextTest : public testing::Test { 48 class PushMessagingPermissionContextTest
49 : public ChromeRenderViewHostTestHarness {
48 public: 50 public:
49 PushMessagingPermissionContextTest() {} 51 PushMessagingPermissionContextTest() {}
50 52
51 protected: 53 protected:
52 void SetContentSetting(Profile* profile, 54 void SetContentSetting(Profile* profile,
53 ContentSettingsType setting, 55 ContentSettingsType setting,
54 ContentSetting value) { 56 ContentSetting value) {
55 ContentSettingsPattern pattern_a = 57 ContentSettingsPattern pattern_a =
56 ContentSettingsPattern::FromString(kOriginA); 58 ContentSettingsPattern::FromString(kOriginA);
57 ContentSettingsPattern insecure_pattern = 59 ContentSettingsPattern insecure_pattern =
58 ContentSettingsPattern::FromString(kInsecureOrigin); 60 ContentSettingsPattern::FromString(kInsecureOrigin);
59 HostContentSettingsMap* host_content_settings_map = 61 HostContentSettingsMap* host_content_settings_map =
60 HostContentSettingsMapFactory::GetForProfile(profile); 62 HostContentSettingsMapFactory::GetForProfile(profile);
61 host_content_settings_map->SetContentSetting(pattern_a, pattern_a, setting, 63 host_content_settings_map->SetContentSetting(pattern_a, pattern_a, setting,
62 std::string(), value); 64 std::string(), value);
63 host_content_settings_map->SetContentSetting( 65 host_content_settings_map->SetContentSetting(
64 insecure_pattern, insecure_pattern, setting, std::string(), value); 66 insecure_pattern, insecure_pattern, setting, std::string(), value);
65 } 67 }
66
67 content::TestBrowserThreadBundle thread_bundle_;
68 }; 68 };
69 69
70 TEST_F(PushMessagingPermissionContextTest, HasPermissionPrompt) { 70 TEST_F(PushMessagingPermissionContextTest, HasPermissionPrompt) {
71 TestingProfile profile; 71 TestingProfile profile;
72 PushMessagingPermissionContext context(&profile); 72 PushMessagingPermissionContext context(&profile);
73 EXPECT_EQ(CONTENT_SETTING_ASK, 73 EXPECT_EQ(CONTENT_SETTING_ASK,
74 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 74 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA)));
75 75
76 // Just granting notifications should still prompt 76 // Just granting notifications should still prompt
77 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 77 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 PermissionRequestID request_id(-1, -1, -1); 174 PermissionRequestID request_id(-1, -1, -1);
175 BrowserPermissionCallback callback; 175 BrowserPermissionCallback callback;
176 176
177 // Requesting and embedding origin are different. 177 // Requesting and embedding origin are different.
178 context.DecidePermission(NULL, request_id, GURL(kOriginA), GURL(kOriginB), 178 context.DecidePermission(NULL, request_id, GURL(kOriginA), GURL(kOriginB),
179 true, callback); 179 true, callback);
180 EXPECT_FALSE(context.was_persisted()); 180 EXPECT_FALSE(context.was_persisted());
181 EXPECT_FALSE(context.was_granted()); 181 EXPECT_FALSE(context.was_granted());
182 182
183 // Insecure origin 183 // Insecure origin
184 context.DecidePermission(NULL, request_id, GURL(kInsecureOrigin), 184 SetContents(CreateTestWebContents());
185 GURL(kInsecureOrigin), true, callback); 185 NavigateAndCommit(GURL(kInsecureOrigin));
186 context.RequestPermission(web_contents(), request_id, GURL(kInsecureOrigin),
187 true, callback);
186 EXPECT_FALSE(context.was_persisted()); 188 EXPECT_FALSE(context.was_persisted());
187 EXPECT_FALSE(context.was_granted()); 189 EXPECT_FALSE(context.was_granted());
188 } 190 }
189 191
190 TEST_F(PushMessagingPermissionContextTest, GetPermissionStatusInsecureOrigin) { 192 TEST_F(PushMessagingPermissionContextTest, GetPermissionStatusInsecureOrigin) {
191 TestingProfile profile; 193 TestingProfile profile;
192 TestPushMessagingPermissionContext context(&profile); 194 TestPushMessagingPermissionContext context(&profile);
193 195
194 // The status should be blocked for an insecure origin, regardless of the 196 // The status should be blocked for an insecure origin, regardless of the
195 // content setting value. 197 // content setting value.
(...skipping 14 matching lines...) Expand all
210 EXPECT_EQ(CONTENT_SETTING_BLOCK, 212 EXPECT_EQ(CONTENT_SETTING_BLOCK,
211 context.GetPermissionStatus(GURL(kInsecureOrigin), 213 context.GetPermissionStatus(GURL(kInsecureOrigin),
212 GURL(kInsecureOrigin))); 214 GURL(kInsecureOrigin)));
213 215
214 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 216 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
215 CONTENT_SETTING_ASK); 217 CONTENT_SETTING_ASK);
216 EXPECT_EQ(CONTENT_SETTING_BLOCK, 218 EXPECT_EQ(CONTENT_SETTING_BLOCK,
217 context.GetPermissionStatus(GURL(kInsecureOrigin), 219 context.GetPermissionStatus(GURL(kInsecureOrigin),
218 GURL(kInsecureOrigin))); 220 GURL(kInsecureOrigin)));
219 } 221 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698