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

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

Issue 9826020: Remove code to keep obsolete content settings patterns pref in sync. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix bad file header. Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/content_settings/content_settings_pref_provider.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/content_settings/content_settings_pref_provider.h" 5 #include "chrome/browser/content_settings/content_settings_pref_provider.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 prefs::kContentSettingsPatternPairs); 394 prefs::kContentSettingsPatternPairs);
395 EXPECT_EQ(1U, const_all_settings_dictionary->size()); 395 EXPECT_EQ(1U, const_all_settings_dictionary->size());
396 EXPECT_FALSE(const_all_settings_dictionary->HasKey(pattern.ToString())); 396 EXPECT_FALSE(const_all_settings_dictionary->HasKey(pattern.ToString()));
397 EXPECT_TRUE(const_all_settings_dictionary->HasKey( 397 EXPECT_TRUE(const_all_settings_dictionary->HasKey(
398 pattern.ToString() + "," + 398 pattern.ToString() + "," +
399 ContentSettingsPattern::Wildcard().ToString())); 399 ContentSettingsPattern::Wildcard().ToString()));
400 400
401 provider.ShutdownOnUIThread(); 401 provider.ShutdownOnUIThread();
402 } 402 }
403 403
404 TEST_F(PrefProviderTest, SyncObsoletePref) {
405 TestingProfile profile;
406 PrefService* prefs = profile.GetPrefs();
407 content_settings::PrefProvider provider(prefs, false);
408
409 // Assert pre-condition.
410 const DictionaryValue* patterns =
411 prefs->GetDictionary(prefs::kContentSettingsPatterns);
412 ASSERT_TRUE(patterns->empty());
413
414 // Simulate a user setting a content setting.
415 ContentSettingsPattern primary_pattern =
416 ContentSettingsPattern::FromString("[*.]example.com");
417 ContentSettingsPattern secondary_pattern =
418 ContentSettingsPattern::Wildcard();
419 provider.SetWebsiteSetting(primary_pattern,
420 secondary_pattern,
421 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
422 std::string(),
423 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
424
425 // Test whether the obsolete preference is synced correctly.
426 patterns = prefs->GetDictionary(prefs::kContentSettingsPatterns);
427 EXPECT_EQ(1U, patterns->size());
428 DictionaryValue* settings = NULL;
429 patterns->GetDictionaryWithoutPathExpansion(primary_pattern.ToString(),
430 &settings);
431 ASSERT_TRUE(NULL != settings);
432 ASSERT_EQ(1U, settings->size());
433 int setting_value;
434 settings->GetInteger("javascript", &setting_value);
435 EXPECT_EQ(setting_value, CONTENT_SETTING_BLOCK);
436
437 // Simulate a sync change of the preference
438 // prefs::kContentSettingsPatternPairs.
439 {
440 DictionaryPrefUpdate update(prefs, prefs::kContentSettingsPatternPairs);
441 DictionaryValue* mutable_pattern_pairs = update.Get();
442 DictionaryValue* mutable_settings = NULL;
443 std::string key(
444 primary_pattern.ToString() + "," + secondary_pattern.ToString());
445 mutable_pattern_pairs->GetDictionaryWithoutPathExpansion(
446 key, &mutable_settings);
447 ASSERT_TRUE(NULL != mutable_settings) << "Dictionary has no key: " << key;
448 mutable_settings->SetInteger("javascript", CONTENT_SETTING_ALLOW);
449 }
450
451 EXPECT_EQ(CONTENT_SETTING_ALLOW,
452 GetContentSetting(&provider,
453 GURL("http://www.example.com"),
454 GURL("http://www.example.com"),
455 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
456 std::string(),
457 false));
458 // Test whether the obsolete preference was synced correctly.
459 settings = NULL;
460 patterns->GetDictionaryWithoutPathExpansion(primary_pattern.ToString(),
461 &settings);
462 ASSERT_TRUE(NULL != settings) << "Dictionary has no key: "
463 << primary_pattern.ToString();
464 ASSERT_EQ(1U, settings->size());
465 settings->GetInteger("javascript", &setting_value);
466 EXPECT_EQ(setting_value, CONTENT_SETTING_ALLOW);
467
468 provider.ShutdownOnUIThread();
469 }
470
471
472 TEST_F(PrefProviderTest, FixOrRemoveMalformedPatternKeysFromObsoletePref) { 404 TEST_F(PrefProviderTest, FixOrRemoveMalformedPatternKeysFromObsoletePref) {
473 TestingProfile profile; 405 TestingProfile profile;
474 PrefService* prefs = profile.GetPrefs(); 406 PrefService* prefs = profile.GetPrefs();
475 407
476 // Set obsolete preference for content settings pattern. 408 // Set obsolete preference for content settings pattern.
477 scoped_ptr<DictionaryValue> settings_dictionary(new DictionaryValue()); 409 scoped_ptr<DictionaryValue> settings_dictionary(new DictionaryValue());
478 settings_dictionary->SetInteger("cookies", 2); 410 settings_dictionary->SetInteger("cookies", 2);
479 settings_dictionary->SetInteger("images", 2); 411 settings_dictionary->SetInteger("images", 2);
480 settings_dictionary->SetInteger("popups", 2); 412 settings_dictionary->SetInteger("popups", 2);
481 scoped_ptr<DictionaryValue> all_settings_dictionary(new DictionaryValue()); 413 scoped_ptr<DictionaryValue> all_settings_dictionary(new DictionaryValue());
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 false)); 537 false));
606 // Check that geolocation settings were not synced to the obsolete content 538 // Check that geolocation settings were not synced to the obsolete content
607 // settings pattern preference. 539 // settings pattern preference.
608 const_obsolete_patterns_dictionary = 540 const_obsolete_patterns_dictionary =
609 prefs->GetDictionary(prefs::kContentSettingsPatterns); 541 prefs->GetDictionary(prefs::kContentSettingsPatterns);
610 EXPECT_TRUE(const_obsolete_patterns_dictionary->empty()); 542 EXPECT_TRUE(const_obsolete_patterns_dictionary->empty());
611 543
612 provider.ShutdownOnUIThread(); 544 provider.ShutdownOnUIThread();
613 } 545 }
614 546
615 TEST_F(PrefProviderTest, SyncObsoleteGeolocationPref) {
616 TestingProfile profile;
617 PrefService* prefs = profile.GetPrefs();
618
619 content_settings::PrefProvider provider(prefs, false);
620
621 // Changing the preferences prefs::kContentSettingsPatternPairs.
622 ContentSettingsPattern primary_pattern=
623 ContentSettingsPattern::FromString("http://www.bar.com");
624 ContentSettingsPattern primary_pattern_2 =
625 ContentSettingsPattern::FromString("http://www.example.com");
626 ContentSettingsPattern secondary_pattern =
627 ContentSettingsPattern::FromString("http://www.foo.com");
628 scoped_ptr<DictionaryValue> settings_dictionary(new DictionaryValue());
629 settings_dictionary->SetInteger("geolocation", CONTENT_SETTING_BLOCK);
630 {
631 DictionaryPrefUpdate update(prefs,
632 prefs::kContentSettingsPatternPairs);
633 DictionaryValue* all_settings_dictionary = update.Get();
634 std::string key(
635 primary_pattern.ToString()+ "," +
636 secondary_pattern.ToString());
637 all_settings_dictionary->SetWithoutPathExpansion(
638 key, settings_dictionary->DeepCopy());
639
640 key = std::string(
641 primary_pattern_2.ToString() + "," +
642 secondary_pattern.ToString());
643 all_settings_dictionary->SetWithoutPathExpansion(
644 key, settings_dictionary->DeepCopy());
645 }
646
647 // Test if the obsolete geolocation preference is kept in sync if the new
648 // preference is changed by a sync.
649 GURL primary_url("http://www.bar.com");
650 GURL primary_url_2("http://www.example.com");
651 GURL secondary_url("http://www.foo.com");
652
653 const DictionaryValue* geo_settings_dictionary =
654 prefs->GetDictionary(prefs::kGeolocationContentSettings);
655 EXPECT_EQ(2U, geo_settings_dictionary->size());
656 ExpectObsoleteGeolocationSetting(*geo_settings_dictionary,
657 primary_url,
658 secondary_url,
659 CONTENT_SETTING_BLOCK);
660 ExpectObsoleteGeolocationSetting(*geo_settings_dictionary,
661 primary_url_2,
662 secondary_url,
663 CONTENT_SETTING_BLOCK);
664
665 provider.ShutdownOnUIThread();
666 }
667
668 TEST_F(PrefProviderTest, AutoSubmitCertificateContentSetting) { 547 TEST_F(PrefProviderTest, AutoSubmitCertificateContentSetting) {
669 TestingProfile profile; 548 TestingProfile profile;
670 TestingPrefService* prefs = profile.GetTestingPrefService(); 549 TestingPrefService* prefs = profile.GetTestingPrefService();
671 GURL primary_url("https://www.example.com"); 550 GURL primary_url("https://www.example.com");
672 GURL secondary_url("https://www.sample.com"); 551 GURL secondary_url("https://www.sample.com");
673 552
674 PrefProvider provider(prefs, false); 553 PrefProvider provider(prefs, false);
675 554
676 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 555 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
677 GetContentSetting( 556 GetContentSetting(
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 false)); 671 false));
793 // Check that geolocation settings were not synced to the obsolete content 672 // Check that geolocation settings were not synced to the obsolete content
794 // settings pattern preference. 673 // settings pattern preference.
795 const_obsolete_patterns_dictionary = 674 const_obsolete_patterns_dictionary =
796 prefs->GetDictionary(prefs::kContentSettingsPatterns); 675 prefs->GetDictionary(prefs::kContentSettingsPatterns);
797 EXPECT_TRUE(const_obsolete_patterns_dictionary->empty()); 676 EXPECT_TRUE(const_obsolete_patterns_dictionary->empty());
798 677
799 provider.ShutdownOnUIThread(); 678 provider.ShutdownOnUIThread();
800 } 679 }
801 680
802 TEST_F(PrefProviderTest, SyncObsoleteNotificationsPref) {
803 TestingProfile profile;
804 PrefService* prefs = profile.GetPrefs();
805
806 content_settings::PrefProvider provider(prefs, false);
807
808 // Changing the preferences prefs::kContentSettingsPatternPairs.
809 ContentSettingsPattern primary_pattern=
810 ContentSettingsPattern::FromString("http://www.bar.com");
811 ContentSettingsPattern primary_pattern_2 =
812 ContentSettingsPattern::FromString("http://www.example.com");
813 ContentSettingsPattern secondary_pattern =
814 ContentSettingsPattern::Wildcard();
815 GURL primary_url("http://www.bar.com");
816 GURL primary_url_2("http://www.example.com");
817
818 {
819 DictionaryPrefUpdate update(prefs,
820 prefs::kContentSettingsPatternPairs);
821 DictionaryValue* all_settings_dictionary = update.Get();
822
823 scoped_ptr<DictionaryValue> settings_dictionary(new DictionaryValue());
824 settings_dictionary->SetInteger("notifications", CONTENT_SETTING_BLOCK);
825 std::string key(
826 primary_pattern.ToString() + "," +
827 secondary_pattern.ToString());
828 all_settings_dictionary->SetWithoutPathExpansion(
829 key, settings_dictionary->DeepCopy());
830
831 settings_dictionary.reset(new DictionaryValue());
832 settings_dictionary->SetInteger("notifications", CONTENT_SETTING_ALLOW);
833 key = primary_pattern_2.ToString() + "," + secondary_pattern.ToString();
834 all_settings_dictionary->SetWithoutPathExpansion(
835 key, settings_dictionary->DeepCopy());
836 }
837
838 // Test if the obsolete notifications preference is kept in sync if the new
839 // preference is changed by a sync.
840 const ListValue* denied_origin_list =
841 prefs->GetList(prefs::kDesktopNotificationAllowedOrigins);
842 EXPECT_EQ(1U, denied_origin_list->GetSize());
843 const ListValue* allowed_origin_list =
844 prefs->GetList(prefs::kDesktopNotificationDeniedOrigins);
845 EXPECT_EQ(1U, allowed_origin_list->GetSize());
846
847 provider.ShutdownOnUIThread();
848 }
849
850 // http://crosbug.com/17760 681 // http://crosbug.com/17760
851 TEST_F(PrefProviderTest, Deadlock) { 682 TEST_F(PrefProviderTest, Deadlock) {
852 TestingPrefService prefs; 683 TestingPrefService prefs;
853 PrefProvider::RegisterUserPrefs(&prefs); 684 PrefProvider::RegisterUserPrefs(&prefs);
854 685
855 // Chain of events: a preference changes, |PrefProvider| notices it, and reads 686 // Chain of events: a preference changes, |PrefProvider| notices it, and reads
856 // and writes the preference. When the preference is written, a notification 687 // and writes the preference. When the preference is written, a notification
857 // is sent, and this used to happen when |PrefProvider| was still holding its 688 // is sent, and this used to happen when |PrefProvider| was still holding its
858 // lock. 689 // lock.
859 690
860 PrefProvider provider(&prefs, false); 691 PrefProvider provider(&prefs, false);
861 DeadlockCheckerObserver observer(&prefs, &provider); 692 DeadlockCheckerObserver observer(&prefs, &provider);
862 { 693 {
863 DictionaryPrefUpdate update(&prefs, 694 DictionaryPrefUpdate update(&prefs,
864 prefs::kContentSettingsPatternPairs); 695 prefs::kContentSettingsPatternPairs);
865 DictionaryValue* mutable_settings = update.Get(); 696 DictionaryValue* mutable_settings = update.Get();
866 mutable_settings->SetWithoutPathExpansion("www.example.com,*", 697 mutable_settings->SetWithoutPathExpansion("www.example.com,*",
867 new base::DictionaryValue()); 698 new base::DictionaryValue());
868 } 699 }
869 EXPECT_TRUE(observer.notification_received()); 700 EXPECT_TRUE(observer.notification_received());
870 701
871 provider.ShutdownOnUIThread(); 702 provider.ShutdownOnUIThread();
872 } 703 }
873 704
874 } // namespace content_settings 705 } // namespace content_settings
OLDNEW
« no previous file with comments | « chrome/browser/content_settings/content_settings_pref_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698