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_availability_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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 TypeAndName(kPolicyIncognitoEnabled, |
204 prefs::kIncognitoEnabled), | 205 prefs::kIncognitoEnabled), |
205 TypeAndName(kPolicyIncognitoForced, | |
206 prefs::kIncognitoForced), | |
207 TypeAndName(kPolicyRemoteAccessClientFirewallTraversal, | 206 TypeAndName(kPolicyRemoteAccessClientFirewallTraversal, |
208 prefs::kRemoteAccessClientFirewallTraversal), | 207 prefs::kRemoteAccessClientFirewallTraversal), |
209 TypeAndName(kPolicyRemoteAccessHostFirewallTraversal, | 208 TypeAndName(kPolicyRemoteAccessHostFirewallTraversal, |
210 prefs::kRemoteAccessHostFirewallTraversal), | 209 prefs::kRemoteAccessHostFirewallTraversal), |
211 TypeAndName(kPolicyCloudPrintProxyEnabled, | 210 TypeAndName(kPolicyCloudPrintProxyEnabled, |
212 prefs::kCloudPrintProxyEnabled), | 211 prefs::kCloudPrintProxyEnabled), |
213 TypeAndName(kPolicySavingBrowserHistoryDisabled, | 212 TypeAndName(kPolicySavingBrowserHistoryDisabled, |
214 prefs::kSavingBrowserHistoryDisabled), | 213 prefs::kSavingBrowserHistoryDisabled), |
215 TypeAndName(kPolicySavingBrowserHistoryDisabled, | 214 TypeAndName(kPolicySavingBrowserHistoryDisabled, |
216 prefs::kSavingBrowserHistoryDisabled), | 215 prefs::kSavingBrowserHistoryDisabled), |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 EXPECT_EQ(PrefStore::READ_NO_VALUE, | 689 EXPECT_EQ(PrefStore::READ_NO_VALUE, |
691 store->GetValue(prefs::kDefaultSearchProviderKeyword, NULL)); | 690 store->GetValue(prefs::kDefaultSearchProviderKeyword, NULL)); |
692 EXPECT_EQ(PrefStore::READ_NO_VALUE, | 691 EXPECT_EQ(PrefStore::READ_NO_VALUE, |
693 store->GetValue(prefs::kDefaultSearchProviderSuggestURL, NULL)); | 692 store->GetValue(prefs::kDefaultSearchProviderSuggestURL, NULL)); |
694 EXPECT_EQ(PrefStore::READ_NO_VALUE, | 693 EXPECT_EQ(PrefStore::READ_NO_VALUE, |
695 store->GetValue(prefs::kDefaultSearchProviderIconURL, NULL)); | 694 store->GetValue(prefs::kDefaultSearchProviderIconURL, NULL)); |
696 EXPECT_EQ(PrefStore::READ_NO_VALUE, | 695 EXPECT_EQ(PrefStore::READ_NO_VALUE, |
697 store->GetValue(prefs::kDefaultSearchProviderEncodings, NULL)); | 696 store->GetValue(prefs::kDefaultSearchProviderEncodings, NULL)); |
698 } | 697 } |
699 | 698 |
| 699 // Tests Incognito mode availability preference setting. |
| 700 class ConfigurationPolicyPrefStoreIncognitoModeTest : public testing::Test { |
| 701 protected: |
| 702 void SetPolicies(bool incognito_enabled, int availability) { |
| 703 provider_.AddPolicy(kPolicyIncognitoEnabled, |
| 704 Value::CreateBooleanValue(incognito_enabled)); |
| 705 provider_.AddPolicy(kPolicyIncognitoModeAvailability, |
| 706 Value::CreateIntegerValue(availability)); |
| 707 store_ = new ConfigurationPolicyPrefStore(&provider_); |
| 708 } |
| 709 |
| 710 void VerifyValues( |
| 711 bool incognito_enabled, |
| 712 IncognitoModeAvailabilityPrefs::IncognitoModeAvailability availability) { |
| 713 const Value* value = NULL; |
| 714 EXPECT_EQ(PrefStore::READ_OK, |
| 715 store_->GetValue(prefs::kIncognitoEnabled, &value)); |
| 716 EXPECT_TRUE(Value::CreateBooleanValue(incognito_enabled)->Equals(value)); |
| 717 |
| 718 EXPECT_EQ(PrefStore::READ_OK, |
| 719 store_->GetValue(prefs::kIncognitoModeAvailability, &value)); |
| 720 EXPECT_TRUE(Value::CreateIntegerValue(availability)->Equals(value)); |
| 721 } |
| 722 MockConfigurationPolicyProvider provider_; |
| 723 scoped_refptr<ConfigurationPolicyPrefStore> store_; |
| 724 }; |
| 725 |
| 726 // The following three testcases verify that if the obsolete IncognitoEnabled |
| 727 // policy is set to true, the IncognitoModeAvailability values should be copied |
| 728 // from policy to pref "as is". |
| 729 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, |
| 730 DefaultObsoletePolicyAndIncognitoEnabled) { |
| 731 SetPolicies(true, IncognitoModeAvailabilityPrefs::ENABLED); |
| 732 VerifyValues(true, IncognitoModeAvailabilityPrefs::ENABLED); |
| 733 } |
| 734 |
| 735 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, |
| 736 DefaultObsoletePolicyAndIncognitoDisabled) { |
| 737 SetPolicies(true, IncognitoModeAvailabilityPrefs::DISABLED); |
| 738 VerifyValues(true, IncognitoModeAvailabilityPrefs::DISABLED); |
| 739 } |
| 740 |
| 741 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, |
| 742 DefaultObsoletePolicyAndIncognitoForced) { |
| 743 SetPolicies(true, IncognitoModeAvailabilityPrefs::FORCED); |
| 744 VerifyValues(true, IncognitoModeAvailabilityPrefs::FORCED); |
| 745 } |
| 746 |
| 747 // Checks that if the obsolete IncognitoEnabled policy is set to false, |
| 748 // IncognitoModeAvailability is overridden to DISABLED only in case it's |
| 749 // originally set to ENABLED. |
| 750 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, |
| 751 ObsoletePolicyDisablesIncognitoEnabledChangesToDisabled) { |
| 752 // kIncognitoEnabled == false overrides kIncognitoModeAvailability. |
| 753 SetPolicies(false, IncognitoModeAvailabilityPrefs::ENABLED); |
| 754 VerifyValues(false, IncognitoModeAvailabilityPrefs::DISABLED); |
| 755 } |
| 756 |
| 757 // DISABLED? - hence, no change is expected. |
| 758 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, |
| 759 ObsoletePolicyDisablesIncognitoNoChangeWhenDisabled) { |
| 760 SetPolicies(false, IncognitoModeAvailabilityPrefs::DISABLED); |
| 761 VerifyValues(false, IncognitoModeAvailabilityPrefs::DISABLED); |
| 762 } |
| 763 |
| 764 // FORCED? - ignore the obsolete policy. |
| 765 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, |
| 766 ObsoletePolicyDisablesIncognitoNoChangeWhenForced) { |
| 767 SetPolicies(false, IncognitoModeAvailabilityPrefs::FORCED); |
| 768 VerifyValues(false, IncognitoModeAvailabilityPrefs::FORCED); |
| 769 } |
| 770 |
700 // Test cases for the Sync policy setting. | 771 // Test cases for the Sync policy setting. |
701 class ConfigurationPolicyPrefStoreSyncTest | 772 class ConfigurationPolicyPrefStoreSyncTest |
702 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> { | 773 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> { |
703 }; | 774 }; |
704 | 775 |
705 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Default) { | 776 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Default) { |
706 EXPECT_EQ(PrefStore::READ_NO_VALUE, | 777 EXPECT_EQ(PrefStore::READ_NO_VALUE, |
707 store_->GetValue(prefs::kSyncManaged, NULL)); | 778 store_->GetValue(prefs::kSyncManaged, NULL)); |
708 } | 779 } |
709 | 780 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 | 942 |
872 provider_.SetInitializationComplete(true); | 943 provider_.SetInitializationComplete(true); |
873 EXPECT_FALSE(store_->IsInitializationComplete()); | 944 EXPECT_FALSE(store_->IsInitializationComplete()); |
874 | 945 |
875 store_->OnUpdatePolicy(); | 946 store_->OnUpdatePolicy(); |
876 Mock::VerifyAndClearExpectations(&observer_); | 947 Mock::VerifyAndClearExpectations(&observer_); |
877 EXPECT_TRUE(store_->IsInitializationComplete()); | 948 EXPECT_TRUE(store_->IsInitializationComplete()); |
878 } | 949 } |
879 | 950 |
880 } // namespace policy | 951 } // namespace policy |
OLD | NEW |