Chromium Code Reviews

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

Issue 1690043004: Use GURLs instead of patterns in SetContentSetting() in geolocation and push_messaging (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scoping_set_content_setting
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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/chrome_render_view_host_test_harness.h"
10 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
(...skipping 43 matching lines...)
54 54
55 class PushMessagingPermissionContextTest 55 class PushMessagingPermissionContextTest
56 : public ChromeRenderViewHostTestHarness { 56 : public ChromeRenderViewHostTestHarness {
57 public: 57 public:
58 PushMessagingPermissionContextTest() {} 58 PushMessagingPermissionContextTest() {}
59 59
60 protected: 60 protected:
61 void SetContentSetting(Profile* profile, 61 void SetContentSetting(Profile* profile,
62 ContentSettingsType setting, 62 ContentSettingsType setting,
63 ContentSetting value) { 63 ContentSetting value) {
64 // These patterns must match those in 64 // These patterns must match those in
Michael van Ouwerkerk 2016/02/17 11:19:26 Please update these comments, they still refer to
lshang 2016/02/18 00:23:53 Done.
65 // PermissionContextBase::UpdateContentSetting, since the tests below use 65 // PermissionContextBase::UpdateContentSetting, since the tests below use
66 // this method to overwrite patterns set as a result of 66 // this method to overwrite patterns set as a result of
67 // PushMessagingPermissionContext::NotifyPermissionSet. 67 // PushMessagingPermissionContext::NotifyPermissionSet.
68 ContentSettingsPattern pattern_a = 68 GURL url_a = GURL(kOriginA);
69 ContentSettingsPattern::FromURLNoWildcard(GURL(kOriginA)); 69 GURL insecure_url = GURL(kInsecureOrigin);
70 ContentSettingsPattern insecure_pattern =
71 ContentSettingsPattern::FromURLNoWildcard(GURL(kInsecureOrigin));
72 HostContentSettingsMap* host_content_settings_map = 70 HostContentSettingsMap* host_content_settings_map =
73 HostContentSettingsMapFactory::GetForProfile(profile); 71 HostContentSettingsMapFactory::GetForProfile(profile);
74 host_content_settings_map->SetContentSetting(pattern_a, pattern_a, setting, 72
75 std::string(), value); 73 if (setting == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
Michael van Ouwerkerk 2016/02/17 11:19:26 Why is this branching needed, just to pass a blank
lshang 2016/02/18 00:23:53 It will fail in DCHECK in: https://codereview.chro
Michael van Ouwerkerk 2016/02/18 09:42:44 I see, thank you!
76 host_content_settings_map->SetContentSetting( 74 host_content_settings_map->SetContentSettingDefaultScope(
77 insecure_pattern, insecure_pattern, setting, std::string(), value); 75 url_a, GURL(), setting, std::string(), value);
76 host_content_settings_map->SetContentSettingDefaultScope(
77 insecure_url, GURL(), setting, std::string(), value);
78 } else if (setting == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING) {
79 host_content_settings_map->SetContentSettingDefaultScope(
80 url_a, url_a, setting, std::string(), value);
81 host_content_settings_map->SetContentSettingDefaultScope(
82 insecure_url, insecure_url, setting, std::string(), value);
83 }
78 } 84 }
79 }; 85 };
80 86
81 } // namespace 87 } // namespace
82 88
83 TEST_F(PushMessagingPermissionContextTest, HasPermissionPrompt) { 89 TEST_F(PushMessagingPermissionContextTest, HasPermissionPrompt) {
84 TestingProfile profile; 90 TestingProfile profile;
85 PushMessagingPermissionContext context(&profile); 91 PushMessagingPermissionContext context(&profile);
86 EXPECT_EQ(CONTENT_SETTING_ASK, 92 EXPECT_EQ(CONTENT_SETTING_ASK,
87 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA))); 93 context.GetPermissionStatus(GURL(kOriginA), GURL(kOriginA)));
(...skipping 204 matching lines...)
292 EXPECT_EQ(CONTENT_SETTING_BLOCK, 298 EXPECT_EQ(CONTENT_SETTING_BLOCK,
293 context.GetPermissionStatus(GURL(kInsecureOrigin), 299 context.GetPermissionStatus(GURL(kInsecureOrigin),
294 GURL(kInsecureOrigin))); 300 GURL(kInsecureOrigin)));
295 301
296 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 302 SetContentSetting(&profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
297 CONTENT_SETTING_ASK); 303 CONTENT_SETTING_ASK);
298 EXPECT_EQ(CONTENT_SETTING_BLOCK, 304 EXPECT_EQ(CONTENT_SETTING_BLOCK,
299 context.GetPermissionStatus(GURL(kInsecureOrigin), 305 context.GetPermissionStatus(GURL(kInsecureOrigin),
300 GURL(kInsecureOrigin))); 306 GURL(kInsecureOrigin)));
301 } 307 }
OLDNEW

Powered by Google App Engine