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/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 7 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
8 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 8 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| 9 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
9 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 10 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
10 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
11 #include "chrome/common/pref_store_observer_mock.h" | 12 #include "chrome/common/pref_store_observer_mock.h" |
12 #include "content/common/notification_service.h" | 13 #include "content/common/notification_service.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 using testing::_; | 17 using testing::_; |
17 using testing::Mock; | 18 using testing::Mock; |
18 | 19 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 TypeAndName(kPolicyPasswordManagerEnabled, | 194 TypeAndName(kPolicyPasswordManagerEnabled, |
194 prefs::kPasswordManagerEnabled), | 195 prefs::kPasswordManagerEnabled), |
195 TypeAndName(kPolicyPasswordManagerAllowShowPasswords, | 196 TypeAndName(kPolicyPasswordManagerAllowShowPasswords, |
196 prefs::kPasswordManagerAllowShowPasswords), | 197 prefs::kPasswordManagerAllowShowPasswords), |
197 TypeAndName(kPolicyShowHomeButton, | 198 TypeAndName(kPolicyShowHomeButton, |
198 prefs::kShowHomeButton), | 199 prefs::kShowHomeButton), |
199 TypeAndName(kPolicyPrintingEnabled, | 200 TypeAndName(kPolicyPrintingEnabled, |
200 prefs::kPrintingEnabled), | 201 prefs::kPrintingEnabled), |
201 TypeAndName(kPolicyJavascriptEnabled, | 202 TypeAndName(kPolicyJavascriptEnabled, |
202 prefs::kWebKitJavascriptEnabled), | 203 prefs::kWebKitJavascriptEnabled), |
203 TypeAndName(kPolicyIncognitoEnabled, | |
204 prefs::kIncognitoEnabled), | |
205 TypeAndName(kPolicyIncognitoForced, | |
206 prefs::kIncognitoForced), | |
207 TypeAndName(kPolicyRemoteAccessClientFirewallTraversal, | 204 TypeAndName(kPolicyRemoteAccessClientFirewallTraversal, |
208 prefs::kRemoteAccessClientFirewallTraversal), | 205 prefs::kRemoteAccessClientFirewallTraversal), |
209 TypeAndName(kPolicyRemoteAccessHostFirewallTraversal, | 206 TypeAndName(kPolicyRemoteAccessHostFirewallTraversal, |
210 prefs::kRemoteAccessHostFirewallTraversal), | 207 prefs::kRemoteAccessHostFirewallTraversal), |
211 TypeAndName(kPolicyCloudPrintProxyEnabled, | 208 TypeAndName(kPolicyCloudPrintProxyEnabled, |
212 prefs::kCloudPrintProxyEnabled), | 209 prefs::kCloudPrintProxyEnabled), |
213 TypeAndName(kPolicySavingBrowserHistoryDisabled, | 210 TypeAndName(kPolicySavingBrowserHistoryDisabled, |
214 prefs::kSavingBrowserHistoryDisabled), | 211 prefs::kSavingBrowserHistoryDisabled), |
215 TypeAndName(kPolicySavingBrowserHistoryDisabled, | 212 TypeAndName(kPolicySavingBrowserHistoryDisabled, |
216 prefs::kSavingBrowserHistoryDisabled), | 213 prefs::kSavingBrowserHistoryDisabled), |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 EXPECT_EQ(PrefStore::READ_NO_VALUE, | 687 EXPECT_EQ(PrefStore::READ_NO_VALUE, |
691 store->GetValue(prefs::kDefaultSearchProviderKeyword, NULL)); | 688 store->GetValue(prefs::kDefaultSearchProviderKeyword, NULL)); |
692 EXPECT_EQ(PrefStore::READ_NO_VALUE, | 689 EXPECT_EQ(PrefStore::READ_NO_VALUE, |
693 store->GetValue(prefs::kDefaultSearchProviderSuggestURL, NULL)); | 690 store->GetValue(prefs::kDefaultSearchProviderSuggestURL, NULL)); |
694 EXPECT_EQ(PrefStore::READ_NO_VALUE, | 691 EXPECT_EQ(PrefStore::READ_NO_VALUE, |
695 store->GetValue(prefs::kDefaultSearchProviderIconURL, NULL)); | 692 store->GetValue(prefs::kDefaultSearchProviderIconURL, NULL)); |
696 EXPECT_EQ(PrefStore::READ_NO_VALUE, | 693 EXPECT_EQ(PrefStore::READ_NO_VALUE, |
697 store->GetValue(prefs::kDefaultSearchProviderEncodings, NULL)); | 694 store->GetValue(prefs::kDefaultSearchProviderEncodings, NULL)); |
698 } | 695 } |
699 | 696 |
| 697 // Tests Incognito mode availability preference setting. |
| 698 class ConfigurationPolicyPrefStoreIncognitoModeTest : public testing::Test { |
| 699 protected: |
| 700 static const int kIncognitoModeAvailabilityNotSet = -1; |
| 701 |
| 702 enum ObsoleteIncognitoEnabledValue { |
| 703 INCOGNITO_ENABLED_UNKNOWN, |
| 704 INCOGNITO_ENABLED_TRUE, |
| 705 INCOGNITO_ENABLED_FALSE |
| 706 }; |
| 707 |
| 708 void SetPolicies(ObsoleteIncognitoEnabledValue incognito_enabled, |
| 709 int availability) { |
| 710 if (incognito_enabled != INCOGNITO_ENABLED_UNKNOWN) { |
| 711 provider_.AddPolicy(kPolicyIncognitoEnabled, |
| 712 Value::CreateBooleanValue( |
| 713 incognito_enabled == INCOGNITO_ENABLED_TRUE)); |
| 714 } |
| 715 if (availability >= 0) { |
| 716 provider_.AddPolicy(kPolicyIncognitoModeAvailability, |
| 717 Value::CreateIntegerValue(availability)); |
| 718 } |
| 719 store_ = new ConfigurationPolicyPrefStore(&provider_); |
| 720 } |
| 721 |
| 722 void VerifyValues(IncognitoModePrefs::Availability availability) { |
| 723 const Value* value = NULL; |
| 724 EXPECT_EQ(PrefStore::READ_OK, |
| 725 store_->GetValue(prefs::kIncognitoModeAvailability, &value)); |
| 726 EXPECT_TRUE(FundamentalValue(availability).Equals(value)); |
| 727 } |
| 728 |
| 729 MockConfigurationPolicyProvider provider_; |
| 730 scoped_refptr<ConfigurationPolicyPrefStore> store_; |
| 731 }; |
| 732 |
| 733 // The following testcases verify that if the obsolete IncognitoEnabled |
| 734 // policy is not set, the IncognitoModeAvailability values should be copied |
| 735 // from IncognitoModeAvailability policy to pref "as is". |
| 736 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, |
| 737 NoObsoletePolicyAndIncognitoEnabled) { |
| 738 SetPolicies(INCOGNITO_ENABLED_UNKNOWN, IncognitoModePrefs::ENABLED); |
| 739 VerifyValues(IncognitoModePrefs::ENABLED); |
| 740 } |
| 741 |
| 742 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, |
| 743 NoObsoletePolicyAndIncognitoDisabled) { |
| 744 SetPolicies(INCOGNITO_ENABLED_UNKNOWN, IncognitoModePrefs::DISABLED); |
| 745 VerifyValues(IncognitoModePrefs::DISABLED); |
| 746 } |
| 747 |
| 748 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, |
| 749 NoObsoletePolicyAndIncognitoForced) { |
| 750 SetPolicies(INCOGNITO_ENABLED_UNKNOWN, IncognitoModePrefs::FORCED); |
| 751 VerifyValues(IncognitoModePrefs::FORCED); |
| 752 } |
| 753 |
| 754 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, |
| 755 NoObsoletePolicyAndNoIncognitoAvailability) { |
| 756 SetPolicies(INCOGNITO_ENABLED_UNKNOWN, kIncognitoModeAvailabilityNotSet); |
| 757 const Value* value = NULL; |
| 758 EXPECT_EQ(PrefStore::READ_NO_VALUE, |
| 759 store_->GetValue(prefs::kIncognitoModeAvailability, &value)); |
| 760 } |
| 761 |
| 762 // Checks that if the obsolete IncognitoEnabled policy is set, if sets |
| 763 // the IncognitoModeAvailability preference only in case |
| 764 // the IncognitoModeAvailability policy is not specified. |
| 765 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, |
| 766 ObsoletePolicyDoesNotAffectAvailabilityEnabled) { |
| 767 SetPolicies(INCOGNITO_ENABLED_FALSE, IncognitoModePrefs::ENABLED); |
| 768 VerifyValues(IncognitoModePrefs::ENABLED); |
| 769 } |
| 770 |
| 771 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, |
| 772 ObsoletePolicyDoesNotAffectAvailabilityForced) { |
| 773 SetPolicies(INCOGNITO_ENABLED_TRUE, IncognitoModePrefs::FORCED); |
| 774 VerifyValues(IncognitoModePrefs::FORCED); |
| 775 } |
| 776 |
| 777 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, |
| 778 ObsoletePolicySetsPreferenceToEnabled) { |
| 779 SetPolicies(INCOGNITO_ENABLED_TRUE, kIncognitoModeAvailabilityNotSet); |
| 780 VerifyValues(IncognitoModePrefs::ENABLED); |
| 781 } |
| 782 |
| 783 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, |
| 784 ObsoletePolicySetsPreferenceToDisabled) { |
| 785 SetPolicies(INCOGNITO_ENABLED_FALSE, kIncognitoModeAvailabilityNotSet); |
| 786 VerifyValues(IncognitoModePrefs::DISABLED); |
| 787 } |
| 788 |
700 // Test cases for the Sync policy setting. | 789 // Test cases for the Sync policy setting. |
701 class ConfigurationPolicyPrefStoreSyncTest | 790 class ConfigurationPolicyPrefStoreSyncTest |
702 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> { | 791 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> { |
703 }; | 792 }; |
704 | 793 |
705 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Default) { | 794 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Default) { |
706 EXPECT_EQ(PrefStore::READ_NO_VALUE, | 795 EXPECT_EQ(PrefStore::READ_NO_VALUE, |
707 store_->GetValue(prefs::kSyncManaged, NULL)); | 796 store_->GetValue(prefs::kSyncManaged, NULL)); |
708 } | 797 } |
709 | 798 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 | 960 |
872 provider_.SetInitializationComplete(true); | 961 provider_.SetInitializationComplete(true); |
873 EXPECT_FALSE(store_->IsInitializationComplete()); | 962 EXPECT_FALSE(store_->IsInitializationComplete()); |
874 | 963 |
875 store_->OnUpdatePolicy(); | 964 store_->OnUpdatePolicy(); |
876 Mock::VerifyAndClearExpectations(&observer_); | 965 Mock::VerifyAndClearExpectations(&observer_); |
877 EXPECT_TRUE(store_->IsInitializationComplete()); | 966 EXPECT_TRUE(store_->IsInitializationComplete()); |
878 } | 967 } |
879 | 968 |
880 } // namespace policy | 969 } // namespace policy |
OLD | NEW |