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

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

Issue 596613002: Remove content dependencies from content settings providers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: shutdown fix Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/auto_reset.h" 5 #include "base/auto_reset.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
11 #include "base/prefs/scoped_user_pref_update.h" 10 #include "base/prefs/scoped_user_pref_update.h"
12 #include "chrome/browser/content_settings/content_settings_mock_observer.h" 11 #include "chrome/browser/content_settings/content_settings_mock_observer.h"
13 #include "chrome/browser/content_settings/cookie_settings.h" 12 #include "chrome/browser/content_settings/cookie_settings.h"
14 #include "chrome/browser/content_settings/host_content_settings_map.h" 13 #include "chrome/browser/content_settings/host_content_settings_map.h"
15 #include "chrome/browser/content_settings/mock_settings_observer.h" 14 #include "chrome/browser/content_settings/mock_settings_observer.h"
16 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
18 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
19 #include "chrome/test/base/testing_pref_service_syncable.h" 18 #include "chrome/test/base/testing_pref_service_syncable.h"
20 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
21 #include "components/content_settings/core/browser/content_settings_details.h" 20 #include "components/content_settings/core/browser/content_settings_details.h"
22 #include "content/public/test/test_browser_thread.h"
23 #include "net/base/static_cookie_policy.h" 21 #include "net/base/static_cookie_policy.h"
24 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
25 #include "url/gurl.h" 23 #include "url/gurl.h"
26 24
27 using content::BrowserThread;
28
29 using ::testing::_; 25 using ::testing::_;
30 26
31 class HostContentSettingsMapTest : public testing::Test { 27 TEST(HostContentSettingsMapTest, DefaultValues) {
32 public:
33 HostContentSettingsMapTest() : ui_thread_(BrowserThread::UI, &message_loop_) {
34 }
35
36 protected:
37 base::MessageLoop message_loop_;
38 content::TestBrowserThread ui_thread_;
39 };
40
41 TEST_F(HostContentSettingsMapTest, DefaultValues) {
42 TestingProfile profile; 28 TestingProfile profile;
43 HostContentSettingsMap* host_content_settings_map = 29 HostContentSettingsMap* host_content_settings_map =
44 profile.GetHostContentSettingsMap(); 30 profile.GetHostContentSettingsMap();
45 31
46 // Check setting defaults. 32 // Check setting defaults.
47 EXPECT_EQ(CONTENT_SETTING_ALLOW, 33 EXPECT_EQ(CONTENT_SETTING_ALLOW,
48 host_content_settings_map->GetDefaultContentSetting( 34 host_content_settings_map->GetDefaultContentSetting(
49 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); 35 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
50 host_content_settings_map->SetDefaultContentSetting( 36 host_content_settings_map->SetDefaultContentSetting(
51 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); 37 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
(...skipping 12 matching lines...) Expand all
64 host_content_settings_map->GetDefaultContentSetting( 50 host_content_settings_map->GetDefaultContentSetting(
65 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 51 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
66 } 52 }
67 host_content_settings_map->SetDefaultContentSetting( 53 host_content_settings_map->SetDefaultContentSetting(
68 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_ALLOW); 54 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_ALLOW);
69 EXPECT_EQ(CONTENT_SETTING_ALLOW, 55 EXPECT_EQ(CONTENT_SETTING_ALLOW,
70 host_content_settings_map->GetDefaultContentSetting( 56 host_content_settings_map->GetDefaultContentSetting(
71 CONTENT_SETTINGS_TYPE_POPUPS, NULL)); 57 CONTENT_SETTINGS_TYPE_POPUPS, NULL));
72 } 58 }
73 59
74 TEST_F(HostContentSettingsMapTest, IndividualSettings) { 60 TEST(HostContentSettingsMapTest, IndividualSettings) {
75 TestingProfile profile; 61 TestingProfile profile;
76 HostContentSettingsMap* host_content_settings_map = 62 HostContentSettingsMap* host_content_settings_map =
77 profile.GetHostContentSettingsMap(); 63 profile.GetHostContentSettingsMap();
78 64
79 // Check returning individual settings. 65 // Check returning individual settings.
80 GURL host("http://example.com/"); 66 GURL host("http://example.com/");
81 ContentSettingsPattern pattern = 67 ContentSettingsPattern pattern =
82 ContentSettingsPattern::FromString("[*.]example.com"); 68 ContentSettingsPattern::FromString("[*.]example.com");
83 EXPECT_EQ(CONTENT_SETTING_ALLOW, 69 EXPECT_EQ(CONTENT_SETTING_ALLOW,
84 host_content_settings_map->GetContentSetting( 70 host_content_settings_map->GetContentSetting(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 host_content_settings_map->GetSettingsForOneType( 159 host_content_settings_map->GetSettingsForOneType(
174 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); 160 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings);
175 // |host_settings| contains the default setting and 2 exceptions. 161 // |host_settings| contains the default setting and 2 exceptions.
176 EXPECT_EQ(3U, host_settings.size()); 162 EXPECT_EQ(3U, host_settings.size());
177 host_content_settings_map->GetSettingsForOneType( 163 host_content_settings_map->GetSettingsForOneType(
178 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings); 164 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings);
179 // |host_settings| contains only the default setting. 165 // |host_settings| contains only the default setting.
180 EXPECT_EQ(1U, host_settings.size()); 166 EXPECT_EQ(1U, host_settings.size());
181 } 167 }
182 168
183 TEST_F(HostContentSettingsMapTest, Clear) { 169 TEST(HostContentSettingsMapTest, Clear) {
184 TestingProfile profile; 170 TestingProfile profile;
185 HostContentSettingsMap* host_content_settings_map = 171 HostContentSettingsMap* host_content_settings_map =
186 profile.GetHostContentSettingsMap(); 172 profile.GetHostContentSettingsMap();
187 173
188 // Check clearing one type. 174 // Check clearing one type.
189 ContentSettingsPattern pattern = 175 ContentSettingsPattern pattern =
190 ContentSettingsPattern::FromString("[*.]example.org"); 176 ContentSettingsPattern::FromString("[*.]example.org");
191 ContentSettingsPattern pattern2 = 177 ContentSettingsPattern pattern2 =
192 ContentSettingsPattern::FromString("[*.]example.net"); 178 ContentSettingsPattern::FromString("[*.]example.net");
193 host_content_settings_map->SetContentSetting( 179 host_content_settings_map->SetContentSetting(
(...skipping 26 matching lines...) Expand all
220 host_content_settings_map->GetSettingsForOneType( 206 host_content_settings_map->GetSettingsForOneType(
221 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings); 207 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings);
222 // |host_settings| contains only the default setting. 208 // |host_settings| contains only the default setting.
223 EXPECT_EQ(1U, host_settings.size()); 209 EXPECT_EQ(1U, host_settings.size());
224 host_content_settings_map->GetSettingsForOneType( 210 host_content_settings_map->GetSettingsForOneType(
225 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); 211 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings);
226 // |host_settings| contains the default setting and an exception. 212 // |host_settings| contains the default setting and an exception.
227 EXPECT_EQ(2U, host_settings.size()); 213 EXPECT_EQ(2U, host_settings.size());
228 } 214 }
229 215
230 TEST_F(HostContentSettingsMapTest, Patterns) { 216 TEST(HostContentSettingsMapTest, Patterns) {
231 TestingProfile profile; 217 TestingProfile profile;
232 HostContentSettingsMap* host_content_settings_map = 218 HostContentSettingsMap* host_content_settings_map =
233 profile.GetHostContentSettingsMap(); 219 profile.GetHostContentSettingsMap();
234 220
235 GURL host1("http://example.com/"); 221 GURL host1("http://example.com/");
236 GURL host2("http://www.example.com/"); 222 GURL host2("http://www.example.com/");
237 GURL host3("http://example.org/"); 223 GURL host3("http://example.org/");
238 ContentSettingsPattern pattern1 = 224 ContentSettingsPattern pattern1 =
239 ContentSettingsPattern::FromString("[*.]example.com"); 225 ContentSettingsPattern::FromString("[*.]example.com");
240 ContentSettingsPattern pattern2 = 226 ContentSettingsPattern pattern2 =
(...skipping 20 matching lines...) Expand all
261 pattern2, 247 pattern2,
262 ContentSettingsPattern::Wildcard(), 248 ContentSettingsPattern::Wildcard(),
263 CONTENT_SETTINGS_TYPE_IMAGES, 249 CONTENT_SETTINGS_TYPE_IMAGES,
264 std::string(), 250 std::string(),
265 CONTENT_SETTING_BLOCK); 251 CONTENT_SETTING_BLOCK);
266 EXPECT_EQ(CONTENT_SETTING_BLOCK, 252 EXPECT_EQ(CONTENT_SETTING_BLOCK,
267 host_content_settings_map->GetContentSetting( 253 host_content_settings_map->GetContentSetting(
268 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 254 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
269 } 255 }
270 256
271 TEST_F(HostContentSettingsMapTest, Observer) { 257 TEST(HostContentSettingsMapTest, Observer) {
272 TestingProfile profile; 258 TestingProfile profile;
273 HostContentSettingsMap* host_content_settings_map = 259 HostContentSettingsMap* host_content_settings_map =
274 profile.GetHostContentSettingsMap(); 260 profile.GetHostContentSettingsMap();
275 MockSettingsObserver observer(host_content_settings_map); 261 MockSettingsObserver observer(host_content_settings_map);
276 262
277 ContentSettingsPattern primary_pattern = 263 ContentSettingsPattern primary_pattern =
278 ContentSettingsPattern::FromString("[*.]example.com"); 264 ContentSettingsPattern::FromString("[*.]example.com");
279 ContentSettingsPattern secondary_pattern = 265 ContentSettingsPattern secondary_pattern =
280 ContentSettingsPattern::Wildcard(); 266 ContentSettingsPattern::Wildcard();
281 EXPECT_CALL(observer, 267 EXPECT_CALL(observer,
(...skipping 20 matching lines...) Expand all
302 ::testing::Mock::VerifyAndClearExpectations(&observer); 288 ::testing::Mock::VerifyAndClearExpectations(&observer);
303 289
304 EXPECT_CALL(observer, 290 EXPECT_CALL(observer,
305 OnContentSettingsChanged(host_content_settings_map, 291 OnContentSettingsChanged(host_content_settings_map,
306 CONTENT_SETTINGS_TYPE_IMAGES, false, 292 CONTENT_SETTINGS_TYPE_IMAGES, false,
307 _, _, true)); 293 _, _, true));
308 host_content_settings_map->SetDefaultContentSetting( 294 host_content_settings_map->SetDefaultContentSetting(
309 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); 295 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
310 } 296 }
311 297
312 TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) { 298 TEST(HostContentSettingsMapTest, ObserveDefaultPref) {
313 TestingProfile profile; 299 TestingProfile profile;
314 HostContentSettingsMap* host_content_settings_map = 300 HostContentSettingsMap* host_content_settings_map =
315 profile.GetHostContentSettingsMap(); 301 profile.GetHostContentSettingsMap();
316 302
317 PrefService* prefs = profile.GetPrefs(); 303 PrefService* prefs = profile.GetPrefs();
318 304
319 // Make a copy of the default pref value so we can reset it later. 305 // Make a copy of the default pref value so we can reset it later.
320 scoped_ptr<base::Value> default_value(prefs->FindPreference( 306 scoped_ptr<base::Value> default_value(prefs->FindPreference(
321 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); 307 prefs::kDefaultContentSettings)->GetValue()->DeepCopy());
322 308
(...skipping 15 matching lines...) Expand all
338 host_content_settings_map->GetContentSetting( 324 host_content_settings_map->GetContentSetting(
339 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 325 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
340 326
341 // Reseting the pref to its previous value should update the cache. 327 // Reseting the pref to its previous value should update the cache.
342 prefs->Set(prefs::kDefaultContentSettings, *new_value); 328 prefs->Set(prefs::kDefaultContentSettings, *new_value);
343 EXPECT_EQ(CONTENT_SETTING_BLOCK, 329 EXPECT_EQ(CONTENT_SETTING_BLOCK,
344 host_content_settings_map->GetContentSetting( 330 host_content_settings_map->GetContentSetting(
345 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 331 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
346 } 332 }
347 333
348 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { 334 TEST(HostContentSettingsMapTest, ObserveExceptionPref) {
349 TestingProfile profile; 335 TestingProfile profile;
350 HostContentSettingsMap* host_content_settings_map = 336 HostContentSettingsMap* host_content_settings_map =
351 profile.GetHostContentSettingsMap(); 337 profile.GetHostContentSettingsMap();
352 338
353 PrefService* prefs = profile.GetPrefs(); 339 PrefService* prefs = profile.GetPrefs();
354 340
355 // Make a copy of the default pref value so we can reset it later. 341 // Make a copy of the default pref value so we can reset it later.
356 scoped_ptr<base::Value> default_value(prefs->FindPreference( 342 scoped_ptr<base::Value> default_value(prefs->FindPreference(
357 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); 343 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy());
358 344
(...skipping 25 matching lines...) Expand all
384 host_content_settings_map->GetContentSetting( 370 host_content_settings_map->GetContentSetting(
385 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 371 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
386 372
387 // Reseting the pref to its previous value should update the cache. 373 // Reseting the pref to its previous value should update the cache.
388 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value); 374 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value);
389 EXPECT_EQ(CONTENT_SETTING_BLOCK, 375 EXPECT_EQ(CONTENT_SETTING_BLOCK,
390 host_content_settings_map->GetContentSetting( 376 host_content_settings_map->GetContentSetting(
391 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 377 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
392 } 378 }
393 379
394 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { 380 TEST(HostContentSettingsMapTest, HostTrimEndingDotCheck) {
395 TestingProfile profile; 381 TestingProfile profile;
396 HostContentSettingsMap* host_content_settings_map = 382 HostContentSettingsMap* host_content_settings_map =
397 profile.GetHostContentSettingsMap(); 383 profile.GetHostContentSettingsMap();
398 CookieSettings* cookie_settings = 384 CookieSettings* cookie_settings =
399 CookieSettings::Factory::GetForProfile(&profile).get(); 385 CookieSettings::Factory::GetForProfile(&profile).get();
400 386
401 ContentSettingsPattern pattern = 387 ContentSettingsPattern pattern =
402 ContentSettingsPattern::FromString("[*.]example.com"); 388 ContentSettingsPattern::FromString("[*.]example.com");
403 GURL host_ending_with_dot("http://example.com./"); 389 GURL host_ending_with_dot("http://example.com./");
404 390
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 std::string(), 525 std::string(),
540 CONTENT_SETTING_ALLOW); 526 CONTENT_SETTING_ALLOW);
541 EXPECT_EQ( 527 EXPECT_EQ(
542 CONTENT_SETTING_ALLOW, 528 CONTENT_SETTING_ALLOW,
543 host_content_settings_map->GetContentSetting(host_ending_with_dot, 529 host_content_settings_map->GetContentSetting(host_ending_with_dot,
544 host_ending_with_dot, 530 host_ending_with_dot,
545 CONTENT_SETTINGS_TYPE_POPUPS, 531 CONTENT_SETTINGS_TYPE_POPUPS,
546 std::string())); 532 std::string()));
547 } 533 }
548 534
549 TEST_F(HostContentSettingsMapTest, NestedSettings) { 535 TEST(HostContentSettingsMapTest, NestedSettings) {
550 TestingProfile profile; 536 TestingProfile profile;
551 HostContentSettingsMap* host_content_settings_map = 537 HostContentSettingsMap* host_content_settings_map =
552 profile.GetHostContentSettingsMap(); 538 profile.GetHostContentSettingsMap();
553 539
554 GURL host("http://a.b.example.com/"); 540 GURL host("http://a.b.example.com/");
555 ContentSettingsPattern pattern1 = 541 ContentSettingsPattern pattern1 =
556 ContentSettingsPattern::FromString("[*.]example.com"); 542 ContentSettingsPattern::FromString("[*.]example.com");
557 ContentSettingsPattern pattern2 = 543 ContentSettingsPattern pattern2 =
558 ContentSettingsPattern::FromString("[*.]b.example.com"); 544 ContentSettingsPattern::FromString("[*.]b.example.com");
559 ContentSettingsPattern pattern3 = 545 ContentSettingsPattern pattern3 =
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 host_content_settings_map->GetContentSetting( 591 host_content_settings_map->GetContentSetting(
606 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); 592 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
607 EXPECT_EQ(CONTENT_SETTING_ASK, 593 EXPECT_EQ(CONTENT_SETTING_ASK,
608 host_content_settings_map->GetContentSetting( 594 host_content_settings_map->GetContentSetting(
609 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string())); 595 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()));
610 EXPECT_EQ(CONTENT_SETTING_ASK, 596 EXPECT_EQ(CONTENT_SETTING_ASK,
611 host_content_settings_map->GetContentSetting( 597 host_content_settings_map->GetContentSetting(
612 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); 598 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()));
613 } 599 }
614 600
615 TEST_F(HostContentSettingsMapTest, OffTheRecord) { 601 TEST(HostContentSettingsMapTest, OffTheRecord) {
616 TestingProfile profile; 602 TestingProfile profile;
617 HostContentSettingsMap* host_content_settings_map = 603 HostContentSettingsMap* host_content_settings_map =
618 profile.GetHostContentSettingsMap(); 604 profile.GetHostContentSettingsMap();
619 scoped_refptr<HostContentSettingsMap> otr_map( 605 scoped_refptr<HostContentSettingsMap> otr_map(
620 new HostContentSettingsMap(profile.GetPrefs(), 606 new HostContentSettingsMap(profile.GetPrefs(),
621 true)); 607 true));
622 608
623 GURL host("http://example.com/"); 609 GURL host("http://example.com/");
624 ContentSettingsPattern pattern = 610 ContentSettingsPattern pattern =
625 ContentSettingsPattern::FromString("[*.]example.com"); 611 ContentSettingsPattern::FromString("[*.]example.com");
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 644 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
659 EXPECT_EQ(CONTENT_SETTING_ALLOW, 645 EXPECT_EQ(CONTENT_SETTING_ALLOW,
660 otr_map->GetContentSetting( 646 otr_map->GetContentSetting(
661 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 647 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
662 648
663 otr_map->ShutdownOnUIThread(); 649 otr_map->ShutdownOnUIThread();
664 } 650 }
665 651
666 // For a single Unicode encoded pattern, check if it gets converted to punycode 652 // For a single Unicode encoded pattern, check if it gets converted to punycode
667 // and old pattern gets deleted. 653 // and old pattern gets deleted.
668 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) { 654 TEST(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) {
669 TestingProfile profile; 655 TestingProfile profile;
670 PrefService* prefs = profile.GetPrefs(); 656 PrefService* prefs = profile.GetPrefs();
671 657
672 // Set utf-8 data. 658 // Set utf-8 data.
673 { 659 {
674 DictionaryPrefUpdate update(prefs, prefs::kContentSettingsPatternPairs); 660 DictionaryPrefUpdate update(prefs, prefs::kContentSettingsPatternPairs);
675 base::DictionaryValue* all_settings_dictionary = update.Get(); 661 base::DictionaryValue* all_settings_dictionary = update.Get();
676 ASSERT_TRUE(NULL != all_settings_dictionary); 662 ASSERT_TRUE(NULL != all_settings_dictionary);
677 663
678 base::DictionaryValue* dummy_payload = new base::DictionaryValue; 664 base::DictionaryValue* dummy_payload = new base::DictionaryValue;
679 dummy_payload->SetInteger("images", CONTENT_SETTING_ALLOW); 665 dummy_payload->SetInteger("images", CONTENT_SETTING_ALLOW);
680 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*", 666 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*",
681 dummy_payload); 667 dummy_payload);
682 } 668 }
683 profile.GetHostContentSettingsMap(); 669 profile.GetHostContentSettingsMap();
684 670
685 const base::DictionaryValue* all_settings_dictionary = 671 const base::DictionaryValue* all_settings_dictionary =
686 prefs->GetDictionary(prefs::kContentSettingsPatternPairs); 672 prefs->GetDictionary(prefs::kContentSettingsPatternPairs);
687 const base::DictionaryValue* result = NULL; 673 const base::DictionaryValue* result = NULL;
688 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( 674 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
689 "[*.]\xC4\x87ira.com,*", &result)); 675 "[*.]\xC4\x87ira.com,*", &result));
690 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( 676 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
691 "[*.]xn--ira-ppa.com,*", &result)); 677 "[*.]xn--ira-ppa.com,*", &result));
692 } 678 }
693 679
694 // If both Unicode and its punycode pattern exist, make sure we don't touch the 680 // If both Unicode and its punycode pattern exist, make sure we don't touch the
695 // settings for the punycode, and that Unicode pattern gets deleted. 681 // settings for the punycode, and that Unicode pattern gets deleted.
696 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) { 682 TEST(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) {
697 TestingProfile profile; 683 TestingProfile profile;
698 684
699 scoped_ptr<base::Value> value(base::JSONReader::Read( 685 scoped_ptr<base::Value> value(base::JSONReader::Read(
700 "{\"[*.]\\xC4\\x87ira.com,*\":{\"images\":1}}")); 686 "{\"[*.]\\xC4\\x87ira.com,*\":{\"images\":1}}"));
701 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *value); 687 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *value);
702 688
703 // Set punycode equivalent, with different setting. 689 // Set punycode equivalent, with different setting.
704 scoped_ptr<base::Value> puny_value(base::JSONReader::Read( 690 scoped_ptr<base::Value> puny_value(base::JSONReader::Read(
705 "{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}")); 691 "{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}"));
706 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *puny_value); 692 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *puny_value);
707 693
708 // Initialize the content map. 694 // Initialize the content map.
709 profile.GetHostContentSettingsMap(); 695 profile.GetHostContentSettingsMap();
710 696
711 const base::DictionaryValue* content_setting_prefs = 697 const base::DictionaryValue* content_setting_prefs =
712 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs); 698 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs);
713 std::string prefs_as_json; 699 std::string prefs_as_json;
714 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json); 700 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json);
715 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}", 701 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}",
716 prefs_as_json.c_str()); 702 prefs_as_json.c_str());
717 } 703 }
718 704
719 // If a default-content-setting is managed, the managed value should be used 705 // If a default-content-setting is managed, the managed value should be used
720 // instead of the default value. 706 // instead of the default value.
721 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) { 707 TEST(HostContentSettingsMapTest, ManagedDefaultContentSetting) {
722 TestingProfile profile; 708 TestingProfile profile;
723 HostContentSettingsMap* host_content_settings_map = 709 HostContentSettingsMap* host_content_settings_map =
724 profile.GetHostContentSettingsMap(); 710 profile.GetHostContentSettingsMap();
725 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 711 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
726 712
727 EXPECT_EQ(CONTENT_SETTING_ALLOW, 713 EXPECT_EQ(CONTENT_SETTING_ALLOW,
728 host_content_settings_map->GetDefaultContentSetting( 714 host_content_settings_map->GetDefaultContentSetting(
729 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); 715 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
730 716
731 // Set managed-default-content-setting through the coresponding preferences. 717 // Set managed-default-content-setting through the coresponding preferences.
(...skipping 16 matching lines...) Expand all
748 host_content_settings_map->GetDefaultContentSetting( 734 host_content_settings_map->GetDefaultContentSetting(
749 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 735 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
750 736
751 // Remove the preference to manage the default-content-setting for Plugins. 737 // Remove the preference to manage the default-content-setting for Plugins.
752 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); 738 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting);
753 EXPECT_EQ(CONTENT_SETTING_ALLOW, 739 EXPECT_EQ(CONTENT_SETTING_ALLOW,
754 host_content_settings_map->GetDefaultContentSetting( 740 host_content_settings_map->GetDefaultContentSetting(
755 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 741 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
756 } 742 }
757 743
758 TEST_F(HostContentSettingsMapTest, 744 TEST(HostContentSettingsMapTest, GetNonDefaultContentSettingsIfTypeManaged) {
759 GetNonDefaultContentSettingsIfTypeManaged) {
760 TestingProfile profile; 745 TestingProfile profile;
761 HostContentSettingsMap* host_content_settings_map = 746 HostContentSettingsMap* host_content_settings_map =
762 profile.GetHostContentSettingsMap(); 747 profile.GetHostContentSettingsMap();
763 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 748 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
764 749
765 // Set pattern for JavaScript setting. 750 // Set pattern for JavaScript setting.
766 ContentSettingsPattern pattern = 751 ContentSettingsPattern pattern =
767 ContentSettingsPattern::FromString("[*.]example.com"); 752 ContentSettingsPattern::FromString("[*.]example.com");
768 host_content_settings_map->SetContentSetting( 753 host_content_settings_map->SetContentSetting(
769 pattern, 754 pattern,
(...skipping 14 matching lines...) Expand all
784 // Set managed-default-content-setting for content-settings-type JavaScript. 769 // Set managed-default-content-setting for content-settings-type JavaScript.
785 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, 770 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
786 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 771 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
787 EXPECT_EQ(CONTENT_SETTING_ALLOW, 772 EXPECT_EQ(CONTENT_SETTING_ALLOW,
788 host_content_settings_map->GetContentSetting( 773 host_content_settings_map->GetContentSetting(
789 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 774 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
790 } 775 }
791 776
792 // Managed default content setting should have higher priority 777 // Managed default content setting should have higher priority
793 // than user defined patterns. 778 // than user defined patterns.
794 TEST_F(HostContentSettingsMapTest, 779 TEST(HostContentSettingsMapTest,
795 ManagedDefaultContentSettingIgnoreUserPattern) { 780 ManagedDefaultContentSettingIgnoreUserPattern) {
796 TestingProfile profile; 781 TestingProfile profile;
797 HostContentSettingsMap* host_content_settings_map = 782 HostContentSettingsMap* host_content_settings_map =
798 profile.GetHostContentSettingsMap(); 783 profile.GetHostContentSettingsMap();
799 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 784 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
800 785
801 // Block all JavaScript. 786 // Block all JavaScript.
802 host_content_settings_map->SetDefaultContentSetting( 787 host_content_settings_map->SetDefaultContentSetting(
803 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); 788 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
804 789
805 // Set an exception to allow "[*.]example.com" 790 // Set an exception to allow "[*.]example.com"
(...skipping 24 matching lines...) Expand all
830 815
831 // Remove managed-default-content-settings-preferences. 816 // Remove managed-default-content-settings-preferences.
832 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting); 817 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting);
833 EXPECT_EQ(CONTENT_SETTING_ALLOW, 818 EXPECT_EQ(CONTENT_SETTING_ALLOW,
834 host_content_settings_map->GetContentSetting( 819 host_content_settings_map->GetContentSetting(
835 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 820 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
836 } 821 }
837 822
838 // If a default-content-setting is set to managed setting, the user defined 823 // If a default-content-setting is set to managed setting, the user defined
839 // setting should be preserved. 824 // setting should be preserved.
840 TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) { 825 TEST(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) {
841 TestingProfile profile; 826 TestingProfile profile;
842 HostContentSettingsMap* host_content_settings_map = 827 HostContentSettingsMap* host_content_settings_map =
843 profile.GetHostContentSettingsMap(); 828 profile.GetHostContentSettingsMap();
844 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 829 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
845 830
846 // Set user defined default-content-setting for Cookies. 831 // Set user defined default-content-setting for Cookies.
847 host_content_settings_map->SetDefaultContentSetting( 832 host_content_settings_map->SetDefaultContentSetting(
848 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); 833 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
849 EXPECT_EQ(CONTENT_SETTING_BLOCK, 834 EXPECT_EQ(CONTENT_SETTING_BLOCK,
850 host_content_settings_map->GetDefaultContentSetting( 835 host_content_settings_map->GetDefaultContentSetting(
851 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); 836 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
852 837
853 // Set preference to manage the default-content-setting for Cookies. 838 // Set preference to manage the default-content-setting for Cookies.
854 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting, 839 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting,
855 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 840 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
856 EXPECT_EQ(CONTENT_SETTING_ALLOW, 841 EXPECT_EQ(CONTENT_SETTING_ALLOW,
857 host_content_settings_map->GetDefaultContentSetting( 842 host_content_settings_map->GetDefaultContentSetting(
858 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); 843 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
859 844
860 // Remove the preference to manage the default-content-setting for Cookies. 845 // Remove the preference to manage the default-content-setting for Cookies.
861 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting); 846 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting);
862 EXPECT_EQ(CONTENT_SETTING_BLOCK, 847 EXPECT_EQ(CONTENT_SETTING_BLOCK,
863 host_content_settings_map->GetDefaultContentSetting( 848 host_content_settings_map->GetDefaultContentSetting(
864 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); 849 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
865 } 850 }
866 851
867 // If a setting for a default-content-setting-type is set while the type is 852 // If a setting for a default-content-setting-type is set while the type is
868 // managed, then the new setting should be preserved and used after the 853 // managed, then the new setting should be preserved and used after the
869 // default-content-setting-type is not managed anymore. 854 // default-content-setting-type is not managed anymore.
870 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) { 855 TEST(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) {
871 TestingProfile profile; 856 TestingProfile profile;
872 HostContentSettingsMap* host_content_settings_map = 857 HostContentSettingsMap* host_content_settings_map =
873 profile.GetHostContentSettingsMap(); 858 profile.GetHostContentSettingsMap();
874 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 859 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
875 860
876 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, 861 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting,
877 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 862 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
878 EXPECT_EQ(CONTENT_SETTING_ALLOW, 863 EXPECT_EQ(CONTENT_SETTING_ALLOW,
879 host_content_settings_map->GetDefaultContentSetting( 864 host_content_settings_map->GetDefaultContentSetting(
880 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 865 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
881 866
882 host_content_settings_map->SetDefaultContentSetting( 867 host_content_settings_map->SetDefaultContentSetting(
883 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); 868 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
884 EXPECT_EQ(CONTENT_SETTING_ALLOW, 869 EXPECT_EQ(CONTENT_SETTING_ALLOW,
885 host_content_settings_map->GetDefaultContentSetting( 870 host_content_settings_map->GetDefaultContentSetting(
886 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 871 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
887 872
888 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); 873 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting);
889 EXPECT_EQ(CONTENT_SETTING_BLOCK, 874 EXPECT_EQ(CONTENT_SETTING_BLOCK,
890 host_content_settings_map->GetDefaultContentSetting( 875 host_content_settings_map->GetDefaultContentSetting(
891 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 876 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
892 } 877 }
893 878
894 TEST_F(HostContentSettingsMapTest, GetContentSetting) { 879 TEST(HostContentSettingsMapTest, GetContentSetting) {
895 TestingProfile profile; 880 TestingProfile profile;
896 HostContentSettingsMap* host_content_settings_map = 881 HostContentSettingsMap* host_content_settings_map =
897 profile.GetHostContentSettingsMap(); 882 profile.GetHostContentSettingsMap();
898 883
899 GURL host("http://example.com/"); 884 GURL host("http://example.com/");
900 GURL embedder("chrome://foo"); 885 GURL embedder("chrome://foo");
901 ContentSettingsPattern pattern = 886 ContentSettingsPattern pattern =
902 ContentSettingsPattern::FromString("[*.]example.com"); 887 ContentSettingsPattern::FromString("[*.]example.com");
903 host_content_settings_map->SetContentSetting( 888 host_content_settings_map->SetContentSetting(
904 pattern, 889 pattern,
905 ContentSettingsPattern::Wildcard(), 890 ContentSettingsPattern::Wildcard(),
906 CONTENT_SETTINGS_TYPE_IMAGES, 891 CONTENT_SETTINGS_TYPE_IMAGES,
907 std::string(), 892 std::string(),
908 CONTENT_SETTING_BLOCK); 893 CONTENT_SETTING_BLOCK);
909 EXPECT_EQ(CONTENT_SETTING_BLOCK, 894 EXPECT_EQ(CONTENT_SETTING_BLOCK,
910 host_content_settings_map->GetContentSetting( 895 host_content_settings_map->GetContentSetting(
911 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 896 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
912 EXPECT_EQ(CONTENT_SETTING_ALLOW, 897 EXPECT_EQ(CONTENT_SETTING_ALLOW,
913 host_content_settings_map->GetContentSetting( 898 host_content_settings_map->GetContentSetting(
914 embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 899 embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
915 } 900 }
916 901
917 TEST_F(HostContentSettingsMapTest, ShouldAllowAllContent) { 902 TEST(HostContentSettingsMapTest, ShouldAllowAllContent) {
918 TestingProfile profile; 903 TestingProfile profile;
919 HostContentSettingsMap* host_content_settings_map = 904 HostContentSettingsMap* host_content_settings_map =
920 profile.GetHostContentSettingsMap(); 905 profile.GetHostContentSettingsMap();
921 906
922 GURL http_host("http://example.com/"); 907 GURL http_host("http://example.com/");
923 GURL https_host("https://example.com/"); 908 GURL https_host("https://example.com/");
924 GURL embedder("chrome://foo"); 909 GURL embedder("chrome://foo");
925 GURL extension("chrome-extension://foo"); 910 GURL extension("chrome-extension://foo");
926 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent( 911 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent(
927 http_host, embedder, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); 912 http_host, embedder, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
(...skipping 13 matching lines...) Expand all
941 #else 926 #else
942 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent( 927 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent(
943 extension, extension, CONTENT_SETTINGS_TYPE_COOKIES)); 928 extension, extension, CONTENT_SETTINGS_TYPE_COOKIES));
944 #endif 929 #endif
945 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent( 930 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent(
946 extension, extension, CONTENT_SETTINGS_TYPE_PLUGINS)); 931 extension, extension, CONTENT_SETTINGS_TYPE_PLUGINS));
947 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent( 932 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent(
948 extension, http_host, CONTENT_SETTINGS_TYPE_COOKIES)); 933 extension, http_host, CONTENT_SETTINGS_TYPE_COOKIES));
949 } 934 }
950 935
951 TEST_F(HostContentSettingsMapTest, MigrateClearOnExit) { 936 TEST(HostContentSettingsMapTest, MigrateClearOnExit) {
952 TestingProfile profile; 937 TestingProfile profile;
953 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 938 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
954 939
955 prefs->SetBoolean(prefs::kClearSiteDataOnExit, true); 940 prefs->SetBoolean(prefs::kClearSiteDataOnExit, true);
956 941
957 scoped_ptr<base::Value> patterns(base::JSONReader::Read( 942 scoped_ptr<base::Value> patterns(base::JSONReader::Read(
958 "{\"[*.]example.com,*\":{\"cookies\": 1}," 943 "{\"[*.]example.com,*\":{\"cookies\": 1},"
959 " \"[*.]other.com,*\":{\"cookies\": 2}," 944 " \"[*.]other.com,*\":{\"cookies\": 2},"
960 " \"[*.]third.com,*\":{\"cookies\": 4}}")); 945 " \"[*.]third.com,*\":{\"cookies\": 4}}"));
961 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *patterns); 946 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *patterns);
(...skipping 20 matching lines...) Expand all
982 CONTENT_SETTINGS_TYPE_COOKIES, 967 CONTENT_SETTINGS_TYPE_COOKIES,
983 std::string())); 968 std::string()));
984 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, 969 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY,
985 host_content_settings_map->GetContentSetting( 970 host_content_settings_map->GetContentSetting(
986 GURL("http://third.com"), 971 GURL("http://third.com"),
987 GURL("http://third.com"), 972 GURL("http://third.com"),
988 CONTENT_SETTINGS_TYPE_COOKIES, 973 CONTENT_SETTINGS_TYPE_COOKIES,
989 std::string())); 974 std::string()));
990 } 975 }
991 976
992 TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) { 977 TEST(HostContentSettingsMapTest, AddContentSettingsObserver) {
993 TestingProfile profile; 978 TestingProfile profile;
994 HostContentSettingsMap* host_content_settings_map = 979 HostContentSettingsMap* host_content_settings_map =
995 profile.GetHostContentSettingsMap(); 980 profile.GetHostContentSettingsMap();
996 content_settings::MockObserver mock_observer; 981 content_settings::MockObserver mock_observer;
997 982
998 GURL host("http://example.com/"); 983 GURL host("http://example.com/");
999 ContentSettingsPattern pattern = 984 ContentSettingsPattern pattern =
1000 ContentSettingsPattern::FromString("[*.]example.com"); 985 ContentSettingsPattern::FromString("[*.]example.com");
1001 EXPECT_CALL(mock_observer, 986 EXPECT_CALL(mock_observer,
1002 OnContentSettingChanged(pattern, 987 OnContentSettingChanged(pattern,
1003 ContentSettingsPattern::Wildcard(), 988 ContentSettingsPattern::Wildcard(),
1004 CONTENT_SETTINGS_TYPE_IMAGES, 989 CONTENT_SETTINGS_TYPE_IMAGES,
1005 "")); 990 ""));
1006 991
1007 host_content_settings_map->AddObserver(&mock_observer); 992 host_content_settings_map->AddObserver(&mock_observer);
1008 993
1009 EXPECT_EQ(CONTENT_SETTING_ALLOW, 994 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1010 host_content_settings_map->GetContentSetting( 995 host_content_settings_map->GetContentSetting(
1011 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 996 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1012 host_content_settings_map->SetContentSetting( 997 host_content_settings_map->SetContentSetting(
1013 pattern, 998 pattern,
1014 ContentSettingsPattern::Wildcard(), 999 ContentSettingsPattern::Wildcard(),
1015 CONTENT_SETTINGS_TYPE_IMAGES, 1000 CONTENT_SETTINGS_TYPE_IMAGES,
1016 std::string(), 1001 std::string(),
1017 CONTENT_SETTING_DEFAULT); 1002 CONTENT_SETTING_DEFAULT);
1018 } 1003 }
1019 1004
1020 TEST_F(HostContentSettingsMapTest, OverrideAllowedWebsiteSetting) { 1005 TEST(HostContentSettingsMapTest, OverrideAllowedWebsiteSetting) {
1021 TestingProfile profile; 1006 TestingProfile profile;
1022 HostContentSettingsMap* host_content_settings_map = 1007 HostContentSettingsMap* host_content_settings_map =
1023 profile.GetHostContentSettingsMap(); 1008 profile.GetHostContentSettingsMap();
1024 GURL host("http://example.com/"); 1009 GURL host("http://example.com/");
1025 ContentSettingsPattern pattern = 1010 ContentSettingsPattern pattern =
1026 ContentSettingsPattern::FromString("[*.]example.com"); 1011 ContentSettingsPattern::FromString("[*.]example.com");
1027 host_content_settings_map->SetContentSetting( 1012 host_content_settings_map->SetContentSetting(
1028 pattern, 1013 pattern,
1029 ContentSettingsPattern::Wildcard(), 1014 ContentSettingsPattern::Wildcard(),
1030 CONTENT_SETTINGS_TYPE_GEOLOCATION, 1015 CONTENT_SETTINGS_TYPE_GEOLOCATION,
(...skipping 11 matching lines...) Expand all
1042 host_content_settings_map->GetContentSetting( 1027 host_content_settings_map->GetContentSetting(
1043 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 1028 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
1044 1029
1045 host_content_settings_map->SetContentSettingOverride( 1030 host_content_settings_map->SetContentSettingOverride(
1046 CONTENT_SETTINGS_TYPE_GEOLOCATION, true); 1031 CONTENT_SETTINGS_TYPE_GEOLOCATION, true);
1047 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1032 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1048 host_content_settings_map->GetContentSetting( 1033 host_content_settings_map->GetContentSetting(
1049 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 1034 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
1050 } 1035 }
1051 1036
1052 TEST_F(HostContentSettingsMapTest, OverrideAllowedDefaultSetting) { 1037 TEST(HostContentSettingsMapTest, OverrideAllowedDefaultSetting) {
1053 TestingProfile profile; 1038 TestingProfile profile;
1054 HostContentSettingsMap* host_content_settings_map = 1039 HostContentSettingsMap* host_content_settings_map =
1055 profile.GetHostContentSettingsMap(); 1040 profile.GetHostContentSettingsMap();
1056 1041
1057 // Check setting defaults. 1042 // Check setting defaults.
1058 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1043 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1059 host_content_settings_map->GetDefaultContentSetting( 1044 host_content_settings_map->GetDefaultContentSetting(
1060 CONTENT_SETTINGS_TYPE_IMAGES, NULL)); 1045 CONTENT_SETTINGS_TYPE_IMAGES, NULL));
1061 1046
1062 GURL host("http://example.com/"); 1047 GURL host("http://example.com/");
(...skipping 13 matching lines...) Expand all
1076 CONTENT_SETTINGS_TYPE_IMAGES, true); 1061 CONTENT_SETTINGS_TYPE_IMAGES, true);
1077 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1062 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1078 host_content_settings_map->GetContentSetting( 1063 host_content_settings_map->GetContentSetting(
1079 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1064 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1080 host_content_settings_map->SetDefaultContentSetting( 1065 host_content_settings_map->SetDefaultContentSetting(
1081 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); 1066 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
1082 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1067 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1083 host_content_settings_map->GetContentSetting( 1068 host_content_settings_map->GetContentSetting(
1084 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1069 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1085 } 1070 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698