OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "components/content_settings/core/browser/content_settings_policy_provi
der.h" | 5 #include "components/content_settings/core/browser/content_settings_policy_provi
der.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting); | 116 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting); |
117 provider.ShutdownOnUIThread(); | 117 provider.ShutdownOnUIThread(); |
118 } | 118 } |
119 | 119 |
120 TEST_F(PolicyProviderTest, GettingManagedContentSettings) { | 120 TEST_F(PolicyProviderTest, GettingManagedContentSettings) { |
121 TestingProfile profile; | 121 TestingProfile profile; |
122 syncable_prefs::TestingPrefServiceSyncable* prefs = | 122 syncable_prefs::TestingPrefServiceSyncable* prefs = |
123 profile.GetTestingPrefService(); | 123 profile.GetTestingPrefService(); |
124 | 124 |
125 base::ListValue* value = new base::ListValue(); | 125 base::ListValue* value = new base::ListValue(); |
126 value->Append(new base::StringValue("[*.]google.com")); | 126 value->AppendString("[*.]google.com"); |
127 prefs->SetManagedPref(prefs::kManagedImagesBlockedForUrls, | 127 prefs->SetManagedPref(prefs::kManagedImagesBlockedForUrls, |
128 value); | 128 value); |
129 | 129 |
130 PolicyProvider provider(prefs); | 130 PolicyProvider provider(prefs); |
131 | 131 |
132 ContentSettingsPattern yt_url_pattern = | 132 ContentSettingsPattern yt_url_pattern = |
133 ContentSettingsPattern::FromString("www.youtube.com"); | 133 ContentSettingsPattern::FromString("www.youtube.com"); |
134 GURL youtube_url("http://www.youtube.com"); | 134 GURL youtube_url("http://www.youtube.com"); |
135 GURL google_url("http://mail.google.com"); | 135 GURL google_url("http://mail.google.com"); |
136 | 136 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 172 |
173 provider.ShutdownOnUIThread(); | 173 provider.ShutdownOnUIThread(); |
174 } | 174 } |
175 | 175 |
176 TEST_F(PolicyProviderTest, ResourceIdentifier) { | 176 TEST_F(PolicyProviderTest, ResourceIdentifier) { |
177 TestingProfile profile; | 177 TestingProfile profile; |
178 syncable_prefs::TestingPrefServiceSyncable* prefs = | 178 syncable_prefs::TestingPrefServiceSyncable* prefs = |
179 profile.GetTestingPrefService(); | 179 profile.GetTestingPrefService(); |
180 | 180 |
181 base::ListValue* value = new base::ListValue(); | 181 base::ListValue* value = new base::ListValue(); |
182 value->Append(new base::StringValue("[*.]google.com")); | 182 value->AppendString("[*.]google.com"); |
183 prefs->SetManagedPref(prefs::kManagedPluginsAllowedForUrls, | 183 prefs->SetManagedPref(prefs::kManagedPluginsAllowedForUrls, |
184 value); | 184 value); |
185 | 185 |
186 PolicyProvider provider(prefs); | 186 PolicyProvider provider(prefs); |
187 | 187 |
188 GURL youtube_url("http://www.youtube.com"); | 188 GURL youtube_url("http://www.youtube.com"); |
189 GURL google_url("http://mail.google.com"); | 189 GURL google_url("http://mail.google.com"); |
190 | 190 |
191 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 191 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
192 TestUtils::GetContentSetting(&provider, youtube_url, youtube_url, | 192 TestUtils::GetContentSetting(&provider, youtube_url, youtube_url, |
(...skipping 26 matching lines...) Expand all Loading... |
219 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue( | 219 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue( |
220 &provider, google_url, google_url, | 220 &provider, google_url, google_url, |
221 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, | 221 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
222 std::string(), false)); | 222 std::string(), false)); |
223 | 223 |
224 // Set the content settings pattern list for origins to auto select | 224 // Set the content settings pattern list for origins to auto select |
225 // certificates. | 225 // certificates. |
226 std::string pattern_str("\"pattern\":\"[*.]google.com\""); | 226 std::string pattern_str("\"pattern\":\"[*.]google.com\""); |
227 std::string filter_str("\"filter\":{\"ISSUER\":{\"CN\":\"issuer name\"}}"); | 227 std::string filter_str("\"filter\":{\"ISSUER\":{\"CN\":\"issuer name\"}}"); |
228 base::ListValue* value = new base::ListValue(); | 228 base::ListValue* value = new base::ListValue(); |
229 value->Append( | 229 value->AppendString("{" + pattern_str + "," + filter_str + "}"); |
230 new base::StringValue("{" + pattern_str + "," + filter_str + "}")); | |
231 prefs->SetManagedPref(prefs::kManagedAutoSelectCertificateForUrls, | 230 prefs->SetManagedPref(prefs::kManagedAutoSelectCertificateForUrls, |
232 value); | 231 value); |
233 GURL youtube_url("https://www.youtube.com"); | 232 GURL youtube_url("https://www.youtube.com"); |
234 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue( | 233 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue( |
235 &provider, youtube_url, youtube_url, | 234 &provider, youtube_url, youtube_url, |
236 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, | 235 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
237 std::string(), false)); | 236 std::string(), false)); |
238 std::unique_ptr<base::Value> cert_filter(TestUtils::GetContentSettingValue( | 237 std::unique_ptr<base::Value> cert_filter(TestUtils::GetContentSettingValue( |
239 &provider, google_url, google_url, | 238 &provider, google_url, google_url, |
240 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), false)); | 239 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), false)); |
241 | 240 |
242 ASSERT_EQ(base::Value::TYPE_DICTIONARY, cert_filter->GetType()); | 241 ASSERT_EQ(base::Value::TYPE_DICTIONARY, cert_filter->GetType()); |
243 base::DictionaryValue* dict_value = | 242 base::DictionaryValue* dict_value = |
244 static_cast<base::DictionaryValue*>(cert_filter.get()); | 243 static_cast<base::DictionaryValue*>(cert_filter.get()); |
245 std::string actual_common_name; | 244 std::string actual_common_name; |
246 ASSERT_TRUE(dict_value->GetString("ISSUER.CN", &actual_common_name)); | 245 ASSERT_TRUE(dict_value->GetString("ISSUER.CN", &actual_common_name)); |
247 EXPECT_EQ("issuer name", actual_common_name); | 246 EXPECT_EQ("issuer name", actual_common_name); |
248 provider.ShutdownOnUIThread(); | 247 provider.ShutdownOnUIThread(); |
249 } | 248 } |
250 | 249 |
251 } // namespace content_settings | 250 } // namespace content_settings |
OLD | NEW |