Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/scoped_temp_dir.h" | 7 #include "base/scoped_temp_dir.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 | 702 |
| 703 void InstallExtControlledPrefIncognito(Extension *ext, | 703 void InstallExtControlledPrefIncognito(Extension *ext, |
| 704 const std::string& key, | 704 const std::string& key, |
| 705 Value* val) { | 705 Value* val) { |
| 706 using namespace extension_prefs_scope; | 706 using namespace extension_prefs_scope; |
| 707 EnsureExtensionInstalled(ext); | 707 EnsureExtensionInstalled(ext); |
| 708 prefs()->SetExtensionControlledPref(ext->id(), key, | 708 prefs()->SetExtensionControlledPref(ext->id(), key, |
| 709 kIncognitoPersistent, val); | 709 kIncognitoPersistent, val); |
| 710 } | 710 } |
| 711 | 711 |
| 712 void InstallExtControlledPrefIncognitoSessionOnly( | |
| 713 Extension *ext, | |
| 714 const std::string& key, | |
| 715 Value* val) { | |
| 716 using namespace extension_prefs_scope; | |
| 717 EnsureExtensionInstalled(ext); | |
| 718 prefs()->SetExtensionControlledPref(ext->id(), key, | |
| 719 kIncognitoSessionOnly, val); | |
| 720 } | |
| 721 | |
| 712 void InstallExtension(Extension *ext) { | 722 void InstallExtension(Extension *ext) { |
| 713 EnsureExtensionInstalled(ext); | 723 EnsureExtensionInstalled(ext); |
| 714 } | 724 } |
| 715 | 725 |
| 716 void UninstallExtension(const std::string& extension_id) { | 726 void UninstallExtension(const std::string& extension_id) { |
| 717 EnsureExtensionUninstalled(extension_id); | 727 EnsureExtensionUninstalled(extension_id); |
| 718 } | 728 } |
| 719 | 729 |
| 720 // Weak references, for convenience. | 730 // Weak references, for convenience. |
| 721 Extension* ext1_; | 731 Extension* ext1_; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 760 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); | 770 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); |
| 761 } | 771 } |
| 762 virtual void Verify() { | 772 virtual void Verify() { |
| 763 std::string actual = prefs()->pref_service()->GetString(kPref1); | 773 std::string actual = prefs()->pref_service()->GetString(kPref1); |
| 764 EXPECT_EQ("val1", actual); | 774 EXPECT_EQ("val1", actual); |
| 765 } | 775 } |
| 766 }; | 776 }; |
| 767 TEST_F(ExtensionPrefsInstallOneExtension, ExtensionPrefsInstallOneExtension) {} | 777 TEST_F(ExtensionPrefsInstallOneExtension, ExtensionPrefsInstallOneExtension) {} |
| 768 | 778 |
| 769 // Check that we do not forget persistent incognito values after a reload. | 779 // Check that we do not forget persistent incognito values after a reload. |
| 770 class ExtensionPrefsInstallIncognito | 780 class ExtensionPrefsInstallIncognitoPers |
|
Matt Perry
2011/05/24 22:07:17
don't abbreviate Persistent
battre
2011/05/25 11:51:30
Done.
| |
| 771 : public ExtensionPrefsPreferencesBase { | 781 : public ExtensionPrefsPreferencesBase { |
| 772 public: | 782 public: |
| 773 virtual void Initialize() { | 783 virtual void Initialize() { |
| 774 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); | 784 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); |
| 775 InstallExtControlledPrefIncognito(ext1_, kPref1, | 785 InstallExtControlledPrefIncognito(ext1_, kPref1, |
| 776 Value::CreateStringValue("val2")); | 786 Value::CreateStringValue("val2")); |
| 777 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); | 787 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); |
| 778 std::string actual = incog_prefs->GetString(kPref1); | 788 std::string actual = incog_prefs->GetString(kPref1); |
| 779 EXPECT_EQ("val2", actual); | 789 EXPECT_EQ("val2", actual); |
| 780 } | 790 } |
| 781 virtual void Verify() { | 791 virtual void Verify() { |
| 782 // Main pref service shall see only non-incognito settings. | 792 // Main pref service shall see only non-incognito settings. |
| 783 std::string actual = prefs()->pref_service()->GetString(kPref1); | 793 std::string actual = prefs()->pref_service()->GetString(kPref1); |
| 784 EXPECT_EQ("val1", actual); | 794 EXPECT_EQ("val1", actual); |
| 785 // Incognito pref service shall see incognito values. | 795 // Incognito pref service shall see incognito values. |
| 786 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); | 796 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); |
| 787 actual = incog_prefs->GetString(kPref1); | 797 actual = incog_prefs->GetString(kPref1); |
| 788 EXPECT_EQ("val2", actual); | 798 EXPECT_EQ("val2", actual); |
| 789 } | 799 } |
| 790 }; | 800 }; |
| 791 TEST_F(ExtensionPrefsInstallIncognito, ExtensionPrefsInstallOneExtension) {} | 801 TEST_F(ExtensionPrefsInstallIncognitoPers, ExtensionPrefsInstallOneExtension) {} |
| 802 | |
| 803 // Check that we forget session only incognito values after a reload. | |
| 804 class ExtensionPrefsInstallIncognitoSess | |
| 805 : public ExtensionPrefsPreferencesBase { | |
| 806 public: | |
| 807 ExtensionPrefsInstallIncognitoSess() : iteration_(0) {} | |
| 808 | |
| 809 virtual void Initialize() { | |
| 810 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); | |
| 811 InstallExtControlledPrefIncognitoSessionOnly( | |
| 812 ext1_, kPref1, Value::CreateStringValue("val2")); | |
| 813 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); | |
| 814 std::string actual = incog_prefs->GetString(kPref1); | |
| 815 EXPECT_EQ("val2", actual); | |
| 816 } | |
| 817 virtual void Verify() { | |
| 818 // Main pref service shall see only non-incognito settings. | |
| 819 std::string actual = prefs()->pref_service()->GetString(kPref1); | |
| 820 EXPECT_EQ("val1", actual); | |
| 821 // Incognito pref service shall see session-only incognito values only | |
| 822 // during first run. Once the pref service was reloaded, all values shall be | |
| 823 // discarded. | |
| 824 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); | |
| 825 actual = incog_prefs->GetString(kPref1); | |
| 826 if (iteration_ == 0) { | |
| 827 EXPECT_EQ("val2", actual); | |
| 828 } else { | |
| 829 EXPECT_EQ("val1", actual); | |
| 830 } | |
| 831 ++iteration_; | |
| 832 } | |
| 833 int iteration_; | |
| 834 }; | |
| 835 TEST_F(ExtensionPrefsInstallIncognitoSess, ExtensionPrefsInstallOneExtension) {} | |
| 792 | 836 |
| 793 class ExtensionPrefsUninstallExtension | 837 class ExtensionPrefsUninstallExtension |
| 794 : public ExtensionPrefsPreferencesBase { | 838 : public ExtensionPrefsPreferencesBase { |
| 795 virtual void Initialize() { | 839 virtual void Initialize() { |
| 796 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); | 840 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); |
| 797 InstallExtControlledPref(ext1_, kPref2, Value::CreateStringValue("val2")); | 841 InstallExtControlledPref(ext1_, kPref2, Value::CreateStringValue("val2")); |
| 798 | 842 |
| 799 UninstallExtension(ext1_->id()); | 843 UninstallExtension(ext1_->id()); |
| 800 } | 844 } |
| 801 virtual void Verify() { | 845 virtual void Verify() { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 845 Mock::VerifyAndClearExpectations(&incognito_observer); | 889 Mock::VerifyAndClearExpectations(&incognito_observer); |
| 846 | 890 |
| 847 // Change value. | 891 // Change value. |
| 848 EXPECT_CALL(observer, Observe(_, _, _)); | 892 EXPECT_CALL(observer, Observe(_, _, _)); |
| 849 EXPECT_CALL(incognito_observer, Observe(_, _, _)); | 893 EXPECT_CALL(incognito_observer, Observe(_, _, _)); |
| 850 InstallExtControlledPref(ext1_, kPref1, | 894 InstallExtControlledPref(ext1_, kPref1, |
| 851 Value::CreateStringValue("chrome://newtab")); | 895 Value::CreateStringValue("chrome://newtab")); |
| 852 Mock::VerifyAndClearExpectations(&observer); | 896 Mock::VerifyAndClearExpectations(&observer); |
| 853 Mock::VerifyAndClearExpectations(&incognito_observer); | 897 Mock::VerifyAndClearExpectations(&incognito_observer); |
| 854 | 898 |
| 855 // Change only incognito value. | 899 // Change only incognito persistent value. |
| 856 EXPECT_CALL(observer, Observe(_, _, _)).Times(0); | 900 EXPECT_CALL(observer, Observe(_, _, _)).Times(0); |
| 857 EXPECT_CALL(incognito_observer, Observe(_, _, _)); | 901 EXPECT_CALL(incognito_observer, Observe(_, _, _)); |
| 858 InstallExtControlledPrefIncognito(ext1_, kPref1, | 902 InstallExtControlledPrefIncognito(ext1_, kPref1, |
| 859 Value::CreateStringValue("chrome://newtab2")); | 903 Value::CreateStringValue("chrome://newtab2")); |
| 860 Mock::VerifyAndClearExpectations(&observer); | 904 Mock::VerifyAndClearExpectations(&observer); |
| 861 Mock::VerifyAndClearExpectations(&incognito_observer); | 905 Mock::VerifyAndClearExpectations(&incognito_observer); |
| 862 | 906 |
| 907 // Change only incognito session-only value. | |
| 908 EXPECT_CALL(observer, Observe(_, _, _)).Times(0); | |
| 909 EXPECT_CALL(incognito_observer, Observe(_, _, _)); | |
| 910 InstallExtControlledPrefIncognito(ext1_, kPref1, | |
| 911 Value::CreateStringValue("chrome://newtab3")); | |
| 912 Mock::VerifyAndClearExpectations(&observer); | |
| 913 Mock::VerifyAndClearExpectations(&incognito_observer); | |
| 914 | |
| 863 // Uninstall. | 915 // Uninstall. |
| 864 EXPECT_CALL(observer, Observe(_, _, _)); | 916 EXPECT_CALL(observer, Observe(_, _, _)); |
| 865 EXPECT_CALL(incognito_observer, Observe(_, _, _)); | 917 EXPECT_CALL(incognito_observer, Observe(_, _, _)); |
| 866 UninstallExtension(ext1_->id()); | 918 UninstallExtension(ext1_->id()); |
| 867 Mock::VerifyAndClearExpectations(&observer); | 919 Mock::VerifyAndClearExpectations(&observer); |
| 868 Mock::VerifyAndClearExpectations(&incognito_observer); | 920 Mock::VerifyAndClearExpectations(&incognito_observer); |
| 869 | 921 |
| 870 registrar.Remove(kPref1, &observer); | 922 registrar.Remove(kPref1, &observer); |
| 871 incognito_registrar.Remove(kPref1, &incognito_observer); | 923 incognito_registrar.Remove(kPref1, &incognito_observer); |
| 872 } | 924 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 948 testing::Mock::VerifyAndClearExpectations(v1i); | 1000 testing::Mock::VerifyAndClearExpectations(v1i); |
| 949 testing::Mock::VerifyAndClearExpectations(v2); | 1001 testing::Mock::VerifyAndClearExpectations(v2); |
| 950 testing::Mock::VerifyAndClearExpectations(v2i); | 1002 testing::Mock::VerifyAndClearExpectations(v2i); |
| 951 } | 1003 } |
| 952 | 1004 |
| 953 virtual void Verify() { | 1005 virtual void Verify() { |
| 954 } | 1006 } |
| 955 }; | 1007 }; |
| 956 TEST_F(ExtensionPrefsSetExtensionControlledPref, | 1008 TEST_F(ExtensionPrefsSetExtensionControlledPref, |
| 957 ExtensionPrefsSetExtensionControlledPref) {} | 1009 ExtensionPrefsSetExtensionControlledPref) {} |
| OLD | NEW |