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_mock_observer.h"
13 #include "chrome/browser/content_settings/cookie_settings_factory.h"
14 #include "chrome/browser/content_settings/mock_settings_observer.h"
15 #include "chrome/common/pref_names.h"
16 #include "chrome/common/url_constants.h"
17 #include "chrome/test/base/testing_pref_service_syncable.h"
18 #include "chrome/test/base/testing_profile.h"
19 #include "components/content_settings/core/browser/content_settings_details.h"
20 #include "components/content_settings/core/browser/cookie_settings.h"
21 #include "components/content_settings/core/browser/host_content_settings_map.h"
22 #include "content/public/test/test_browser_thread.h"
23 #include "net/base/static_cookie_policy.h"
24 #include "testing/gtest/include/gtest/gtest.h"
27 using content::BrowserThread
;
31 class HostContentSettingsMapTest
: public testing::Test
{
33 HostContentSettingsMapTest() : ui_thread_(BrowserThread::UI
, &message_loop_
) {
37 base::MessageLoop message_loop_
;
38 content::TestBrowserThread ui_thread_
;
41 TEST_F(HostContentSettingsMapTest
, DefaultValues
) {
42 TestingProfile profile
;
43 HostContentSettingsMap
* host_content_settings_map
=
44 profile
.GetHostContentSettingsMap();
46 // Check setting defaults.
47 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
48 host_content_settings_map
->GetDefaultContentSetting(
49 CONTENT_SETTINGS_TYPE_JAVASCRIPT
, NULL
));
50 host_content_settings_map
->SetDefaultContentSetting(
51 CONTENT_SETTINGS_TYPE_IMAGES
, CONTENT_SETTING_BLOCK
);
52 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
53 host_content_settings_map
->GetDefaultContentSetting(
54 CONTENT_SETTINGS_TYPE_IMAGES
, NULL
));
55 EXPECT_EQ(CONTENT_SETTING_ALLOW
, host_content_settings_map
->GetContentSetting(
56 GURL(chrome::kChromeUINewTabURL
),
57 GURL(chrome::kChromeUINewTabURL
),
58 CONTENT_SETTINGS_TYPE_IMAGES
,
61 host_content_settings_map
->SetDefaultContentSetting(
62 CONTENT_SETTINGS_TYPE_PLUGINS
, CONTENT_SETTING_ALLOW
);
63 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
64 host_content_settings_map
->GetDefaultContentSetting(
65 CONTENT_SETTINGS_TYPE_PLUGINS
, NULL
));
66 host_content_settings_map
->SetDefaultContentSetting(
67 CONTENT_SETTINGS_TYPE_PLUGINS
, CONTENT_SETTING_BLOCK
);
68 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
69 host_content_settings_map
->GetDefaultContentSetting(
70 CONTENT_SETTINGS_TYPE_PLUGINS
, NULL
));
71 host_content_settings_map
->SetDefaultContentSetting(
72 CONTENT_SETTINGS_TYPE_PLUGINS
, CONTENT_SETTING_DETECT_IMPORTANT_CONTENT
);
73 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT
,
74 host_content_settings_map
->GetDefaultContentSetting(
75 CONTENT_SETTINGS_TYPE_PLUGINS
, NULL
));
77 host_content_settings_map
->SetDefaultContentSetting(
78 CONTENT_SETTINGS_TYPE_POPUPS
, CONTENT_SETTING_ALLOW
);
79 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
80 host_content_settings_map
->GetDefaultContentSetting(
81 CONTENT_SETTINGS_TYPE_POPUPS
, NULL
));
84 TEST_F(HostContentSettingsMapTest
, IndividualSettings
) {
85 TestingProfile profile
;
86 HostContentSettingsMap
* host_content_settings_map
=
87 profile
.GetHostContentSettingsMap();
89 // Check returning individual settings.
90 GURL
host("http://example.com/");
91 ContentSettingsPattern pattern
=
92 ContentSettingsPattern::FromString("[*.]example.com");
93 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
94 host_content_settings_map
->GetContentSetting(
95 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
96 host_content_settings_map
->SetContentSetting(
98 ContentSettingsPattern::Wildcard(),
99 CONTENT_SETTINGS_TYPE_IMAGES
,
101 CONTENT_SETTING_DEFAULT
);
102 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
103 host_content_settings_map
->GetContentSetting(
104 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
105 host_content_settings_map
->SetContentSetting(
107 ContentSettingsPattern::Wildcard(),
108 CONTENT_SETTINGS_TYPE_IMAGES
,
110 CONTENT_SETTING_BLOCK
);
111 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
112 host_content_settings_map
->GetContentSetting(
113 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
114 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
115 host_content_settings_map
->GetContentSetting(
116 host
, host
, CONTENT_SETTINGS_TYPE_PLUGINS
, std::string()));
118 // Check returning all settings for a host.
119 host_content_settings_map
->SetContentSetting(
121 ContentSettingsPattern::Wildcard(),
122 CONTENT_SETTINGS_TYPE_IMAGES
,
124 CONTENT_SETTING_DEFAULT
);
125 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
126 host_content_settings_map
->GetContentSetting(
127 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
128 host_content_settings_map
->SetContentSetting(
130 ContentSettingsPattern::Wildcard(),
131 CONTENT_SETTINGS_TYPE_JAVASCRIPT
,
133 CONTENT_SETTING_BLOCK
);
134 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
135 host_content_settings_map
->GetContentSetting(
136 host
, host
, CONTENT_SETTINGS_TYPE_JAVASCRIPT
, std::string()));
137 host_content_settings_map
->SetContentSetting(
139 ContentSettingsPattern::Wildcard(),
140 CONTENT_SETTINGS_TYPE_PLUGINS
,
142 CONTENT_SETTING_ALLOW
);
143 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
144 host_content_settings_map
->GetContentSetting(
145 host
, host
, CONTENT_SETTINGS_TYPE_PLUGINS
, std::string()));
146 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
147 host_content_settings_map
->GetContentSetting(
148 host
, host
, CONTENT_SETTINGS_TYPE_POPUPS
, std::string()));
149 EXPECT_EQ(CONTENT_SETTING_ASK
,
150 host_content_settings_map
->GetContentSetting(
151 host
, host
, CONTENT_SETTINGS_TYPE_GEOLOCATION
, std::string()));
154 host_content_settings_map
->GetContentSetting(
155 host
, host
, CONTENT_SETTINGS_TYPE_NOTIFICATIONS
, std::string()));
156 EXPECT_EQ(CONTENT_SETTING_ASK
,
157 host_content_settings_map
->GetContentSetting(
158 host
, host
, CONTENT_SETTINGS_TYPE_FULLSCREEN
, std::string()));
159 EXPECT_EQ(CONTENT_SETTING_ASK
,
160 host_content_settings_map
->GetContentSetting(
161 host
, host
, CONTENT_SETTINGS_TYPE_MOUSELOCK
, std::string()));
163 // Check returning all hosts for a setting.
164 ContentSettingsPattern pattern2
=
165 ContentSettingsPattern::FromString("[*.]example.org");
166 host_content_settings_map
->SetContentSetting(
168 ContentSettingsPattern::Wildcard(),
169 CONTENT_SETTINGS_TYPE_IMAGES
,
171 CONTENT_SETTING_BLOCK
);
172 host_content_settings_map
->SetContentSetting(
174 ContentSettingsPattern::Wildcard(),
175 CONTENT_SETTINGS_TYPE_PLUGINS
,
177 CONTENT_SETTING_BLOCK
);
178 ContentSettingsForOneType host_settings
;
179 host_content_settings_map
->GetSettingsForOneType(
180 CONTENT_SETTINGS_TYPE_IMAGES
, std::string(), &host_settings
);
181 // |host_settings| contains the default setting and an exception.
182 EXPECT_EQ(2U, host_settings
.size());
183 host_content_settings_map
->GetSettingsForOneType(
184 CONTENT_SETTINGS_TYPE_PLUGINS
, std::string(), &host_settings
);
185 // |host_settings| contains the default setting and 2 exceptions.
186 EXPECT_EQ(3U, host_settings
.size());
187 host_content_settings_map
->GetSettingsForOneType(
188 CONTENT_SETTINGS_TYPE_POPUPS
, std::string(), &host_settings
);
189 // |host_settings| contains only the default setting.
190 EXPECT_EQ(1U, host_settings
.size());
193 TEST_F(HostContentSettingsMapTest
, Clear
) {
194 TestingProfile profile
;
195 HostContentSettingsMap
* host_content_settings_map
=
196 profile
.GetHostContentSettingsMap();
198 // Check clearing one type.
199 ContentSettingsPattern pattern
=
200 ContentSettingsPattern::FromString("[*.]example.org");
201 ContentSettingsPattern pattern2
=
202 ContentSettingsPattern::FromString("[*.]example.net");
203 host_content_settings_map
->SetContentSetting(
205 ContentSettingsPattern::Wildcard(),
206 CONTENT_SETTINGS_TYPE_IMAGES
,
208 CONTENT_SETTING_BLOCK
);
209 host_content_settings_map
->SetContentSetting(
211 ContentSettingsPattern::Wildcard(),
212 CONTENT_SETTINGS_TYPE_IMAGES
,
214 CONTENT_SETTING_BLOCK
);
215 host_content_settings_map
->SetContentSetting(
217 ContentSettingsPattern::Wildcard(),
218 CONTENT_SETTINGS_TYPE_PLUGINS
,
220 CONTENT_SETTING_BLOCK
);
221 host_content_settings_map
->SetContentSetting(
223 ContentSettingsPattern::Wildcard(),
224 CONTENT_SETTINGS_TYPE_IMAGES
,
226 CONTENT_SETTING_BLOCK
);
227 host_content_settings_map
->ClearSettingsForOneType(
228 CONTENT_SETTINGS_TYPE_IMAGES
);
229 ContentSettingsForOneType host_settings
;
230 host_content_settings_map
->GetSettingsForOneType(
231 CONTENT_SETTINGS_TYPE_IMAGES
, std::string(), &host_settings
);
232 // |host_settings| contains only the default setting.
233 EXPECT_EQ(1U, host_settings
.size());
234 host_content_settings_map
->GetSettingsForOneType(
235 CONTENT_SETTINGS_TYPE_PLUGINS
, std::string(), &host_settings
);
236 // |host_settings| contains the default setting and an exception.
237 EXPECT_EQ(2U, host_settings
.size());
240 TEST_F(HostContentSettingsMapTest
, Patterns
) {
241 TestingProfile profile
;
242 HostContentSettingsMap
* host_content_settings_map
=
243 profile
.GetHostContentSettingsMap();
245 GURL
host1("http://example.com/");
246 GURL
host2("http://www.example.com/");
247 GURL
host3("http://example.org/");
248 ContentSettingsPattern pattern1
=
249 ContentSettingsPattern::FromString("[*.]example.com");
250 ContentSettingsPattern pattern2
=
251 ContentSettingsPattern::FromString("example.org");
252 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
253 host_content_settings_map
->GetContentSetting(
254 host1
, host1
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
255 host_content_settings_map
->SetContentSetting(
257 ContentSettingsPattern::Wildcard(),
258 CONTENT_SETTINGS_TYPE_IMAGES
,
260 CONTENT_SETTING_BLOCK
);
261 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
262 host_content_settings_map
->GetContentSetting(
263 host1
, host1
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
264 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
265 host_content_settings_map
->GetContentSetting(
266 host2
, host2
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
267 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
268 host_content_settings_map
->GetContentSetting(
269 host3
, host3
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
270 host_content_settings_map
->SetContentSetting(
272 ContentSettingsPattern::Wildcard(),
273 CONTENT_SETTINGS_TYPE_IMAGES
,
275 CONTENT_SETTING_BLOCK
);
276 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
277 host_content_settings_map
->GetContentSetting(
278 host3
, host3
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
281 TEST_F(HostContentSettingsMapTest
, Observer
) {
282 TestingProfile profile
;
283 HostContentSettingsMap
* host_content_settings_map
=
284 profile
.GetHostContentSettingsMap();
285 MockSettingsObserver
observer(host_content_settings_map
);
287 ContentSettingsPattern primary_pattern
=
288 ContentSettingsPattern::FromString("[*.]example.com");
289 ContentSettingsPattern secondary_pattern
=
290 ContentSettingsPattern::Wildcard();
291 EXPECT_CALL(observer
,
292 OnContentSettingsChanged(host_content_settings_map
,
293 CONTENT_SETTINGS_TYPE_IMAGES
,
298 host_content_settings_map
->SetContentSetting(
301 CONTENT_SETTINGS_TYPE_IMAGES
,
303 CONTENT_SETTING_ALLOW
);
304 ::testing::Mock::VerifyAndClearExpectations(&observer
);
306 EXPECT_CALL(observer
,
307 OnContentSettingsChanged(host_content_settings_map
,
308 CONTENT_SETTINGS_TYPE_IMAGES
, false,
310 host_content_settings_map
->ClearSettingsForOneType(
311 CONTENT_SETTINGS_TYPE_IMAGES
);
312 ::testing::Mock::VerifyAndClearExpectations(&observer
);
314 EXPECT_CALL(observer
,
315 OnContentSettingsChanged(host_content_settings_map
,
316 CONTENT_SETTINGS_TYPE_IMAGES
, false,
318 host_content_settings_map
->SetDefaultContentSetting(
319 CONTENT_SETTINGS_TYPE_IMAGES
, CONTENT_SETTING_BLOCK
);
322 TEST_F(HostContentSettingsMapTest
, ObserveDefaultPref
) {
323 TestingProfile profile
;
324 HostContentSettingsMap
* host_content_settings_map
=
325 profile
.GetHostContentSettingsMap();
327 PrefService
* prefs
= profile
.GetPrefs();
328 GURL
host("http://example.com");
330 host_content_settings_map
->SetDefaultContentSetting(
331 CONTENT_SETTINGS_TYPE_IMAGES
, CONTENT_SETTING_BLOCK
);
332 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
333 host_content_settings_map
->GetContentSetting(
334 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
336 // Clearing the backing pref should also clear the internal cache.
337 prefs
->ClearPref(prefs::kDefaultImagesSetting
);
338 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
339 host_content_settings_map
->GetContentSetting(
340 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
342 // Reseting the pref to its previous value should update the cache.
343 prefs
->SetInteger(prefs::kDefaultImagesSetting
, CONTENT_SETTING_BLOCK
);
344 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
345 host_content_settings_map
->GetContentSetting(
346 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
349 TEST_F(HostContentSettingsMapTest
, ObserveExceptionPref
) {
350 TestingProfile profile
;
351 HostContentSettingsMap
* host_content_settings_map
=
352 profile
.GetHostContentSettingsMap();
354 PrefService
* prefs
= profile
.GetPrefs();
356 // Make a copy of the default pref value so we can reset it later.
357 scoped_ptr
<base::Value
> default_value(prefs
->FindPreference(
358 prefs::kContentSettingsPatternPairs
)->GetValue()->DeepCopy());
360 ContentSettingsPattern pattern
=
361 ContentSettingsPattern::FromString("[*.]example.com");
362 GURL
host("http://example.com");
364 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
365 host_content_settings_map
->GetContentSetting(
366 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
368 host_content_settings_map
->SetContentSetting(
370 ContentSettingsPattern::Wildcard(),
371 CONTENT_SETTINGS_TYPE_IMAGES
,
373 CONTENT_SETTING_BLOCK
);
374 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
375 host_content_settings_map
->GetContentSetting(
376 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
378 // Make a copy of the pref's new value so we can reset it later.
379 scoped_ptr
<base::Value
> new_value(prefs
->FindPreference(
380 prefs::kContentSettingsPatternPairs
)->GetValue()->DeepCopy());
382 // Clearing the backing pref should also clear the internal cache.
383 prefs
->Set(prefs::kContentSettingsPatternPairs
, *default_value
);
384 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
385 host_content_settings_map
->GetContentSetting(
386 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
388 // Reseting the pref to its previous value should update the cache.
389 prefs
->Set(prefs::kContentSettingsPatternPairs
, *new_value
);
390 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
391 host_content_settings_map
->GetContentSetting(
392 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
395 TEST_F(HostContentSettingsMapTest
, HostTrimEndingDotCheck
) {
396 TestingProfile profile
;
397 HostContentSettingsMap
* host_content_settings_map
=
398 profile
.GetHostContentSettingsMap();
399 content_settings::CookieSettings
* cookie_settings
=
400 CookieSettingsFactory::GetForProfile(&profile
).get();
402 ContentSettingsPattern pattern
=
403 ContentSettingsPattern::FromString("[*.]example.com");
404 GURL
host_ending_with_dot("http://example.com./");
406 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
407 host_content_settings_map
->GetContentSetting(
408 host_ending_with_dot
,
409 host_ending_with_dot
,
410 CONTENT_SETTINGS_TYPE_IMAGES
,
412 host_content_settings_map
->SetContentSetting(
414 ContentSettingsPattern::Wildcard(),
415 CONTENT_SETTINGS_TYPE_IMAGES
,
417 CONTENT_SETTING_DEFAULT
);
419 CONTENT_SETTING_ALLOW
,
420 host_content_settings_map
->GetContentSetting(host_ending_with_dot
,
421 host_ending_with_dot
,
422 CONTENT_SETTINGS_TYPE_IMAGES
,
424 host_content_settings_map
->SetContentSetting(
426 ContentSettingsPattern::Wildcard(),
427 CONTENT_SETTINGS_TYPE_IMAGES
,
429 CONTENT_SETTING_BLOCK
);
431 CONTENT_SETTING_BLOCK
,
432 host_content_settings_map
->GetContentSetting(host_ending_with_dot
,
433 host_ending_with_dot
,
434 CONTENT_SETTINGS_TYPE_IMAGES
,
437 EXPECT_TRUE(cookie_settings
->IsSettingCookieAllowed(
438 host_ending_with_dot
, host_ending_with_dot
));
439 host_content_settings_map
->SetContentSetting(
441 ContentSettingsPattern::Wildcard(),
442 CONTENT_SETTINGS_TYPE_COOKIES
,
444 CONTENT_SETTING_DEFAULT
);
445 EXPECT_TRUE(cookie_settings
->IsSettingCookieAllowed(
446 host_ending_with_dot
, host_ending_with_dot
));
447 host_content_settings_map
->SetContentSetting(
449 ContentSettingsPattern::Wildcard(),
450 CONTENT_SETTINGS_TYPE_COOKIES
,
452 CONTENT_SETTING_BLOCK
);
453 EXPECT_FALSE(cookie_settings
->IsSettingCookieAllowed(
454 host_ending_with_dot
, host_ending_with_dot
));
456 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
457 host_content_settings_map
->GetContentSetting(
458 host_ending_with_dot
,
459 host_ending_with_dot
,
460 CONTENT_SETTINGS_TYPE_JAVASCRIPT
,
462 host_content_settings_map
->SetContentSetting(
464 ContentSettingsPattern::Wildcard(),
465 CONTENT_SETTINGS_TYPE_JAVASCRIPT
,
467 CONTENT_SETTING_DEFAULT
);
468 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
469 host_content_settings_map
->GetContentSetting(
470 host_ending_with_dot
,
471 host_ending_with_dot
,
472 CONTENT_SETTINGS_TYPE_JAVASCRIPT
,
474 host_content_settings_map
->SetContentSetting(
476 ContentSettingsPattern::Wildcard(),
477 CONTENT_SETTINGS_TYPE_JAVASCRIPT
,
479 CONTENT_SETTING_BLOCK
);
480 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
481 host_content_settings_map
->GetContentSetting(
482 host_ending_with_dot
,
483 host_ending_with_dot
,
484 CONTENT_SETTINGS_TYPE_JAVASCRIPT
,
487 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
488 host_content_settings_map
->GetContentSetting(
489 host_ending_with_dot
,
490 host_ending_with_dot
,
491 CONTENT_SETTINGS_TYPE_PLUGINS
,
493 host_content_settings_map
->SetContentSetting(
495 ContentSettingsPattern::Wildcard(),
496 CONTENT_SETTINGS_TYPE_PLUGINS
,
498 CONTENT_SETTING_DEFAULT
);
499 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
500 host_content_settings_map
->GetContentSetting(
501 host_ending_with_dot
,
502 host_ending_with_dot
,
503 CONTENT_SETTINGS_TYPE_PLUGINS
,
505 host_content_settings_map
->SetContentSetting(
507 ContentSettingsPattern::Wildcard(),
508 CONTENT_SETTINGS_TYPE_PLUGINS
,
510 CONTENT_SETTING_BLOCK
);
511 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
512 host_content_settings_map
->GetContentSetting(
513 host_ending_with_dot
,
514 host_ending_with_dot
,
515 CONTENT_SETTINGS_TYPE_PLUGINS
,
519 CONTENT_SETTING_BLOCK
,
520 host_content_settings_map
->GetContentSetting(host_ending_with_dot
,
521 host_ending_with_dot
,
522 CONTENT_SETTINGS_TYPE_POPUPS
,
524 host_content_settings_map
->SetContentSetting(
526 ContentSettingsPattern::Wildcard(),
527 CONTENT_SETTINGS_TYPE_POPUPS
,
529 CONTENT_SETTING_DEFAULT
);
531 CONTENT_SETTING_BLOCK
,
532 host_content_settings_map
->GetContentSetting(host_ending_with_dot
,
533 host_ending_with_dot
,
534 CONTENT_SETTINGS_TYPE_POPUPS
,
536 host_content_settings_map
->SetContentSetting(
538 ContentSettingsPattern::Wildcard(),
539 CONTENT_SETTINGS_TYPE_POPUPS
,
541 CONTENT_SETTING_ALLOW
);
543 CONTENT_SETTING_ALLOW
,
544 host_content_settings_map
->GetContentSetting(host_ending_with_dot
,
545 host_ending_with_dot
,
546 CONTENT_SETTINGS_TYPE_POPUPS
,
550 TEST_F(HostContentSettingsMapTest
, NestedSettings
) {
551 TestingProfile profile
;
552 HostContentSettingsMap
* host_content_settings_map
=
553 profile
.GetHostContentSettingsMap();
555 GURL
host("http://a.b.example.com/");
556 ContentSettingsPattern pattern1
=
557 ContentSettingsPattern::FromString("[*.]example.com");
558 ContentSettingsPattern pattern2
=
559 ContentSettingsPattern::FromString("[*.]b.example.com");
560 ContentSettingsPattern pattern3
=
561 ContentSettingsPattern::FromString("a.b.example.com");
563 host_content_settings_map
->SetContentSetting(
565 ContentSettingsPattern::Wildcard(),
566 CONTENT_SETTINGS_TYPE_IMAGES
,
568 CONTENT_SETTING_BLOCK
);
570 host_content_settings_map
->SetContentSetting(
572 ContentSettingsPattern::Wildcard(),
573 CONTENT_SETTINGS_TYPE_COOKIES
,
575 CONTENT_SETTING_BLOCK
);
577 host_content_settings_map
->SetContentSetting(
579 ContentSettingsPattern::Wildcard(),
580 CONTENT_SETTINGS_TYPE_PLUGINS
,
582 CONTENT_SETTING_BLOCK
);
583 host_content_settings_map
->SetDefaultContentSetting(
584 CONTENT_SETTINGS_TYPE_JAVASCRIPT
, CONTENT_SETTING_BLOCK
);
586 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
587 host_content_settings_map
->GetContentSetting(
588 host
, host
, CONTENT_SETTINGS_TYPE_COOKIES
, std::string()));
589 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
590 host_content_settings_map
->GetContentSetting(
591 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
592 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
593 host_content_settings_map
->GetContentSetting(
594 host
, host
, CONTENT_SETTINGS_TYPE_JAVASCRIPT
, std::string()));
595 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
596 host_content_settings_map
->GetContentSetting(
597 host
, host
, CONTENT_SETTINGS_TYPE_PLUGINS
, std::string()));
598 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
599 host_content_settings_map
->GetContentSetting(
600 host
, host
, CONTENT_SETTINGS_TYPE_POPUPS
, std::string()));
601 EXPECT_EQ(CONTENT_SETTING_ASK
,
602 host_content_settings_map
->GetContentSetting(
603 host
, host
, CONTENT_SETTINGS_TYPE_GEOLOCATION
, std::string()));
606 host_content_settings_map
->GetContentSetting(
607 host
, host
, CONTENT_SETTINGS_TYPE_NOTIFICATIONS
, std::string()));
608 EXPECT_EQ(CONTENT_SETTING_ASK
,
609 host_content_settings_map
->GetContentSetting(
610 host
, host
, CONTENT_SETTINGS_TYPE_FULLSCREEN
, std::string()));
611 EXPECT_EQ(CONTENT_SETTING_ASK
,
612 host_content_settings_map
->GetContentSetting(
613 host
, host
, CONTENT_SETTINGS_TYPE_MOUSELOCK
, std::string()));
616 TEST_F(HostContentSettingsMapTest
, OffTheRecord
) {
617 TestingProfile profile
;
618 HostContentSettingsMap
* host_content_settings_map
=
619 profile
.GetHostContentSettingsMap();
620 scoped_refptr
<HostContentSettingsMap
> otr_map(
621 new HostContentSettingsMap(profile
.GetPrefs(),
624 GURL
host("http://example.com/");
625 ContentSettingsPattern pattern
=
626 ContentSettingsPattern::FromString("[*.]example.com");
628 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
629 host_content_settings_map
->GetContentSetting(
630 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
631 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
632 otr_map
->GetContentSetting(
633 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
635 // Changing content settings on the main map should also affect the
637 host_content_settings_map
->SetContentSetting(
639 ContentSettingsPattern::Wildcard(),
640 CONTENT_SETTINGS_TYPE_IMAGES
,
642 CONTENT_SETTING_BLOCK
);
643 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
644 host_content_settings_map
->GetContentSetting(
645 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
646 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
647 otr_map
->GetContentSetting(
648 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
650 // Changing content settings on the incognito map should NOT affect the
652 otr_map
->SetContentSetting(pattern
,
653 ContentSettingsPattern::Wildcard(),
654 CONTENT_SETTINGS_TYPE_IMAGES
,
656 CONTENT_SETTING_ALLOW
);
657 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
658 host_content_settings_map
->GetContentSetting(
659 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
660 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
661 otr_map
->GetContentSetting(
662 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
664 otr_map
->ShutdownOnUIThread();
667 // For a single Unicode encoded pattern, check if it gets converted to punycode
668 // and old pattern gets deleted.
669 TEST_F(HostContentSettingsMapTest
, CanonicalizeExceptionsUnicodeOnly
) {
670 TestingProfile profile
;
671 PrefService
* prefs
= profile
.GetPrefs();
675 DictionaryPrefUpdate
update(
676 prefs
, prefs::kContentSettingsPatternPairs
);
677 base::DictionaryValue
* all_settings_dictionary
= update
.Get();
678 ASSERT_TRUE(NULL
!= all_settings_dictionary
);
680 base::DictionaryValue
* dummy_payload
= new base::DictionaryValue
;
681 dummy_payload
->SetInteger("images", CONTENT_SETTING_ALLOW
);
682 all_settings_dictionary
->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*",
686 profile
.GetHostContentSettingsMap();
688 const base::DictionaryValue
* all_settings_dictionary
=
689 prefs
->GetDictionary(prefs::kContentSettingsImagesPatternPairs
);
690 const base::DictionaryValue
* result
= NULL
;
691 EXPECT_FALSE(all_settings_dictionary
->GetDictionaryWithoutPathExpansion(
692 "[*.]\xC4\x87ira.com,*", &result
));
693 EXPECT_TRUE(all_settings_dictionary
->GetDictionaryWithoutPathExpansion(
694 "[*.]xn--ira-ppa.com,*", &result
));
697 // If both Unicode and its punycode pattern exist, make sure we don't touch the
698 // settings for the punycode, and that Unicode pattern gets deleted.
699 TEST_F(HostContentSettingsMapTest
, CanonicalizeExceptionsUnicodeAndPunycode
) {
700 TestingProfile profile
;
702 scoped_ptr
<base::Value
> value(base::JSONReader::DeprecatedRead(
703 "{\"[*.]\\xC4\\x87ira.com,*\":{\"images\":1}}"));
704 profile
.GetPrefs()->Set(prefs::kContentSettingsPatternPairs
, *value
);
706 // Set punycode equivalent, with different setting.
707 scoped_ptr
<base::Value
> puny_value(base::JSONReader::DeprecatedRead(
708 "{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}"));
709 profile
.GetPrefs()->Set(
710 prefs::kContentSettingsPatternPairs
, *puny_value
);
712 // Initialize the content map.
713 profile
.GetHostContentSettingsMap();
715 const base::DictionaryValue
& content_setting_prefs
=
716 *profile
.GetPrefs()->GetDictionary(
717 prefs::kContentSettingsImagesPatternPairs
);
718 std::string prefs_as_json
;
719 base::JSONWriter::Write(content_setting_prefs
, &prefs_as_json
);
720 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"setting\":2}}",
721 prefs_as_json
.c_str());
724 // If a default-content-setting is managed, the managed value should be used
725 // instead of the default value.
726 TEST_F(HostContentSettingsMapTest
, ManagedDefaultContentSetting
) {
727 TestingProfile profile
;
728 HostContentSettingsMap
* host_content_settings_map
=
729 profile
.GetHostContentSettingsMap();
730 TestingPrefServiceSyncable
* prefs
= profile
.GetTestingPrefService();
732 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
733 host_content_settings_map
->GetDefaultContentSetting(
734 CONTENT_SETTINGS_TYPE_JAVASCRIPT
, NULL
));
736 // Set managed-default-content-setting through the coresponding preferences.
737 prefs
->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting
,
738 new base::FundamentalValue(CONTENT_SETTING_BLOCK
));
739 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
740 host_content_settings_map
->GetDefaultContentSetting(
741 CONTENT_SETTINGS_TYPE_JAVASCRIPT
, NULL
));
743 // Remove managed-default-content-settings-preferences.
744 prefs
->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting
);
745 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
746 host_content_settings_map
->GetDefaultContentSetting(
747 CONTENT_SETTINGS_TYPE_JAVASCRIPT
, NULL
));
749 // Set preference to manage the default-content-setting for Plugins.
750 prefs
->SetManagedPref(prefs::kManagedDefaultPluginsSetting
,
751 new base::FundamentalValue(CONTENT_SETTING_BLOCK
));
752 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
753 host_content_settings_map
->GetDefaultContentSetting(
754 CONTENT_SETTINGS_TYPE_PLUGINS
, NULL
));
756 // Remove the preference to manage the default-content-setting for Plugins.
757 prefs
->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting
);
758 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
759 host_content_settings_map
->GetDefaultContentSetting(
760 CONTENT_SETTINGS_TYPE_PLUGINS
, NULL
));
763 TEST_F(HostContentSettingsMapTest
,
764 GetNonDefaultContentSettingsIfTypeManaged
) {
765 TestingProfile profile
;
766 HostContentSettingsMap
* host_content_settings_map
=
767 profile
.GetHostContentSettingsMap();
768 TestingPrefServiceSyncable
* prefs
= profile
.GetTestingPrefService();
770 // Set pattern for JavaScript setting.
771 ContentSettingsPattern pattern
=
772 ContentSettingsPattern::FromString("[*.]example.com");
773 host_content_settings_map
->SetContentSetting(
775 ContentSettingsPattern::Wildcard(),
776 CONTENT_SETTINGS_TYPE_JAVASCRIPT
,
778 CONTENT_SETTING_BLOCK
);
780 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
781 host_content_settings_map
->GetDefaultContentSetting(
782 CONTENT_SETTINGS_TYPE_JAVASCRIPT
, NULL
));
784 GURL
host("http://example.com/");
785 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
786 host_content_settings_map
->GetContentSetting(
787 host
, host
, CONTENT_SETTINGS_TYPE_JAVASCRIPT
, std::string()));
789 // Set managed-default-content-setting for content-settings-type JavaScript.
790 prefs
->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting
,
791 new base::FundamentalValue(CONTENT_SETTING_ALLOW
));
792 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
793 host_content_settings_map
->GetContentSetting(
794 host
, host
, CONTENT_SETTINGS_TYPE_JAVASCRIPT
, std::string()));
797 // Managed default content setting should have higher priority
798 // than user defined patterns.
799 TEST_F(HostContentSettingsMapTest
,
800 ManagedDefaultContentSettingIgnoreUserPattern
) {
801 TestingProfile profile
;
802 HostContentSettingsMap
* host_content_settings_map
=
803 profile
.GetHostContentSettingsMap();
804 TestingPrefServiceSyncable
* prefs
= profile
.GetTestingPrefService();
806 // Block all JavaScript.
807 host_content_settings_map
->SetDefaultContentSetting(
808 CONTENT_SETTINGS_TYPE_JAVASCRIPT
, CONTENT_SETTING_BLOCK
);
810 // Set an exception to allow "[*.]example.com"
811 ContentSettingsPattern pattern
=
812 ContentSettingsPattern::FromString("[*.]example.com");
814 host_content_settings_map
->SetContentSetting(
816 ContentSettingsPattern::Wildcard(),
817 CONTENT_SETTINGS_TYPE_JAVASCRIPT
,
819 CONTENT_SETTING_ALLOW
);
821 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
822 host_content_settings_map
->GetDefaultContentSetting(
823 CONTENT_SETTINGS_TYPE_JAVASCRIPT
, NULL
));
824 GURL
host("http://example.com/");
825 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
826 host_content_settings_map
->GetContentSetting(
827 host
, host
, CONTENT_SETTINGS_TYPE_JAVASCRIPT
, std::string()));
829 // Set managed-default-content-settings-preferences.
830 prefs
->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting
,
831 new base::FundamentalValue(CONTENT_SETTING_BLOCK
));
832 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
833 host_content_settings_map
->GetContentSetting(
834 host
, host
, CONTENT_SETTINGS_TYPE_JAVASCRIPT
, std::string()));
836 // Remove managed-default-content-settings-preferences.
837 prefs
->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting
);
838 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
839 host_content_settings_map
->GetContentSetting(
840 host
, host
, CONTENT_SETTINGS_TYPE_JAVASCRIPT
, std::string()));
843 // If a default-content-setting is set to managed setting, the user defined
844 // setting should be preserved.
845 TEST_F(HostContentSettingsMapTest
, OverwrittenDefaultContentSetting
) {
846 TestingProfile profile
;
847 HostContentSettingsMap
* host_content_settings_map
=
848 profile
.GetHostContentSettingsMap();
849 TestingPrefServiceSyncable
* prefs
= profile
.GetTestingPrefService();
851 // Set user defined default-content-setting for Cookies.
852 host_content_settings_map
->SetDefaultContentSetting(
853 CONTENT_SETTINGS_TYPE_COOKIES
, CONTENT_SETTING_BLOCK
);
854 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
855 host_content_settings_map
->GetDefaultContentSetting(
856 CONTENT_SETTINGS_TYPE_COOKIES
, NULL
));
858 // Set preference to manage the default-content-setting for Cookies.
859 prefs
->SetManagedPref(prefs::kManagedDefaultCookiesSetting
,
860 new base::FundamentalValue(CONTENT_SETTING_ALLOW
));
861 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
862 host_content_settings_map
->GetDefaultContentSetting(
863 CONTENT_SETTINGS_TYPE_COOKIES
, NULL
));
865 // Remove the preference to manage the default-content-setting for Cookies.
866 prefs
->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting
);
867 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
868 host_content_settings_map
->GetDefaultContentSetting(
869 CONTENT_SETTINGS_TYPE_COOKIES
, NULL
));
872 // If a setting for a default-content-setting-type is set while the type is
873 // managed, then the new setting should be preserved and used after the
874 // default-content-setting-type is not managed anymore.
875 TEST_F(HostContentSettingsMapTest
, SettingDefaultContentSettingsWhenManaged
) {
876 TestingProfile profile
;
877 HostContentSettingsMap
* host_content_settings_map
=
878 profile
.GetHostContentSettingsMap();
879 TestingPrefServiceSyncable
* prefs
= profile
.GetTestingPrefService();
881 prefs
->SetManagedPref(prefs::kManagedDefaultPluginsSetting
,
882 new base::FundamentalValue(CONTENT_SETTING_ALLOW
));
883 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
884 host_content_settings_map
->GetDefaultContentSetting(
885 CONTENT_SETTINGS_TYPE_PLUGINS
, NULL
));
887 host_content_settings_map
->SetDefaultContentSetting(
888 CONTENT_SETTINGS_TYPE_PLUGINS
, CONTENT_SETTING_BLOCK
);
889 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
890 host_content_settings_map
->GetDefaultContentSetting(
891 CONTENT_SETTINGS_TYPE_PLUGINS
, NULL
));
893 prefs
->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting
);
894 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
895 host_content_settings_map
->GetDefaultContentSetting(
896 CONTENT_SETTINGS_TYPE_PLUGINS
, NULL
));
899 TEST_F(HostContentSettingsMapTest
, GetContentSetting
) {
900 TestingProfile profile
;
901 HostContentSettingsMap
* host_content_settings_map
=
902 profile
.GetHostContentSettingsMap();
904 GURL
host("http://example.com/");
905 GURL
embedder("chrome://foo");
906 ContentSettingsPattern pattern
=
907 ContentSettingsPattern::FromString("[*.]example.com");
908 host_content_settings_map
->SetContentSetting(
910 ContentSettingsPattern::Wildcard(),
911 CONTENT_SETTINGS_TYPE_IMAGES
,
913 CONTENT_SETTING_BLOCK
);
914 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
915 host_content_settings_map
->GetContentSetting(
916 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
917 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
918 host_content_settings_map
->GetContentSetting(
919 embedder
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
922 TEST_F(HostContentSettingsMapTest
, ShouldAllowAllContent
) {
923 GURL
http_host("http://example.com/");
924 GURL
https_host("https://example.com/");
925 GURL
embedder("chrome://foo");
926 GURL
extension("chrome-extension://foo");
927 EXPECT_FALSE(HostContentSettingsMap::ShouldAllowAllContent(
928 http_host
, embedder
, CONTENT_SETTINGS_TYPE_NOTIFICATIONS
));
929 EXPECT_FALSE(HostContentSettingsMap::ShouldAllowAllContent(
930 http_host
, embedder
, CONTENT_SETTINGS_TYPE_GEOLOCATION
));
931 EXPECT_FALSE(HostContentSettingsMap::ShouldAllowAllContent(
932 http_host
, embedder
, CONTENT_SETTINGS_TYPE_COOKIES
));
933 EXPECT_TRUE(HostContentSettingsMap::ShouldAllowAllContent(
934 https_host
, embedder
, CONTENT_SETTINGS_TYPE_COOKIES
));
935 EXPECT_TRUE(HostContentSettingsMap::ShouldAllowAllContent(
936 https_host
, embedder
, CONTENT_SETTINGS_TYPE_COOKIES
));
937 EXPECT_TRUE(HostContentSettingsMap::ShouldAllowAllContent(
938 embedder
, http_host
, CONTENT_SETTINGS_TYPE_COOKIES
));
939 #if defined(ENABLE_EXTENSIONS)
940 EXPECT_TRUE(HostContentSettingsMap::ShouldAllowAllContent(
941 extension
, extension
, CONTENT_SETTINGS_TYPE_COOKIES
));
943 EXPECT_FALSE(HostContentSettingsMap::ShouldAllowAllContent(
944 extension
, extension
, CONTENT_SETTINGS_TYPE_COOKIES
));
946 EXPECT_FALSE(HostContentSettingsMap::ShouldAllowAllContent(
947 extension
, extension
, CONTENT_SETTINGS_TYPE_PLUGINS
));
948 EXPECT_FALSE(HostContentSettingsMap::ShouldAllowAllContent(
949 extension
, http_host
, CONTENT_SETTINGS_TYPE_COOKIES
));
952 TEST_F(HostContentSettingsMapTest
, IsSettingAllowedForType
) {
953 TestingProfile profile
;
954 PrefService
* prefs
= profile
.GetPrefs();
956 EXPECT_TRUE(HostContentSettingsMap::IsSettingAllowedForType(
957 prefs
, CONTENT_SETTING_ASK
,
958 CONTENT_SETTINGS_TYPE_FULLSCREEN
));
960 // The mediastream setting is deprecated.
961 EXPECT_FALSE(HostContentSettingsMap::IsSettingAllowedForType(
962 prefs
, CONTENT_SETTING_ALLOW
,
963 CONTENT_SETTINGS_TYPE_MEDIASTREAM
));
964 EXPECT_FALSE(HostContentSettingsMap::IsSettingAllowedForType(
965 prefs
, CONTENT_SETTING_ASK
,
966 CONTENT_SETTINGS_TYPE_MEDIASTREAM
));
967 EXPECT_FALSE(HostContentSettingsMap::IsSettingAllowedForType(
968 prefs
, CONTENT_SETTING_BLOCK
,
969 CONTENT_SETTINGS_TYPE_MEDIASTREAM
));
971 // We support the ALLOW value for media permission exceptions,
972 // but not as the default setting.
973 EXPECT_TRUE(HostContentSettingsMap::IsSettingAllowedForType(
974 prefs
, CONTENT_SETTING_ALLOW
,
975 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC
));
976 EXPECT_TRUE(HostContentSettingsMap::IsSettingAllowedForType(
977 prefs
, CONTENT_SETTING_ALLOW
,
978 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA
));
979 EXPECT_FALSE(HostContentSettingsMap::IsDefaultSettingAllowedForType(
980 prefs
, CONTENT_SETTING_ALLOW
,
981 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC
));
982 EXPECT_FALSE(HostContentSettingsMap::IsDefaultSettingAllowedForType(
983 prefs
, CONTENT_SETTING_ALLOW
,
984 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA
));
986 // TODO(msramek): Add more checks for setting type - setting pairs where
987 // it is not obvious whether or not they are allowed.
990 TEST_F(HostContentSettingsMapTest
, AddContentSettingsObserver
) {
991 TestingProfile profile
;
992 HostContentSettingsMap
* host_content_settings_map
=
993 profile
.GetHostContentSettingsMap();
994 content_settings::MockObserver mock_observer
;
996 GURL
host("http://example.com/");
997 ContentSettingsPattern pattern
=
998 ContentSettingsPattern::FromString("[*.]example.com");
999 EXPECT_CALL(mock_observer
,
1000 OnContentSettingChanged(pattern
,
1001 ContentSettingsPattern::Wildcard(),
1002 CONTENT_SETTINGS_TYPE_IMAGES
,
1005 host_content_settings_map
->AddObserver(&mock_observer
);
1007 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
1008 host_content_settings_map
->GetContentSetting(
1009 host
, host
, CONTENT_SETTINGS_TYPE_IMAGES
, std::string()));
1010 host_content_settings_map
->SetContentSetting(
1012 ContentSettingsPattern::Wildcard(),
1013 CONTENT_SETTINGS_TYPE_IMAGES
,
1015 CONTENT_SETTING_DEFAULT
);