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
3 // found in the LICENSE file.
5 #include "base/auto_reset.h"
6 #include "base/command_line.h"
7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_service.h"
11 #include "base/prefs/scoped_user_pref_update.h"
12 #include "chrome/browser/content_settings/content_settings_details.h"
13 #include "chrome/browser/content_settings/cookie_settings.h"
14 #include "chrome/browser/content_settings/host_content_settings_map.h"
15 #include "chrome/browser/content_settings/mock_settings_observer.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/pref_names.h"
18 #include "chrome/common/url_constants.h"
19 #include "chrome/test/base/testing_pref_service_syncable.h"
20 #include "chrome/test/base/testing_profile.h"
21 #include "content/public/test/test_browser_thread.h"
22 #include "net/base/static_cookie_policy.h"
23 #include "testing/gtest/include/gtest/gtest.h"
26 using content::BrowserThread;
30 class HostContentSettingsMapTest : public testing::Test {
32 HostContentSettingsMapTest() : ui_thread_(BrowserThread::UI, &message_loop_) {
36 base::MessageLoop message_loop_;
37 content::TestBrowserThread ui_thread_;
40 TEST_F(HostContentSettingsMapTest, DefaultValues) {
41 TestingProfile profile;
42 HostContentSettingsMap* host_content_settings_map =
43 profile.GetHostContentSettingsMap();
45 // Check setting defaults.
46 EXPECT_EQ(CONTENT_SETTING_ALLOW,
47 host_content_settings_map->GetDefaultContentSetting(
48 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
49 host_content_settings_map->SetDefaultContentSetting(
50 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
51 EXPECT_EQ(CONTENT_SETTING_BLOCK,
52 host_content_settings_map->GetDefaultContentSetting(
53 CONTENT_SETTINGS_TYPE_IMAGES, NULL));
54 EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting(
55 GURL(chrome::kChromeUINewTabURL),
56 GURL(chrome::kChromeUINewTabURL),
57 CONTENT_SETTINGS_TYPE_IMAGES,
60 host_content_settings_map->SetDefaultContentSetting(
61 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ASK);
62 EXPECT_EQ(CONTENT_SETTING_ASK,
63 host_content_settings_map->GetDefaultContentSetting(
64 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
66 host_content_settings_map->SetDefaultContentSetting(
67 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_ALLOW);
68 EXPECT_EQ(CONTENT_SETTING_ALLOW,
69 host_content_settings_map->GetDefaultContentSetting(
70 CONTENT_SETTINGS_TYPE_POPUPS, NULL));
73 TEST_F(HostContentSettingsMapTest, IndividualSettings) {
74 TestingProfile profile;
75 HostContentSettingsMap* host_content_settings_map =
76 profile.GetHostContentSettingsMap();
78 // Check returning individual settings.
79 GURL host("http://example.com/");
80 ContentSettingsPattern pattern =
81 ContentSettingsPattern::FromString("[*.]example.com");
82 EXPECT_EQ(CONTENT_SETTING_ALLOW,
83 host_content_settings_map->GetContentSetting(
84 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
85 host_content_settings_map->SetContentSetting(
87 ContentSettingsPattern::Wildcard(),
88 CONTENT_SETTINGS_TYPE_IMAGES,
90 CONTENT_SETTING_DEFAULT);
91 EXPECT_EQ(CONTENT_SETTING_ALLOW,
92 host_content_settings_map->GetContentSetting(
93 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
94 host_content_settings_map->SetContentSetting(
96 ContentSettingsPattern::Wildcard(),
97 CONTENT_SETTINGS_TYPE_IMAGES,
99 CONTENT_SETTING_BLOCK);
100 EXPECT_EQ(CONTENT_SETTING_BLOCK,
101 host_content_settings_map->GetContentSetting(
102 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
103 EXPECT_EQ(CONTENT_SETTING_ALLOW,
104 host_content_settings_map->GetContentSetting(
105 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
107 // Check returning all settings for a host.
108 host_content_settings_map->SetContentSetting(
110 ContentSettingsPattern::Wildcard(),
111 CONTENT_SETTINGS_TYPE_IMAGES,
113 CONTENT_SETTING_DEFAULT);
114 EXPECT_EQ(CONTENT_SETTING_ALLOW,
115 host_content_settings_map->GetContentSetting(
116 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
117 host_content_settings_map->SetContentSetting(
119 ContentSettingsPattern::Wildcard(),
120 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
122 CONTENT_SETTING_BLOCK);
123 EXPECT_EQ(CONTENT_SETTING_BLOCK,
124 host_content_settings_map->GetContentSetting(
125 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
126 host_content_settings_map->SetContentSetting(
128 ContentSettingsPattern::Wildcard(),
129 CONTENT_SETTINGS_TYPE_PLUGINS,
131 CONTENT_SETTING_ALLOW);
132 EXPECT_EQ(CONTENT_SETTING_ALLOW,
133 host_content_settings_map->GetContentSetting(
134 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
135 EXPECT_EQ(CONTENT_SETTING_BLOCK,
136 host_content_settings_map->GetContentSetting(
137 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
138 EXPECT_EQ(CONTENT_SETTING_ASK,
139 host_content_settings_map->GetContentSetting(
140 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
143 host_content_settings_map->GetContentSetting(
144 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
145 EXPECT_EQ(CONTENT_SETTING_ASK,
146 host_content_settings_map->GetContentSetting(
147 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()));
148 EXPECT_EQ(CONTENT_SETTING_ASK,
149 host_content_settings_map->GetContentSetting(
150 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()));
152 // Check returning all hosts for a setting.
153 ContentSettingsPattern pattern2 =
154 ContentSettingsPattern::FromString("[*.]example.org");
155 host_content_settings_map->SetContentSetting(
157 ContentSettingsPattern::Wildcard(),
158 CONTENT_SETTINGS_TYPE_IMAGES,
160 CONTENT_SETTING_BLOCK);
161 host_content_settings_map->SetContentSetting(
163 ContentSettingsPattern::Wildcard(),
164 CONTENT_SETTINGS_TYPE_PLUGINS,
166 CONTENT_SETTING_BLOCK);
167 ContentSettingsForOneType host_settings;
168 host_content_settings_map->GetSettingsForOneType(
169 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings);
170 // |host_settings| contains the default setting and an exception.
171 EXPECT_EQ(2U, host_settings.size());
172 host_content_settings_map->GetSettingsForOneType(
173 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings);
174 // |host_settings| contains the default setting and 2 exceptions.
175 EXPECT_EQ(3U, host_settings.size());
176 host_content_settings_map->GetSettingsForOneType(
177 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings);
178 // |host_settings| contains only the default setting.
179 EXPECT_EQ(1U, host_settings.size());
182 TEST_F(HostContentSettingsMapTest, Clear) {
183 TestingProfile profile;
184 HostContentSettingsMap* host_content_settings_map =
185 profile.GetHostContentSettingsMap();
187 // Check clearing one type.
188 ContentSettingsPattern pattern =
189 ContentSettingsPattern::FromString("[*.]example.org");
190 ContentSettingsPattern pattern2 =
191 ContentSettingsPattern::FromString("[*.]example.net");
192 host_content_settings_map->SetContentSetting(
194 ContentSettingsPattern::Wildcard(),
195 CONTENT_SETTINGS_TYPE_IMAGES,
197 CONTENT_SETTING_BLOCK);
198 host_content_settings_map->SetContentSetting(
200 ContentSettingsPattern::Wildcard(),
201 CONTENT_SETTINGS_TYPE_IMAGES,
203 CONTENT_SETTING_BLOCK);
204 host_content_settings_map->SetContentSetting(
206 ContentSettingsPattern::Wildcard(),
207 CONTENT_SETTINGS_TYPE_PLUGINS,
209 CONTENT_SETTING_BLOCK);
210 host_content_settings_map->SetContentSetting(
212 ContentSettingsPattern::Wildcard(),
213 CONTENT_SETTINGS_TYPE_IMAGES,
215 CONTENT_SETTING_BLOCK);
216 host_content_settings_map->ClearSettingsForOneType(
217 CONTENT_SETTINGS_TYPE_IMAGES);
218 ContentSettingsForOneType host_settings;
219 host_content_settings_map->GetSettingsForOneType(
220 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings);
221 // |host_settings| contains only the default setting.
222 EXPECT_EQ(1U, host_settings.size());
223 host_content_settings_map->GetSettingsForOneType(
224 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings);
225 // |host_settings| contains the default setting and an exception.
226 EXPECT_EQ(2U, host_settings.size());
229 TEST_F(HostContentSettingsMapTest, Patterns) {
230 TestingProfile profile;
231 HostContentSettingsMap* host_content_settings_map =
232 profile.GetHostContentSettingsMap();
234 GURL host1("http://example.com/");
235 GURL host2("http://www.example.com/");
236 GURL host3("http://example.org/");
237 ContentSettingsPattern pattern1 =
238 ContentSettingsPattern::FromString("[*.]example.com");
239 ContentSettingsPattern pattern2 =
240 ContentSettingsPattern::FromString("example.org");
241 EXPECT_EQ(CONTENT_SETTING_ALLOW,
242 host_content_settings_map->GetContentSetting(
243 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
244 host_content_settings_map->SetContentSetting(
246 ContentSettingsPattern::Wildcard(),
247 CONTENT_SETTINGS_TYPE_IMAGES,
249 CONTENT_SETTING_BLOCK);
250 EXPECT_EQ(CONTENT_SETTING_BLOCK,
251 host_content_settings_map->GetContentSetting(
252 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
253 EXPECT_EQ(CONTENT_SETTING_BLOCK,
254 host_content_settings_map->GetContentSetting(
255 host2, host2, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
256 EXPECT_EQ(CONTENT_SETTING_ALLOW,
257 host_content_settings_map->GetContentSetting(
258 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
259 host_content_settings_map->SetContentSetting(
261 ContentSettingsPattern::Wildcard(),
262 CONTENT_SETTINGS_TYPE_IMAGES,
264 CONTENT_SETTING_BLOCK);
265 EXPECT_EQ(CONTENT_SETTING_BLOCK,
266 host_content_settings_map->GetContentSetting(
267 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
270 TEST_F(HostContentSettingsMapTest, Observer) {
271 TestingProfile profile;
272 HostContentSettingsMap* host_content_settings_map =
273 profile.GetHostContentSettingsMap();
274 MockSettingsObserver observer;
276 ContentSettingsPattern primary_pattern =
277 ContentSettingsPattern::FromString("[*.]example.com");
278 ContentSettingsPattern secondary_pattern =
279 ContentSettingsPattern::Wildcard();
280 EXPECT_CALL(observer,
281 OnContentSettingsChanged(host_content_settings_map,
282 CONTENT_SETTINGS_TYPE_IMAGES,
287 host_content_settings_map->SetContentSetting(
290 CONTENT_SETTINGS_TYPE_IMAGES,
292 CONTENT_SETTING_ALLOW);
293 ::testing::Mock::VerifyAndClearExpectations(&observer);
295 EXPECT_CALL(observer,
296 OnContentSettingsChanged(host_content_settings_map,
297 CONTENT_SETTINGS_TYPE_IMAGES, false,
299 host_content_settings_map->ClearSettingsForOneType(
300 CONTENT_SETTINGS_TYPE_IMAGES);
301 ::testing::Mock::VerifyAndClearExpectations(&observer);
303 EXPECT_CALL(observer,
304 OnContentSettingsChanged(host_content_settings_map,
305 CONTENT_SETTINGS_TYPE_IMAGES, false,
307 host_content_settings_map->SetDefaultContentSetting(
308 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
311 TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) {
312 TestingProfile profile;
313 HostContentSettingsMap* host_content_settings_map =
314 profile.GetHostContentSettingsMap();
316 PrefService* prefs = profile.GetPrefs();
318 // Make a copy of the default pref value so we can reset it later.
319 scoped_ptr<Value> default_value(prefs->FindPreference(
320 prefs::kDefaultContentSettings)->GetValue()->DeepCopy());
322 GURL host("http://example.com");
324 host_content_settings_map->SetDefaultContentSetting(
325 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
326 EXPECT_EQ(CONTENT_SETTING_BLOCK,
327 host_content_settings_map->GetContentSetting(
328 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
330 // Make a copy of the pref's new value so we can reset it later.
331 scoped_ptr<Value> new_value(prefs->FindPreference(
332 prefs::kDefaultContentSettings)->GetValue()->DeepCopy());
334 // Clearing the backing pref should also clear the internal cache.
335 prefs->Set(prefs::kDefaultContentSettings, *default_value);
336 EXPECT_EQ(CONTENT_SETTING_ALLOW,
337 host_content_settings_map->GetContentSetting(
338 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
340 // Reseting the pref to its previous value should update the cache.
341 prefs->Set(prefs::kDefaultContentSettings, *new_value);
342 EXPECT_EQ(CONTENT_SETTING_BLOCK,
343 host_content_settings_map->GetContentSetting(
344 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
347 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) {
348 TestingProfile profile;
349 HostContentSettingsMap* host_content_settings_map =
350 profile.GetHostContentSettingsMap();
352 PrefService* prefs = profile.GetPrefs();
354 // Make a copy of the default pref value so we can reset it later.
355 scoped_ptr<Value> default_value(prefs->FindPreference(
356 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy());
358 ContentSettingsPattern pattern =
359 ContentSettingsPattern::FromString("[*.]example.com");
360 GURL host("http://example.com");
362 EXPECT_EQ(CONTENT_SETTING_ALLOW,
363 host_content_settings_map->GetContentSetting(
364 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
366 host_content_settings_map->SetContentSetting(
368 ContentSettingsPattern::Wildcard(),
369 CONTENT_SETTINGS_TYPE_IMAGES,
371 CONTENT_SETTING_BLOCK);
372 EXPECT_EQ(CONTENT_SETTING_BLOCK,
373 host_content_settings_map->GetContentSetting(
374 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
376 // Make a copy of the pref's new value so we can reset it later.
377 scoped_ptr<Value> new_value(prefs->FindPreference(
378 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy());
380 // Clearing the backing pref should also clear the internal cache.
381 prefs->Set(prefs::kContentSettingsPatternPairs, *default_value);
382 EXPECT_EQ(CONTENT_SETTING_ALLOW,
383 host_content_settings_map->GetContentSetting(
384 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
386 // Reseting the pref to its previous value should update the cache.
387 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value);
388 EXPECT_EQ(CONTENT_SETTING_BLOCK,
389 host_content_settings_map->GetContentSetting(
390 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
393 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) {
394 TestingProfile profile;
395 HostContentSettingsMap* host_content_settings_map =
396 profile.GetHostContentSettingsMap();
397 CookieSettings* cookie_settings =
398 CookieSettings::Factory::GetForProfile(&profile).get();
400 ContentSettingsPattern pattern =
401 ContentSettingsPattern::FromString("[*.]example.com");
402 GURL host_ending_with_dot("http://example.com./");
404 EXPECT_EQ(CONTENT_SETTING_ALLOW,
405 host_content_settings_map->GetContentSetting(
406 host_ending_with_dot,
407 host_ending_with_dot,
408 CONTENT_SETTINGS_TYPE_IMAGES,
410 host_content_settings_map->SetContentSetting(
412 ContentSettingsPattern::Wildcard(),
413 CONTENT_SETTINGS_TYPE_IMAGES,
415 CONTENT_SETTING_DEFAULT);
417 CONTENT_SETTING_ALLOW,
418 host_content_settings_map->GetContentSetting(host_ending_with_dot,
419 host_ending_with_dot,
420 CONTENT_SETTINGS_TYPE_IMAGES,
422 host_content_settings_map->SetContentSetting(
424 ContentSettingsPattern::Wildcard(),
425 CONTENT_SETTINGS_TYPE_IMAGES,
427 CONTENT_SETTING_BLOCK);
429 CONTENT_SETTING_BLOCK,
430 host_content_settings_map->GetContentSetting(host_ending_with_dot,
431 host_ending_with_dot,
432 CONTENT_SETTINGS_TYPE_IMAGES,
435 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
436 host_ending_with_dot, host_ending_with_dot));
437 host_content_settings_map->SetContentSetting(
439 ContentSettingsPattern::Wildcard(),
440 CONTENT_SETTINGS_TYPE_COOKIES,
442 CONTENT_SETTING_DEFAULT);
443 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
444 host_ending_with_dot, host_ending_with_dot));
445 host_content_settings_map->SetContentSetting(
447 ContentSettingsPattern::Wildcard(),
448 CONTENT_SETTINGS_TYPE_COOKIES,
450 CONTENT_SETTING_BLOCK);
451 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed(
452 host_ending_with_dot, host_ending_with_dot));
454 EXPECT_EQ(CONTENT_SETTING_ALLOW,
455 host_content_settings_map->GetContentSetting(
456 host_ending_with_dot,
457 host_ending_with_dot,
458 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
460 host_content_settings_map->SetContentSetting(
462 ContentSettingsPattern::Wildcard(),
463 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
465 CONTENT_SETTING_DEFAULT);
466 EXPECT_EQ(CONTENT_SETTING_ALLOW,
467 host_content_settings_map->GetContentSetting(
468 host_ending_with_dot,
469 host_ending_with_dot,
470 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
472 host_content_settings_map->SetContentSetting(
474 ContentSettingsPattern::Wildcard(),
475 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
477 CONTENT_SETTING_BLOCK);
478 EXPECT_EQ(CONTENT_SETTING_BLOCK,
479 host_content_settings_map->GetContentSetting(
480 host_ending_with_dot,
481 host_ending_with_dot,
482 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
485 EXPECT_EQ(CONTENT_SETTING_ALLOW,
486 host_content_settings_map->GetContentSetting(
487 host_ending_with_dot,
488 host_ending_with_dot,
489 CONTENT_SETTINGS_TYPE_PLUGINS,
491 host_content_settings_map->SetContentSetting(
493 ContentSettingsPattern::Wildcard(),
494 CONTENT_SETTINGS_TYPE_PLUGINS,
496 CONTENT_SETTING_DEFAULT);
497 EXPECT_EQ(CONTENT_SETTING_ALLOW,
498 host_content_settings_map->GetContentSetting(
499 host_ending_with_dot,
500 host_ending_with_dot,
501 CONTENT_SETTINGS_TYPE_PLUGINS,
503 host_content_settings_map->SetContentSetting(
505 ContentSettingsPattern::Wildcard(),
506 CONTENT_SETTINGS_TYPE_PLUGINS,
508 CONTENT_SETTING_BLOCK);
509 EXPECT_EQ(CONTENT_SETTING_BLOCK,
510 host_content_settings_map->GetContentSetting(
511 host_ending_with_dot,
512 host_ending_with_dot,
513 CONTENT_SETTINGS_TYPE_PLUGINS,
517 CONTENT_SETTING_BLOCK,
518 host_content_settings_map->GetContentSetting(host_ending_with_dot,
519 host_ending_with_dot,
520 CONTENT_SETTINGS_TYPE_POPUPS,
522 host_content_settings_map->SetContentSetting(
524 ContentSettingsPattern::Wildcard(),
525 CONTENT_SETTINGS_TYPE_POPUPS,
527 CONTENT_SETTING_DEFAULT);
529 CONTENT_SETTING_BLOCK,
530 host_content_settings_map->GetContentSetting(host_ending_with_dot,
531 host_ending_with_dot,
532 CONTENT_SETTINGS_TYPE_POPUPS,
534 host_content_settings_map->SetContentSetting(
536 ContentSettingsPattern::Wildcard(),
537 CONTENT_SETTINGS_TYPE_POPUPS,
539 CONTENT_SETTING_ALLOW);
541 CONTENT_SETTING_ALLOW,
542 host_content_settings_map->GetContentSetting(host_ending_with_dot,
543 host_ending_with_dot,
544 CONTENT_SETTINGS_TYPE_POPUPS,
548 TEST_F(HostContentSettingsMapTest, NestedSettings) {
549 TestingProfile profile;
550 HostContentSettingsMap* host_content_settings_map =
551 profile.GetHostContentSettingsMap();
553 GURL host("http://a.b.example.com/");
554 ContentSettingsPattern pattern1 =
555 ContentSettingsPattern::FromString("[*.]example.com");
556 ContentSettingsPattern pattern2 =
557 ContentSettingsPattern::FromString("[*.]b.example.com");
558 ContentSettingsPattern pattern3 =
559 ContentSettingsPattern::FromString("a.b.example.com");
561 host_content_settings_map->SetContentSetting(
563 ContentSettingsPattern::Wildcard(),
564 CONTENT_SETTINGS_TYPE_IMAGES,
566 CONTENT_SETTING_BLOCK);
568 host_content_settings_map->SetContentSetting(
570 ContentSettingsPattern::Wildcard(),
571 CONTENT_SETTINGS_TYPE_COOKIES,
573 CONTENT_SETTING_BLOCK);
575 host_content_settings_map->SetContentSetting(
577 ContentSettingsPattern::Wildcard(),
578 CONTENT_SETTINGS_TYPE_PLUGINS,
580 CONTENT_SETTING_BLOCK);
581 host_content_settings_map->SetDefaultContentSetting(
582 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
584 EXPECT_EQ(CONTENT_SETTING_BLOCK,
585 host_content_settings_map->GetContentSetting(
586 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
587 EXPECT_EQ(CONTENT_SETTING_BLOCK,
588 host_content_settings_map->GetContentSetting(
589 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
590 EXPECT_EQ(CONTENT_SETTING_BLOCK,
591 host_content_settings_map->GetContentSetting(
592 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
593 EXPECT_EQ(CONTENT_SETTING_BLOCK,
594 host_content_settings_map->GetContentSetting(
595 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
596 EXPECT_EQ(CONTENT_SETTING_BLOCK,
597 host_content_settings_map->GetContentSetting(
598 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
599 EXPECT_EQ(CONTENT_SETTING_ASK,
600 host_content_settings_map->GetContentSetting(
601 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
604 host_content_settings_map->GetContentSetting(
605 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
606 EXPECT_EQ(CONTENT_SETTING_ASK,
607 host_content_settings_map->GetContentSetting(
608 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()));
609 EXPECT_EQ(CONTENT_SETTING_ASK,
610 host_content_settings_map->GetContentSetting(
611 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()));
614 TEST_F(HostContentSettingsMapTest, OffTheRecord) {
615 TestingProfile profile;
616 HostContentSettingsMap* host_content_settings_map =
617 profile.GetHostContentSettingsMap();
618 scoped_refptr<HostContentSettingsMap> otr_map(
619 new HostContentSettingsMap(profile.GetPrefs(),
622 GURL host("http://example.com/");
623 ContentSettingsPattern pattern =
624 ContentSettingsPattern::FromString("[*.]example.com");
626 EXPECT_EQ(CONTENT_SETTING_ALLOW,
627 host_content_settings_map->GetContentSetting(
628 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
629 EXPECT_EQ(CONTENT_SETTING_ALLOW,
630 otr_map->GetContentSetting(
631 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
633 // Changing content settings on the main map should also affect the
635 host_content_settings_map->SetContentSetting(
637 ContentSettingsPattern::Wildcard(),
638 CONTENT_SETTINGS_TYPE_IMAGES,
640 CONTENT_SETTING_BLOCK);
641 EXPECT_EQ(CONTENT_SETTING_BLOCK,
642 host_content_settings_map->GetContentSetting(
643 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
644 EXPECT_EQ(CONTENT_SETTING_BLOCK,
645 otr_map->GetContentSetting(
646 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
648 // Changing content settings on the incognito map should NOT affect the
650 otr_map->SetContentSetting(pattern,
651 ContentSettingsPattern::Wildcard(),
652 CONTENT_SETTINGS_TYPE_IMAGES,
654 CONTENT_SETTING_ALLOW);
655 EXPECT_EQ(CONTENT_SETTING_BLOCK,
656 host_content_settings_map->GetContentSetting(
657 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
658 EXPECT_EQ(CONTENT_SETTING_ALLOW,
659 otr_map->GetContentSetting(
660 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
662 otr_map->ShutdownOnUIThread();
665 // For a single Unicode encoded pattern, check if it gets converted to punycode
666 // and old pattern gets deleted.
667 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) {
668 TestingProfile profile;
669 PrefService* prefs = profile.GetPrefs();
673 DictionaryPrefUpdate update(prefs, prefs::kContentSettingsPatternPairs);
674 DictionaryValue* all_settings_dictionary = update.Get();
675 ASSERT_TRUE(NULL != all_settings_dictionary);
677 DictionaryValue* dummy_payload = new DictionaryValue;
678 dummy_payload->SetInteger("images", CONTENT_SETTING_ALLOW);
679 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*",
682 profile.GetHostContentSettingsMap();
684 const DictionaryValue* all_settings_dictionary =
685 prefs->GetDictionary(prefs::kContentSettingsPatternPairs);
686 const DictionaryValue* result = NULL;
687 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
688 "[*.]\xC4\x87ira.com,*", &result));
689 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
690 "[*.]xn--ira-ppa.com,*", &result));
693 // If both Unicode and its punycode pattern exist, make sure we don't touch the
694 // settings for the punycode, and that Unicode pattern gets deleted.
695 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) {
696 TestingProfile profile;
698 scoped_ptr<Value> value(base::JSONReader::Read(
699 "{\"[*.]\\xC4\\x87ira.com,*\":{\"images\":1}}"));
700 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *value);
702 // Set punycode equivalent, with different setting.
703 scoped_ptr<Value> puny_value(base::JSONReader::Read(
704 "{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}"));
705 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *puny_value);
707 // Initialize the content map.
708 profile.GetHostContentSettingsMap();
710 const DictionaryValue* content_setting_prefs =
711 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs);
712 std::string prefs_as_json;
713 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json);
714 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}",
715 prefs_as_json.c_str());
718 TEST_F(HostContentSettingsMapTest, ResourceIdentifier) {
719 // This feature is currently behind a flag.
720 CommandLine* cmd = CommandLine::ForCurrentProcess();
721 base::AutoReset<CommandLine> auto_reset(cmd, *cmd);
722 cmd->AppendSwitch(switches::kEnableResourceContentSettings);
724 TestingProfile profile;
725 HostContentSettingsMap* host_content_settings_map =
726 profile.GetHostContentSettingsMap();
728 GURL host("http://example.com/");
729 ContentSettingsPattern pattern =
730 ContentSettingsPattern::FromString("[*.]example.com");
731 std::string resource1("someplugin");
732 std::string resource2("otherplugin");
734 // If resource content settings are enabled, GetContentSettings should return
735 // the default values for all plugins
736 ContentSetting default_plugin_setting =
737 host_content_settings_map->GetDefaultContentSetting(
738 CONTENT_SETTINGS_TYPE_PLUGINS, NULL);
739 EXPECT_EQ(default_plugin_setting,
740 host_content_settings_map->GetContentSetting(
741 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
743 // If no resource-specific content settings are defined, the setting should be
745 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
746 host_content_settings_map->GetContentSetting(
747 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1));
749 host_content_settings_map->SetContentSetting(
751 ContentSettingsPattern::Wildcard(),
752 CONTENT_SETTINGS_TYPE_PLUGINS,
754 CONTENT_SETTING_BLOCK);
755 EXPECT_EQ(CONTENT_SETTING_BLOCK,
756 host_content_settings_map->GetContentSetting(
757 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1));
758 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
759 host_content_settings_map->GetContentSetting(
760 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource2));
763 TEST_F(HostContentSettingsMapTest, ResourceIdentifierPrefs) {
764 // This feature is currently behind a flag.
765 CommandLine* cmd = CommandLine::ForCurrentProcess();
766 base::AutoReset<CommandLine> auto_reset(cmd, *cmd);
767 cmd->AppendSwitch(switches::kEnableResourceContentSettings);
769 TestingProfile profile;
770 scoped_ptr<Value> value(base::JSONReader::Read(
771 "{\"[*.]example.com,*\":{\"per_plugin\":{\"someplugin\":2}}}"));
772 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *value);
773 HostContentSettingsMap* host_content_settings_map =
774 profile.GetHostContentSettingsMap();
776 GURL host("http://example.com/");
777 ContentSettingsPattern item_pattern =
778 ContentSettingsPattern::FromString("[*.]example.com");
779 ContentSettingsPattern top_level_frame_pattern =
780 ContentSettingsPattern::Wildcard();
781 std::string resource1("someplugin");
782 std::string resource2("otherplugin");
784 EXPECT_EQ(CONTENT_SETTING_BLOCK,
785 host_content_settings_map->GetContentSetting(
786 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1));
788 host_content_settings_map->SetContentSetting(
790 top_level_frame_pattern,
791 CONTENT_SETTINGS_TYPE_PLUGINS,
793 CONTENT_SETTING_DEFAULT);
795 const DictionaryValue* content_setting_prefs =
796 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs);
797 std::string prefs_as_json;
798 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json);
799 EXPECT_EQ("{}", prefs_as_json);
801 host_content_settings_map->SetContentSetting(
803 top_level_frame_pattern,
804 CONTENT_SETTINGS_TYPE_PLUGINS,
806 CONTENT_SETTING_BLOCK);
808 content_setting_prefs =
809 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs);
810 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json);
811 EXPECT_EQ("{\"[*.]example.com,*\":{\"per_plugin\":{\"otherplugin\":2}}}",
815 // If a default-content-setting is managed, the managed value should be used
816 // instead of the default value.
817 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) {
818 TestingProfile profile;
819 HostContentSettingsMap* host_content_settings_map =
820 profile.GetHostContentSettingsMap();
821 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
823 EXPECT_EQ(CONTENT_SETTING_ALLOW,
824 host_content_settings_map->GetDefaultContentSetting(
825 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
827 // Set managed-default-content-setting through the coresponding preferences.
828 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
829 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
830 EXPECT_EQ(CONTENT_SETTING_BLOCK,
831 host_content_settings_map->GetDefaultContentSetting(
832 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
834 // Remove managed-default-content-settings-preferences.
835 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting);
836 EXPECT_EQ(CONTENT_SETTING_ALLOW,
837 host_content_settings_map->GetDefaultContentSetting(
838 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
840 // Set preference to manage the default-content-setting for Plugins.
841 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting,
842 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
843 EXPECT_EQ(CONTENT_SETTING_BLOCK,
844 host_content_settings_map->GetDefaultContentSetting(
845 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
847 // Remove the preference to manage the default-content-setting for Plugins.
848 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting);
849 EXPECT_EQ(CONTENT_SETTING_ALLOW,
850 host_content_settings_map->GetDefaultContentSetting(
851 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
854 TEST_F(HostContentSettingsMapTest,
855 GetNonDefaultContentSettingsIfTypeManaged) {
856 TestingProfile profile;
857 HostContentSettingsMap* host_content_settings_map =
858 profile.GetHostContentSettingsMap();
859 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
861 // Set pattern for JavaScript setting.
862 ContentSettingsPattern pattern =
863 ContentSettingsPattern::FromString("[*.]example.com");
864 host_content_settings_map->SetContentSetting(
866 ContentSettingsPattern::Wildcard(),
867 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
869 CONTENT_SETTING_BLOCK);
871 EXPECT_EQ(CONTENT_SETTING_ALLOW,
872 host_content_settings_map->GetDefaultContentSetting(
873 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
875 GURL host("http://example.com/");
876 EXPECT_EQ(CONTENT_SETTING_BLOCK,
877 host_content_settings_map->GetContentSetting(
878 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
880 // Set managed-default-content-setting for content-settings-type JavaScript.
881 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
882 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
883 EXPECT_EQ(CONTENT_SETTING_ALLOW,
884 host_content_settings_map->GetContentSetting(
885 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
888 // Managed default content setting should have higher priority
889 // than user defined patterns.
890 TEST_F(HostContentSettingsMapTest,
891 ManagedDefaultContentSettingIgnoreUserPattern) {
892 TestingProfile profile;
893 HostContentSettingsMap* host_content_settings_map =
894 profile.GetHostContentSettingsMap();
895 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
897 // Block all JavaScript.
898 host_content_settings_map->SetDefaultContentSetting(
899 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
901 // Set an exception to allow "[*.]example.com"
902 ContentSettingsPattern pattern =
903 ContentSettingsPattern::FromString("[*.]example.com");
905 host_content_settings_map->SetContentSetting(
907 ContentSettingsPattern::Wildcard(),
908 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
910 CONTENT_SETTING_ALLOW);
912 EXPECT_EQ(CONTENT_SETTING_BLOCK,
913 host_content_settings_map->GetDefaultContentSetting(
914 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
915 GURL host("http://example.com/");
916 EXPECT_EQ(CONTENT_SETTING_ALLOW,
917 host_content_settings_map->GetContentSetting(
918 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
920 // Set managed-default-content-settings-preferences.
921 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
922 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
923 EXPECT_EQ(CONTENT_SETTING_BLOCK,
924 host_content_settings_map->GetContentSetting(
925 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
927 // Remove managed-default-content-settings-preferences.
928 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting);
929 EXPECT_EQ(CONTENT_SETTING_ALLOW,
930 host_content_settings_map->GetContentSetting(
931 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
934 // If a default-content-setting is set to managed setting, the user defined
935 // setting should be preserved.
936 TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) {
937 TestingProfile profile;
938 HostContentSettingsMap* host_content_settings_map =
939 profile.GetHostContentSettingsMap();
940 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
942 // Set user defined default-content-setting for Cookies.
943 host_content_settings_map->SetDefaultContentSetting(
944 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
945 EXPECT_EQ(CONTENT_SETTING_BLOCK,
946 host_content_settings_map->GetDefaultContentSetting(
947 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
949 // Set preference to manage the default-content-setting for Cookies.
950 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting,
951 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
952 EXPECT_EQ(CONTENT_SETTING_ALLOW,
953 host_content_settings_map->GetDefaultContentSetting(
954 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
956 // Remove the preference to manage the default-content-setting for Cookies.
957 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting);
958 EXPECT_EQ(CONTENT_SETTING_BLOCK,
959 host_content_settings_map->GetDefaultContentSetting(
960 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
963 // If a setting for a default-content-setting-type is set while the type is
964 // managed, then the new setting should be preserved and used after the
965 // default-content-setting-type is not managed anymore.
966 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) {
967 TestingProfile profile;
968 HostContentSettingsMap* host_content_settings_map =
969 profile.GetHostContentSettingsMap();
970 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
972 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting,
973 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
974 EXPECT_EQ(CONTENT_SETTING_ALLOW,
975 host_content_settings_map->GetDefaultContentSetting(
976 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
978 host_content_settings_map->SetDefaultContentSetting(
979 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
980 EXPECT_EQ(CONTENT_SETTING_ALLOW,
981 host_content_settings_map->GetDefaultContentSetting(
982 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
984 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting);
985 EXPECT_EQ(CONTENT_SETTING_BLOCK,
986 host_content_settings_map->GetDefaultContentSetting(
987 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
990 TEST_F(HostContentSettingsMapTest, GetContentSetting) {
991 TestingProfile profile;
992 HostContentSettingsMap* host_content_settings_map =
993 profile.GetHostContentSettingsMap();
995 GURL host("http://example.com/");
996 GURL embedder("chrome://foo");
997 ContentSettingsPattern pattern =
998 ContentSettingsPattern::FromString("[*.]example.com");
999 host_content_settings_map->SetContentSetting(
1001 ContentSettingsPattern::Wildcard(),
1002 CONTENT_SETTINGS_TYPE_IMAGES,
1004 CONTENT_SETTING_BLOCK);
1005 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1006 host_content_settings_map->GetContentSetting(
1007 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1008 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1009 host_content_settings_map->GetContentSetting(
1010 embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1013 TEST_F(HostContentSettingsMapTest, ShouldAllowAllContent) {
1014 TestingProfile profile;
1015 HostContentSettingsMap* host_content_settings_map =
1016 profile.GetHostContentSettingsMap();
1018 GURL http_host("http://example.com/");
1019 GURL https_host("https://example.com/");
1020 GURL embedder("chrome://foo");
1021 GURL extension("chrome-extension://foo");
1022 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent(
1023 http_host, embedder, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
1024 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent(
1025 http_host, embedder, CONTENT_SETTINGS_TYPE_GEOLOCATION));
1026 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent(
1027 http_host, embedder, CONTENT_SETTINGS_TYPE_COOKIES));
1028 EXPECT_TRUE(host_content_settings_map->ShouldAllowAllContent(
1029 https_host, embedder, CONTENT_SETTINGS_TYPE_COOKIES));
1030 EXPECT_TRUE(host_content_settings_map->ShouldAllowAllContent(
1031 https_host, embedder, CONTENT_SETTINGS_TYPE_COOKIES));
1032 EXPECT_TRUE(host_content_settings_map->ShouldAllowAllContent(
1033 embedder, http_host, CONTENT_SETTINGS_TYPE_COOKIES));
1034 EXPECT_TRUE(host_content_settings_map->ShouldAllowAllContent(
1035 extension, extension, CONTENT_SETTINGS_TYPE_COOKIES));
1036 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent(
1037 extension, extension, CONTENT_SETTINGS_TYPE_PLUGINS));
1038 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent(
1039 extension, http_host, CONTENT_SETTINGS_TYPE_COOKIES));
1042 TEST_F(HostContentSettingsMapTest, MigrateClearOnExit) {
1043 TestingProfile profile;
1044 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
1046 prefs->SetBoolean(prefs::kClearSiteDataOnExit, true);
1048 scoped_ptr<Value> patterns(base::JSONReader::Read(
1049 "{\"[*.]example.com,*\":{\"cookies\": 1},"
1050 " \"[*.]other.com,*\":{\"cookies\": 2},"
1051 " \"[*.]third.com,*\":{\"cookies\": 4}}"));
1052 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *patterns);
1054 scoped_ptr<Value> defaults(base::JSONReader::Read("{\"cookies\": 1}"));
1055 profile.GetPrefs()->Set(prefs::kDefaultContentSettings, *defaults);
1057 HostContentSettingsMap* host_content_settings_map =
1058 profile.GetHostContentSettingsMap();
1060 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY,
1061 host_content_settings_map->GetDefaultContentSetting(
1062 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
1063 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY,
1064 host_content_settings_map->GetContentSetting(
1065 GURL("http://example.com"),
1066 GURL("http://example.com"),
1067 CONTENT_SETTINGS_TYPE_COOKIES,
1069 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1070 host_content_settings_map->GetContentSetting(
1071 GURL("http://other.com"),
1072 GURL("http://other.com"),
1073 CONTENT_SETTINGS_TYPE_COOKIES,
1075 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY,
1076 host_content_settings_map->GetContentSetting(
1077 GURL("http://third.com"),
1078 GURL("http://third.com"),
1079 CONTENT_SETTINGS_TYPE_COOKIES,