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 void SetPolicies(bool incognito_enabled, int availability) { | |
701 provider_.AddPolicy(kPolicyIncognitoEnabled, | |
702 Value::CreateBooleanValue(incognito_enabled)); | |
703 if (availability >= 0) | |
704 provider_.AddPolicy(kPolicyIncognitoModeAvailability, | |
705 Value::CreateIntegerValue(availability)); | |
706 store_ = new ConfigurationPolicyPrefStore(&provider_); | |
707 } | |
Mattias Nissler (ping if slow)
2011/08/01 11:13:40
newline
rustema
2011/08/01 23:55:33
Done.
| |
708 void VerifyValues(IncognitoModePrefs::Availability availability) { | |
709 const Value* value = NULL; | |
710 EXPECT_EQ(PrefStore::READ_OK, | |
711 store_->GetValue(prefs::kIncognitoModeAvailability, &value)); | |
712 EXPECT_TRUE(Value::CreateIntegerValue(availability)->Equals(value)); | |
Mattias Nissler (ping if slow)
2011/08/01 11:13:40
You are leaking the created Value here. Just use F
rustema
2011/08/01 23:55:33
Nuts! Chrome tests do not link in heap checker?!
Mattias Nissler (ping if slow)
2011/08/03 09:16:08
We do have valgrind and the tcmalloc heap checker.
rustema
2011/08/04 07:00:49
Cool! Thanks for the pointers!
| |
713 } | |
Mattias Nissler (ping if slow)
2011/08/01 11:13:40
newline
rustema
2011/08/01 23:55:33
Done.
| |
714 MockConfigurationPolicyProvider provider_; | |
715 scoped_refptr<ConfigurationPolicyPrefStore> store_; | |
716 }; | |
717 | |
718 // The following three testcases verify that if the obsolete IncognitoEnabled | |
719 // policy is set to true, the IncognitoModeAvailability values should be copied | |
720 // from policy to pref "as is". | |
Mattias Nissler (ping if slow)
2011/08/01 11:13:40
Shouldn't it rather check that if the new-style po
rustema
2011/08/01 23:55:33
Updated.
| |
721 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, | |
722 DefaultObsoletePolicyAndIncognitoEnabled) { | |
723 SetPolicies(true, IncognitoModePrefs::ENABLED); | |
724 VerifyValues(IncognitoModePrefs::ENABLED); | |
725 } | |
726 | |
727 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, | |
728 DefaultObsoletePolicyAndIncognitoDisabled) { | |
729 SetPolicies(true, IncognitoModePrefs::DISABLED); | |
730 VerifyValues(IncognitoModePrefs::DISABLED); | |
731 } | |
732 | |
733 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, | |
734 DefaultObsoletePolicyAndIncognitoForced) { | |
735 SetPolicies(true, IncognitoModePrefs::FORCED); | |
736 VerifyValues(IncognitoModePrefs::FORCED); | |
737 } | |
738 | |
739 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, | |
740 DefaultObsoletePolicyAndIncognitoAvailabilityNotSet) { | |
741 SetPolicies(true, -1); | |
742 const Value* value = NULL; | |
743 EXPECT_EQ(PrefStore::READ_NO_VALUE, | |
Mattias Nissler (ping if slow)
2011/08/01 11:13:40
In this case, it should return READ_OK with Incogn
rustema
2011/08/01 23:55:33
Nope, -1 here means no IncognitoModeAvailability s
Mattias Nissler (ping if slow)
2011/08/03 09:16:08
I was actually referring to the fact that you set
rustema
2011/08/04 07:00:49
Yep, ObsoletePolicySetsPreferenceToEnabled verifie
| |
744 store_->GetValue(prefs::kIncognitoModeAvailability, &value)); | |
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 was not specified. | |
Mattias Nissler (ping if slow)
2011/08/01 11:13:40
grammar
rustema
2011/08/01 23:55:33
Updated.
| |
750 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, | |
751 ObsoletePolicyDoesNotAffectAvailabilityEnabled) { | |
752 SetPolicies(false, IncognitoModePrefs::ENABLED); | |
753 VerifyValues(IncognitoModePrefs::ENABLED); | |
754 } | |
755 | |
756 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, | |
757 ObsoletePolicyDoesNotAffectAvailabilityDisabled) { | |
758 SetPolicies(false, IncognitoModePrefs::DISABLED); | |
759 VerifyValues(IncognitoModePrefs::DISABLED); | |
760 } | |
761 | |
762 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, | |
763 ObsoletePolicyDoesNotAffectAvailabilityForced) { | |
764 SetPolicies(false, IncognitoModePrefs::FORCED); | |
765 VerifyValues(IncognitoModePrefs::FORCED); | |
766 } | |
767 | |
768 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, | |
769 DefaultObsoletePolicyDisablesAvailabilityWhenLatterNotSpecified) { | |
Mattias Nissler (ping if slow)
2011/08/01 11:13:40
If the policy isn't specified correctly, shouldn't
rustema
2011/08/01 23:55:33
-1 means "not specified".
Mattias Nissler (ping if slow)
2011/08/03 09:16:08
Right, sorry for the confusion.
| |
770 SetPolicies(false, -1); | |
771 VerifyValues(IncognitoModePrefs::DISABLED); | |
772 } | |
773 | |
700 // Test cases for the Sync policy setting. | 774 // Test cases for the Sync policy setting. |
701 class ConfigurationPolicyPrefStoreSyncTest | 775 class ConfigurationPolicyPrefStoreSyncTest |
702 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> { | 776 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> { |
703 }; | 777 }; |
704 | 778 |
705 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Default) { | 779 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Default) { |
706 EXPECT_EQ(PrefStore::READ_NO_VALUE, | 780 EXPECT_EQ(PrefStore::READ_NO_VALUE, |
707 store_->GetValue(prefs::kSyncManaged, NULL)); | 781 store_->GetValue(prefs::kSyncManaged, NULL)); |
708 } | 782 } |
709 | 783 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
871 | 945 |
872 provider_.SetInitializationComplete(true); | 946 provider_.SetInitializationComplete(true); |
873 EXPECT_FALSE(store_->IsInitializationComplete()); | 947 EXPECT_FALSE(store_->IsInitializationComplete()); |
874 | 948 |
875 store_->OnUpdatePolicy(); | 949 store_->OnUpdatePolicy(); |
876 Mock::VerifyAndClearExpectations(&observer_); | 950 Mock::VerifyAndClearExpectations(&observer_); |
877 EXPECT_TRUE(store_->IsInitializationComplete()); | 951 EXPECT_TRUE(store_->IsInitializationComplete()); |
878 } | 952 } |
879 | 953 |
880 } // namespace policy | 954 } // namespace policy |
OLD | NEW |