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

Side by Side Diff: chrome/browser/content_settings/host_content_settings_map_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) 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 "base/auto_reset.h" 5 #include "base/auto_reset.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 TestingProfile profile; 74 TestingProfile profile;
75 HostContentSettingsMap* host_content_settings_map = 75 HostContentSettingsMap* host_content_settings_map =
76 profile.GetHostContentSettingsMap(); 76 profile.GetHostContentSettingsMap();
77 77
78 // Check returning individual settings. 78 // Check returning individual settings.
79 GURL host("http://example.com/"); 79 GURL host("http://example.com/");
80 ContentSettingsPattern pattern = 80 ContentSettingsPattern pattern =
81 ContentSettingsPattern::FromString("[*.]example.com"); 81 ContentSettingsPattern::FromString("[*.]example.com");
82 EXPECT_EQ(CONTENT_SETTING_ALLOW, 82 EXPECT_EQ(CONTENT_SETTING_ALLOW,
83 host_content_settings_map->GetContentSetting( 83 host_content_settings_map->GetContentSetting(
84 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 84 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
85 host_content_settings_map->SetContentSetting( 85 host_content_settings_map->SetContentSetting(
86 pattern, 86 pattern,
87 ContentSettingsPattern::Wildcard(), 87 ContentSettingsPattern::Wildcard(),
88 CONTENT_SETTINGS_TYPE_IMAGES, 88 CONTENT_SETTINGS_TYPE_IMAGES,
89 "", 89 std::string(),
90 CONTENT_SETTING_DEFAULT); 90 CONTENT_SETTING_DEFAULT);
91 EXPECT_EQ(CONTENT_SETTING_ALLOW, 91 EXPECT_EQ(CONTENT_SETTING_ALLOW,
92 host_content_settings_map->GetContentSetting( 92 host_content_settings_map->GetContentSetting(
93 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 93 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
94 host_content_settings_map->SetContentSetting( 94 host_content_settings_map->SetContentSetting(
95 pattern, 95 pattern,
96 ContentSettingsPattern::Wildcard(), 96 ContentSettingsPattern::Wildcard(),
97 CONTENT_SETTINGS_TYPE_IMAGES, 97 CONTENT_SETTINGS_TYPE_IMAGES,
98 std::string(), 98 std::string(),
99 CONTENT_SETTING_BLOCK); 99 CONTENT_SETTING_BLOCK);
100 EXPECT_EQ(CONTENT_SETTING_BLOCK, 100 EXPECT_EQ(CONTENT_SETTING_BLOCK,
101 host_content_settings_map->GetContentSetting( 101 host_content_settings_map->GetContentSetting(
102 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 102 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
103 EXPECT_EQ(CONTENT_SETTING_ALLOW, 103 EXPECT_EQ(CONTENT_SETTING_ALLOW,
104 host_content_settings_map->GetContentSetting( 104 host_content_settings_map->GetContentSetting(
105 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, "")); 105 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
106 106
107 // Check returning all settings for a host. 107 // Check returning all settings for a host.
108 host_content_settings_map->SetContentSetting( 108 host_content_settings_map->SetContentSetting(
109 pattern, 109 pattern,
110 ContentSettingsPattern::Wildcard(), 110 ContentSettingsPattern::Wildcard(),
111 CONTENT_SETTINGS_TYPE_IMAGES, 111 CONTENT_SETTINGS_TYPE_IMAGES,
112 std::string(), 112 std::string(),
113 CONTENT_SETTING_DEFAULT); 113 CONTENT_SETTING_DEFAULT);
114 EXPECT_EQ(CONTENT_SETTING_ALLOW, 114 EXPECT_EQ(CONTENT_SETTING_ALLOW,
115 host_content_settings_map->GetContentSetting( 115 host_content_settings_map->GetContentSetting(
116 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 116 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
117 host_content_settings_map->SetContentSetting( 117 host_content_settings_map->SetContentSetting(
118 pattern, 118 pattern,
119 ContentSettingsPattern::Wildcard(), 119 ContentSettingsPattern::Wildcard(),
120 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 120 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
121 std::string(), 121 std::string(),
122 CONTENT_SETTING_BLOCK); 122 CONTENT_SETTING_BLOCK);
123 EXPECT_EQ(CONTENT_SETTING_BLOCK, 123 EXPECT_EQ(CONTENT_SETTING_BLOCK,
124 host_content_settings_map->GetContentSetting( 124 host_content_settings_map->GetContentSetting(
125 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, "")); 125 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
126 host_content_settings_map->SetContentSetting( 126 host_content_settings_map->SetContentSetting(
127 pattern, 127 pattern,
128 ContentSettingsPattern::Wildcard(), 128 ContentSettingsPattern::Wildcard(),
129 CONTENT_SETTINGS_TYPE_PLUGINS, 129 CONTENT_SETTINGS_TYPE_PLUGINS,
130 std::string(), 130 std::string(),
131 CONTENT_SETTING_ALLOW); 131 CONTENT_SETTING_ALLOW);
132 EXPECT_EQ(CONTENT_SETTING_ALLOW, 132 EXPECT_EQ(CONTENT_SETTING_ALLOW,
133 host_content_settings_map->GetContentSetting( 133 host_content_settings_map->GetContentSetting(
134 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, "")); 134 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
135 EXPECT_EQ(CONTENT_SETTING_BLOCK, 135 EXPECT_EQ(CONTENT_SETTING_BLOCK,
136 host_content_settings_map->GetContentSetting( 136 host_content_settings_map->GetContentSetting(
137 host, host, CONTENT_SETTINGS_TYPE_POPUPS, "")); 137 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
138 EXPECT_EQ(CONTENT_SETTING_ASK, 138 EXPECT_EQ(CONTENT_SETTING_ASK,
139 host_content_settings_map->GetContentSetting( 139 host_content_settings_map->GetContentSetting(
140 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, "")); 140 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
141 EXPECT_EQ(
142 CONTENT_SETTING_ASK,
143 host_content_settings_map->GetContentSetting(
144 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
141 EXPECT_EQ(CONTENT_SETTING_ASK, 145 EXPECT_EQ(CONTENT_SETTING_ASK,
142 host_content_settings_map->GetContentSetting( 146 host_content_settings_map->GetContentSetting(
143 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "")); 147 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()));
144 EXPECT_EQ(CONTENT_SETTING_ASK, 148 EXPECT_EQ(CONTENT_SETTING_ASK,
145 host_content_settings_map->GetContentSetting( 149 host_content_settings_map->GetContentSetting(
146 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, "")); 150 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()));
147 EXPECT_EQ(CONTENT_SETTING_ASK,
148 host_content_settings_map->GetContentSetting(
149 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, ""));
150 151
151 // Check returning all hosts for a setting. 152 // Check returning all hosts for a setting.
152 ContentSettingsPattern pattern2 = 153 ContentSettingsPattern pattern2 =
153 ContentSettingsPattern::FromString("[*.]example.org"); 154 ContentSettingsPattern::FromString("[*.]example.org");
154 host_content_settings_map->SetContentSetting( 155 host_content_settings_map->SetContentSetting(
155 pattern2, 156 pattern2,
156 ContentSettingsPattern::Wildcard(), 157 ContentSettingsPattern::Wildcard(),
157 CONTENT_SETTINGS_TYPE_IMAGES, 158 CONTENT_SETTINGS_TYPE_IMAGES,
158 std::string(), 159 std::string(),
159 CONTENT_SETTING_BLOCK); 160 CONTENT_SETTING_BLOCK);
160 host_content_settings_map->SetContentSetting( 161 host_content_settings_map->SetContentSetting(
161 pattern2, 162 pattern2,
162 ContentSettingsPattern::Wildcard(), 163 ContentSettingsPattern::Wildcard(),
163 CONTENT_SETTINGS_TYPE_PLUGINS, 164 CONTENT_SETTINGS_TYPE_PLUGINS,
164 std::string(), 165 std::string(),
165 CONTENT_SETTING_BLOCK); 166 CONTENT_SETTING_BLOCK);
166 ContentSettingsForOneType host_settings; 167 ContentSettingsForOneType host_settings;
167 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, 168 host_content_settings_map->GetSettingsForOneType(
168 "", 169 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings);
169 &host_settings);
170 // |host_settings| contains the default setting and an exception. 170 // |host_settings| contains the default setting and an exception.
171 EXPECT_EQ(2U, host_settings.size()); 171 EXPECT_EQ(2U, host_settings.size());
172 host_content_settings_map->GetSettingsForOneType( 172 host_content_settings_map->GetSettingsForOneType(
173 CONTENT_SETTINGS_TYPE_PLUGINS, "", &host_settings); 173 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings);
174 // |host_settings| contains the default setting and 2 exceptions. 174 // |host_settings| contains the default setting and 2 exceptions.
175 EXPECT_EQ(3U, host_settings.size()); 175 EXPECT_EQ(3U, host_settings.size());
176 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, 176 host_content_settings_map->GetSettingsForOneType(
177 "", 177 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings);
178 &host_settings);
179 // |host_settings| contains only the default setting. 178 // |host_settings| contains only the default setting.
180 EXPECT_EQ(1U, host_settings.size()); 179 EXPECT_EQ(1U, host_settings.size());
181 } 180 }
182 181
183 TEST_F(HostContentSettingsMapTest, Clear) { 182 TEST_F(HostContentSettingsMapTest, Clear) {
184 TestingProfile profile; 183 TestingProfile profile;
185 HostContentSettingsMap* host_content_settings_map = 184 HostContentSettingsMap* host_content_settings_map =
186 profile.GetHostContentSettingsMap(); 185 profile.GetHostContentSettingsMap();
187 186
188 // Check clearing one type. 187 // Check clearing one type.
(...skipping 21 matching lines...) Expand all
210 CONTENT_SETTING_BLOCK); 209 CONTENT_SETTING_BLOCK);
211 host_content_settings_map->SetContentSetting( 210 host_content_settings_map->SetContentSetting(
212 pattern2, 211 pattern2,
213 ContentSettingsPattern::Wildcard(), 212 ContentSettingsPattern::Wildcard(),
214 CONTENT_SETTINGS_TYPE_IMAGES, 213 CONTENT_SETTINGS_TYPE_IMAGES,
215 std::string(), 214 std::string(),
216 CONTENT_SETTING_BLOCK); 215 CONTENT_SETTING_BLOCK);
217 host_content_settings_map->ClearSettingsForOneType( 216 host_content_settings_map->ClearSettingsForOneType(
218 CONTENT_SETTINGS_TYPE_IMAGES); 217 CONTENT_SETTINGS_TYPE_IMAGES);
219 ContentSettingsForOneType host_settings; 218 ContentSettingsForOneType host_settings;
220 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, 219 host_content_settings_map->GetSettingsForOneType(
221 "", 220 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings);
222 &host_settings);
223 // |host_settings| contains only the default setting. 221 // |host_settings| contains only the default setting.
224 EXPECT_EQ(1U, host_settings.size()); 222 EXPECT_EQ(1U, host_settings.size());
225 host_content_settings_map->GetSettingsForOneType( 223 host_content_settings_map->GetSettingsForOneType(
226 CONTENT_SETTINGS_TYPE_PLUGINS, "", &host_settings); 224 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings);
227 // |host_settings| contains the default setting and an exception. 225 // |host_settings| contains the default setting and an exception.
228 EXPECT_EQ(2U, host_settings.size()); 226 EXPECT_EQ(2U, host_settings.size());
229 } 227 }
230 228
231 TEST_F(HostContentSettingsMapTest, Patterns) { 229 TEST_F(HostContentSettingsMapTest, Patterns) {
232 TestingProfile profile; 230 TestingProfile profile;
233 HostContentSettingsMap* host_content_settings_map = 231 HostContentSettingsMap* host_content_settings_map =
234 profile.GetHostContentSettingsMap(); 232 profile.GetHostContentSettingsMap();
235 233
236 GURL host1("http://example.com/"); 234 GURL host1("http://example.com/");
237 GURL host2("http://www.example.com/"); 235 GURL host2("http://www.example.com/");
238 GURL host3("http://example.org/"); 236 GURL host3("http://example.org/");
239 ContentSettingsPattern pattern1 = 237 ContentSettingsPattern pattern1 =
240 ContentSettingsPattern::FromString("[*.]example.com"); 238 ContentSettingsPattern::FromString("[*.]example.com");
241 ContentSettingsPattern pattern2 = 239 ContentSettingsPattern pattern2 =
242 ContentSettingsPattern::FromString("example.org"); 240 ContentSettingsPattern::FromString("example.org");
243 EXPECT_EQ(CONTENT_SETTING_ALLOW, 241 EXPECT_EQ(CONTENT_SETTING_ALLOW,
244 host_content_settings_map->GetContentSetting( 242 host_content_settings_map->GetContentSetting(
245 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, "")); 243 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
246 host_content_settings_map->SetContentSetting( 244 host_content_settings_map->SetContentSetting(
247 pattern1, 245 pattern1,
248 ContentSettingsPattern::Wildcard(), 246 ContentSettingsPattern::Wildcard(),
249 CONTENT_SETTINGS_TYPE_IMAGES, 247 CONTENT_SETTINGS_TYPE_IMAGES,
250 std::string(), 248 std::string(),
251 CONTENT_SETTING_BLOCK); 249 CONTENT_SETTING_BLOCK);
252 EXPECT_EQ(CONTENT_SETTING_BLOCK, 250 EXPECT_EQ(CONTENT_SETTING_BLOCK,
253 host_content_settings_map->GetContentSetting( 251 host_content_settings_map->GetContentSetting(
254 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, "")); 252 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
255 EXPECT_EQ(CONTENT_SETTING_BLOCK, 253 EXPECT_EQ(CONTENT_SETTING_BLOCK,
256 host_content_settings_map->GetContentSetting( 254 host_content_settings_map->GetContentSetting(
257 host2, host2, CONTENT_SETTINGS_TYPE_IMAGES, "")); 255 host2, host2, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
258 EXPECT_EQ(CONTENT_SETTING_ALLOW, 256 EXPECT_EQ(CONTENT_SETTING_ALLOW,
259 host_content_settings_map->GetContentSetting( 257 host_content_settings_map->GetContentSetting(
260 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, "")); 258 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
261 host_content_settings_map->SetContentSetting( 259 host_content_settings_map->SetContentSetting(
262 pattern2, 260 pattern2,
263 ContentSettingsPattern::Wildcard(), 261 ContentSettingsPattern::Wildcard(),
264 CONTENT_SETTINGS_TYPE_IMAGES, 262 CONTENT_SETTINGS_TYPE_IMAGES,
265 std::string(), 263 std::string(),
266 CONTENT_SETTING_BLOCK); 264 CONTENT_SETTING_BLOCK);
267 EXPECT_EQ(CONTENT_SETTING_BLOCK, 265 EXPECT_EQ(CONTENT_SETTING_BLOCK,
268 host_content_settings_map->GetContentSetting( 266 host_content_settings_map->GetContentSetting(
269 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, "")); 267 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
270 } 268 }
271 269
272 TEST_F(HostContentSettingsMapTest, Observer) { 270 TEST_F(HostContentSettingsMapTest, Observer) {
273 TestingProfile profile; 271 TestingProfile profile;
274 HostContentSettingsMap* host_content_settings_map = 272 HostContentSettingsMap* host_content_settings_map =
275 profile.GetHostContentSettingsMap(); 273 profile.GetHostContentSettingsMap();
276 MockSettingsObserver observer; 274 MockSettingsObserver observer;
277 275
278 ContentSettingsPattern primary_pattern = 276 ContentSettingsPattern primary_pattern =
279 ContentSettingsPattern::FromString("[*.]example.com"); 277 ContentSettingsPattern::FromString("[*.]example.com");
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 // Make a copy of the default pref value so we can reset it later. 318 // Make a copy of the default pref value so we can reset it later.
321 scoped_ptr<Value> default_value(prefs->FindPreference( 319 scoped_ptr<Value> default_value(prefs->FindPreference(
322 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); 320 prefs::kDefaultContentSettings)->GetValue()->DeepCopy());
323 321
324 GURL host("http://example.com"); 322 GURL host("http://example.com");
325 323
326 host_content_settings_map->SetDefaultContentSetting( 324 host_content_settings_map->SetDefaultContentSetting(
327 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); 325 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
328 EXPECT_EQ(CONTENT_SETTING_BLOCK, 326 EXPECT_EQ(CONTENT_SETTING_BLOCK,
329 host_content_settings_map->GetContentSetting( 327 host_content_settings_map->GetContentSetting(
330 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 328 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
331 329
332 // Make a copy of the pref's new value so we can reset it later. 330 // Make a copy of the pref's new value so we can reset it later.
333 scoped_ptr<Value> new_value(prefs->FindPreference( 331 scoped_ptr<Value> new_value(prefs->FindPreference(
334 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); 332 prefs::kDefaultContentSettings)->GetValue()->DeepCopy());
335 333
336 // Clearing the backing pref should also clear the internal cache. 334 // Clearing the backing pref should also clear the internal cache.
337 prefs->Set(prefs::kDefaultContentSettings, *default_value); 335 prefs->Set(prefs::kDefaultContentSettings, *default_value);
338 EXPECT_EQ(CONTENT_SETTING_ALLOW, 336 EXPECT_EQ(CONTENT_SETTING_ALLOW,
339 host_content_settings_map->GetContentSetting( 337 host_content_settings_map->GetContentSetting(
340 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 338 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
341 339
342 // Reseting the pref to its previous value should update the cache. 340 // Reseting the pref to its previous value should update the cache.
343 prefs->Set(prefs::kDefaultContentSettings, *new_value); 341 prefs->Set(prefs::kDefaultContentSettings, *new_value);
344 EXPECT_EQ(CONTENT_SETTING_BLOCK, 342 EXPECT_EQ(CONTENT_SETTING_BLOCK,
345 host_content_settings_map->GetContentSetting( 343 host_content_settings_map->GetContentSetting(
346 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 344 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
347 } 345 }
348 346
349 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { 347 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) {
350 TestingProfile profile; 348 TestingProfile profile;
351 HostContentSettingsMap* host_content_settings_map = 349 HostContentSettingsMap* host_content_settings_map =
352 profile.GetHostContentSettingsMap(); 350 profile.GetHostContentSettingsMap();
353 351
354 PrefService* prefs = profile.GetPrefs(); 352 PrefService* prefs = profile.GetPrefs();
355 353
356 // Make a copy of the default pref value so we can reset it later. 354 // Make a copy of the default pref value so we can reset it later.
357 scoped_ptr<Value> default_value(prefs->FindPreference( 355 scoped_ptr<Value> default_value(prefs->FindPreference(
358 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); 356 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy());
359 357
360 ContentSettingsPattern pattern = 358 ContentSettingsPattern pattern =
361 ContentSettingsPattern::FromString("[*.]example.com"); 359 ContentSettingsPattern::FromString("[*.]example.com");
362 GURL host("http://example.com"); 360 GURL host("http://example.com");
363 361
364 EXPECT_EQ(CONTENT_SETTING_ALLOW, 362 EXPECT_EQ(CONTENT_SETTING_ALLOW,
365 host_content_settings_map->GetContentSetting( 363 host_content_settings_map->GetContentSetting(
366 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 364 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
367 365
368 host_content_settings_map->SetContentSetting( 366 host_content_settings_map->SetContentSetting(
369 pattern, 367 pattern,
370 ContentSettingsPattern::Wildcard(), 368 ContentSettingsPattern::Wildcard(),
371 CONTENT_SETTINGS_TYPE_IMAGES, 369 CONTENT_SETTINGS_TYPE_IMAGES,
372 std::string(), 370 std::string(),
373 CONTENT_SETTING_BLOCK); 371 CONTENT_SETTING_BLOCK);
374 EXPECT_EQ(CONTENT_SETTING_BLOCK, 372 EXPECT_EQ(CONTENT_SETTING_BLOCK,
375 host_content_settings_map->GetContentSetting( 373 host_content_settings_map->GetContentSetting(
376 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 374 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
377 375
378 // Make a copy of the pref's new value so we can reset it later. 376 // Make a copy of the pref's new value so we can reset it later.
379 scoped_ptr<Value> new_value(prefs->FindPreference( 377 scoped_ptr<Value> new_value(prefs->FindPreference(
380 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); 378 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy());
381 379
382 // Clearing the backing pref should also clear the internal cache. 380 // Clearing the backing pref should also clear the internal cache.
383 prefs->Set(prefs::kContentSettingsPatternPairs, *default_value); 381 prefs->Set(prefs::kContentSettingsPatternPairs, *default_value);
384 EXPECT_EQ(CONTENT_SETTING_ALLOW, 382 EXPECT_EQ(CONTENT_SETTING_ALLOW,
385 host_content_settings_map->GetContentSetting( 383 host_content_settings_map->GetContentSetting(
386 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 384 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
387 385
388 // Reseting the pref to its previous value should update the cache. 386 // Reseting the pref to its previous value should update the cache.
389 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value); 387 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value);
390 EXPECT_EQ(CONTENT_SETTING_BLOCK, 388 EXPECT_EQ(CONTENT_SETTING_BLOCK,
391 host_content_settings_map->GetContentSetting( 389 host_content_settings_map->GetContentSetting(
392 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 390 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
393 } 391 }
394 392
395 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { 393 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) {
396 TestingProfile profile; 394 TestingProfile profile;
397 HostContentSettingsMap* host_content_settings_map = 395 HostContentSettingsMap* host_content_settings_map =
398 profile.GetHostContentSettingsMap(); 396 profile.GetHostContentSettingsMap();
399 CookieSettings* cookie_settings = 397 CookieSettings* cookie_settings =
400 CookieSettings::Factory::GetForProfile(&profile); 398 CookieSettings::Factory::GetForProfile(&profile);
401 399
402 ContentSettingsPattern pattern = 400 ContentSettingsPattern pattern =
403 ContentSettingsPattern::FromString("[*.]example.com"); 401 ContentSettingsPattern::FromString("[*.]example.com");
404 GURL host_ending_with_dot("http://example.com./"); 402 GURL host_ending_with_dot("http://example.com./");
405 403
406 EXPECT_EQ(CONTENT_SETTING_ALLOW, 404 EXPECT_EQ(CONTENT_SETTING_ALLOW,
407 host_content_settings_map->GetContentSetting( 405 host_content_settings_map->GetContentSetting(
408 host_ending_with_dot, 406 host_ending_with_dot,
409 host_ending_with_dot, 407 host_ending_with_dot,
410 CONTENT_SETTINGS_TYPE_IMAGES, 408 CONTENT_SETTINGS_TYPE_IMAGES,
411 std::string())); 409 std::string()));
412 host_content_settings_map->SetContentSetting( 410 host_content_settings_map->SetContentSetting(
413 pattern, 411 pattern,
414 ContentSettingsPattern::Wildcard(), 412 ContentSettingsPattern::Wildcard(),
415 CONTENT_SETTINGS_TYPE_IMAGES, 413 CONTENT_SETTINGS_TYPE_IMAGES,
416 "", 414 std::string(),
417 CONTENT_SETTING_DEFAULT); 415 CONTENT_SETTING_DEFAULT);
418 EXPECT_EQ(CONTENT_SETTING_ALLOW, 416 EXPECT_EQ(
419 host_content_settings_map->GetContentSetting( 417 CONTENT_SETTING_ALLOW,
420 host_ending_with_dot, 418 host_content_settings_map->GetContentSetting(host_ending_with_dot,
421 host_ending_with_dot, 419 host_ending_with_dot,
422 CONTENT_SETTINGS_TYPE_IMAGES, 420 CONTENT_SETTINGS_TYPE_IMAGES,
423 "")); 421 std::string()));
424 host_content_settings_map->SetContentSetting( 422 host_content_settings_map->SetContentSetting(
425 pattern, 423 pattern,
426 ContentSettingsPattern::Wildcard(), 424 ContentSettingsPattern::Wildcard(),
427 CONTENT_SETTINGS_TYPE_IMAGES, 425 CONTENT_SETTINGS_TYPE_IMAGES,
428 "", 426 std::string(),
429 CONTENT_SETTING_BLOCK); 427 CONTENT_SETTING_BLOCK);
430 EXPECT_EQ(CONTENT_SETTING_BLOCK, 428 EXPECT_EQ(
431 host_content_settings_map->GetContentSetting( 429 CONTENT_SETTING_BLOCK,
432 host_ending_with_dot, 430 host_content_settings_map->GetContentSetting(host_ending_with_dot,
433 host_ending_with_dot, 431 host_ending_with_dot,
434 CONTENT_SETTINGS_TYPE_IMAGES, 432 CONTENT_SETTINGS_TYPE_IMAGES,
435 "")); 433 std::string()));
436 434
437 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( 435 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
438 host_ending_with_dot, host_ending_with_dot)); 436 host_ending_with_dot, host_ending_with_dot));
439 host_content_settings_map->SetContentSetting( 437 host_content_settings_map->SetContentSetting(
440 pattern, 438 pattern,
441 ContentSettingsPattern::Wildcard(), 439 ContentSettingsPattern::Wildcard(),
442 CONTENT_SETTINGS_TYPE_COOKIES, 440 CONTENT_SETTINGS_TYPE_COOKIES,
443 "", 441 std::string(),
444 CONTENT_SETTING_DEFAULT); 442 CONTENT_SETTING_DEFAULT);
445 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( 443 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
446 host_ending_with_dot, host_ending_with_dot)); 444 host_ending_with_dot, host_ending_with_dot));
447 host_content_settings_map->SetContentSetting( 445 host_content_settings_map->SetContentSetting(
448 pattern, 446 pattern,
449 ContentSettingsPattern::Wildcard(), 447 ContentSettingsPattern::Wildcard(),
450 CONTENT_SETTINGS_TYPE_COOKIES, 448 CONTENT_SETTINGS_TYPE_COOKIES,
451 "", 449 std::string(),
452 CONTENT_SETTING_BLOCK); 450 CONTENT_SETTING_BLOCK);
453 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( 451 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed(
454 host_ending_with_dot, host_ending_with_dot)); 452 host_ending_with_dot, host_ending_with_dot));
455 453
456 EXPECT_EQ(CONTENT_SETTING_ALLOW, 454 EXPECT_EQ(CONTENT_SETTING_ALLOW,
457 host_content_settings_map->GetContentSetting( 455 host_content_settings_map->GetContentSetting(
458 host_ending_with_dot, 456 host_ending_with_dot,
459 host_ending_with_dot, 457 host_ending_with_dot,
460 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 458 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
461 "")); 459 std::string()));
462 host_content_settings_map->SetContentSetting( 460 host_content_settings_map->SetContentSetting(
463 pattern, 461 pattern,
464 ContentSettingsPattern::Wildcard(), 462 ContentSettingsPattern::Wildcard(),
465 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 463 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
466 "", 464 std::string(),
467 CONTENT_SETTING_DEFAULT); 465 CONTENT_SETTING_DEFAULT);
468 EXPECT_EQ(CONTENT_SETTING_ALLOW, 466 EXPECT_EQ(CONTENT_SETTING_ALLOW,
469 host_content_settings_map->GetContentSetting( 467 host_content_settings_map->GetContentSetting(
470 host_ending_with_dot, 468 host_ending_with_dot,
471 host_ending_with_dot, 469 host_ending_with_dot,
472 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 470 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
473 "")); 471 std::string()));
474 host_content_settings_map->SetContentSetting( 472 host_content_settings_map->SetContentSetting(
475 pattern, 473 pattern,
476 ContentSettingsPattern::Wildcard(), 474 ContentSettingsPattern::Wildcard(),
477 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 475 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
478 "", 476 std::string(),
479 CONTENT_SETTING_BLOCK); 477 CONTENT_SETTING_BLOCK);
480 EXPECT_EQ(CONTENT_SETTING_BLOCK, 478 EXPECT_EQ(CONTENT_SETTING_BLOCK,
481 host_content_settings_map->GetContentSetting( 479 host_content_settings_map->GetContentSetting(
482 host_ending_with_dot, 480 host_ending_with_dot,
483 host_ending_with_dot, 481 host_ending_with_dot,
484 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 482 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
485 "")); 483 std::string()));
486 484
487 EXPECT_EQ(CONTENT_SETTING_ALLOW, 485 EXPECT_EQ(CONTENT_SETTING_ALLOW,
488 host_content_settings_map->GetContentSetting( 486 host_content_settings_map->GetContentSetting(
489 host_ending_with_dot, 487 host_ending_with_dot,
490 host_ending_with_dot, 488 host_ending_with_dot,
491 CONTENT_SETTINGS_TYPE_PLUGINS, 489 CONTENT_SETTINGS_TYPE_PLUGINS,
492 "")); 490 std::string()));
493 host_content_settings_map->SetContentSetting( 491 host_content_settings_map->SetContentSetting(
494 pattern, 492 pattern,
495 ContentSettingsPattern::Wildcard(), 493 ContentSettingsPattern::Wildcard(),
496 CONTENT_SETTINGS_TYPE_PLUGINS, 494 CONTENT_SETTINGS_TYPE_PLUGINS,
497 "", 495 std::string(),
498 CONTENT_SETTING_DEFAULT); 496 CONTENT_SETTING_DEFAULT);
499 EXPECT_EQ(CONTENT_SETTING_ALLOW, 497 EXPECT_EQ(CONTENT_SETTING_ALLOW,
500 host_content_settings_map->GetContentSetting( 498 host_content_settings_map->GetContentSetting(
501 host_ending_with_dot, 499 host_ending_with_dot,
502 host_ending_with_dot, 500 host_ending_with_dot,
503 CONTENT_SETTINGS_TYPE_PLUGINS, 501 CONTENT_SETTINGS_TYPE_PLUGINS,
504 "")); 502 std::string()));
505 host_content_settings_map->SetContentSetting( 503 host_content_settings_map->SetContentSetting(
506 pattern, 504 pattern,
507 ContentSettingsPattern::Wildcard(), 505 ContentSettingsPattern::Wildcard(),
508 CONTENT_SETTINGS_TYPE_PLUGINS, 506 CONTENT_SETTINGS_TYPE_PLUGINS,
509 "", 507 std::string(),
510 CONTENT_SETTING_BLOCK); 508 CONTENT_SETTING_BLOCK);
511 EXPECT_EQ(CONTENT_SETTING_BLOCK, 509 EXPECT_EQ(CONTENT_SETTING_BLOCK,
512 host_content_settings_map->GetContentSetting( 510 host_content_settings_map->GetContentSetting(
513 host_ending_with_dot, 511 host_ending_with_dot,
514 host_ending_with_dot, 512 host_ending_with_dot,
515 CONTENT_SETTINGS_TYPE_PLUGINS, 513 CONTENT_SETTINGS_TYPE_PLUGINS,
516 "")); 514 std::string()));
517 515
518 EXPECT_EQ(CONTENT_SETTING_BLOCK, 516 EXPECT_EQ(
519 host_content_settings_map->GetContentSetting( 517 CONTENT_SETTING_BLOCK,
520 host_ending_with_dot, 518 host_content_settings_map->GetContentSetting(host_ending_with_dot,
521 host_ending_with_dot, 519 host_ending_with_dot,
522 CONTENT_SETTINGS_TYPE_POPUPS, 520 CONTENT_SETTINGS_TYPE_POPUPS,
523 "")); 521 std::string()));
524 host_content_settings_map->SetContentSetting( 522 host_content_settings_map->SetContentSetting(
525 pattern, 523 pattern,
526 ContentSettingsPattern::Wildcard(), 524 ContentSettingsPattern::Wildcard(),
527 CONTENT_SETTINGS_TYPE_POPUPS, 525 CONTENT_SETTINGS_TYPE_POPUPS,
528 "", 526 std::string(),
529 CONTENT_SETTING_DEFAULT); 527 CONTENT_SETTING_DEFAULT);
530 EXPECT_EQ(CONTENT_SETTING_BLOCK, 528 EXPECT_EQ(
531 host_content_settings_map->GetContentSetting( 529 CONTENT_SETTING_BLOCK,
532 host_ending_with_dot, 530 host_content_settings_map->GetContentSetting(host_ending_with_dot,
533 host_ending_with_dot, 531 host_ending_with_dot,
534 CONTENT_SETTINGS_TYPE_POPUPS, 532 CONTENT_SETTINGS_TYPE_POPUPS,
535 "")); 533 std::string()));
536 host_content_settings_map->SetContentSetting( 534 host_content_settings_map->SetContentSetting(
537 pattern, 535 pattern,
538 ContentSettingsPattern::Wildcard(), 536 ContentSettingsPattern::Wildcard(),
539 CONTENT_SETTINGS_TYPE_POPUPS, 537 CONTENT_SETTINGS_TYPE_POPUPS,
540 "", 538 std::string(),
541 CONTENT_SETTING_ALLOW); 539 CONTENT_SETTING_ALLOW);
542 EXPECT_EQ(CONTENT_SETTING_ALLOW, 540 EXPECT_EQ(
543 host_content_settings_map->GetContentSetting( 541 CONTENT_SETTING_ALLOW,
544 host_ending_with_dot, 542 host_content_settings_map->GetContentSetting(host_ending_with_dot,
545 host_ending_with_dot, 543 host_ending_with_dot,
546 CONTENT_SETTINGS_TYPE_POPUPS, 544 CONTENT_SETTINGS_TYPE_POPUPS,
547 "")); 545 std::string()));
548 } 546 }
549 547
550 TEST_F(HostContentSettingsMapTest, NestedSettings) { 548 TEST_F(HostContentSettingsMapTest, NestedSettings) {
551 TestingProfile profile; 549 TestingProfile profile;
552 HostContentSettingsMap* host_content_settings_map = 550 HostContentSettingsMap* host_content_settings_map =
553 profile.GetHostContentSettingsMap(); 551 profile.GetHostContentSettingsMap();
554 552
555 GURL host("http://a.b.example.com/"); 553 GURL host("http://a.b.example.com/");
556 ContentSettingsPattern pattern1 = 554 ContentSettingsPattern pattern1 =
557 ContentSettingsPattern::FromString("[*.]example.com"); 555 ContentSettingsPattern::FromString("[*.]example.com");
558 ContentSettingsPattern pattern2 = 556 ContentSettingsPattern pattern2 =
559 ContentSettingsPattern::FromString("[*.]b.example.com"); 557 ContentSettingsPattern::FromString("[*.]b.example.com");
560 ContentSettingsPattern pattern3 = 558 ContentSettingsPattern pattern3 =
561 ContentSettingsPattern::FromString("a.b.example.com"); 559 ContentSettingsPattern::FromString("a.b.example.com");
562 560
563 host_content_settings_map->SetContentSetting( 561 host_content_settings_map->SetContentSetting(
564 pattern1, 562 pattern1,
565 ContentSettingsPattern::Wildcard(), 563 ContentSettingsPattern::Wildcard(),
566 CONTENT_SETTINGS_TYPE_IMAGES, 564 CONTENT_SETTINGS_TYPE_IMAGES,
567 "", 565 std::string(),
568 CONTENT_SETTING_BLOCK); 566 CONTENT_SETTING_BLOCK);
569 567
570 host_content_settings_map->SetContentSetting( 568 host_content_settings_map->SetContentSetting(
571 pattern2, 569 pattern2,
572 ContentSettingsPattern::Wildcard(), 570 ContentSettingsPattern::Wildcard(),
573 CONTENT_SETTINGS_TYPE_COOKIES, 571 CONTENT_SETTINGS_TYPE_COOKIES,
574 "", 572 std::string(),
575 CONTENT_SETTING_BLOCK); 573 CONTENT_SETTING_BLOCK);
576 574
577 host_content_settings_map->SetContentSetting( 575 host_content_settings_map->SetContentSetting(
578 pattern3, 576 pattern3,
579 ContentSettingsPattern::Wildcard(), 577 ContentSettingsPattern::Wildcard(),
580 CONTENT_SETTINGS_TYPE_PLUGINS, 578 CONTENT_SETTINGS_TYPE_PLUGINS,
581 "", 579 std::string(),
582 CONTENT_SETTING_BLOCK); 580 CONTENT_SETTING_BLOCK);
583 host_content_settings_map->SetDefaultContentSetting( 581 host_content_settings_map->SetDefaultContentSetting(
584 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); 582 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
585 583
586 EXPECT_EQ(CONTENT_SETTING_BLOCK, 584 EXPECT_EQ(CONTENT_SETTING_BLOCK,
587 host_content_settings_map->GetContentSetting( 585 host_content_settings_map->GetContentSetting(
588 host, host, CONTENT_SETTINGS_TYPE_COOKIES, "")); 586 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
589 EXPECT_EQ(CONTENT_SETTING_BLOCK, 587 EXPECT_EQ(CONTENT_SETTING_BLOCK,
590 host_content_settings_map->GetContentSetting( 588 host_content_settings_map->GetContentSetting(
591 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 589 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
592 EXPECT_EQ(CONTENT_SETTING_BLOCK, 590 EXPECT_EQ(CONTENT_SETTING_BLOCK,
593 host_content_settings_map->GetContentSetting( 591 host_content_settings_map->GetContentSetting(
594 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, "")); 592 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
595 EXPECT_EQ(CONTENT_SETTING_BLOCK, 593 EXPECT_EQ(CONTENT_SETTING_BLOCK,
596 host_content_settings_map->GetContentSetting( 594 host_content_settings_map->GetContentSetting(
597 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, "")); 595 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
598 EXPECT_EQ(CONTENT_SETTING_BLOCK, 596 EXPECT_EQ(CONTENT_SETTING_BLOCK,
599 host_content_settings_map->GetContentSetting( 597 host_content_settings_map->GetContentSetting(
600 host, host, CONTENT_SETTINGS_TYPE_POPUPS, "")); 598 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
601 EXPECT_EQ(CONTENT_SETTING_ASK, 599 EXPECT_EQ(CONTENT_SETTING_ASK,
602 host_content_settings_map->GetContentSetting( 600 host_content_settings_map->GetContentSetting(
603 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, "")); 601 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
602 EXPECT_EQ(
603 CONTENT_SETTING_ASK,
604 host_content_settings_map->GetContentSetting(
605 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
604 EXPECT_EQ(CONTENT_SETTING_ASK, 606 EXPECT_EQ(CONTENT_SETTING_ASK,
605 host_content_settings_map->GetContentSetting( 607 host_content_settings_map->GetContentSetting(
606 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "")); 608 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()));
607 EXPECT_EQ(CONTENT_SETTING_ASK, 609 EXPECT_EQ(CONTENT_SETTING_ASK,
608 host_content_settings_map->GetContentSetting( 610 host_content_settings_map->GetContentSetting(
609 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, "")); 611 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()));
610 EXPECT_EQ(CONTENT_SETTING_ASK,
611 host_content_settings_map->GetContentSetting(
612 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, ""));
613 } 612 }
614 613
615 TEST_F(HostContentSettingsMapTest, OffTheRecord) { 614 TEST_F(HostContentSettingsMapTest, OffTheRecord) {
616 TestingProfile profile; 615 TestingProfile profile;
617 HostContentSettingsMap* host_content_settings_map = 616 HostContentSettingsMap* host_content_settings_map =
618 profile.GetHostContentSettingsMap(); 617 profile.GetHostContentSettingsMap();
619 scoped_refptr<HostContentSettingsMap> otr_map( 618 scoped_refptr<HostContentSettingsMap> otr_map(
620 new HostContentSettingsMap(profile.GetPrefs(), 619 new HostContentSettingsMap(profile.GetPrefs(),
621 true)); 620 true));
622 621
623 GURL host("http://example.com/"); 622 GURL host("http://example.com/");
624 ContentSettingsPattern pattern = 623 ContentSettingsPattern pattern =
625 ContentSettingsPattern::FromString("[*.]example.com"); 624 ContentSettingsPattern::FromString("[*.]example.com");
626 625
627 EXPECT_EQ(CONTENT_SETTING_ALLOW, 626 EXPECT_EQ(CONTENT_SETTING_ALLOW,
628 host_content_settings_map->GetContentSetting( 627 host_content_settings_map->GetContentSetting(
629 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 628 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
630 EXPECT_EQ(CONTENT_SETTING_ALLOW, 629 EXPECT_EQ(CONTENT_SETTING_ALLOW,
631 otr_map->GetContentSetting( 630 otr_map->GetContentSetting(
632 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 631 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
633 632
634 // Changing content settings on the main map should also affect the 633 // Changing content settings on the main map should also affect the
635 // incognito map. 634 // incognito map.
636 host_content_settings_map->SetContentSetting( 635 host_content_settings_map->SetContentSetting(
637 pattern, 636 pattern,
638 ContentSettingsPattern::Wildcard(), 637 ContentSettingsPattern::Wildcard(),
639 CONTENT_SETTINGS_TYPE_IMAGES, 638 CONTENT_SETTINGS_TYPE_IMAGES,
640 "", 639 std::string(),
641 CONTENT_SETTING_BLOCK); 640 CONTENT_SETTING_BLOCK);
642 EXPECT_EQ(CONTENT_SETTING_BLOCK, 641 EXPECT_EQ(CONTENT_SETTING_BLOCK,
643 host_content_settings_map->GetContentSetting( 642 host_content_settings_map->GetContentSetting(
644 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 643 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
645 EXPECT_EQ(CONTENT_SETTING_BLOCK, 644 EXPECT_EQ(CONTENT_SETTING_BLOCK,
646 otr_map->GetContentSetting( 645 otr_map->GetContentSetting(
647 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 646 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
648 647
649 // Changing content settings on the incognito map should NOT affect the 648 // Changing content settings on the incognito map should NOT affect the
650 // main map. 649 // main map.
651 otr_map->SetContentSetting( 650 otr_map->SetContentSetting(pattern,
652 pattern, 651 ContentSettingsPattern::Wildcard(),
653 ContentSettingsPattern::Wildcard(), 652 CONTENT_SETTINGS_TYPE_IMAGES,
654 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_ALLOW); 653 std::string(),
654 CONTENT_SETTING_ALLOW);
655 EXPECT_EQ(CONTENT_SETTING_BLOCK, 655 EXPECT_EQ(CONTENT_SETTING_BLOCK,
656 host_content_settings_map->GetContentSetting( 656 host_content_settings_map->GetContentSetting(
657 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 657 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
658 EXPECT_EQ(CONTENT_SETTING_ALLOW, 658 EXPECT_EQ(CONTENT_SETTING_ALLOW,
659 otr_map->GetContentSetting( 659 otr_map->GetContentSetting(
660 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 660 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
661 661
662 otr_map->ShutdownOnUIThread(); 662 otr_map->ShutdownOnUIThread();
663 } 663 }
664 664
665 // For a single Unicode encoded pattern, check if it gets converted to punycode 665 // For a single Unicode encoded pattern, check if it gets converted to punycode
666 // and old pattern gets deleted. 666 // and old pattern gets deleted.
667 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) { 667 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) {
668 TestingProfile profile; 668 TestingProfile profile;
669 PrefService* prefs = profile.GetPrefs(); 669 PrefService* prefs = profile.GetPrefs();
670 670
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 std::string resource1("someplugin"); 731 std::string resource1("someplugin");
732 std::string resource2("otherplugin"); 732 std::string resource2("otherplugin");
733 733
734 // If resource content settings are enabled, GetContentSettings should return 734 // If resource content settings are enabled, GetContentSettings should return
735 // the default values for all plugins 735 // the default values for all plugins
736 ContentSetting default_plugin_setting = 736 ContentSetting default_plugin_setting =
737 host_content_settings_map->GetDefaultContentSetting( 737 host_content_settings_map->GetDefaultContentSetting(
738 CONTENT_SETTINGS_TYPE_PLUGINS, NULL); 738 CONTENT_SETTINGS_TYPE_PLUGINS, NULL);
739 EXPECT_EQ(default_plugin_setting, 739 EXPECT_EQ(default_plugin_setting,
740 host_content_settings_map->GetContentSetting( 740 host_content_settings_map->GetContentSetting(
741 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, "")); 741 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
742 742
743 // If no resource-specific content settings are defined, the setting should be 743 // If no resource-specific content settings are defined, the setting should be
744 // DEFAULT. 744 // DEFAULT.
745 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 745 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
746 host_content_settings_map->GetContentSetting( 746 host_content_settings_map->GetContentSetting(
747 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); 747 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1));
748 748
749 host_content_settings_map->SetContentSetting( 749 host_content_settings_map->SetContentSetting(
750 pattern, 750 pattern,
751 ContentSettingsPattern::Wildcard(), 751 ContentSettingsPattern::Wildcard(),
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 profile.GetHostContentSettingsMap(); 858 profile.GetHostContentSettingsMap();
859 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 859 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
860 860
861 // Set pattern for JavaScript setting. 861 // Set pattern for JavaScript setting.
862 ContentSettingsPattern pattern = 862 ContentSettingsPattern pattern =
863 ContentSettingsPattern::FromString("[*.]example.com"); 863 ContentSettingsPattern::FromString("[*.]example.com");
864 host_content_settings_map->SetContentSetting( 864 host_content_settings_map->SetContentSetting(
865 pattern, 865 pattern,
866 ContentSettingsPattern::Wildcard(), 866 ContentSettingsPattern::Wildcard(),
867 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 867 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
868 "", 868 std::string(),
869 CONTENT_SETTING_BLOCK); 869 CONTENT_SETTING_BLOCK);
870 870
871 EXPECT_EQ(CONTENT_SETTING_ALLOW, 871 EXPECT_EQ(CONTENT_SETTING_ALLOW,
872 host_content_settings_map->GetDefaultContentSetting( 872 host_content_settings_map->GetDefaultContentSetting(
873 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); 873 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
874 874
875 GURL host("http://example.com/"); 875 GURL host("http://example.com/");
876 EXPECT_EQ(CONTENT_SETTING_BLOCK, 876 EXPECT_EQ(CONTENT_SETTING_BLOCK,
877 host_content_settings_map->GetContentSetting( 877 host_content_settings_map->GetContentSetting(
878 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, "")); 878 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
879 879
880 // Set managed-default-content-setting for content-settings-type JavaScript. 880 // Set managed-default-content-setting for content-settings-type JavaScript.
881 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, 881 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
882 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); 882 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
883 EXPECT_EQ(CONTENT_SETTING_ALLOW, 883 EXPECT_EQ(CONTENT_SETTING_ALLOW,
884 host_content_settings_map->GetContentSetting( 884 host_content_settings_map->GetContentSetting(
885 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, "")); 885 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
886 } 886 }
887 887
888 // Managed default content setting should have higher priority 888 // Managed default content setting should have higher priority
889 // than user defined patterns. 889 // than user defined patterns.
890 TEST_F(HostContentSettingsMapTest, 890 TEST_F(HostContentSettingsMapTest,
891 ManagedDefaultContentSettingIgnoreUserPattern) { 891 ManagedDefaultContentSettingIgnoreUserPattern) {
892 TestingProfile profile; 892 TestingProfile profile;
893 HostContentSettingsMap* host_content_settings_map = 893 HostContentSettingsMap* host_content_settings_map =
894 profile.GetHostContentSettingsMap(); 894 profile.GetHostContentSettingsMap();
895 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 895 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
896 896
897 // Block all JavaScript. 897 // Block all JavaScript.
898 host_content_settings_map->SetDefaultContentSetting( 898 host_content_settings_map->SetDefaultContentSetting(
899 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); 899 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
900 900
901 // Set an exception to allow "[*.]example.com" 901 // Set an exception to allow "[*.]example.com"
902 ContentSettingsPattern pattern = 902 ContentSettingsPattern pattern =
903 ContentSettingsPattern::FromString("[*.]example.com"); 903 ContentSettingsPattern::FromString("[*.]example.com");
904 904
905 host_content_settings_map->SetContentSetting( 905 host_content_settings_map->SetContentSetting(
906 pattern, 906 pattern,
907 ContentSettingsPattern::Wildcard(), 907 ContentSettingsPattern::Wildcard(),
908 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 908 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
909 "", 909 std::string(),
910 CONTENT_SETTING_ALLOW); 910 CONTENT_SETTING_ALLOW);
911 911
912 EXPECT_EQ(CONTENT_SETTING_BLOCK, 912 EXPECT_EQ(CONTENT_SETTING_BLOCK,
913 host_content_settings_map->GetDefaultContentSetting( 913 host_content_settings_map->GetDefaultContentSetting(
914 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); 914 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
915 GURL host("http://example.com/"); 915 GURL host("http://example.com/");
916 EXPECT_EQ(CONTENT_SETTING_ALLOW, 916 EXPECT_EQ(CONTENT_SETTING_ALLOW,
917 host_content_settings_map->GetContentSetting( 917 host_content_settings_map->GetContentSetting(
918 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, "")); 918 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
919 919
920 // Set managed-default-content-settings-preferences. 920 // Set managed-default-content-settings-preferences.
921 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, 921 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
922 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); 922 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
923 EXPECT_EQ(CONTENT_SETTING_BLOCK, 923 EXPECT_EQ(CONTENT_SETTING_BLOCK,
924 host_content_settings_map->GetContentSetting( 924 host_content_settings_map->GetContentSetting(
925 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, "")); 925 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
926 926
927 // Remove managed-default-content-settings-preferences. 927 // Remove managed-default-content-settings-preferences.
928 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting); 928 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting);
929 EXPECT_EQ(CONTENT_SETTING_ALLOW, 929 EXPECT_EQ(CONTENT_SETTING_ALLOW,
930 host_content_settings_map->GetContentSetting( 930 host_content_settings_map->GetContentSetting(
931 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, "")); 931 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
932 } 932 }
933 933
934 // If a default-content-setting is set to managed setting, the user defined 934 // If a default-content-setting is set to managed setting, the user defined
935 // setting should be preserved. 935 // setting should be preserved.
936 TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) { 936 TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) {
937 TestingProfile profile; 937 TestingProfile profile;
938 HostContentSettingsMap* host_content_settings_map = 938 HostContentSettingsMap* host_content_settings_map =
939 profile.GetHostContentSettingsMap(); 939 profile.GetHostContentSettingsMap();
940 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 940 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
941 941
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 ContentSettingsPattern pattern = 997 ContentSettingsPattern pattern =
998 ContentSettingsPattern::FromString("[*.]example.com"); 998 ContentSettingsPattern::FromString("[*.]example.com");
999 host_content_settings_map->SetContentSetting( 999 host_content_settings_map->SetContentSetting(
1000 pattern, 1000 pattern,
1001 ContentSettingsPattern::Wildcard(), 1001 ContentSettingsPattern::Wildcard(),
1002 CONTENT_SETTINGS_TYPE_IMAGES, 1002 CONTENT_SETTINGS_TYPE_IMAGES,
1003 std::string(), 1003 std::string(),
1004 CONTENT_SETTING_BLOCK); 1004 CONTENT_SETTING_BLOCK);
1005 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1005 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1006 host_content_settings_map->GetContentSetting( 1006 host_content_settings_map->GetContentSetting(
1007 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 1007 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1008 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1008 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1009 host_content_settings_map->GetContentSetting( 1009 host_content_settings_map->GetContentSetting(
1010 embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 1010 embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1011 } 1011 }
1012 1012
1013 TEST_F(HostContentSettingsMapTest, ShouldAllowAllContent) { 1013 TEST_F(HostContentSettingsMapTest, ShouldAllowAllContent) {
1014 TestingProfile profile; 1014 TestingProfile profile;
1015 HostContentSettingsMap* host_content_settings_map = 1015 HostContentSettingsMap* host_content_settings_map =
1016 profile.GetHostContentSettingsMap(); 1016 profile.GetHostContentSettingsMap();
1017 1017
1018 GURL http_host("http://example.com/"); 1018 GURL http_host("http://example.com/");
1019 GURL https_host("https://example.com/"); 1019 GURL https_host("https://example.com/");
1020 GURL embedder("chrome://foo"); 1020 GURL embedder("chrome://foo");
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 GURL("http://other.com"), 1072 GURL("http://other.com"),
1073 CONTENT_SETTINGS_TYPE_COOKIES, 1073 CONTENT_SETTINGS_TYPE_COOKIES,
1074 std::string())); 1074 std::string()));
1075 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, 1075 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY,
1076 host_content_settings_map->GetContentSetting( 1076 host_content_settings_map->GetContentSetting(
1077 GURL("http://third.com"), 1077 GURL("http://third.com"),
1078 GURL("http://third.com"), 1078 GURL("http://third.com"),
1079 CONTENT_SETTINGS_TYPE_COOKIES, 1079 CONTENT_SETTINGS_TYPE_COOKIES,
1080 std::string())); 1080 std::string()));
1081 } 1081 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698