| 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 ExtensionPrefsInstallIncognitoPersistent |
| 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(ExtensionPrefsInstallIncognitoPersistent, |
| 802 ExtensionPrefsInstallOneExtension) {} |
| 803 |
| 804 // Check that we forget 'session only' incognito values after a reload. |
| 805 class ExtensionPrefsInstallIncognitoSessionOnly |
| 806 : public ExtensionPrefsPreferencesBase { |
| 807 public: |
| 808 ExtensionPrefsInstallIncognitoSessionOnly() : iteration_(0) {} |
| 809 |
| 810 virtual void Initialize() { |
| 811 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); |
| 812 InstallExtControlledPrefIncognitoSessionOnly( |
| 813 ext1_, kPref1, Value::CreateStringValue("val2")); |
| 814 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); |
| 815 std::string actual = incog_prefs->GetString(kPref1); |
| 816 EXPECT_EQ("val2", actual); |
| 817 } |
| 818 virtual void Verify() { |
| 819 // Main pref service shall see only non-incognito settings. |
| 820 std::string actual = prefs()->pref_service()->GetString(kPref1); |
| 821 EXPECT_EQ("val1", actual); |
| 822 // Incognito pref service shall see session-only incognito values only |
| 823 // during first run. Once the pref service was reloaded, all values shall be |
| 824 // discarded. |
| 825 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); |
| 826 actual = incog_prefs->GetString(kPref1); |
| 827 if (iteration_ == 0) { |
| 828 EXPECT_EQ("val2", actual); |
| 829 } else { |
| 830 EXPECT_EQ("val1", actual); |
| 831 } |
| 832 ++iteration_; |
| 833 } |
| 834 int iteration_; |
| 835 }; |
| 836 TEST_F(ExtensionPrefsInstallIncognitoSessionOnly, |
| 837 ExtensionPrefsInstallOneExtension) {} |
| 792 | 838 |
| 793 class ExtensionPrefsUninstallExtension | 839 class ExtensionPrefsUninstallExtension |
| 794 : public ExtensionPrefsPreferencesBase { | 840 : public ExtensionPrefsPreferencesBase { |
| 795 virtual void Initialize() { | 841 virtual void Initialize() { |
| 796 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); | 842 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); |
| 797 InstallExtControlledPref(ext1_, kPref2, Value::CreateStringValue("val2")); | 843 InstallExtControlledPref(ext1_, kPref2, Value::CreateStringValue("val2")); |
| 798 | 844 |
| 799 UninstallExtension(ext1_->id()); | 845 UninstallExtension(ext1_->id()); |
| 800 } | 846 } |
| 801 virtual void Verify() { | 847 virtual void Verify() { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 Mock::VerifyAndClearExpectations(&incognito_observer); | 891 Mock::VerifyAndClearExpectations(&incognito_observer); |
| 846 | 892 |
| 847 // Change value. | 893 // Change value. |
| 848 EXPECT_CALL(observer, Observe(_, _, _)); | 894 EXPECT_CALL(observer, Observe(_, _, _)); |
| 849 EXPECT_CALL(incognito_observer, Observe(_, _, _)); | 895 EXPECT_CALL(incognito_observer, Observe(_, _, _)); |
| 850 InstallExtControlledPref(ext1_, kPref1, | 896 InstallExtControlledPref(ext1_, kPref1, |
| 851 Value::CreateStringValue("chrome://newtab")); | 897 Value::CreateStringValue("chrome://newtab")); |
| 852 Mock::VerifyAndClearExpectations(&observer); | 898 Mock::VerifyAndClearExpectations(&observer); |
| 853 Mock::VerifyAndClearExpectations(&incognito_observer); | 899 Mock::VerifyAndClearExpectations(&incognito_observer); |
| 854 | 900 |
| 855 // Change only incognito value. | 901 // Change only incognito persistent value. |
| 856 EXPECT_CALL(observer, Observe(_, _, _)).Times(0); | 902 EXPECT_CALL(observer, Observe(_, _, _)).Times(0); |
| 857 EXPECT_CALL(incognito_observer, Observe(_, _, _)); | 903 EXPECT_CALL(incognito_observer, Observe(_, _, _)); |
| 858 InstallExtControlledPrefIncognito(ext1_, kPref1, | 904 InstallExtControlledPrefIncognito(ext1_, kPref1, |
| 859 Value::CreateStringValue("chrome://newtab2")); | 905 Value::CreateStringValue("chrome://newtab2")); |
| 860 Mock::VerifyAndClearExpectations(&observer); | 906 Mock::VerifyAndClearExpectations(&observer); |
| 861 Mock::VerifyAndClearExpectations(&incognito_observer); | 907 Mock::VerifyAndClearExpectations(&incognito_observer); |
| 862 | 908 |
| 909 // Change only incognito session-only value. |
| 910 EXPECT_CALL(observer, Observe(_, _, _)).Times(0); |
| 911 EXPECT_CALL(incognito_observer, Observe(_, _, _)); |
| 912 InstallExtControlledPrefIncognito(ext1_, kPref1, |
| 913 Value::CreateStringValue("chrome://newtab3")); |
| 914 Mock::VerifyAndClearExpectations(&observer); |
| 915 Mock::VerifyAndClearExpectations(&incognito_observer); |
| 916 |
| 863 // Uninstall. | 917 // Uninstall. |
| 864 EXPECT_CALL(observer, Observe(_, _, _)); | 918 EXPECT_CALL(observer, Observe(_, _, _)); |
| 865 EXPECT_CALL(incognito_observer, Observe(_, _, _)); | 919 EXPECT_CALL(incognito_observer, Observe(_, _, _)); |
| 866 UninstallExtension(ext1_->id()); | 920 UninstallExtension(ext1_->id()); |
| 867 Mock::VerifyAndClearExpectations(&observer); | 921 Mock::VerifyAndClearExpectations(&observer); |
| 868 Mock::VerifyAndClearExpectations(&incognito_observer); | 922 Mock::VerifyAndClearExpectations(&incognito_observer); |
| 869 | 923 |
| 870 registrar.Remove(kPref1, &observer); | 924 registrar.Remove(kPref1, &observer); |
| 871 incognito_registrar.Remove(kPref1, &incognito_observer); | 925 incognito_registrar.Remove(kPref1, &incognito_observer); |
| 872 } | 926 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 testing::Mock::VerifyAndClearExpectations(v1i); | 1002 testing::Mock::VerifyAndClearExpectations(v1i); |
| 949 testing::Mock::VerifyAndClearExpectations(v2); | 1003 testing::Mock::VerifyAndClearExpectations(v2); |
| 950 testing::Mock::VerifyAndClearExpectations(v2i); | 1004 testing::Mock::VerifyAndClearExpectations(v2i); |
| 951 } | 1005 } |
| 952 | 1006 |
| 953 virtual void Verify() { | 1007 virtual void Verify() { |
| 954 } | 1008 } |
| 955 }; | 1009 }; |
| 956 TEST_F(ExtensionPrefsSetExtensionControlledPref, | 1010 TEST_F(ExtensionPrefsSetExtensionControlledPref, |
| 957 ExtensionPrefsSetExtensionControlledPref) {} | 1011 ExtensionPrefsSetExtensionControlledPref) {} |
| OLD | NEW |