Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: chrome/browser/policy/configuration_policy_pref_store_unittest.cc

Issue 7520023: Converted IncognitoForced boolean policy into IncognitoModeAvailability enum policy. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Converted incognito pref functions to a class. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 if (availability >= 0)
706 provider_.AddPolicy(kPolicyIncognitoModeAvailability,
707 Value::CreateIntegerValue(availability));
708 store_ = new ConfigurationPolicyPrefStore(&provider_);
709 }
710 void VerifyValues(IncognitoModePrefs::Availability availability) {
711 const Value* value = NULL;
712 EXPECT_EQ(PrefStore::READ_OK,
713 store_->GetValue(prefs::kIncognitoModeAvailability, &value));
714 EXPECT_TRUE(Value::CreateIntegerValue(availability)->Equals(value));
715 }
716 MockConfigurationPolicyProvider provider_;
717 scoped_refptr<ConfigurationPolicyPrefStore> store_;
718 };
719
720 // The following three testcases verify that if the obsolete IncognitoEnabled
721 // policy is set to true, the IncognitoModeAvailability values should be copied
722 // from policy to pref "as is".
723 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest,
724 DefaultObsoletePolicyAndIncognitoEnabled) {
725 SetPolicies(true, IncognitoModePrefs::ENABLED);
726 VerifyValues(IncognitoModePrefs::ENABLED);
727 }
728
729 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest,
730 DefaultObsoletePolicyAndIncognitoDisabled) {
731 SetPolicies(true, IncognitoModePrefs::DISABLED);
732 VerifyValues(IncognitoModePrefs::DISABLED);
733 }
734
735 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest,
736 DefaultObsoletePolicyAndIncognitoForced) {
737 SetPolicies(true, IncognitoModePrefs::FORCED);
738 VerifyValues(IncognitoModePrefs::FORCED);
739 }
740
741 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest,
742 DefaultObsoletePolicyAndIncognitoAvailabilityNotSet) {
743 SetPolicies(true, -1);
744 const Value* value = NULL;
745 EXPECT_EQ(PrefStore::READ_NO_VALUE,
746 store_->GetValue(prefs::kIncognitoModeAvailability, &value));
747 }
748
749 // Checks that if the obsolete IncognitoEnabled policy is set to false,
750 // IncognitoModeAvailability is overridden to DISABLED only in case it's
751 // originally was not specified.
752 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest,
753 ObsoletePolicyDoesNotAffectAvailabilityEnabled) {
754 SetPolicies(false, IncognitoModePrefs::ENABLED);
755 VerifyValues(IncognitoModePrefs::ENABLED);
756 }
757
758 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest,
759 ObsoletePolicyDoesNotAffectAvailabilityDisabled) {
760 SetPolicies(false, IncognitoModePrefs::DISABLED);
761 VerifyValues(IncognitoModePrefs::DISABLED);
762 }
763
764 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest,
765 ObsoletePolicyDoesNotAffectAvailabilityForced) {
766 SetPolicies(false, IncognitoModePrefs::FORCED);
767 VerifyValues(IncognitoModePrefs::FORCED);
768 }
769
770 TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest,
771 DefaultObsoletePolicyDisablesAvailabilityWhenLatterNotSpecified) {
772 SetPolicies(false, -1);
773 VerifyValues(IncognitoModePrefs::DISABLED);
774 }
775
700 // Test cases for the Sync policy setting. 776 // Test cases for the Sync policy setting.
701 class ConfigurationPolicyPrefStoreSyncTest 777 class ConfigurationPolicyPrefStoreSyncTest
702 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> { 778 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> {
703 }; 779 };
704 780
705 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Default) { 781 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Default) {
706 EXPECT_EQ(PrefStore::READ_NO_VALUE, 782 EXPECT_EQ(PrefStore::READ_NO_VALUE,
707 store_->GetValue(prefs::kSyncManaged, NULL)); 783 store_->GetValue(prefs::kSyncManaged, NULL));
708 } 784 }
709 785
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 947
872 provider_.SetInitializationComplete(true); 948 provider_.SetInitializationComplete(true);
873 EXPECT_FALSE(store_->IsInitializationComplete()); 949 EXPECT_FALSE(store_->IsInitializationComplete());
874 950
875 store_->OnUpdatePolicy(); 951 store_->OnUpdatePolicy();
876 Mock::VerifyAndClearExpectations(&observer_); 952 Mock::VerifyAndClearExpectations(&observer_);
877 EXPECT_TRUE(store_->IsInitializationComplete()); 953 EXPECT_TRUE(store_->IsInitializationComplete());
878 } 954 }
879 955
880 } // namespace policy 956 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698