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

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

Issue 13145003: Rewrite std::string("") to std::string(), Linux edition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ugh Created 7 years, 8 months 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 | Annotate | Revision Log
OLDNEW
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 "chrome/browser/content_settings/content_settings_policy_provider.h" 5 #include "chrome/browser/content_settings/content_settings_policy_provider.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 value); 143 value);
144 144
145 PolicyProvider provider(prefs); 145 PolicyProvider provider(prefs);
146 146
147 ContentSettingsPattern yt_url_pattern = 147 ContentSettingsPattern yt_url_pattern =
148 ContentSettingsPattern::FromString("www.youtube.com"); 148 ContentSettingsPattern::FromString("www.youtube.com");
149 GURL youtube_url("http://www.youtube.com"); 149 GURL youtube_url("http://www.youtube.com");
150 GURL google_url("http://mail.google.com"); 150 GURL google_url("http://mail.google.com");
151 151
152 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 152 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
153 GetContentSetting( 153 GetContentSetting(&provider,
154 &provider, youtube_url, youtube_url, 154 youtube_url,
155 CONTENT_SETTINGS_TYPE_COOKIES, "", false)); 155 youtube_url,
156 CONTENT_SETTINGS_TYPE_COOKIES,
157 std::string(),
158 false));
156 EXPECT_EQ(NULL, 159 EXPECT_EQ(NULL,
157 GetContentSettingValue( 160 GetContentSettingValue(&provider,
158 &provider, youtube_url, youtube_url, 161 youtube_url,
159 CONTENT_SETTINGS_TYPE_COOKIES, "", false)); 162 youtube_url,
163 CONTENT_SETTINGS_TYPE_COOKIES,
164 std::string(),
165 false));
160 166
161 EXPECT_EQ(CONTENT_SETTING_BLOCK, 167 EXPECT_EQ(CONTENT_SETTING_BLOCK,
162 GetContentSetting( 168 GetContentSetting(&provider,
163 &provider, google_url, google_url, 169 google_url,
164 CONTENT_SETTINGS_TYPE_IMAGES, "", false)); 170 google_url,
171 CONTENT_SETTINGS_TYPE_IMAGES,
172 std::string(),
173 false));
165 scoped_ptr<Value> value_ptr( 174 scoped_ptr<Value> value_ptr(
166 GetContentSettingValue( 175 GetContentSettingValue(&provider,
167 &provider, google_url, google_url, 176 google_url,
168 CONTENT_SETTINGS_TYPE_IMAGES, "", false)); 177 google_url,
178 CONTENT_SETTINGS_TYPE_IMAGES,
179 std::string(),
180 false));
169 181
170 int int_value = -1; 182 int int_value = -1;
171 value_ptr->GetAsInteger(&int_value); 183 value_ptr->GetAsInteger(&int_value);
172 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); 184 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value));
173 185
174 // The PolicyProvider does not allow setting content settings as they are 186 // The PolicyProvider does not allow setting content settings as they are
175 // enforced via policies and not set by the user or extension. So a call to 187 // enforced via policies and not set by the user or extension. So a call to
176 // SetWebsiteSetting does nothing. 188 // SetWebsiteSetting does nothing.
177 scoped_ptr<base::Value> value_block( 189 scoped_ptr<base::Value> value_block(
178 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); 190 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
179 bool owned = provider.SetWebsiteSetting( 191 bool owned = provider.SetWebsiteSetting(yt_url_pattern,
180 yt_url_pattern, 192 yt_url_pattern,
181 yt_url_pattern, 193 CONTENT_SETTINGS_TYPE_COOKIES,
182 CONTENT_SETTINGS_TYPE_COOKIES, 194 std::string(),
183 "", 195 value_block.get());
184 value_block.get());
185 EXPECT_FALSE(owned); 196 EXPECT_FALSE(owned);
186 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 197 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
187 GetContentSetting( 198 GetContentSetting(&provider,
188 &provider, youtube_url, youtube_url, 199 youtube_url,
189 CONTENT_SETTINGS_TYPE_COOKIES, "", false)); 200 youtube_url,
201 CONTENT_SETTINGS_TYPE_COOKIES,
202 std::string(),
203 false));
190 204
191 provider.ShutdownOnUIThread(); 205 provider.ShutdownOnUIThread();
192 } 206 }
193 207
194 TEST_F(PolicyProviderTest, ResourceIdentifier) { 208 TEST_F(PolicyProviderTest, ResourceIdentifier) {
195 TestingProfile profile; 209 TestingProfile profile;
196 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 210 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
197 211
198 ListValue* value = new ListValue(); 212 ListValue* value = new ListValue();
199 value->Append(Value::CreateStringValue("[*.]google.com")); 213 value->Append(Value::CreateStringValue("[*.]google.com"));
200 prefs->SetManagedPref(prefs::kManagedPluginsAllowedForUrls, 214 prefs->SetManagedPref(prefs::kManagedPluginsAllowedForUrls,
201 value); 215 value);
202 216
203 PolicyProvider provider(prefs); 217 PolicyProvider provider(prefs);
204 218
205 GURL youtube_url("http://www.youtube.com"); 219 GURL youtube_url("http://www.youtube.com");
206 GURL google_url("http://mail.google.com"); 220 GURL google_url("http://mail.google.com");
207 221
208 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 222 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
209 GetContentSetting( 223 GetContentSetting(
210 &provider, youtube_url, youtube_url, 224 &provider, youtube_url, youtube_url,
211 CONTENT_SETTINGS_TYPE_PLUGINS, "someplugin", false)); 225 CONTENT_SETTINGS_TYPE_PLUGINS, "someplugin", false));
212 226
213 // There is currently no policy support for resource content settings. 227 // There is currently no policy support for resource content settings.
214 // Resource identifiers are simply ignored by the PolicyProvider. 228 // Resource identifiers are simply ignored by the PolicyProvider.
215 EXPECT_EQ(CONTENT_SETTING_ALLOW, 229 EXPECT_EQ(CONTENT_SETTING_ALLOW,
216 GetContentSetting( 230 GetContentSetting(&provider,
217 &provider, google_url, google_url, 231 google_url,
218 CONTENT_SETTINGS_TYPE_PLUGINS, "", false)); 232 google_url,
233 CONTENT_SETTINGS_TYPE_PLUGINS,
234 std::string(),
235 false));
219 236
220 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 237 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
221 GetContentSetting( 238 GetContentSetting(
222 &provider, google_url, google_url, 239 &provider, google_url, google_url,
223 CONTENT_SETTINGS_TYPE_PLUGINS, "someplugin", false)); 240 CONTENT_SETTINGS_TYPE_PLUGINS, "someplugin", false));
224 241
225 provider.ShutdownOnUIThread(); 242 provider.ShutdownOnUIThread();
226 } 243 }
227 244
228 TEST_F(PolicyProviderTest, AutoSelectCertificateList) { 245 TEST_F(PolicyProviderTest, AutoSelectCertificateList) {
229 TestingProfile profile; 246 TestingProfile profile;
230 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 247 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
231 248
232 PolicyProvider provider(prefs); 249 PolicyProvider provider(prefs);
233 GURL google_url("https://mail.google.com"); 250 GURL google_url("https://mail.google.com");
234 // Tests the default setting for auto selecting certificates 251 // Tests the default setting for auto selecting certificates
235 EXPECT_EQ(NULL, 252 EXPECT_EQ(
236 GetContentSettingValue( 253 NULL,
237 &provider, google_url, google_url, 254 GetContentSettingValue(&provider,
238 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "", false)); 255 google_url,
256 google_url,
257 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
258 std::string(),
259 false));
239 260
240 // Set the content settings pattern list for origins to auto select 261 // Set the content settings pattern list for origins to auto select
241 // certificates. 262 // certificates.
242 std::string pattern_str("\"pattern\":\"[*.]google.com\""); 263 std::string pattern_str("\"pattern\":\"[*.]google.com\"");
243 std::string filter_str("\"filter\":{\"ISSUER\":{\"CN\":\"issuer name\"}}"); 264 std::string filter_str("\"filter\":{\"ISSUER\":{\"CN\":\"issuer name\"}}");
244 ListValue* value = new ListValue(); 265 ListValue* value = new ListValue();
245 value->Append(Value::CreateStringValue( 266 value->Append(Value::CreateStringValue(
246 "{" + pattern_str + "," + filter_str + "}")); 267 "{" + pattern_str + "," + filter_str + "}"));
247 prefs->SetManagedPref(prefs::kManagedAutoSelectCertificateForUrls, 268 prefs->SetManagedPref(prefs::kManagedAutoSelectCertificateForUrls,
248 value); 269 value);
249 GURL youtube_url("https://www.youtube.com"); 270 GURL youtube_url("https://www.youtube.com");
250 EXPECT_EQ(NULL, 271 EXPECT_EQ(
251 GetContentSettingValue( 272 NULL,
252 &provider, youtube_url, youtube_url, 273 GetContentSettingValue(&provider,
253 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "", false)); 274 youtube_url,
254 scoped_ptr<Value> cert_filter(GetContentSettingValue( 275 youtube_url,
255 &provider, google_url, google_url, 276 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
256 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "", false)); 277 std::string(),
278 false));
279 scoped_ptr<Value> cert_filter(
280 GetContentSettingValue(&provider,
281 google_url,
282 google_url,
283 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
284 std::string(),
285 false));
257 286
258 ASSERT_EQ(Value::TYPE_DICTIONARY, cert_filter->GetType()); 287 ASSERT_EQ(Value::TYPE_DICTIONARY, cert_filter->GetType());
259 DictionaryValue* dict_value = 288 DictionaryValue* dict_value =
260 static_cast<DictionaryValue*>(cert_filter.get()); 289 static_cast<DictionaryValue*>(cert_filter.get());
261 std::string actual_common_name; 290 std::string actual_common_name;
262 ASSERT_TRUE(dict_value->GetString("ISSUER.CN", &actual_common_name)); 291 ASSERT_TRUE(dict_value->GetString("ISSUER.CN", &actual_common_name));
263 EXPECT_EQ("issuer name", actual_common_name); 292 EXPECT_EQ("issuer name", actual_common_name);
264 provider.ShutdownOnUIThread(); 293 provider.ShutdownOnUIThread();
265 } 294 }
266 295
267 } // namespace content_settings 296 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698