ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / content_settings / host_content_settings_map_unittest.cc
blob6ec5c367483b703c903479779ed5c67ed9f3ebfd
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.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/host_content_settings_map.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"
24 #include "url/gurl.h"
26 using content::BrowserThread;
28 using ::testing::_;
30 class HostContentSettingsMapTest : public testing::Test {
31 public:
32 HostContentSettingsMapTest() : ui_thread_(BrowserThread::UI, &message_loop_) {
35 protected:
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,
58 std::string()));
60 host_content_settings_map->SetDefaultContentSetting(
61 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ALLOW);
62 EXPECT_EQ(CONTENT_SETTING_ALLOW,
63 host_content_settings_map->GetDefaultContentSetting(
64 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
65 host_content_settings_map->SetDefaultContentSetting(
66 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
67 EXPECT_EQ(CONTENT_SETTING_BLOCK,
68 host_content_settings_map->GetDefaultContentSetting(
69 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
70 host_content_settings_map->SetDefaultContentSetting(
71 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_DETECT_IMPORTANT_CONTENT);
72 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT,
73 host_content_settings_map->GetDefaultContentSetting(
74 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
76 host_content_settings_map->SetDefaultContentSetting(
77 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_ALLOW);
78 EXPECT_EQ(CONTENT_SETTING_ALLOW,
79 host_content_settings_map->GetDefaultContentSetting(
80 CONTENT_SETTINGS_TYPE_POPUPS, NULL));
83 TEST_F(HostContentSettingsMapTest, IndividualSettings) {
84 TestingProfile profile;
85 HostContentSettingsMap* host_content_settings_map =
86 profile.GetHostContentSettingsMap();
88 // Check returning individual settings.
89 GURL host("http://example.com/");
90 ContentSettingsPattern pattern =
91 ContentSettingsPattern::FromString("[*.]example.com");
92 EXPECT_EQ(CONTENT_SETTING_ALLOW,
93 host_content_settings_map->GetContentSetting(
94 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
95 host_content_settings_map->SetContentSetting(
96 pattern,
97 ContentSettingsPattern::Wildcard(),
98 CONTENT_SETTINGS_TYPE_IMAGES,
99 std::string(),
100 CONTENT_SETTING_DEFAULT);
101 EXPECT_EQ(CONTENT_SETTING_ALLOW,
102 host_content_settings_map->GetContentSetting(
103 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
104 host_content_settings_map->SetContentSetting(
105 pattern,
106 ContentSettingsPattern::Wildcard(),
107 CONTENT_SETTINGS_TYPE_IMAGES,
108 std::string(),
109 CONTENT_SETTING_BLOCK);
110 EXPECT_EQ(CONTENT_SETTING_BLOCK,
111 host_content_settings_map->GetContentSetting(
112 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
113 EXPECT_EQ(CONTENT_SETTING_ALLOW,
114 host_content_settings_map->GetContentSetting(
115 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
117 // Check returning all settings for a host.
118 host_content_settings_map->SetContentSetting(
119 pattern,
120 ContentSettingsPattern::Wildcard(),
121 CONTENT_SETTINGS_TYPE_IMAGES,
122 std::string(),
123 CONTENT_SETTING_DEFAULT);
124 EXPECT_EQ(CONTENT_SETTING_ALLOW,
125 host_content_settings_map->GetContentSetting(
126 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
127 host_content_settings_map->SetContentSetting(
128 pattern,
129 ContentSettingsPattern::Wildcard(),
130 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
131 std::string(),
132 CONTENT_SETTING_BLOCK);
133 EXPECT_EQ(CONTENT_SETTING_BLOCK,
134 host_content_settings_map->GetContentSetting(
135 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
136 host_content_settings_map->SetContentSetting(
137 pattern,
138 ContentSettingsPattern::Wildcard(),
139 CONTENT_SETTINGS_TYPE_PLUGINS,
140 std::string(),
141 CONTENT_SETTING_ALLOW);
142 EXPECT_EQ(CONTENT_SETTING_ALLOW,
143 host_content_settings_map->GetContentSetting(
144 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
145 EXPECT_EQ(CONTENT_SETTING_BLOCK,
146 host_content_settings_map->GetContentSetting(
147 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
148 EXPECT_EQ(CONTENT_SETTING_ASK,
149 host_content_settings_map->GetContentSetting(
150 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
151 EXPECT_EQ(
152 CONTENT_SETTING_ASK,
153 host_content_settings_map->GetContentSetting(
154 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
155 EXPECT_EQ(CONTENT_SETTING_ASK,
156 host_content_settings_map->GetContentSetting(
157 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()));
158 EXPECT_EQ(CONTENT_SETTING_ASK,
159 host_content_settings_map->GetContentSetting(
160 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()));
162 // Check returning all hosts for a setting.
163 ContentSettingsPattern pattern2 =
164 ContentSettingsPattern::FromString("[*.]example.org");
165 host_content_settings_map->SetContentSetting(
166 pattern2,
167 ContentSettingsPattern::Wildcard(),
168 CONTENT_SETTINGS_TYPE_IMAGES,
169 std::string(),
170 CONTENT_SETTING_BLOCK);
171 host_content_settings_map->SetContentSetting(
172 pattern2,
173 ContentSettingsPattern::Wildcard(),
174 CONTENT_SETTINGS_TYPE_PLUGINS,
175 std::string(),
176 CONTENT_SETTING_BLOCK);
177 ContentSettingsForOneType host_settings;
178 host_content_settings_map->GetSettingsForOneType(
179 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings);
180 // |host_settings| contains the default setting and an exception.
181 EXPECT_EQ(2U, host_settings.size());
182 host_content_settings_map->GetSettingsForOneType(
183 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings);
184 // |host_settings| contains the default setting and 2 exceptions.
185 EXPECT_EQ(3U, host_settings.size());
186 host_content_settings_map->GetSettingsForOneType(
187 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings);
188 // |host_settings| contains only the default setting.
189 EXPECT_EQ(1U, host_settings.size());
192 TEST_F(HostContentSettingsMapTest, Clear) {
193 TestingProfile profile;
194 HostContentSettingsMap* host_content_settings_map =
195 profile.GetHostContentSettingsMap();
197 // Check clearing one type.
198 ContentSettingsPattern pattern =
199 ContentSettingsPattern::FromString("[*.]example.org");
200 ContentSettingsPattern pattern2 =
201 ContentSettingsPattern::FromString("[*.]example.net");
202 host_content_settings_map->SetContentSetting(
203 pattern2,
204 ContentSettingsPattern::Wildcard(),
205 CONTENT_SETTINGS_TYPE_IMAGES,
206 std::string(),
207 CONTENT_SETTING_BLOCK);
208 host_content_settings_map->SetContentSetting(
209 pattern,
210 ContentSettingsPattern::Wildcard(),
211 CONTENT_SETTINGS_TYPE_IMAGES,
212 std::string(),
213 CONTENT_SETTING_BLOCK);
214 host_content_settings_map->SetContentSetting(
215 pattern,
216 ContentSettingsPattern::Wildcard(),
217 CONTENT_SETTINGS_TYPE_PLUGINS,
218 std::string(),
219 CONTENT_SETTING_BLOCK);
220 host_content_settings_map->SetContentSetting(
221 pattern2,
222 ContentSettingsPattern::Wildcard(),
223 CONTENT_SETTINGS_TYPE_IMAGES,
224 std::string(),
225 CONTENT_SETTING_BLOCK);
226 host_content_settings_map->ClearSettingsForOneType(
227 CONTENT_SETTINGS_TYPE_IMAGES);
228 ContentSettingsForOneType host_settings;
229 host_content_settings_map->GetSettingsForOneType(
230 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings);
231 // |host_settings| contains only the default setting.
232 EXPECT_EQ(1U, host_settings.size());
233 host_content_settings_map->GetSettingsForOneType(
234 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings);
235 // |host_settings| contains the default setting and an exception.
236 EXPECT_EQ(2U, host_settings.size());
239 TEST_F(HostContentSettingsMapTest, Patterns) {
240 TestingProfile profile;
241 HostContentSettingsMap* host_content_settings_map =
242 profile.GetHostContentSettingsMap();
244 GURL host1("http://example.com/");
245 GURL host2("http://www.example.com/");
246 GURL host3("http://example.org/");
247 ContentSettingsPattern pattern1 =
248 ContentSettingsPattern::FromString("[*.]example.com");
249 ContentSettingsPattern pattern2 =
250 ContentSettingsPattern::FromString("example.org");
251 EXPECT_EQ(CONTENT_SETTING_ALLOW,
252 host_content_settings_map->GetContentSetting(
253 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
254 host_content_settings_map->SetContentSetting(
255 pattern1,
256 ContentSettingsPattern::Wildcard(),
257 CONTENT_SETTINGS_TYPE_IMAGES,
258 std::string(),
259 CONTENT_SETTING_BLOCK);
260 EXPECT_EQ(CONTENT_SETTING_BLOCK,
261 host_content_settings_map->GetContentSetting(
262 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
263 EXPECT_EQ(CONTENT_SETTING_BLOCK,
264 host_content_settings_map->GetContentSetting(
265 host2, host2, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
266 EXPECT_EQ(CONTENT_SETTING_ALLOW,
267 host_content_settings_map->GetContentSetting(
268 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
269 host_content_settings_map->SetContentSetting(
270 pattern2,
271 ContentSettingsPattern::Wildcard(),
272 CONTENT_SETTINGS_TYPE_IMAGES,
273 std::string(),
274 CONTENT_SETTING_BLOCK);
275 EXPECT_EQ(CONTENT_SETTING_BLOCK,
276 host_content_settings_map->GetContentSetting(
277 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
280 TEST_F(HostContentSettingsMapTest, Observer) {
281 TestingProfile profile;
282 HostContentSettingsMap* host_content_settings_map =
283 profile.GetHostContentSettingsMap();
284 MockSettingsObserver observer(host_content_settings_map);
286 ContentSettingsPattern primary_pattern =
287 ContentSettingsPattern::FromString("[*.]example.com");
288 ContentSettingsPattern secondary_pattern =
289 ContentSettingsPattern::Wildcard();
290 EXPECT_CALL(observer,
291 OnContentSettingsChanged(host_content_settings_map,
292 CONTENT_SETTINGS_TYPE_IMAGES,
293 false,
294 primary_pattern,
295 secondary_pattern,
296 false));
297 host_content_settings_map->SetContentSetting(
298 primary_pattern,
299 secondary_pattern,
300 CONTENT_SETTINGS_TYPE_IMAGES,
301 std::string(),
302 CONTENT_SETTING_ALLOW);
303 ::testing::Mock::VerifyAndClearExpectations(&observer);
305 EXPECT_CALL(observer,
306 OnContentSettingsChanged(host_content_settings_map,
307 CONTENT_SETTINGS_TYPE_IMAGES, false,
308 _, _, true));
309 host_content_settings_map->ClearSettingsForOneType(
310 CONTENT_SETTINGS_TYPE_IMAGES);
311 ::testing::Mock::VerifyAndClearExpectations(&observer);
313 EXPECT_CALL(observer,
314 OnContentSettingsChanged(host_content_settings_map,
315 CONTENT_SETTINGS_TYPE_IMAGES, false,
316 _, _, true));
317 host_content_settings_map->SetDefaultContentSetting(
318 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
321 TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) {
322 TestingProfile profile;
323 HostContentSettingsMap* host_content_settings_map =
324 profile.GetHostContentSettingsMap();
326 PrefService* prefs = profile.GetPrefs();
328 // Make a copy of the default pref value so we can reset it later.
329 scoped_ptr<base::Value> default_value(prefs->FindPreference(
330 prefs::kDefaultContentSettings)->GetValue()->DeepCopy());
332 GURL host("http://example.com");
334 host_content_settings_map->SetDefaultContentSetting(
335 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
336 EXPECT_EQ(CONTENT_SETTING_BLOCK,
337 host_content_settings_map->GetContentSetting(
338 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
340 // Make a copy of the pref's new value so we can reset it later.
341 scoped_ptr<base::Value> new_value(prefs->FindPreference(
342 prefs::kDefaultContentSettings)->GetValue()->DeepCopy());
344 // Clearing the backing pref should also clear the internal cache.
345 prefs->Set(prefs::kDefaultContentSettings, *default_value);
346 EXPECT_EQ(CONTENT_SETTING_ALLOW,
347 host_content_settings_map->GetContentSetting(
348 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
350 // Reseting the pref to its previous value should update the cache.
351 prefs->Set(prefs::kDefaultContentSettings, *new_value);
352 EXPECT_EQ(CONTENT_SETTING_BLOCK,
353 host_content_settings_map->GetContentSetting(
354 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
357 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) {
358 TestingProfile profile;
359 HostContentSettingsMap* host_content_settings_map =
360 profile.GetHostContentSettingsMap();
362 PrefService* prefs = profile.GetPrefs();
364 // Make a copy of the default pref value so we can reset it later.
365 scoped_ptr<base::Value> default_value(prefs->FindPreference(
366 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy());
368 ContentSettingsPattern pattern =
369 ContentSettingsPattern::FromString("[*.]example.com");
370 GURL host("http://example.com");
372 EXPECT_EQ(CONTENT_SETTING_ALLOW,
373 host_content_settings_map->GetContentSetting(
374 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
376 host_content_settings_map->SetContentSetting(
377 pattern,
378 ContentSettingsPattern::Wildcard(),
379 CONTENT_SETTINGS_TYPE_IMAGES,
380 std::string(),
381 CONTENT_SETTING_BLOCK);
382 EXPECT_EQ(CONTENT_SETTING_BLOCK,
383 host_content_settings_map->GetContentSetting(
384 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
386 // Make a copy of the pref's new value so we can reset it later.
387 scoped_ptr<base::Value> new_value(prefs->FindPreference(
388 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy());
390 // Clearing the backing pref should also clear the internal cache.
391 prefs->Set(prefs::kContentSettingsPatternPairs, *default_value);
392 EXPECT_EQ(CONTENT_SETTING_ALLOW,
393 host_content_settings_map->GetContentSetting(
394 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
396 // Reseting the pref to its previous value should update the cache.
397 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value);
398 EXPECT_EQ(CONTENT_SETTING_BLOCK,
399 host_content_settings_map->GetContentSetting(
400 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
403 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) {
404 TestingProfile profile;
405 HostContentSettingsMap* host_content_settings_map =
406 profile.GetHostContentSettingsMap();
407 CookieSettings* cookie_settings =
408 CookieSettings::Factory::GetForProfile(&profile).get();
410 ContentSettingsPattern pattern =
411 ContentSettingsPattern::FromString("[*.]example.com");
412 GURL host_ending_with_dot("http://example.com./");
414 EXPECT_EQ(CONTENT_SETTING_ALLOW,
415 host_content_settings_map->GetContentSetting(
416 host_ending_with_dot,
417 host_ending_with_dot,
418 CONTENT_SETTINGS_TYPE_IMAGES,
419 std::string()));
420 host_content_settings_map->SetContentSetting(
421 pattern,
422 ContentSettingsPattern::Wildcard(),
423 CONTENT_SETTINGS_TYPE_IMAGES,
424 std::string(),
425 CONTENT_SETTING_DEFAULT);
426 EXPECT_EQ(
427 CONTENT_SETTING_ALLOW,
428 host_content_settings_map->GetContentSetting(host_ending_with_dot,
429 host_ending_with_dot,
430 CONTENT_SETTINGS_TYPE_IMAGES,
431 std::string()));
432 host_content_settings_map->SetContentSetting(
433 pattern,
434 ContentSettingsPattern::Wildcard(),
435 CONTENT_SETTINGS_TYPE_IMAGES,
436 std::string(),
437 CONTENT_SETTING_BLOCK);
438 EXPECT_EQ(
439 CONTENT_SETTING_BLOCK,
440 host_content_settings_map->GetContentSetting(host_ending_with_dot,
441 host_ending_with_dot,
442 CONTENT_SETTINGS_TYPE_IMAGES,
443 std::string()));
445 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
446 host_ending_with_dot, host_ending_with_dot));
447 host_content_settings_map->SetContentSetting(
448 pattern,
449 ContentSettingsPattern::Wildcard(),
450 CONTENT_SETTINGS_TYPE_COOKIES,
451 std::string(),
452 CONTENT_SETTING_DEFAULT);
453 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
454 host_ending_with_dot, host_ending_with_dot));
455 host_content_settings_map->SetContentSetting(
456 pattern,
457 ContentSettingsPattern::Wildcard(),
458 CONTENT_SETTINGS_TYPE_COOKIES,
459 std::string(),
460 CONTENT_SETTING_BLOCK);
461 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed(
462 host_ending_with_dot, host_ending_with_dot));
464 EXPECT_EQ(CONTENT_SETTING_ALLOW,
465 host_content_settings_map->GetContentSetting(
466 host_ending_with_dot,
467 host_ending_with_dot,
468 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
469 std::string()));
470 host_content_settings_map->SetContentSetting(
471 pattern,
472 ContentSettingsPattern::Wildcard(),
473 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
474 std::string(),
475 CONTENT_SETTING_DEFAULT);
476 EXPECT_EQ(CONTENT_SETTING_ALLOW,
477 host_content_settings_map->GetContentSetting(
478 host_ending_with_dot,
479 host_ending_with_dot,
480 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
481 std::string()));
482 host_content_settings_map->SetContentSetting(
483 pattern,
484 ContentSettingsPattern::Wildcard(),
485 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
486 std::string(),
487 CONTENT_SETTING_BLOCK);
488 EXPECT_EQ(CONTENT_SETTING_BLOCK,
489 host_content_settings_map->GetContentSetting(
490 host_ending_with_dot,
491 host_ending_with_dot,
492 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
493 std::string()));
495 EXPECT_EQ(CONTENT_SETTING_ALLOW,
496 host_content_settings_map->GetContentSetting(
497 host_ending_with_dot,
498 host_ending_with_dot,
499 CONTENT_SETTINGS_TYPE_PLUGINS,
500 std::string()));
501 host_content_settings_map->SetContentSetting(
502 pattern,
503 ContentSettingsPattern::Wildcard(),
504 CONTENT_SETTINGS_TYPE_PLUGINS,
505 std::string(),
506 CONTENT_SETTING_DEFAULT);
507 EXPECT_EQ(CONTENT_SETTING_ALLOW,
508 host_content_settings_map->GetContentSetting(
509 host_ending_with_dot,
510 host_ending_with_dot,
511 CONTENT_SETTINGS_TYPE_PLUGINS,
512 std::string()));
513 host_content_settings_map->SetContentSetting(
514 pattern,
515 ContentSettingsPattern::Wildcard(),
516 CONTENT_SETTINGS_TYPE_PLUGINS,
517 std::string(),
518 CONTENT_SETTING_BLOCK);
519 EXPECT_EQ(CONTENT_SETTING_BLOCK,
520 host_content_settings_map->GetContentSetting(
521 host_ending_with_dot,
522 host_ending_with_dot,
523 CONTENT_SETTINGS_TYPE_PLUGINS,
524 std::string()));
526 EXPECT_EQ(
527 CONTENT_SETTING_BLOCK,
528 host_content_settings_map->GetContentSetting(host_ending_with_dot,
529 host_ending_with_dot,
530 CONTENT_SETTINGS_TYPE_POPUPS,
531 std::string()));
532 host_content_settings_map->SetContentSetting(
533 pattern,
534 ContentSettingsPattern::Wildcard(),
535 CONTENT_SETTINGS_TYPE_POPUPS,
536 std::string(),
537 CONTENT_SETTING_DEFAULT);
538 EXPECT_EQ(
539 CONTENT_SETTING_BLOCK,
540 host_content_settings_map->GetContentSetting(host_ending_with_dot,
541 host_ending_with_dot,
542 CONTENT_SETTINGS_TYPE_POPUPS,
543 std::string()));
544 host_content_settings_map->SetContentSetting(
545 pattern,
546 ContentSettingsPattern::Wildcard(),
547 CONTENT_SETTINGS_TYPE_POPUPS,
548 std::string(),
549 CONTENT_SETTING_ALLOW);
550 EXPECT_EQ(
551 CONTENT_SETTING_ALLOW,
552 host_content_settings_map->GetContentSetting(host_ending_with_dot,
553 host_ending_with_dot,
554 CONTENT_SETTINGS_TYPE_POPUPS,
555 std::string()));
558 TEST_F(HostContentSettingsMapTest, NestedSettings) {
559 TestingProfile profile;
560 HostContentSettingsMap* host_content_settings_map =
561 profile.GetHostContentSettingsMap();
563 GURL host("http://a.b.example.com/");
564 ContentSettingsPattern pattern1 =
565 ContentSettingsPattern::FromString("[*.]example.com");
566 ContentSettingsPattern pattern2 =
567 ContentSettingsPattern::FromString("[*.]b.example.com");
568 ContentSettingsPattern pattern3 =
569 ContentSettingsPattern::FromString("a.b.example.com");
571 host_content_settings_map->SetContentSetting(
572 pattern1,
573 ContentSettingsPattern::Wildcard(),
574 CONTENT_SETTINGS_TYPE_IMAGES,
575 std::string(),
576 CONTENT_SETTING_BLOCK);
578 host_content_settings_map->SetContentSetting(
579 pattern2,
580 ContentSettingsPattern::Wildcard(),
581 CONTENT_SETTINGS_TYPE_COOKIES,
582 std::string(),
583 CONTENT_SETTING_BLOCK);
585 host_content_settings_map->SetContentSetting(
586 pattern3,
587 ContentSettingsPattern::Wildcard(),
588 CONTENT_SETTINGS_TYPE_PLUGINS,
589 std::string(),
590 CONTENT_SETTING_BLOCK);
591 host_content_settings_map->SetDefaultContentSetting(
592 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
594 EXPECT_EQ(CONTENT_SETTING_BLOCK,
595 host_content_settings_map->GetContentSetting(
596 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
597 EXPECT_EQ(CONTENT_SETTING_BLOCK,
598 host_content_settings_map->GetContentSetting(
599 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
600 EXPECT_EQ(CONTENT_SETTING_BLOCK,
601 host_content_settings_map->GetContentSetting(
602 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
603 EXPECT_EQ(CONTENT_SETTING_BLOCK,
604 host_content_settings_map->GetContentSetting(
605 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
606 EXPECT_EQ(CONTENT_SETTING_BLOCK,
607 host_content_settings_map->GetContentSetting(
608 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
609 EXPECT_EQ(CONTENT_SETTING_ASK,
610 host_content_settings_map->GetContentSetting(
611 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
612 EXPECT_EQ(
613 CONTENT_SETTING_ASK,
614 host_content_settings_map->GetContentSetting(
615 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
616 EXPECT_EQ(CONTENT_SETTING_ASK,
617 host_content_settings_map->GetContentSetting(
618 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()));
619 EXPECT_EQ(CONTENT_SETTING_ASK,
620 host_content_settings_map->GetContentSetting(
621 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()));
624 TEST_F(HostContentSettingsMapTest, OffTheRecord) {
625 TestingProfile profile;
626 HostContentSettingsMap* host_content_settings_map =
627 profile.GetHostContentSettingsMap();
628 scoped_refptr<HostContentSettingsMap> otr_map(
629 new HostContentSettingsMap(profile.GetPrefs(),
630 true));
632 GURL host("http://example.com/");
633 ContentSettingsPattern pattern =
634 ContentSettingsPattern::FromString("[*.]example.com");
636 EXPECT_EQ(CONTENT_SETTING_ALLOW,
637 host_content_settings_map->GetContentSetting(
638 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
639 EXPECT_EQ(CONTENT_SETTING_ALLOW,
640 otr_map->GetContentSetting(
641 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
643 // Changing content settings on the main map should also affect the
644 // incognito map.
645 host_content_settings_map->SetContentSetting(
646 pattern,
647 ContentSettingsPattern::Wildcard(),
648 CONTENT_SETTINGS_TYPE_IMAGES,
649 std::string(),
650 CONTENT_SETTING_BLOCK);
651 EXPECT_EQ(CONTENT_SETTING_BLOCK,
652 host_content_settings_map->GetContentSetting(
653 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
654 EXPECT_EQ(CONTENT_SETTING_BLOCK,
655 otr_map->GetContentSetting(
656 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
658 // Changing content settings on the incognito map should NOT affect the
659 // main map.
660 otr_map->SetContentSetting(pattern,
661 ContentSettingsPattern::Wildcard(),
662 CONTENT_SETTINGS_TYPE_IMAGES,
663 std::string(),
664 CONTENT_SETTING_ALLOW);
665 EXPECT_EQ(CONTENT_SETTING_BLOCK,
666 host_content_settings_map->GetContentSetting(
667 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
668 EXPECT_EQ(CONTENT_SETTING_ALLOW,
669 otr_map->GetContentSetting(
670 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
672 otr_map->ShutdownOnUIThread();
675 // For a single Unicode encoded pattern, check if it gets converted to punycode
676 // and old pattern gets deleted.
677 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) {
678 TestingProfile profile;
679 PrefService* prefs = profile.GetPrefs();
681 // Set utf-8 data.
683 DictionaryPrefUpdate update(prefs, prefs::kContentSettingsPatternPairs);
684 base::DictionaryValue* all_settings_dictionary = update.Get();
685 ASSERT_TRUE(NULL != all_settings_dictionary);
687 base::DictionaryValue* dummy_payload = new base::DictionaryValue;
688 dummy_payload->SetInteger("images", CONTENT_SETTING_ALLOW);
689 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*",
690 dummy_payload);
692 profile.GetHostContentSettingsMap();
694 const base::DictionaryValue* all_settings_dictionary =
695 prefs->GetDictionary(prefs::kContentSettingsPatternPairs);
696 const base::DictionaryValue* result = NULL;
697 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
698 "[*.]\xC4\x87ira.com,*", &result));
699 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
700 "[*.]xn--ira-ppa.com,*", &result));
703 // If both Unicode and its punycode pattern exist, make sure we don't touch the
704 // settings for the punycode, and that Unicode pattern gets deleted.
705 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) {
706 TestingProfile profile;
708 scoped_ptr<base::Value> value(base::JSONReader::Read(
709 "{\"[*.]\\xC4\\x87ira.com,*\":{\"images\":1}}"));
710 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *value);
712 // Set punycode equivalent, with different setting.
713 scoped_ptr<base::Value> puny_value(base::JSONReader::Read(
714 "{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}"));
715 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *puny_value);
717 // Initialize the content map.
718 profile.GetHostContentSettingsMap();
720 const base::DictionaryValue* content_setting_prefs =
721 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs);
722 std::string prefs_as_json;
723 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json);
724 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}",
725 prefs_as_json.c_str());
728 // If a default-content-setting is managed, the managed value should be used
729 // instead of the default value.
730 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) {
731 TestingProfile profile;
732 HostContentSettingsMap* host_content_settings_map =
733 profile.GetHostContentSettingsMap();
734 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
736 EXPECT_EQ(CONTENT_SETTING_ALLOW,
737 host_content_settings_map->GetDefaultContentSetting(
738 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
740 // Set managed-default-content-setting through the coresponding preferences.
741 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
742 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
743 EXPECT_EQ(CONTENT_SETTING_BLOCK,
744 host_content_settings_map->GetDefaultContentSetting(
745 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
747 // Remove managed-default-content-settings-preferences.
748 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting);
749 EXPECT_EQ(CONTENT_SETTING_ALLOW,
750 host_content_settings_map->GetDefaultContentSetting(
751 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
753 // Set preference to manage the default-content-setting for Plugins.
754 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting,
755 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
756 EXPECT_EQ(CONTENT_SETTING_BLOCK,
757 host_content_settings_map->GetDefaultContentSetting(
758 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
760 // Remove the preference to manage the default-content-setting for Plugins.
761 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting);
762 EXPECT_EQ(CONTENT_SETTING_ALLOW,
763 host_content_settings_map->GetDefaultContentSetting(
764 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
767 TEST_F(HostContentSettingsMapTest,
768 GetNonDefaultContentSettingsIfTypeManaged) {
769 TestingProfile profile;
770 HostContentSettingsMap* host_content_settings_map =
771 profile.GetHostContentSettingsMap();
772 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
774 // Set pattern for JavaScript setting.
775 ContentSettingsPattern pattern =
776 ContentSettingsPattern::FromString("[*.]example.com");
777 host_content_settings_map->SetContentSetting(
778 pattern,
779 ContentSettingsPattern::Wildcard(),
780 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
781 std::string(),
782 CONTENT_SETTING_BLOCK);
784 EXPECT_EQ(CONTENT_SETTING_ALLOW,
785 host_content_settings_map->GetDefaultContentSetting(
786 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
788 GURL host("http://example.com/");
789 EXPECT_EQ(CONTENT_SETTING_BLOCK,
790 host_content_settings_map->GetContentSetting(
791 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
793 // Set managed-default-content-setting for content-settings-type JavaScript.
794 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
795 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
796 EXPECT_EQ(CONTENT_SETTING_ALLOW,
797 host_content_settings_map->GetContentSetting(
798 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
801 // Managed default content setting should have higher priority
802 // than user defined patterns.
803 TEST_F(HostContentSettingsMapTest,
804 ManagedDefaultContentSettingIgnoreUserPattern) {
805 TestingProfile profile;
806 HostContentSettingsMap* host_content_settings_map =
807 profile.GetHostContentSettingsMap();
808 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
810 // Block all JavaScript.
811 host_content_settings_map->SetDefaultContentSetting(
812 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
814 // Set an exception to allow "[*.]example.com"
815 ContentSettingsPattern pattern =
816 ContentSettingsPattern::FromString("[*.]example.com");
818 host_content_settings_map->SetContentSetting(
819 pattern,
820 ContentSettingsPattern::Wildcard(),
821 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
822 std::string(),
823 CONTENT_SETTING_ALLOW);
825 EXPECT_EQ(CONTENT_SETTING_BLOCK,
826 host_content_settings_map->GetDefaultContentSetting(
827 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
828 GURL host("http://example.com/");
829 EXPECT_EQ(CONTENT_SETTING_ALLOW,
830 host_content_settings_map->GetContentSetting(
831 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
833 // Set managed-default-content-settings-preferences.
834 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
835 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
836 EXPECT_EQ(CONTENT_SETTING_BLOCK,
837 host_content_settings_map->GetContentSetting(
838 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
840 // Remove managed-default-content-settings-preferences.
841 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting);
842 EXPECT_EQ(CONTENT_SETTING_ALLOW,
843 host_content_settings_map->GetContentSetting(
844 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
847 // If a default-content-setting is set to managed setting, the user defined
848 // setting should be preserved.
849 TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) {
850 TestingProfile profile;
851 HostContentSettingsMap* host_content_settings_map =
852 profile.GetHostContentSettingsMap();
853 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
855 // Set user defined default-content-setting for Cookies.
856 host_content_settings_map->SetDefaultContentSetting(
857 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
858 EXPECT_EQ(CONTENT_SETTING_BLOCK,
859 host_content_settings_map->GetDefaultContentSetting(
860 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
862 // Set preference to manage the default-content-setting for Cookies.
863 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting,
864 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
865 EXPECT_EQ(CONTENT_SETTING_ALLOW,
866 host_content_settings_map->GetDefaultContentSetting(
867 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
869 // Remove the preference to manage the default-content-setting for Cookies.
870 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting);
871 EXPECT_EQ(CONTENT_SETTING_BLOCK,
872 host_content_settings_map->GetDefaultContentSetting(
873 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
876 // If a setting for a default-content-setting-type is set while the type is
877 // managed, then the new setting should be preserved and used after the
878 // default-content-setting-type is not managed anymore.
879 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) {
880 TestingProfile profile;
881 HostContentSettingsMap* host_content_settings_map =
882 profile.GetHostContentSettingsMap();
883 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
885 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting,
886 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
887 EXPECT_EQ(CONTENT_SETTING_ALLOW,
888 host_content_settings_map->GetDefaultContentSetting(
889 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
891 host_content_settings_map->SetDefaultContentSetting(
892 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
893 EXPECT_EQ(CONTENT_SETTING_ALLOW,
894 host_content_settings_map->GetDefaultContentSetting(
895 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
897 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting);
898 EXPECT_EQ(CONTENT_SETTING_BLOCK,
899 host_content_settings_map->GetDefaultContentSetting(
900 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
903 TEST_F(HostContentSettingsMapTest, GetContentSetting) {
904 TestingProfile profile;
905 HostContentSettingsMap* host_content_settings_map =
906 profile.GetHostContentSettingsMap();
908 GURL host("http://example.com/");
909 GURL embedder("chrome://foo");
910 ContentSettingsPattern pattern =
911 ContentSettingsPattern::FromString("[*.]example.com");
912 host_content_settings_map->SetContentSetting(
913 pattern,
914 ContentSettingsPattern::Wildcard(),
915 CONTENT_SETTINGS_TYPE_IMAGES,
916 std::string(),
917 CONTENT_SETTING_BLOCK);
918 EXPECT_EQ(CONTENT_SETTING_BLOCK,
919 host_content_settings_map->GetContentSetting(
920 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
921 EXPECT_EQ(CONTENT_SETTING_ALLOW,
922 host_content_settings_map->GetContentSetting(
923 embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
926 TEST_F(HostContentSettingsMapTest, ShouldAllowAllContent) {
927 GURL http_host("http://example.com/");
928 GURL https_host("https://example.com/");
929 GURL embedder("chrome://foo");
930 GURL extension("chrome-extension://foo");
931 EXPECT_FALSE(HostContentSettingsMap::ShouldAllowAllContent(
932 http_host, embedder, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
933 EXPECT_FALSE(HostContentSettingsMap::ShouldAllowAllContent(
934 http_host, embedder, CONTENT_SETTINGS_TYPE_GEOLOCATION));
935 EXPECT_FALSE(HostContentSettingsMap::ShouldAllowAllContent(
936 http_host, embedder, CONTENT_SETTINGS_TYPE_COOKIES));
937 EXPECT_TRUE(HostContentSettingsMap::ShouldAllowAllContent(
938 https_host, embedder, CONTENT_SETTINGS_TYPE_COOKIES));
939 EXPECT_TRUE(HostContentSettingsMap::ShouldAllowAllContent(
940 https_host, embedder, CONTENT_SETTINGS_TYPE_COOKIES));
941 EXPECT_TRUE(HostContentSettingsMap::ShouldAllowAllContent(
942 embedder, http_host, CONTENT_SETTINGS_TYPE_COOKIES));
943 #if defined(ENABLE_EXTENSIONS)
944 EXPECT_TRUE(HostContentSettingsMap::ShouldAllowAllContent(
945 extension, extension, CONTENT_SETTINGS_TYPE_COOKIES));
946 #else
947 EXPECT_FALSE(HostContentSettingsMap::ShouldAllowAllContent(
948 extension, extension, CONTENT_SETTINGS_TYPE_COOKIES));
949 #endif
950 EXPECT_FALSE(HostContentSettingsMap::ShouldAllowAllContent(
951 extension, extension, CONTENT_SETTINGS_TYPE_PLUGINS));
952 EXPECT_FALSE(HostContentSettingsMap::ShouldAllowAllContent(
953 extension, http_host, CONTENT_SETTINGS_TYPE_COOKIES));
956 TEST_F(HostContentSettingsMapTest, IsSettingAllowedForType) {
957 TestingProfile profile;
958 PrefService* prefs = profile.GetPrefs();
960 EXPECT_TRUE(HostContentSettingsMap::IsSettingAllowedForType(
961 prefs, CONTENT_SETTING_ASK,
962 CONTENT_SETTINGS_TYPE_FULLSCREEN));
964 // TODO(msramek): Add more checks for setting type - setting pairs where
965 // it is not obvious whether or not they are allowed.
968 TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) {
969 TestingProfile profile;
970 HostContentSettingsMap* host_content_settings_map =
971 profile.GetHostContentSettingsMap();
972 content_settings::MockObserver mock_observer;
974 GURL host("http://example.com/");
975 ContentSettingsPattern pattern =
976 ContentSettingsPattern::FromString("[*.]example.com");
977 EXPECT_CALL(mock_observer,
978 OnContentSettingChanged(pattern,
979 ContentSettingsPattern::Wildcard(),
980 CONTENT_SETTINGS_TYPE_IMAGES,
981 ""));
983 host_content_settings_map->AddObserver(&mock_observer);
985 EXPECT_EQ(CONTENT_SETTING_ALLOW,
986 host_content_settings_map->GetContentSetting(
987 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
988 host_content_settings_map->SetContentSetting(
989 pattern,
990 ContentSettingsPattern::Wildcard(),
991 CONTENT_SETTINGS_TYPE_IMAGES,
992 std::string(),
993 CONTENT_SETTING_DEFAULT);
996 TEST_F(HostContentSettingsMapTest, OverrideAllowedWebsiteSetting) {
997 TestingProfile profile;
998 HostContentSettingsMap* host_content_settings_map =
999 profile.GetHostContentSettingsMap();
1000 GURL host("http://example.com/");
1001 ContentSettingsPattern pattern =
1002 ContentSettingsPattern::FromString("[*.]example.com");
1003 host_content_settings_map->SetContentSetting(
1004 pattern,
1005 ContentSettingsPattern::Wildcard(),
1006 CONTENT_SETTINGS_TYPE_GEOLOCATION,
1007 std::string(),
1008 CONTENT_SETTING_ALLOW);
1010 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1011 host_content_settings_map->GetContentSetting(
1012 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
1014 // Disabling should override an allowed exception.
1015 host_content_settings_map->SetContentSettingOverride(
1016 CONTENT_SETTINGS_TYPE_GEOLOCATION, false);
1017 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1018 host_content_settings_map->GetContentSetting(
1019 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
1021 host_content_settings_map->SetContentSettingOverride(
1022 CONTENT_SETTINGS_TYPE_GEOLOCATION, true);
1023 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1024 host_content_settings_map->GetContentSetting(
1025 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
1028 TEST_F(HostContentSettingsMapTest, OverrideAllowedDefaultSetting) {
1029 TestingProfile profile;
1030 HostContentSettingsMap* host_content_settings_map =
1031 profile.GetHostContentSettingsMap();
1033 // Check setting defaults.
1034 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1035 host_content_settings_map->GetDefaultContentSetting(
1036 CONTENT_SETTINGS_TYPE_IMAGES, NULL));
1038 GURL host("http://example.com/");
1039 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1040 host_content_settings_map->GetContentSetting(
1041 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1043 // Disabling should override an allowed default setting.
1044 host_content_settings_map->SetContentSettingOverride(
1045 CONTENT_SETTINGS_TYPE_IMAGES, false);
1046 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1047 host_content_settings_map->GetContentSetting(
1048 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1050 // Enabling shouldn't override positively.
1051 host_content_settings_map->SetContentSettingOverride(
1052 CONTENT_SETTINGS_TYPE_IMAGES, true);
1053 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1054 host_content_settings_map->GetContentSetting(
1055 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1056 host_content_settings_map->SetDefaultContentSetting(
1057 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
1058 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1059 host_content_settings_map->GetContentSetting(
1060 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));