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

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

Issue 1686343002: Change HostContentSettingsMap::SetContentSetting to use GURLs instead of patterns (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor change in comments Created 4 years, 9 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
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/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "chrome/browser/content_settings/content_settings_mock_observer.h" 10 #include "chrome/browser/content_settings/content_settings_mock_observer.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 CONTENT_SETTINGS_TYPE_KEYGEN, NULL)); 95 CONTENT_SETTINGS_TYPE_KEYGEN, NULL));
96 } 96 }
97 97
98 TEST_F(HostContentSettingsMapTest, IndividualSettings) { 98 TEST_F(HostContentSettingsMapTest, IndividualSettings) {
99 TestingProfile profile; 99 TestingProfile profile;
100 HostContentSettingsMap* host_content_settings_map = 100 HostContentSettingsMap* host_content_settings_map =
101 HostContentSettingsMapFactory::GetForProfile(&profile); 101 HostContentSettingsMapFactory::GetForProfile(&profile);
102 102
103 // Check returning individual settings. 103 // Check returning individual settings.
104 GURL host("http://example.com/"); 104 GURL host("http://example.com/");
105 ContentSettingsPattern pattern =
106 ContentSettingsPattern::FromString("[*.]example.com");
107 EXPECT_EQ(CONTENT_SETTING_ALLOW, 105 EXPECT_EQ(CONTENT_SETTING_ALLOW,
108 host_content_settings_map->GetContentSetting( 106 host_content_settings_map->GetContentSetting(
109 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 107 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
110 host_content_settings_map->SetContentSetting( 108 host_content_settings_map->SetContentSettingDefaultScope(
111 pattern, 109 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
112 ContentSettingsPattern::Wildcard(),
113 CONTENT_SETTINGS_TYPE_IMAGES,
114 std::string(),
115 CONTENT_SETTING_DEFAULT); 110 CONTENT_SETTING_DEFAULT);
116 EXPECT_EQ(CONTENT_SETTING_ALLOW, 111 EXPECT_EQ(CONTENT_SETTING_ALLOW,
117 host_content_settings_map->GetContentSetting( 112 host_content_settings_map->GetContentSetting(
118 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 113 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
119 host_content_settings_map->SetContentSetting( 114 host_content_settings_map->SetContentSettingDefaultScope(
120 pattern, 115 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
121 ContentSettingsPattern::Wildcard(),
122 CONTENT_SETTINGS_TYPE_IMAGES,
123 std::string(),
124 CONTENT_SETTING_BLOCK); 116 CONTENT_SETTING_BLOCK);
125 EXPECT_EQ(CONTENT_SETTING_BLOCK, 117 EXPECT_EQ(CONTENT_SETTING_BLOCK,
126 host_content_settings_map->GetContentSetting( 118 host_content_settings_map->GetContentSetting(
127 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 119 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
128 #if defined(ENABLE_PLUGINS) 120 #if defined(ENABLE_PLUGINS)
129 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, 121 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT,
130 host_content_settings_map->GetContentSetting( 122 host_content_settings_map->GetContentSetting(
131 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string())); 123 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
132 #endif 124 #endif
133 125
134 // Check returning all settings for a host. 126 // Check returning all settings for a host.
135 host_content_settings_map->SetContentSetting( 127 host_content_settings_map->SetContentSettingDefaultScope(
136 pattern, 128 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
137 ContentSettingsPattern::Wildcard(),
138 CONTENT_SETTINGS_TYPE_IMAGES,
139 std::string(),
140 CONTENT_SETTING_DEFAULT); 129 CONTENT_SETTING_DEFAULT);
141 EXPECT_EQ(CONTENT_SETTING_ALLOW, 130 EXPECT_EQ(CONTENT_SETTING_ALLOW,
142 host_content_settings_map->GetContentSetting( 131 host_content_settings_map->GetContentSetting(
143 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 132 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
144 host_content_settings_map->SetContentSetting( 133 host_content_settings_map->SetContentSettingDefaultScope(
145 pattern, 134 host, GURL(), CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(),
146 ContentSettingsPattern::Wildcard(),
147 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
148 std::string(),
149 CONTENT_SETTING_BLOCK); 135 CONTENT_SETTING_BLOCK);
150 EXPECT_EQ(CONTENT_SETTING_BLOCK, 136 EXPECT_EQ(CONTENT_SETTING_BLOCK,
151 host_content_settings_map->GetContentSetting( 137 host_content_settings_map->GetContentSetting(
152 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 138 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
153 #if defined(ENABLE_PLUGINS) 139 #if defined(ENABLE_PLUGINS)
154 host_content_settings_map->SetContentSetting( 140 host_content_settings_map->SetContentSettingDefaultScope(
155 pattern, 141 host, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(),
156 ContentSettingsPattern::Wildcard(),
157 CONTENT_SETTINGS_TYPE_PLUGINS,
158 std::string(),
159 CONTENT_SETTING_ALLOW); 142 CONTENT_SETTING_ALLOW);
160 EXPECT_EQ(CONTENT_SETTING_ALLOW, 143 EXPECT_EQ(CONTENT_SETTING_ALLOW,
161 host_content_settings_map->GetContentSetting( 144 host_content_settings_map->GetContentSetting(
162 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string())); 145 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
163 #endif 146 #endif
164 EXPECT_EQ(CONTENT_SETTING_BLOCK, 147 EXPECT_EQ(CONTENT_SETTING_BLOCK,
165 host_content_settings_map->GetContentSetting( 148 host_content_settings_map->GetContentSetting(
166 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); 149 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
167 EXPECT_EQ(CONTENT_SETTING_ASK, 150 EXPECT_EQ(CONTENT_SETTING_ASK,
168 host_content_settings_map->GetContentSetting( 151 host_content_settings_map->GetContentSetting(
169 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 152 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
170 EXPECT_EQ( 153 EXPECT_EQ(
171 CONTENT_SETTING_ASK, 154 CONTENT_SETTING_ASK,
172 host_content_settings_map->GetContentSetting( 155 host_content_settings_map->GetContentSetting(
173 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); 156 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
174 EXPECT_EQ(CONTENT_SETTING_ASK, 157 EXPECT_EQ(CONTENT_SETTING_ASK,
175 host_content_settings_map->GetContentSetting( 158 host_content_settings_map->GetContentSetting(
176 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string())); 159 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()));
177 EXPECT_EQ(CONTENT_SETTING_ASK, 160 EXPECT_EQ(CONTENT_SETTING_ASK,
178 host_content_settings_map->GetContentSetting( 161 host_content_settings_map->GetContentSetting(
179 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); 162 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()));
180 host_content_settings_map->SetContentSetting( 163
181 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_KEYGEN, 164 host_content_settings_map->SetContentSettingDefaultScope(
182 std::string(), CONTENT_SETTING_ALLOW); 165 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(),
166 CONTENT_SETTING_ALLOW);
183 EXPECT_EQ(CONTENT_SETTING_ALLOW, 167 EXPECT_EQ(CONTENT_SETTING_ALLOW,
184 host_content_settings_map->GetContentSetting( 168 host_content_settings_map->GetContentSetting(
185 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); 169 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
186 170
187 // Check returning all hosts for a setting. 171 // Check returning all hosts for a setting.
188 ContentSettingsPattern pattern2 = 172 GURL host2("http://example.org/");
189 ContentSettingsPattern::FromString("[*.]example.org"); 173 host_content_settings_map->SetContentSettingDefaultScope(
190 host_content_settings_map->SetContentSetting( 174 host2, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
191 pattern2,
192 ContentSettingsPattern::Wildcard(),
193 CONTENT_SETTINGS_TYPE_IMAGES,
194 std::string(),
195 CONTENT_SETTING_BLOCK); 175 CONTENT_SETTING_BLOCK);
196 #if defined(ENABLE_PLUGINS) 176 #if defined(ENABLE_PLUGINS)
197 host_content_settings_map->SetContentSetting( 177 host_content_settings_map->SetContentSettingDefaultScope(
198 pattern2, 178 host2, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(),
199 ContentSettingsPattern::Wildcard(),
200 CONTENT_SETTINGS_TYPE_PLUGINS,
201 std::string(),
202 CONTENT_SETTING_BLOCK); 179 CONTENT_SETTING_BLOCK);
203 #endif 180 #endif
204 ContentSettingsForOneType host_settings; 181 ContentSettingsForOneType host_settings;
205 host_content_settings_map->GetSettingsForOneType( 182 host_content_settings_map->GetSettingsForOneType(
206 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings); 183 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings);
207 // |host_settings| contains the default setting and an exception. 184 // |host_settings| contains the default setting and an exception.
208 EXPECT_EQ(2U, host_settings.size()); 185 EXPECT_EQ(2U, host_settings.size());
209 #if defined(ENABLE_PLUGINS) 186 #if defined(ENABLE_PLUGINS)
210 host_content_settings_map->GetSettingsForOneType( 187 host_content_settings_map->GetSettingsForOneType(
211 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); 188 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings);
212 // |host_settings| contains the default setting and 2 exceptions. 189 // |host_settings| contains the default setting and 2 exceptions.
213 EXPECT_EQ(3U, host_settings.size()); 190 EXPECT_EQ(3U, host_settings.size());
214 #endif 191 #endif
215 host_content_settings_map->GetSettingsForOneType( 192 host_content_settings_map->GetSettingsForOneType(
216 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings); 193 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings);
217 // |host_settings| contains only the default setting. 194 // |host_settings| contains only the default setting.
218 EXPECT_EQ(1U, host_settings.size()); 195 EXPECT_EQ(1U, host_settings.size());
219 } 196 }
220 197
221 TEST_F(HostContentSettingsMapTest, Clear) { 198 TEST_F(HostContentSettingsMapTest, Clear) {
222 TestingProfile profile; 199 TestingProfile profile;
223 HostContentSettingsMap* host_content_settings_map = 200 HostContentSettingsMap* host_content_settings_map =
224 HostContentSettingsMapFactory::GetForProfile(&profile); 201 HostContentSettingsMapFactory::GetForProfile(&profile);
225 202
226 // Check clearing one type. 203 // Check clearing one type.
227 ContentSettingsPattern pattern = 204 GURL host("http://example.org/");
228 ContentSettingsPattern::FromString("[*.]example.org"); 205 GURL host2("http://example.net/");
229 ContentSettingsPattern pattern2 = 206 host_content_settings_map->SetContentSettingDefaultScope(
230 ContentSettingsPattern::FromString("[*.]example.net"); 207 host2, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
231 host_content_settings_map->SetContentSetting(
232 pattern2,
233 ContentSettingsPattern::Wildcard(),
234 CONTENT_SETTINGS_TYPE_IMAGES,
235 std::string(),
236 CONTENT_SETTING_BLOCK); 208 CONTENT_SETTING_BLOCK);
237 host_content_settings_map->SetContentSetting( 209 host_content_settings_map->SetContentSettingDefaultScope(
238 pattern, 210 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
239 ContentSettingsPattern::Wildcard(),
240 CONTENT_SETTINGS_TYPE_IMAGES,
241 std::string(),
242 CONTENT_SETTING_BLOCK); 211 CONTENT_SETTING_BLOCK);
243 #if defined(ENABLE_PLUGINS) 212 #if defined(ENABLE_PLUGINS)
244 host_content_settings_map->SetContentSetting( 213 host_content_settings_map->SetContentSettingDefaultScope(
245 pattern, 214 host, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(),
246 ContentSettingsPattern::Wildcard(),
247 CONTENT_SETTINGS_TYPE_PLUGINS,
248 std::string(),
249 CONTENT_SETTING_BLOCK); 215 CONTENT_SETTING_BLOCK);
250 #endif 216 #endif
251 host_content_settings_map->SetContentSetting( 217 host_content_settings_map->SetContentSettingDefaultScope(
252 pattern2, 218 host2, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
253 ContentSettingsPattern::Wildcard(),
254 CONTENT_SETTINGS_TYPE_IMAGES,
255 std::string(),
256 CONTENT_SETTING_BLOCK); 219 CONTENT_SETTING_BLOCK);
257 host_content_settings_map->ClearSettingsForOneType( 220 host_content_settings_map->ClearSettingsForOneType(
258 CONTENT_SETTINGS_TYPE_IMAGES); 221 CONTENT_SETTINGS_TYPE_IMAGES);
259 ContentSettingsForOneType host_settings; 222 ContentSettingsForOneType host_settings;
260 host_content_settings_map->GetSettingsForOneType( 223 host_content_settings_map->GetSettingsForOneType(
261 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings); 224 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings);
262 // |host_settings| contains only the default setting. 225 // |host_settings| contains only the default setting.
263 EXPECT_EQ(1U, host_settings.size()); 226 EXPECT_EQ(1U, host_settings.size());
264 #if defined(ENABLE_PLUGINS) 227 #if defined(ENABLE_PLUGINS)
265 host_content_settings_map->GetSettingsForOneType( 228 host_content_settings_map->GetSettingsForOneType(
266 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); 229 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings);
267 // |host_settings| contains the default setting and an exception. 230 // |host_settings| contains the default setting and an exception.
268 EXPECT_EQ(2U, host_settings.size()); 231 EXPECT_EQ(2U, host_settings.size());
269 #endif 232 #endif
270 } 233 }
271 234
272 TEST_F(HostContentSettingsMapTest, Patterns) { 235 TEST_F(HostContentSettingsMapTest, Patterns) {
273 TestingProfile profile; 236 TestingProfile profile;
274 HostContentSettingsMap* host_content_settings_map = 237 HostContentSettingsMap* host_content_settings_map =
275 HostContentSettingsMapFactory::GetForProfile(&profile); 238 HostContentSettingsMapFactory::GetForProfile(&profile);
276 239
277 GURL host1("http://example.com/"); 240 GURL host1("http://example.com/");
278 GURL host2("http://www.example.com/"); 241 GURL host2("http://www.example.com/");
279 GURL host3("http://example.org/"); 242 GURL host3("http://example.org/");
280 ContentSettingsPattern pattern1 =
281 ContentSettingsPattern::FromString("[*.]example.com");
282 ContentSettingsPattern pattern2 =
283 ContentSettingsPattern::FromString("example.org");
284 EXPECT_EQ(CONTENT_SETTING_ALLOW, 243 EXPECT_EQ(CONTENT_SETTING_ALLOW,
285 host_content_settings_map->GetContentSetting( 244 host_content_settings_map->GetContentSetting(
286 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 245 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
287 host_content_settings_map->SetContentSetting( 246 host_content_settings_map->SetContentSettingDefaultScope(
288 pattern1, 247 host1, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
289 ContentSettingsPattern::Wildcard(),
290 CONTENT_SETTINGS_TYPE_IMAGES,
291 std::string(),
292 CONTENT_SETTING_BLOCK); 248 CONTENT_SETTING_BLOCK);
293 EXPECT_EQ(CONTENT_SETTING_BLOCK, 249 EXPECT_EQ(CONTENT_SETTING_BLOCK,
294 host_content_settings_map->GetContentSetting( 250 host_content_settings_map->GetContentSetting(
295 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 251 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
296 EXPECT_EQ(CONTENT_SETTING_BLOCK, 252 EXPECT_EQ(CONTENT_SETTING_BLOCK,
297 host_content_settings_map->GetContentSetting( 253 host_content_settings_map->GetContentSetting(
298 host2, host2, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 254 host2, host2, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
299 EXPECT_EQ(CONTENT_SETTING_ALLOW, 255 EXPECT_EQ(CONTENT_SETTING_ALLOW,
300 host_content_settings_map->GetContentSetting( 256 host_content_settings_map->GetContentSetting(
301 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 257 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
302 host_content_settings_map->SetContentSetting( 258 host_content_settings_map->SetContentSettingDefaultScope(
303 pattern2, 259 host3, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
304 ContentSettingsPattern::Wildcard(),
305 CONTENT_SETTINGS_TYPE_IMAGES,
306 std::string(),
307 CONTENT_SETTING_BLOCK); 260 CONTENT_SETTING_BLOCK);
308 EXPECT_EQ(CONTENT_SETTING_BLOCK, 261 EXPECT_EQ(CONTENT_SETTING_BLOCK,
309 host_content_settings_map->GetContentSetting( 262 host_content_settings_map->GetContentSetting(
310 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 263 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
311 } 264 }
312 265
313 TEST_F(HostContentSettingsMapTest, Observer) { 266 TEST_F(HostContentSettingsMapTest, Observer) {
314 TestingProfile profile; 267 TestingProfile profile;
315 HostContentSettingsMap* host_content_settings_map = 268 HostContentSettingsMap* host_content_settings_map =
316 HostContentSettingsMapFactory::GetForProfile(&profile); 269 HostContentSettingsMapFactory::GetForProfile(&profile);
317 MockSettingsObserver observer(host_content_settings_map); 270 MockSettingsObserver observer(host_content_settings_map);
318 271
272 GURL host("http://example.com/");
319 ContentSettingsPattern primary_pattern = 273 ContentSettingsPattern primary_pattern =
320 ContentSettingsPattern::FromString("[*.]example.com"); 274 ContentSettingsPattern::FromString("[*.]example.com");
321 ContentSettingsPattern secondary_pattern = 275 ContentSettingsPattern secondary_pattern =
322 ContentSettingsPattern::Wildcard(); 276 ContentSettingsPattern::Wildcard();
323 EXPECT_CALL(observer, 277 EXPECT_CALL(observer,
324 OnContentSettingsChanged(host_content_settings_map, 278 OnContentSettingsChanged(host_content_settings_map,
325 CONTENT_SETTINGS_TYPE_IMAGES, 279 CONTENT_SETTINGS_TYPE_IMAGES,
326 false, 280 false,
327 primary_pattern, 281 primary_pattern,
328 secondary_pattern, 282 secondary_pattern,
329 false)); 283 false));
330 host_content_settings_map->SetContentSetting( 284 host_content_settings_map->SetContentSettingDefaultScope(
331 primary_pattern, 285 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
332 secondary_pattern,
333 CONTENT_SETTINGS_TYPE_IMAGES,
334 std::string(),
335 CONTENT_SETTING_ALLOW); 286 CONTENT_SETTING_ALLOW);
336 ::testing::Mock::VerifyAndClearExpectations(&observer); 287 ::testing::Mock::VerifyAndClearExpectations(&observer);
337 288
338 EXPECT_CALL(observer, 289 EXPECT_CALL(observer,
339 OnContentSettingsChanged(host_content_settings_map, 290 OnContentSettingsChanged(host_content_settings_map,
340 CONTENT_SETTINGS_TYPE_IMAGES, false, 291 CONTENT_SETTINGS_TYPE_IMAGES, false,
341 _, _, true)); 292 _, _, true));
342 host_content_settings_map->ClearSettingsForOneType( 293 host_content_settings_map->ClearSettingsForOneType(
343 CONTENT_SETTINGS_TYPE_IMAGES); 294 CONTENT_SETTINGS_TYPE_IMAGES);
344 ::testing::Mock::VerifyAndClearExpectations(&observer); 295 ::testing::Mock::VerifyAndClearExpectations(&observer);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 HostContentSettingsMapFactory::GetForProfile(&profile); 338 HostContentSettingsMapFactory::GetForProfile(&profile);
388 339
389 PrefService* prefs = profile.GetPrefs(); 340 PrefService* prefs = profile.GetPrefs();
390 341
391 // Make a copy of the default pref value so we can reset it later. 342 // Make a copy of the default pref value so we can reset it later.
392 scoped_ptr<base::Value> default_value( 343 scoped_ptr<base::Value> default_value(
393 prefs->FindPreference(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)) 344 prefs->FindPreference(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES))
394 ->GetValue() 345 ->GetValue()
395 ->DeepCopy()); 346 ->DeepCopy());
396 347
397 ContentSettingsPattern pattern =
398 ContentSettingsPattern::FromString("[*.]example.com");
399 GURL host("http://example.com"); 348 GURL host("http://example.com");
400 349
401 EXPECT_EQ(CONTENT_SETTING_ALLOW, 350 EXPECT_EQ(CONTENT_SETTING_ALLOW,
402 host_content_settings_map->GetContentSetting( 351 host_content_settings_map->GetContentSetting(
403 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 352 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
404 353
405 host_content_settings_map->SetContentSetting( 354 host_content_settings_map->SetContentSettingDefaultScope(
406 pattern, 355 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
407 ContentSettingsPattern::Wildcard(),
408 CONTENT_SETTINGS_TYPE_IMAGES,
409 std::string(),
410 CONTENT_SETTING_BLOCK); 356 CONTENT_SETTING_BLOCK);
411 EXPECT_EQ(CONTENT_SETTING_BLOCK, 357 EXPECT_EQ(CONTENT_SETTING_BLOCK,
412 host_content_settings_map->GetContentSetting( 358 host_content_settings_map->GetContentSetting(
413 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 359 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
414 360
415 // Make a copy of the pref's new value so we can reset it later. 361 // Make a copy of the pref's new value so we can reset it later.
416 scoped_ptr<base::Value> new_value( 362 scoped_ptr<base::Value> new_value(
417 prefs->FindPreference(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)) 363 prefs->FindPreference(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES))
418 ->GetValue() 364 ->GetValue()
419 ->DeepCopy()); 365 ->DeepCopy());
(...skipping 11 matching lines...) Expand all
431 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 377 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
432 } 378 }
433 379
434 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { 380 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) {
435 TestingProfile profile; 381 TestingProfile profile;
436 HostContentSettingsMap* host_content_settings_map = 382 HostContentSettingsMap* host_content_settings_map =
437 HostContentSettingsMapFactory::GetForProfile(&profile); 383 HostContentSettingsMapFactory::GetForProfile(&profile);
438 content_settings::CookieSettings* cookie_settings = 384 content_settings::CookieSettings* cookie_settings =
439 CookieSettingsFactory::GetForProfile(&profile).get(); 385 CookieSettingsFactory::GetForProfile(&profile).get();
440 386
441 ContentSettingsPattern pattern =
442 ContentSettingsPattern::FromString("[*.]example.com");
443 GURL host_ending_with_dot("http://example.com./"); 387 GURL host_ending_with_dot("http://example.com./");
444 388
445 EXPECT_EQ(CONTENT_SETTING_ALLOW, 389 EXPECT_EQ(CONTENT_SETTING_ALLOW,
446 host_content_settings_map->GetContentSetting( 390 host_content_settings_map->GetContentSetting(
447 host_ending_with_dot, 391 host_ending_with_dot,
448 host_ending_with_dot, 392 host_ending_with_dot,
449 CONTENT_SETTINGS_TYPE_IMAGES, 393 CONTENT_SETTINGS_TYPE_IMAGES,
450 std::string())); 394 std::string()));
451 host_content_settings_map->SetContentSetting( 395 host_content_settings_map->SetContentSettingDefaultScope(
452 pattern, 396 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
453 ContentSettingsPattern::Wildcard(),
454 CONTENT_SETTINGS_TYPE_IMAGES,
455 std::string(),
456 CONTENT_SETTING_DEFAULT); 397 CONTENT_SETTING_DEFAULT);
457 EXPECT_EQ( 398 EXPECT_EQ(
458 CONTENT_SETTING_ALLOW, 399 CONTENT_SETTING_ALLOW,
459 host_content_settings_map->GetContentSetting(host_ending_with_dot, 400 host_content_settings_map->GetContentSetting(host_ending_with_dot,
460 host_ending_with_dot, 401 host_ending_with_dot,
461 CONTENT_SETTINGS_TYPE_IMAGES, 402 CONTENT_SETTINGS_TYPE_IMAGES,
462 std::string())); 403 std::string()));
463 host_content_settings_map->SetContentSetting( 404 host_content_settings_map->SetContentSettingDefaultScope(
464 pattern, 405 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
465 ContentSettingsPattern::Wildcard(),
466 CONTENT_SETTINGS_TYPE_IMAGES,
467 std::string(),
468 CONTENT_SETTING_BLOCK); 406 CONTENT_SETTING_BLOCK);
469 EXPECT_EQ( 407 EXPECT_EQ(
470 CONTENT_SETTING_BLOCK, 408 CONTENT_SETTING_BLOCK,
471 host_content_settings_map->GetContentSetting(host_ending_with_dot, 409 host_content_settings_map->GetContentSetting(host_ending_with_dot,
472 host_ending_with_dot, 410 host_ending_with_dot,
473 CONTENT_SETTINGS_TYPE_IMAGES, 411 CONTENT_SETTINGS_TYPE_IMAGES,
474 std::string())); 412 std::string()));
475 413
476 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( 414 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
477 host_ending_with_dot, host_ending_with_dot)); 415 host_ending_with_dot, host_ending_with_dot));
478 host_content_settings_map->SetContentSetting( 416 host_content_settings_map->SetContentSettingDefaultScope(
479 pattern, 417 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_COOKIES,
480 ContentSettingsPattern::Wildcard(), 418 std::string(), CONTENT_SETTING_DEFAULT);
481 CONTENT_SETTINGS_TYPE_COOKIES,
482 std::string(),
483 CONTENT_SETTING_DEFAULT);
484 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( 419 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
485 host_ending_with_dot, host_ending_with_dot)); 420 host_ending_with_dot, host_ending_with_dot));
486 host_content_settings_map->SetContentSetting( 421 host_content_settings_map->SetContentSettingDefaultScope(
487 pattern, 422 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_COOKIES,
488 ContentSettingsPattern::Wildcard(), 423 std::string(), CONTENT_SETTING_BLOCK);
489 CONTENT_SETTINGS_TYPE_COOKIES,
490 std::string(),
491 CONTENT_SETTING_BLOCK);
492 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( 424 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed(
493 host_ending_with_dot, host_ending_with_dot)); 425 host_ending_with_dot, host_ending_with_dot));
494 426
495 EXPECT_EQ(CONTENT_SETTING_ALLOW, 427 EXPECT_EQ(CONTENT_SETTING_ALLOW,
496 host_content_settings_map->GetContentSetting( 428 host_content_settings_map->GetContentSetting(
497 host_ending_with_dot, 429 host_ending_with_dot,
498 host_ending_with_dot, 430 host_ending_with_dot,
499 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 431 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
500 std::string())); 432 std::string()));
501 host_content_settings_map->SetContentSetting( 433 host_content_settings_map->SetContentSettingDefaultScope(
502 pattern, 434 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_JAVASCRIPT,
503 ContentSettingsPattern::Wildcard(), 435 std::string(), CONTENT_SETTING_DEFAULT);
504 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
505 std::string(),
506 CONTENT_SETTING_DEFAULT);
507 EXPECT_EQ(CONTENT_SETTING_ALLOW, 436 EXPECT_EQ(CONTENT_SETTING_ALLOW,
508 host_content_settings_map->GetContentSetting( 437 host_content_settings_map->GetContentSetting(
509 host_ending_with_dot, 438 host_ending_with_dot,
510 host_ending_with_dot, 439 host_ending_with_dot,
511 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 440 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
512 std::string())); 441 std::string()));
513 host_content_settings_map->SetContentSetting( 442 host_content_settings_map->SetContentSettingDefaultScope(
514 pattern, 443 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_JAVASCRIPT,
515 ContentSettingsPattern::Wildcard(), 444 std::string(), CONTENT_SETTING_BLOCK);
516 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
517 std::string(),
518 CONTENT_SETTING_BLOCK);
519 EXPECT_EQ(CONTENT_SETTING_BLOCK, 445 EXPECT_EQ(CONTENT_SETTING_BLOCK,
520 host_content_settings_map->GetContentSetting( 446 host_content_settings_map->GetContentSetting(
521 host_ending_with_dot, 447 host_ending_with_dot,
522 host_ending_with_dot, 448 host_ending_with_dot,
523 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 449 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
524 std::string())); 450 std::string()));
525 451
526 #if defined(ENABLE_PLUGINS) 452 #if defined(ENABLE_PLUGINS)
527 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, 453 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT,
528 host_content_settings_map->GetContentSetting( 454 host_content_settings_map->GetContentSetting(
529 host_ending_with_dot, 455 host_ending_with_dot,
530 host_ending_with_dot, 456 host_ending_with_dot,
531 CONTENT_SETTINGS_TYPE_PLUGINS, 457 CONTENT_SETTINGS_TYPE_PLUGINS,
532 std::string())); 458 std::string()));
533 host_content_settings_map->SetContentSetting( 459 host_content_settings_map->SetContentSettingDefaultScope(
534 pattern, 460 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS,
535 ContentSettingsPattern::Wildcard(), 461 std::string(), CONTENT_SETTING_DEFAULT);
536 CONTENT_SETTINGS_TYPE_PLUGINS,
537 std::string(),
538 CONTENT_SETTING_DEFAULT);
539 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, 462 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT,
540 host_content_settings_map->GetContentSetting( 463 host_content_settings_map->GetContentSetting(
541 host_ending_with_dot, 464 host_ending_with_dot,
542 host_ending_with_dot, 465 host_ending_with_dot,
543 CONTENT_SETTINGS_TYPE_PLUGINS, 466 CONTENT_SETTINGS_TYPE_PLUGINS,
544 std::string())); 467 std::string()));
545 host_content_settings_map->SetContentSetting( 468 host_content_settings_map->SetContentSettingDefaultScope(
546 pattern, 469 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS,
547 ContentSettingsPattern::Wildcard(), 470 std::string(), CONTENT_SETTING_BLOCK);
548 CONTENT_SETTINGS_TYPE_PLUGINS,
549 std::string(),
550 CONTENT_SETTING_BLOCK);
551 EXPECT_EQ(CONTENT_SETTING_BLOCK, 471 EXPECT_EQ(CONTENT_SETTING_BLOCK,
552 host_content_settings_map->GetContentSetting( 472 host_content_settings_map->GetContentSetting(
553 host_ending_with_dot, 473 host_ending_with_dot,
554 host_ending_with_dot, 474 host_ending_with_dot,
555 CONTENT_SETTINGS_TYPE_PLUGINS, 475 CONTENT_SETTINGS_TYPE_PLUGINS,
556 std::string())); 476 std::string()));
557 #endif 477 #endif
558 478
559 EXPECT_EQ( 479 EXPECT_EQ(
560 CONTENT_SETTING_BLOCK, 480 CONTENT_SETTING_BLOCK,
561 host_content_settings_map->GetContentSetting(host_ending_with_dot, 481 host_content_settings_map->GetContentSetting(host_ending_with_dot,
562 host_ending_with_dot, 482 host_ending_with_dot,
563 CONTENT_SETTINGS_TYPE_POPUPS, 483 CONTENT_SETTINGS_TYPE_POPUPS,
564 std::string())); 484 std::string()));
565 host_content_settings_map->SetContentSetting( 485 host_content_settings_map->SetContentSettingDefaultScope(
566 pattern, 486 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(),
567 ContentSettingsPattern::Wildcard(),
568 CONTENT_SETTINGS_TYPE_POPUPS,
569 std::string(),
570 CONTENT_SETTING_DEFAULT); 487 CONTENT_SETTING_DEFAULT);
571 EXPECT_EQ( 488 EXPECT_EQ(
572 CONTENT_SETTING_BLOCK, 489 CONTENT_SETTING_BLOCK,
573 host_content_settings_map->GetContentSetting(host_ending_with_dot, 490 host_content_settings_map->GetContentSetting(host_ending_with_dot,
574 host_ending_with_dot, 491 host_ending_with_dot,
575 CONTENT_SETTINGS_TYPE_POPUPS, 492 CONTENT_SETTINGS_TYPE_POPUPS,
576 std::string())); 493 std::string()));
577 host_content_settings_map->SetContentSetting( 494 host_content_settings_map->SetContentSettingDefaultScope(
578 pattern, 495 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(),
579 ContentSettingsPattern::Wildcard(),
580 CONTENT_SETTINGS_TYPE_POPUPS,
581 std::string(),
582 CONTENT_SETTING_ALLOW); 496 CONTENT_SETTING_ALLOW);
583 EXPECT_EQ( 497 EXPECT_EQ(
584 CONTENT_SETTING_ALLOW, 498 CONTENT_SETTING_ALLOW,
585 host_content_settings_map->GetContentSetting(host_ending_with_dot, 499 host_content_settings_map->GetContentSetting(host_ending_with_dot,
586 host_ending_with_dot, 500 host_ending_with_dot,
587 CONTENT_SETTINGS_TYPE_POPUPS, 501 CONTENT_SETTINGS_TYPE_POPUPS,
588 std::string())); 502 std::string()));
589 503
590 EXPECT_EQ(CONTENT_SETTING_BLOCK, 504 EXPECT_EQ(CONTENT_SETTING_BLOCK,
591 host_content_settings_map->GetContentSetting( 505 host_content_settings_map->GetContentSetting(
592 host_ending_with_dot, host_ending_with_dot, 506 host_ending_with_dot, host_ending_with_dot,
593 CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); 507 CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
594 host_content_settings_map->SetContentSetting( 508 host_content_settings_map->SetContentSettingDefaultScope(
595 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_KEYGEN, 509 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(),
596 std::string(), CONTENT_SETTING_ALLOW); 510 CONTENT_SETTING_ALLOW);
597 EXPECT_EQ(CONTENT_SETTING_ALLOW, 511 EXPECT_EQ(CONTENT_SETTING_ALLOW,
598 host_content_settings_map->GetContentSetting( 512 host_content_settings_map->GetContentSetting(
599 host_ending_with_dot, host_ending_with_dot, 513 host_ending_with_dot, host_ending_with_dot,
600 CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); 514 CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
601 host_content_settings_map->SetContentSetting( 515 host_content_settings_map->SetContentSettingDefaultScope(
602 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_KEYGEN, 516 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(),
603 std::string(), CONTENT_SETTING_DEFAULT); 517 CONTENT_SETTING_DEFAULT);
604 EXPECT_EQ(CONTENT_SETTING_BLOCK, 518 EXPECT_EQ(CONTENT_SETTING_BLOCK,
605 host_content_settings_map->GetContentSetting( 519 host_content_settings_map->GetContentSetting(
606 host_ending_with_dot, host_ending_with_dot, 520 host_ending_with_dot, host_ending_with_dot,
607 CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); 521 CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
608 } 522 }
609 523
610 TEST_F(HostContentSettingsMapTest, NestedSettings) { 524 TEST_F(HostContentSettingsMapTest, NestedSettings) {
611 TestingProfile profile; 525 TestingProfile profile;
612 HostContentSettingsMap* host_content_settings_map = 526 HostContentSettingsMap* host_content_settings_map =
613 HostContentSettingsMapFactory::GetForProfile(&profile); 527 HostContentSettingsMapFactory::GetForProfile(&profile);
614 528
615 GURL host("http://a.b.example.com/"); 529 GURL host("http://a.b.example.com/");
616 ContentSettingsPattern pattern1 = 530 GURL host1("http://example.com/");
617 ContentSettingsPattern::FromString("[*.]example.com"); 531 GURL host2("http://b.example.com/");
618 ContentSettingsPattern pattern2 =
619 ContentSettingsPattern::FromString("[*.]b.example.com");
620 ContentSettingsPattern pattern3 =
621 ContentSettingsPattern::FromString("a.b.example.com");
622 532
623 host_content_settings_map->SetContentSetting( 533 host_content_settings_map->SetContentSettingDefaultScope(
624 pattern1, 534 host1, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
625 ContentSettingsPattern::Wildcard(),
626 CONTENT_SETTINGS_TYPE_IMAGES,
627 std::string(),
628 CONTENT_SETTING_BLOCK); 535 CONTENT_SETTING_BLOCK);
629 536
630 host_content_settings_map->SetContentSetting( 537 host_content_settings_map->SetContentSettingDefaultScope(
631 pattern2, 538 host2, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
632 ContentSettingsPattern::Wildcard(),
633 CONTENT_SETTINGS_TYPE_COOKIES,
634 std::string(),
635 CONTENT_SETTING_BLOCK); 539 CONTENT_SETTING_BLOCK);
636 540
637 host_content_settings_map->SetContentSetting( 541 host_content_settings_map->SetContentSettingDefaultScope(
638 pattern3, 542 host, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(),
639 ContentSettingsPattern::Wildcard(),
640 CONTENT_SETTINGS_TYPE_PLUGINS,
641 std::string(),
642 CONTENT_SETTING_BLOCK); 543 CONTENT_SETTING_BLOCK);
643 host_content_settings_map->SetDefaultContentSetting( 544 host_content_settings_map->SetDefaultContentSetting(
644 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); 545 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
645 546
646 EXPECT_EQ(CONTENT_SETTING_BLOCK, 547 EXPECT_EQ(CONTENT_SETTING_BLOCK,
647 host_content_settings_map->GetContentSetting( 548 host_content_settings_map->GetContentSetting(
648 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); 549 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
649 EXPECT_EQ(CONTENT_SETTING_BLOCK, 550 EXPECT_EQ(CONTENT_SETTING_BLOCK,
650 host_content_settings_map->GetContentSetting( 551 host_content_settings_map->GetContentSetting(
651 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 552 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
(...skipping 26 matching lines...) Expand all
678 579
679 TEST_F(HostContentSettingsMapTest, OffTheRecord) { 580 TEST_F(HostContentSettingsMapTest, OffTheRecord) {
680 TestingProfile profile; 581 TestingProfile profile;
681 Profile* otr_profile = profile.GetOffTheRecordProfile(); 582 Profile* otr_profile = profile.GetOffTheRecordProfile();
682 HostContentSettingsMap* host_content_settings_map = 583 HostContentSettingsMap* host_content_settings_map =
683 HostContentSettingsMapFactory::GetForProfile(&profile); 584 HostContentSettingsMapFactory::GetForProfile(&profile);
684 HostContentSettingsMap* otr_map = 585 HostContentSettingsMap* otr_map =
685 HostContentSettingsMapFactory::GetForProfile(otr_profile); 586 HostContentSettingsMapFactory::GetForProfile(otr_profile);
686 587
687 GURL host("http://example.com/"); 588 GURL host("http://example.com/");
688 ContentSettingsPattern pattern =
689 ContentSettingsPattern::FromString("[*.]example.com");
690 589
691 EXPECT_EQ(CONTENT_SETTING_ALLOW, 590 EXPECT_EQ(CONTENT_SETTING_ALLOW,
692 host_content_settings_map->GetContentSetting( 591 host_content_settings_map->GetContentSetting(
693 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 592 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
694 EXPECT_EQ(CONTENT_SETTING_ALLOW, 593 EXPECT_EQ(CONTENT_SETTING_ALLOW,
695 otr_map->GetContentSetting( 594 otr_map->GetContentSetting(
696 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 595 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
697 596
698 // Changing content settings on the main map should also affect the 597 // Changing content settings on the main map should also affect the
699 // incognito map. 598 // incognito map.
700 host_content_settings_map->SetContentSetting( 599 host_content_settings_map->SetContentSettingDefaultScope(
701 pattern, 600 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
702 ContentSettingsPattern::Wildcard(),
703 CONTENT_SETTINGS_TYPE_IMAGES,
704 std::string(),
705 CONTENT_SETTING_BLOCK); 601 CONTENT_SETTING_BLOCK);
706 EXPECT_EQ(CONTENT_SETTING_BLOCK, 602 EXPECT_EQ(CONTENT_SETTING_BLOCK,
707 host_content_settings_map->GetContentSetting( 603 host_content_settings_map->GetContentSetting(
708 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 604 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
709 EXPECT_EQ(CONTENT_SETTING_BLOCK, 605 EXPECT_EQ(CONTENT_SETTING_BLOCK,
710 otr_map->GetContentSetting( 606 otr_map->GetContentSetting(
711 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 607 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
712 608
713 // Changing content settings on the incognito map should NOT affect the 609 // Changing content settings on the incognito map should NOT affect the
714 // main map. 610 // main map.
715 otr_map->SetContentSetting(pattern, 611 otr_map->SetContentSettingDefaultScope(host, GURL(),
716 ContentSettingsPattern::Wildcard(), 612 CONTENT_SETTINGS_TYPE_IMAGES,
717 CONTENT_SETTINGS_TYPE_IMAGES, 613 std::string(), CONTENT_SETTING_ALLOW);
718 std::string(),
719 CONTENT_SETTING_ALLOW);
720 EXPECT_EQ(CONTENT_SETTING_BLOCK, 614 EXPECT_EQ(CONTENT_SETTING_BLOCK,
721 host_content_settings_map->GetContentSetting( 615 host_content_settings_map->GetContentSetting(
722 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 616 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
723 EXPECT_EQ(CONTENT_SETTING_ALLOW, 617 EXPECT_EQ(CONTENT_SETTING_ALLOW,
724 otr_map->GetContentSetting( 618 otr_map->GetContentSetting(
725 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 619 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
726 } 620 }
727 621
728 TEST_F(HostContentSettingsMapTest, OffTheRecordPartialInheritPref) { 622 TEST_F(HostContentSettingsMapTest, OffTheRecordPartialInheritPref) {
729 // Permissions marked INHERIT_IN_INCOGNITO_EXCEPT_ALLOW in 623 // Permissions marked INHERIT_IN_INCOGNITO_EXCEPT_ALLOW in
730 // ContentSettingsRegistry (e.g. push & notifications) only inherit BLOCK 624 // ContentSettingsRegistry (e.g. push & notifications) only inherit BLOCK
731 // settings from regular to incognito. 625 // settings from regular to incognito.
732 TestingProfile profile; 626 TestingProfile profile;
733 Profile* otr_profile = profile.GetOffTheRecordProfile(); 627 Profile* otr_profile = profile.GetOffTheRecordProfile();
734 HostContentSettingsMap* host_content_settings_map = 628 HostContentSettingsMap* host_content_settings_map =
735 HostContentSettingsMapFactory::GetForProfile(&profile); 629 HostContentSettingsMapFactory::GetForProfile(&profile);
736 HostContentSettingsMap* otr_map = 630 HostContentSettingsMap* otr_map =
737 HostContentSettingsMapFactory::GetForProfile(otr_profile); 631 HostContentSettingsMapFactory::GetForProfile(otr_profile);
738 632
739 GURL host("http://example.com/"); 633 GURL host("http://example.com/");
740 ContentSettingsPattern pattern =
741 ContentSettingsPattern::FromURLNoWildcard(host);
742 634
743 EXPECT_EQ( 635 EXPECT_EQ(
744 CONTENT_SETTING_ASK, 636 CONTENT_SETTING_ASK,
745 host_content_settings_map->GetContentSetting( 637 host_content_settings_map->GetContentSetting(
746 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); 638 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
747 EXPECT_EQ( 639 EXPECT_EQ(
748 CONTENT_SETTING_ASK, 640 CONTENT_SETTING_ASK,
749 otr_map->GetContentSetting( 641 otr_map->GetContentSetting(
750 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); 642 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
751 643
752 // BLOCK should be inherited from the main map to the incognito map. 644 // BLOCK should be inherited from the main map to the incognito map.
753 host_content_settings_map->SetContentSetting( 645 host_content_settings_map->SetContentSettingDefaultScope(
754 pattern, 646 host, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(),
755 ContentSettingsPattern::Wildcard(),
756 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
757 std::string(),
758 CONTENT_SETTING_BLOCK); 647 CONTENT_SETTING_BLOCK);
759 EXPECT_EQ( 648 EXPECT_EQ(
760 CONTENT_SETTING_BLOCK, 649 CONTENT_SETTING_BLOCK,
761 host_content_settings_map->GetContentSetting( 650 host_content_settings_map->GetContentSetting(
762 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); 651 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
763 EXPECT_EQ( 652 EXPECT_EQ(
764 CONTENT_SETTING_BLOCK, 653 CONTENT_SETTING_BLOCK,
765 otr_map->GetContentSetting( 654 otr_map->GetContentSetting(
766 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); 655 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
767 656
768 // ALLOW should not be inherited from the main map to the incognito map (but 657 // ALLOW should not be inherited from the main map to the incognito map (but
769 // it still overwrites the BLOCK, hence incognito reverts to ASK). 658 // it still overwrites the BLOCK, hence incognito reverts to ASK).
770 host_content_settings_map->SetContentSetting( 659 host_content_settings_map->SetContentSettingDefaultScope(
771 pattern, 660 host, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(),
772 ContentSettingsPattern::Wildcard(),
773 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
774 std::string(),
775 CONTENT_SETTING_ALLOW); 661 CONTENT_SETTING_ALLOW);
776 EXPECT_EQ( 662 EXPECT_EQ(
777 CONTENT_SETTING_ALLOW, 663 CONTENT_SETTING_ALLOW,
778 host_content_settings_map->GetContentSetting( 664 host_content_settings_map->GetContentSetting(
779 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); 665 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
780 EXPECT_EQ( 666 EXPECT_EQ(
781 CONTENT_SETTING_ASK, 667 CONTENT_SETTING_ASK,
782 otr_map->GetContentSetting( 668 otr_map->GetContentSetting(
783 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); 669 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
784 } 670 }
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 } 890 }
1005 891
1006 TEST_F(HostContentSettingsMapTest, 892 TEST_F(HostContentSettingsMapTest,
1007 GetNonDefaultContentSettingsIfTypeManaged) { 893 GetNonDefaultContentSettingsIfTypeManaged) {
1008 TestingProfile profile; 894 TestingProfile profile;
1009 HostContentSettingsMap* host_content_settings_map = 895 HostContentSettingsMap* host_content_settings_map =
1010 HostContentSettingsMapFactory::GetForProfile(&profile); 896 HostContentSettingsMapFactory::GetForProfile(&profile);
1011 syncable_prefs::TestingPrefServiceSyncable* prefs = 897 syncable_prefs::TestingPrefServiceSyncable* prefs =
1012 profile.GetTestingPrefService(); 898 profile.GetTestingPrefService();
1013 899
1014 // Set pattern for JavaScript setting. 900 // Set url for JavaScript setting.
1015 ContentSettingsPattern pattern = 901 GURL host("http://example.com/");
1016 ContentSettingsPattern::FromString("[*.]example.com"); 902 host_content_settings_map->SetContentSettingDefaultScope(
1017 host_content_settings_map->SetContentSetting( 903 host, GURL(), CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(),
1018 pattern,
1019 ContentSettingsPattern::Wildcard(),
1020 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
1021 std::string(),
1022 CONTENT_SETTING_BLOCK); 904 CONTENT_SETTING_BLOCK);
1023 905
1024 EXPECT_EQ(CONTENT_SETTING_ALLOW, 906 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1025 host_content_settings_map->GetDefaultContentSetting( 907 host_content_settings_map->GetDefaultContentSetting(
1026 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); 908 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
1027 909
1028 GURL host("http://example.com/");
1029 EXPECT_EQ(CONTENT_SETTING_BLOCK, 910 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1030 host_content_settings_map->GetContentSetting( 911 host_content_settings_map->GetContentSetting(
1031 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 912 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
1032 913
1033 // Set managed-default-content-setting for content-settings-type JavaScript. 914 // Set managed-default-content-setting for content-settings-type JavaScript.
1034 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, 915 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
1035 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 916 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
1036 EXPECT_EQ(CONTENT_SETTING_ALLOW, 917 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1037 host_content_settings_map->GetContentSetting( 918 host_content_settings_map->GetContentSetting(
1038 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 919 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
1039 } 920 }
1040 921
1041 // Managed default content setting should have higher priority 922 // Managed default content setting should have higher priority
1042 // than user defined patterns. 923 // than user defined patterns.
1043 TEST_F(HostContentSettingsMapTest, 924 TEST_F(HostContentSettingsMapTest,
1044 ManagedDefaultContentSettingIgnoreUserPattern) { 925 ManagedDefaultContentSettingIgnoreUserPattern) {
1045 TestingProfile profile; 926 TestingProfile profile;
1046 HostContentSettingsMap* host_content_settings_map = 927 HostContentSettingsMap* host_content_settings_map =
1047 HostContentSettingsMapFactory::GetForProfile(&profile); 928 HostContentSettingsMapFactory::GetForProfile(&profile);
1048 syncable_prefs::TestingPrefServiceSyncable* prefs = 929 syncable_prefs::TestingPrefServiceSyncable* prefs =
1049 profile.GetTestingPrefService(); 930 profile.GetTestingPrefService();
1050 931
1051 // Block all JavaScript. 932 // Block all JavaScript.
1052 host_content_settings_map->SetDefaultContentSetting( 933 host_content_settings_map->SetDefaultContentSetting(
1053 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); 934 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
1054 935
1055 // Set an exception to allow "[*.]example.com" 936 // Set an exception to allow "[*.]example.com"
1056 ContentSettingsPattern pattern = 937 GURL host("http://example.com/");
1057 ContentSettingsPattern::FromString("[*.]example.com");
1058 938
1059 host_content_settings_map->SetContentSetting( 939 host_content_settings_map->SetContentSettingDefaultScope(
1060 pattern, 940 host, GURL(), CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(),
1061 ContentSettingsPattern::Wildcard(),
1062 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
1063 std::string(),
1064 CONTENT_SETTING_ALLOW); 941 CONTENT_SETTING_ALLOW);
1065 942
1066 EXPECT_EQ(CONTENT_SETTING_BLOCK, 943 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1067 host_content_settings_map->GetDefaultContentSetting( 944 host_content_settings_map->GetDefaultContentSetting(
1068 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); 945 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
1069 GURL host("http://example.com/"); 946
1070 EXPECT_EQ(CONTENT_SETTING_ALLOW, 947 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1071 host_content_settings_map->GetContentSetting( 948 host_content_settings_map->GetContentSetting(
1072 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 949 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
1073 950
1074 // Set managed-default-content-settings-preferences. 951 // Set managed-default-content-settings-preferences.
1075 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, 952 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
1076 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 953 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
1077 EXPECT_EQ(CONTENT_SETTING_BLOCK, 954 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1078 host_content_settings_map->GetContentSetting( 955 host_content_settings_map->GetContentSetting(
1079 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 956 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 1020 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
1144 } 1021 }
1145 1022
1146 TEST_F(HostContentSettingsMapTest, GetContentSetting) { 1023 TEST_F(HostContentSettingsMapTest, GetContentSetting) {
1147 TestingProfile profile; 1024 TestingProfile profile;
1148 HostContentSettingsMap* host_content_settings_map = 1025 HostContentSettingsMap* host_content_settings_map =
1149 HostContentSettingsMapFactory::GetForProfile(&profile); 1026 HostContentSettingsMapFactory::GetForProfile(&profile);
1150 1027
1151 GURL host("http://example.com/"); 1028 GURL host("http://example.com/");
1152 GURL embedder("chrome://foo"); 1029 GURL embedder("chrome://foo");
1153 ContentSettingsPattern pattern = 1030 host_content_settings_map->SetContentSettingDefaultScope(
1154 ContentSettingsPattern::FromString("[*.]example.com"); 1031 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
1155 host_content_settings_map->SetContentSetting(
1156 pattern,
1157 ContentSettingsPattern::Wildcard(),
1158 CONTENT_SETTINGS_TYPE_IMAGES,
1159 std::string(),
1160 CONTENT_SETTING_BLOCK); 1032 CONTENT_SETTING_BLOCK);
1161 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1033 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1162 host_content_settings_map->GetContentSetting( 1034 host_content_settings_map->GetContentSetting(
1163 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1035 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1164 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1036 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1165 host_content_settings_map->GetContentSetting( 1037 host_content_settings_map->GetContentSetting(
1166 embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1038 embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1167 } 1039 }
1168 1040
1169 TEST_F(HostContentSettingsMapTest, IsDefaultSettingAllowedForType) { 1041 TEST_F(HostContentSettingsMapTest, IsDefaultSettingAllowedForType) {
(...skipping 16 matching lines...) Expand all
1186 OnContentSettingChanged(pattern, 1058 OnContentSettingChanged(pattern,
1187 ContentSettingsPattern::Wildcard(), 1059 ContentSettingsPattern::Wildcard(),
1188 CONTENT_SETTINGS_TYPE_IMAGES, 1060 CONTENT_SETTINGS_TYPE_IMAGES,
1189 "")); 1061 ""));
1190 1062
1191 host_content_settings_map->AddObserver(&mock_observer); 1063 host_content_settings_map->AddObserver(&mock_observer);
1192 1064
1193 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1065 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1194 host_content_settings_map->GetContentSetting( 1066 host_content_settings_map->GetContentSetting(
1195 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1067 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1196 host_content_settings_map->SetContentSetting( 1068 host_content_settings_map->SetContentSettingDefaultScope(
1197 pattern, 1069 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
1198 ContentSettingsPattern::Wildcard(),
1199 CONTENT_SETTINGS_TYPE_IMAGES,
1200 std::string(),
1201 CONTENT_SETTING_DEFAULT); 1070 CONTENT_SETTING_DEFAULT);
1202 } 1071 }
1203 1072
1204 TEST_F(HostContentSettingsMapTest, GuestProfile) { 1073 TEST_F(HostContentSettingsMapTest, GuestProfile) {
1205 TestingProfile profile; 1074 TestingProfile profile;
1206 profile.SetGuestSession(true); 1075 profile.SetGuestSession(true);
1207 HostContentSettingsMap* host_content_settings_map = 1076 HostContentSettingsMap* host_content_settings_map =
1208 HostContentSettingsMapFactory::GetForProfile(&profile); 1077 HostContentSettingsMapFactory::GetForProfile(&profile);
1209 1078
1210 GURL host("http://example.com/"); 1079 GURL host("http://example.com/");
1211 ContentSettingsPattern pattern = 1080 ContentSettingsPattern pattern =
1212 ContentSettingsPattern::FromString("[*.]example.com"); 1081 ContentSettingsPattern::FromString("[*.]example.com");
1213 1082
1214 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1083 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1215 host_content_settings_map->GetContentSetting( 1084 host_content_settings_map->GetContentSetting(
1216 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1085 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1217 1086
1218 // Changing content settings should not result in any prefs being stored 1087 // Changing content settings should not result in any prefs being stored
1219 // however the value should be set in memory. 1088 // however the value should be set in memory.
1220 host_content_settings_map->SetContentSetting( 1089 host_content_settings_map->SetContentSettingDefaultScope(
1221 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_IMAGES, 1090 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
1222 std::string(), CONTENT_SETTING_BLOCK); 1091 CONTENT_SETTING_BLOCK);
1223 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1092 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1224 host_content_settings_map->GetContentSetting( 1093 host_content_settings_map->GetContentSetting(
1225 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1094 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1226 1095
1227 const base::DictionaryValue* all_settings_dictionary = 1096 const base::DictionaryValue* all_settings_dictionary =
1228 profile.GetPrefs()->GetDictionary( 1097 profile.GetPrefs()->GetDictionary(
1229 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)); 1098 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES));
1230 EXPECT_TRUE(all_settings_dictionary->empty()); 1099 EXPECT_TRUE(all_settings_dictionary->empty());
1231 } 1100 }
1232 1101
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *value); 1134 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *value);
1266 1135
1267 // Test that during construction all the prefs get cleared. 1136 // Test that during construction all the prefs get cleared.
1268 HostContentSettingsMapFactory::GetForProfile(&profile); 1137 HostContentSettingsMapFactory::GetForProfile(&profile);
1269 1138
1270 const base::DictionaryValue* all_settings_dictionary = 1139 const base::DictionaryValue* all_settings_dictionary =
1271 profile.GetPrefs()->GetDictionary( 1140 profile.GetPrefs()->GetDictionary(
1272 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)); 1141 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES));
1273 EXPECT_TRUE(all_settings_dictionary->empty()); 1142 EXPECT_TRUE(all_settings_dictionary->empty());
1274 } 1143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698