| 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 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 kDefaultPref3, | 688 kDefaultPref3, |
| 689 PrefService::UNSYNCABLE_PREF); | 689 PrefService::UNSYNCABLE_PREF); |
| 690 prefs()->pref_service()->RegisterStringPref(kPref4, | 690 prefs()->pref_service()->RegisterStringPref(kPref4, |
| 691 kDefaultPref4, | 691 kDefaultPref4, |
| 692 PrefService::UNSYNCABLE_PREF); | 692 PrefService::UNSYNCABLE_PREF); |
| 693 } | 693 } |
| 694 | 694 |
| 695 void InstallExtControlledPref(Extension *ext, | 695 void InstallExtControlledPref(Extension *ext, |
| 696 const std::string& key, | 696 const std::string& key, |
| 697 Value* val) { | 697 Value* val) { |
| 698 using namespace extension_prefs_scope; |
| 698 EnsureExtensionInstalled(ext); | 699 EnsureExtensionInstalled(ext); |
| 699 prefs()->SetExtensionControlledPref(ext->id(), key, false, val); | 700 prefs()->SetExtensionControlledPref(ext->id(), key, kRegular, val); |
| 700 } | 701 } |
| 701 | 702 |
| 702 void InstallExtControlledPrefIncognito(Extension *ext, | 703 void InstallExtControlledPrefIncognito(Extension *ext, |
| 703 const std::string& key, | 704 const std::string& key, |
| 704 Value* val) { | 705 Value* val) { |
| 706 using namespace extension_prefs_scope; |
| 705 EnsureExtensionInstalled(ext); | 707 EnsureExtensionInstalled(ext); |
| 706 prefs()->SetExtensionControlledPref(ext->id(), key, true, val); | 708 prefs()->SetExtensionControlledPref(ext->id(), key, |
| 709 kIncognitoPersistent, val); |
| 707 } | 710 } |
| 708 | 711 |
| 709 void InstallExtension(Extension *ext) { | 712 void InstallExtension(Extension *ext) { |
| 710 EnsureExtensionInstalled(ext); | 713 EnsureExtensionInstalled(ext); |
| 711 } | 714 } |
| 712 | 715 |
| 713 void UninstallExtension(const std::string& extension_id) { | 716 void UninstallExtension(const std::string& extension_id) { |
| 714 EnsureExtensionUninstalled(extension_id); | 717 EnsureExtensionUninstalled(extension_id); |
| 715 } | 718 } |
| 716 | 719 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 virtual void Initialize() { | 759 virtual void Initialize() { |
| 757 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); | 760 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); |
| 758 } | 761 } |
| 759 virtual void Verify() { | 762 virtual void Verify() { |
| 760 std::string actual = prefs()->pref_service()->GetString(kPref1); | 763 std::string actual = prefs()->pref_service()->GetString(kPref1); |
| 761 EXPECT_EQ("val1", actual); | 764 EXPECT_EQ("val1", actual); |
| 762 } | 765 } |
| 763 }; | 766 }; |
| 764 TEST_F(ExtensionPrefsInstallOneExtension, ExtensionPrefsInstallOneExtension) {} | 767 TEST_F(ExtensionPrefsInstallOneExtension, ExtensionPrefsInstallOneExtension) {} |
| 765 | 768 |
| 766 // Check that we forget incognito values after a reload. | 769 // Check that we do not forget persistent incognito values after a reload. |
| 767 class ExtensionPrefsInstallIncognito | 770 class ExtensionPrefsInstallIncognito |
| 768 : public ExtensionPrefsPreferencesBase { | 771 : public ExtensionPrefsPreferencesBase { |
| 769 public: | 772 public: |
| 770 ExtensionPrefsInstallIncognito() : iteration_(0) {} | |
| 771 | |
| 772 virtual void Initialize() { | 773 virtual void Initialize() { |
| 773 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); | 774 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); |
| 774 InstallExtControlledPrefIncognito(ext1_, kPref1, | 775 InstallExtControlledPrefIncognito(ext1_, kPref1, |
| 775 Value::CreateStringValue("val2")); | 776 Value::CreateStringValue("val2")); |
| 776 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); | 777 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); |
| 777 std::string actual = incog_prefs->GetString(kPref1); | 778 std::string actual = incog_prefs->GetString(kPref1); |
| 778 EXPECT_EQ("val2", actual); | 779 EXPECT_EQ("val2", actual); |
| 779 } | 780 } |
| 780 virtual void Verify() { | 781 virtual void Verify() { |
| 781 // Main pref service shall see only non-incognito settings. | 782 // Main pref service shall see only non-incognito settings. |
| 782 std::string actual = prefs()->pref_service()->GetString(kPref1); | 783 std::string actual = prefs()->pref_service()->GetString(kPref1); |
| 783 EXPECT_EQ("val1", actual); | 784 EXPECT_EQ("val1", actual); |
| 784 // Incognito pref service shall see incognito values only during first run. | 785 // Incognito pref service shall see incognito values. |
| 785 // Once the pref service was reloaded, all values shall be discarded. | |
| 786 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); | 786 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); |
| 787 actual = incog_prefs->GetString(kPref1); | 787 actual = incog_prefs->GetString(kPref1); |
| 788 if (iteration_ == 0) { | 788 EXPECT_EQ("val2", actual); |
| 789 EXPECT_EQ("val2", actual); | |
| 790 } else { | |
| 791 EXPECT_EQ("val1", actual); | |
| 792 } | |
| 793 ++iteration_; | |
| 794 } | 789 } |
| 795 int iteration_; | |
| 796 }; | 790 }; |
| 797 TEST_F(ExtensionPrefsInstallIncognito, ExtensionPrefsInstallOneExtension) {} | 791 TEST_F(ExtensionPrefsInstallIncognito, ExtensionPrefsInstallOneExtension) {} |
| 798 | 792 |
| 799 class ExtensionPrefsUninstallExtension | 793 class ExtensionPrefsUninstallExtension |
| 800 : public ExtensionPrefsPreferencesBase { | 794 : public ExtensionPrefsPreferencesBase { |
| 801 virtual void Initialize() { | 795 virtual void Initialize() { |
| 802 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); | 796 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); |
| 803 InstallExtControlledPref(ext1_, kPref2, Value::CreateStringValue("val2")); | 797 InstallExtControlledPref(ext1_, kPref2, Value::CreateStringValue("val2")); |
| 804 | 798 |
| 805 UninstallExtension(ext1_->id()); | 799 UninstallExtension(ext1_->id()); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 testing::Mock::VerifyAndClearExpectations(v1i); | 948 testing::Mock::VerifyAndClearExpectations(v1i); |
| 955 testing::Mock::VerifyAndClearExpectations(v2); | 949 testing::Mock::VerifyAndClearExpectations(v2); |
| 956 testing::Mock::VerifyAndClearExpectations(v2i); | 950 testing::Mock::VerifyAndClearExpectations(v2i); |
| 957 } | 951 } |
| 958 | 952 |
| 959 virtual void Verify() { | 953 virtual void Verify() { |
| 960 } | 954 } |
| 961 }; | 955 }; |
| 962 TEST_F(ExtensionPrefsSetExtensionControlledPref, | 956 TEST_F(ExtensionPrefsSetExtensionControlledPref, |
| 963 ExtensionPrefsSetExtensionControlledPref) {} | 957 ExtensionPrefsSetExtensionControlledPref) {} |
| OLD | NEW |