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

Side by Side Diff: chrome/browser/content_settings/host_content_settings_map_unittest.cc

Issue 2459823002: [Sync] Rename syncable_prefs to sync_preferences. (Closed)
Patch Set: Created 4 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/auto_reset.h" 8 #include "base/auto_reset.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "chrome/browser/content_settings/content_settings_mock_observer.h" 14 #include "chrome/browser/content_settings/content_settings_mock_observer.h"
15 #include "chrome/browser/content_settings/cookie_settings_factory.h" 15 #include "chrome/browser/content_settings/cookie_settings_factory.h"
16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
17 #include "chrome/browser/content_settings/mock_settings_observer.h" 17 #include "chrome/browser/content_settings/mock_settings_observer.h"
18 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
19 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
20 #include "components/content_settings/core/browser/content_settings_details.h" 20 #include "components/content_settings/core/browser/content_settings_details.h"
21 #include "components/content_settings/core/browser/cookie_settings.h" 21 #include "components/content_settings/core/browser/cookie_settings.h"
22 #include "components/content_settings/core/browser/host_content_settings_map.h" 22 #include "components/content_settings/core/browser/host_content_settings_map.h"
23 #include "components/content_settings/core/browser/website_settings_info.h" 23 #include "components/content_settings/core/browser/website_settings_info.h"
24 #include "components/content_settings/core/browser/website_settings_registry.h" 24 #include "components/content_settings/core/browser/website_settings_registry.h"
25 #include "components/content_settings/core/common/pref_names.h" 25 #include "components/content_settings/core/common/pref_names.h"
26 #include "components/prefs/pref_service.h" 26 #include "components/prefs/pref_service.h"
27 #include "components/prefs/scoped_user_pref_update.h" 27 #include "components/prefs/scoped_user_pref_update.h"
28 #include "components/syncable_prefs/testing_pref_service_syncable.h" 28 #include "components/sync_preferences/testing_pref_service_syncable.h"
29 #include "content/public/test/test_browser_thread.h" 29 #include "content/public/test/test_browser_thread.h"
30 #include "net/base/static_cookie_policy.h" 30 #include "net/base/static_cookie_policy.h"
31 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
32 #include "url/gurl.h" 32 #include "url/gurl.h"
33 33
34 using content::BrowserThread; 34 using content::BrowserThread;
35 35
36 using ::testing::_; 36 using ::testing::_;
37 37
38 namespace { 38 namespace {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 const std::string& url_str) { 105 const std::string& url_str) {
106 GURL url(url_str); 106 GURL url(url_str);
107 content_settings::SettingInfo setting_info; 107 content_settings::SettingInfo setting_info;
108 std::unique_ptr<base::Value> result = 108 std::unique_ptr<base::Value> result =
109 host_content_settings_map_->GetWebsiteSetting( 109 host_content_settings_map_->GetWebsiteSetting(
110 url, url, content_type_, std::string(), &setting_info); 110 url, url, content_type_, std::string(), &setting_info);
111 return setting_info.source; 111 return setting_info.source;
112 } 112 }
113 113
114 private: 114 private:
115 syncable_prefs::TestingPrefServiceSyncable* prefs_; 115 sync_preferences::TestingPrefServiceSyncable* prefs_;
116 HostContentSettingsMap* host_content_settings_map_; 116 HostContentSettingsMap* host_content_settings_map_;
117 ContentSettingsType content_type_; 117 ContentSettingsType content_type_;
118 const char* policy_default_setting_; 118 const char* policy_default_setting_;
119 119
120 DISALLOW_COPY_AND_ASSIGN(TesterForType); 120 DISALLOW_COPY_AND_ASSIGN(TesterForType);
121 }; 121 };
122 122
123 TEST_F(HostContentSettingsMapTest, DefaultValues) { 123 TEST_F(HostContentSettingsMapTest, DefaultValues) {
124 TestingProfile profile; 124 TestingProfile profile;
125 HostContentSettingsMap* host_content_settings_map = 125 HostContentSettingsMap* host_content_settings_map =
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"setting\":2}}", 1000 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"setting\":2}}",
1001 prefs_as_json.c_str()); 1001 prefs_as_json.c_str());
1002 } 1002 }
1003 1003
1004 // If a default-content-setting is managed, the managed value should be used 1004 // If a default-content-setting is managed, the managed value should be used
1005 // instead of the default value. 1005 // instead of the default value.
1006 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) { 1006 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) {
1007 TestingProfile profile; 1007 TestingProfile profile;
1008 HostContentSettingsMap* host_content_settings_map = 1008 HostContentSettingsMap* host_content_settings_map =
1009 HostContentSettingsMapFactory::GetForProfile(&profile); 1009 HostContentSettingsMapFactory::GetForProfile(&profile);
1010 syncable_prefs::TestingPrefServiceSyncable* prefs = 1010 sync_preferences::TestingPrefServiceSyncable* prefs =
1011 profile.GetTestingPrefService(); 1011 profile.GetTestingPrefService();
1012 1012
1013 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1013 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1014 host_content_settings_map->GetDefaultContentSetting( 1014 host_content_settings_map->GetDefaultContentSetting(
1015 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); 1015 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
1016 1016
1017 // Set managed-default-content-setting through the coresponding preferences. 1017 // Set managed-default-content-setting through the coresponding preferences.
1018 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, 1018 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
1019 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 1019 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
1020 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1020 EXPECT_EQ(CONTENT_SETTING_BLOCK,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1058 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1059 host_content_settings_map->GetDefaultContentSetting( 1059 host_content_settings_map->GetDefaultContentSetting(
1060 CONTENT_SETTINGS_TYPE_KEYGEN, NULL)); 1060 CONTENT_SETTINGS_TYPE_KEYGEN, NULL));
1061 } 1061 }
1062 1062
1063 TEST_F(HostContentSettingsMapTest, 1063 TEST_F(HostContentSettingsMapTest,
1064 GetNonDefaultContentSettingsIfTypeManaged) { 1064 GetNonDefaultContentSettingsIfTypeManaged) {
1065 TestingProfile profile; 1065 TestingProfile profile;
1066 HostContentSettingsMap* host_content_settings_map = 1066 HostContentSettingsMap* host_content_settings_map =
1067 HostContentSettingsMapFactory::GetForProfile(&profile); 1067 HostContentSettingsMapFactory::GetForProfile(&profile);
1068 syncable_prefs::TestingPrefServiceSyncable* prefs = 1068 sync_preferences::TestingPrefServiceSyncable* prefs =
1069 profile.GetTestingPrefService(); 1069 profile.GetTestingPrefService();
1070 1070
1071 // Set url for JavaScript setting. 1071 // Set url for JavaScript setting.
1072 GURL host("http://example.com/"); 1072 GURL host("http://example.com/");
1073 host_content_settings_map->SetContentSettingDefaultScope( 1073 host_content_settings_map->SetContentSettingDefaultScope(
1074 host, GURL(), CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), 1074 host, GURL(), CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(),
1075 CONTENT_SETTING_BLOCK); 1075 CONTENT_SETTING_BLOCK);
1076 1076
1077 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1077 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1078 host_content_settings_map->GetDefaultContentSetting( 1078 host_content_settings_map->GetDefaultContentSetting(
(...skipping 11 matching lines...) Expand all
1090 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 1090 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
1091 } 1091 }
1092 1092
1093 // Managed default content setting should have higher priority 1093 // Managed default content setting should have higher priority
1094 // than user defined patterns. 1094 // than user defined patterns.
1095 TEST_F(HostContentSettingsMapTest, 1095 TEST_F(HostContentSettingsMapTest,
1096 ManagedDefaultContentSettingIgnoreUserPattern) { 1096 ManagedDefaultContentSettingIgnoreUserPattern) {
1097 TestingProfile profile; 1097 TestingProfile profile;
1098 HostContentSettingsMap* host_content_settings_map = 1098 HostContentSettingsMap* host_content_settings_map =
1099 HostContentSettingsMapFactory::GetForProfile(&profile); 1099 HostContentSettingsMapFactory::GetForProfile(&profile);
1100 syncable_prefs::TestingPrefServiceSyncable* prefs = 1100 sync_preferences::TestingPrefServiceSyncable* prefs =
1101 profile.GetTestingPrefService(); 1101 profile.GetTestingPrefService();
1102 1102
1103 // Block all JavaScript. 1103 // Block all JavaScript.
1104 host_content_settings_map->SetDefaultContentSetting( 1104 host_content_settings_map->SetDefaultContentSetting(
1105 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); 1105 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
1106 1106
1107 // Set an exception to allow "[*.]example.com" 1107 // Set an exception to allow "[*.]example.com"
1108 GURL host("http://example.com/"); 1108 GURL host("http://example.com/");
1109 1109
1110 host_content_settings_map->SetContentSettingDefaultScope( 1110 host_content_settings_map->SetContentSettingDefaultScope(
(...skipping 21 matching lines...) Expand all
1132 host_content_settings_map->GetContentSetting( 1132 host_content_settings_map->GetContentSetting(
1133 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 1133 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
1134 } 1134 }
1135 1135
1136 // If a default-content-setting is set to managed setting, the user defined 1136 // If a default-content-setting is set to managed setting, the user defined
1137 // setting should be preserved. 1137 // setting should be preserved.
1138 TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) { 1138 TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) {
1139 TestingProfile profile; 1139 TestingProfile profile;
1140 HostContentSettingsMap* host_content_settings_map = 1140 HostContentSettingsMap* host_content_settings_map =
1141 HostContentSettingsMapFactory::GetForProfile(&profile); 1141 HostContentSettingsMapFactory::GetForProfile(&profile);
1142 syncable_prefs::TestingPrefServiceSyncable* prefs = 1142 sync_preferences::TestingPrefServiceSyncable* prefs =
1143 profile.GetTestingPrefService(); 1143 profile.GetTestingPrefService();
1144 1144
1145 // Set user defined default-content-setting for Cookies. 1145 // Set user defined default-content-setting for Cookies.
1146 host_content_settings_map->SetDefaultContentSetting( 1146 host_content_settings_map->SetDefaultContentSetting(
1147 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); 1147 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
1148 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1148 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1149 host_content_settings_map->GetDefaultContentSetting( 1149 host_content_settings_map->GetDefaultContentSetting(
1150 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); 1150 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
1151 1151
1152 // Set preference to manage the default-content-setting for Cookies. 1152 // Set preference to manage the default-content-setting for Cookies.
(...skipping 10 matching lines...) Expand all
1163 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); 1163 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
1164 } 1164 }
1165 1165
1166 // If a setting for a default-content-setting-type is set while the type is 1166 // If a setting for a default-content-setting-type is set while the type is
1167 // managed, then the new setting should be preserved and used after the 1167 // managed, then the new setting should be preserved and used after the
1168 // default-content-setting-type is not managed anymore. 1168 // default-content-setting-type is not managed anymore.
1169 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) { 1169 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) {
1170 TestingProfile profile; 1170 TestingProfile profile;
1171 HostContentSettingsMap* host_content_settings_map = 1171 HostContentSettingsMap* host_content_settings_map =
1172 HostContentSettingsMapFactory::GetForProfile(&profile); 1172 HostContentSettingsMapFactory::GetForProfile(&profile);
1173 syncable_prefs::TestingPrefServiceSyncable* prefs = 1173 sync_preferences::TestingPrefServiceSyncable* prefs =
1174 profile.GetTestingPrefService(); 1174 profile.GetTestingPrefService();
1175 1175
1176 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting, 1176 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting,
1177 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 1177 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
1178 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1178 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1179 host_content_settings_map->GetDefaultContentSetting( 1179 host_content_settings_map->GetDefaultContentSetting(
1180 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); 1180 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
1181 1181
1182 host_content_settings_map->SetDefaultContentSetting( 1182 host_content_settings_map->SetDefaultContentSetting(
1183 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); 1183 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
1737 host_content_settings_map->ClearSettingsForOneTypeWithPredicate( 1737 host_content_settings_map->ClearSettingsForOneTypeWithPredicate(
1738 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, 1738 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
1739 base::Bind(&MatchPrimaryPattern, http_pattern)); 1739 base::Bind(&MatchPrimaryPattern, http_pattern));
1740 // Verify we only have one, and it's url1. 1740 // Verify we only have one, and it's url1.
1741 host_content_settings_map->GetSettingsForOneType( 1741 host_content_settings_map->GetSettingsForOneType(
1742 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); 1742 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings);
1743 EXPECT_EQ(1u, host_settings.size()); 1743 EXPECT_EQ(1u, host_settings.size());
1744 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1), 1744 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1),
1745 host_settings[0].primary_pattern); 1745 host_settings[0].primary_pattern);
1746 } 1746 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698