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) | |
Mattias Nissler (ping if slow)
2011/08/03 09:16:08
need curlies.
rustema
2011/08/04 07:00:49
Done.
| |
716 provider_.AddPolicy(kPolicyIncognitoModeAvailability, | |
717 Value::CreateIntegerValue(availability)); | |
718 store_ = new ConfigurationPolicyPrefStore(&provider_); | |
719 } | |
720 | |
721 void VerifyValues(IncognitoModePrefs::Availability availability) { | |
722 const Value* value = NULL; | |
723 EXPECT_EQ(PrefStore::READ_OK, | |
724 store_->GetValue(prefs::kIncognitoModeAvailability, &value)); | |
725 EXPECT_TRUE(FundamentalValue(availability).Equals(value)); | |
726 } | |
727 | |
728 MockConfigurationPolicyProvider provider_; | |
729 scoped_refptr<ConfigurationPolicyPrefStore> store_; | |
730 }; | |
731 | |
732 // The following testcases verify that if the obsolete IncognitoEnabled | |
733 // policy is not set, the IncognitoModeAvailability values should be copied | |
734 // from IncognitoModeAvailability policy to pref "as is". | |
735 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, | |
736 NoObsoletePolicyAndIncognitoEnabled) { | |
737 SetPolicies(INCOGNITO_ENABLED_UNKNOWN, IncognitoModePrefs::ENABLED); | |
738 VerifyValues(IncognitoModePrefs::ENABLED); | |
739 } | |
740 | |
741 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, | |
742 NoObsoletePolicyAndIncognitoDisabled) { | |
743 SetPolicies(INCOGNITO_ENABLED_UNKNOWN, IncognitoModePrefs::DISABLED); | |
744 VerifyValues(IncognitoModePrefs::DISABLED); | |
745 } | |
746 | |
747 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, | |
748 NoObsoletePolicyAndIncognitoForced) { | |
749 SetPolicies(INCOGNITO_ENABLED_UNKNOWN, IncognitoModePrefs::FORCED); | |
750 VerifyValues(IncognitoModePrefs::FORCED); | |
751 } | |
752 | |
753 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, | |
754 NoObsoletePolicyAndNoIncognitoAvailability) { | |
755 SetPolicies(INCOGNITO_ENABLED_UNKNOWN, kIncognitoModeAvailabilityNotSet); | |
756 const Value* value = NULL; | |
757 EXPECT_EQ(PrefStore::READ_NO_VALUE, | |
758 store_->GetValue(prefs::kIncognitoModeAvailability, &value)); | |
759 } | |
760 | |
761 // Checks that if the obsolete IncognitoEnabled policy is set, if sets | |
762 // the IncognitoModeAvailability preference only in case | |
763 // the IncognitoModeAvailability policy is not specified. | |
764 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, | |
765 ObsoletePolicyDoesNotAffectAvailabilityEnabled) { | |
766 SetPolicies(INCOGNITO_ENABLED_FALSE, IncognitoModePrefs::ENABLED); | |
767 VerifyValues(IncognitoModePrefs::ENABLED); | |
768 } | |
769 | |
770 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, | |
771 ObsoletePolicyDoesNotAffectAvailabilityForced) { | |
772 SetPolicies(INCOGNITO_ENABLED_TRUE, IncognitoModePrefs::FORCED); | |
773 VerifyValues(IncognitoModePrefs::FORCED); | |
774 } | |
775 | |
776 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, | |
777 ObsoletePolicySetsPreferenceToEnabled) { | |
778 SetPolicies(INCOGNITO_ENABLED_TRUE, kIncognitoModeAvailabilityNotSet); | |
779 VerifyValues(IncognitoModePrefs::ENABLED); | |
780 } | |
781 | |
782 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, | |
783 ObsoletePolicySetsPreferenceToDisabled) { | |
784 SetPolicies(INCOGNITO_ENABLED_FALSE, kIncognitoModeAvailabilityNotSet); | |
785 VerifyValues(IncognitoModePrefs::DISABLED); | |
786 } | |
787 | |
700 // Test cases for the Sync policy setting. | 788 // Test cases for the Sync policy setting. |
701 class ConfigurationPolicyPrefStoreSyncTest | 789 class ConfigurationPolicyPrefStoreSyncTest |
702 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> { | 790 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> { |
703 }; | 791 }; |
704 | 792 |
705 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Default) { | 793 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Default) { |
706 EXPECT_EQ(PrefStore::READ_NO_VALUE, | 794 EXPECT_EQ(PrefStore::READ_NO_VALUE, |
707 store_->GetValue(prefs::kSyncManaged, NULL)); | 795 store_->GetValue(prefs::kSyncManaged, NULL)); |
708 } | 796 } |
709 | 797 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
871 | 959 |
872 provider_.SetInitializationComplete(true); | 960 provider_.SetInitializationComplete(true); |
873 EXPECT_FALSE(store_->IsInitializationComplete()); | 961 EXPECT_FALSE(store_->IsInitializationComplete()); |
874 | 962 |
875 store_->OnUpdatePolicy(); | 963 store_->OnUpdatePolicy(); |
876 Mock::VerifyAndClearExpectations(&observer_); | 964 Mock::VerifyAndClearExpectations(&observer_); |
877 EXPECT_TRUE(store_->IsInitializationComplete()); | 965 EXPECT_TRUE(store_->IsInitializationComplete()); |
878 } | 966 } |
879 | 967 |
880 } // namespace policy | 968 } // namespace policy |
OLD | NEW |