| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/profiles/incognito_mode_policy_handler.h" | 5 #include "chrome/browser/profiles/incognito_mode_policy_handler.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 8 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 9 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
| 10 #include "components/policy/core/browser/configuration_policy_pref_store.h" | 10 #include "components/policy/core/browser/configuration_policy_pref_store.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 INCOGNITO_ENABLED_TRUE, | 30 INCOGNITO_ENABLED_TRUE, |
| 31 INCOGNITO_ENABLED_FALSE | 31 INCOGNITO_ENABLED_FALSE |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 void SetPolicies(ObsoleteIncognitoEnabledValue incognito_enabled, | 34 void SetPolicies(ObsoleteIncognitoEnabledValue incognito_enabled, |
| 35 int availability) { | 35 int availability) { |
| 36 PolicyMap policy; | 36 PolicyMap policy; |
| 37 if (incognito_enabled != INCOGNITO_ENABLED_UNKNOWN) { | 37 if (incognito_enabled != INCOGNITO_ENABLED_UNKNOWN) { |
| 38 policy.Set(key::kIncognitoEnabled, POLICY_LEVEL_MANDATORY, | 38 policy.Set(key::kIncognitoEnabled, POLICY_LEVEL_MANDATORY, |
| 39 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 39 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 40 base::MakeUnique<base::FundamentalValue>( | 40 base::MakeUnique<base::Value>( |
| 41 incognito_enabled == INCOGNITO_ENABLED_TRUE), | 41 incognito_enabled == INCOGNITO_ENABLED_TRUE), |
| 42 nullptr); | 42 nullptr); |
| 43 } | 43 } |
| 44 if (availability >= 0) { | 44 if (availability >= 0) { |
| 45 policy.Set(key::kIncognitoModeAvailability, POLICY_LEVEL_MANDATORY, | 45 policy.Set(key::kIncognitoModeAvailability, POLICY_LEVEL_MANDATORY, |
| 46 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 46 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 47 base::MakeUnique<base::FundamentalValue>(availability), | 47 base::MakeUnique<base::Value>(availability), |
| 48 nullptr); | 48 nullptr); |
| 49 } | 49 } |
| 50 UpdateProviderPolicy(policy); | 50 UpdateProviderPolicy(policy); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void VerifyValues(IncognitoModePrefs::Availability availability) { | 53 void VerifyValues(IncognitoModePrefs::Availability availability) { |
| 54 const base::Value* value = NULL; | 54 const base::Value* value = NULL; |
| 55 EXPECT_TRUE(store_->GetValue(prefs::kIncognitoModeAvailability, &value)); | 55 EXPECT_TRUE(store_->GetValue(prefs::kIncognitoModeAvailability, &value)); |
| 56 EXPECT_TRUE(base::FundamentalValue(availability).Equals(value)); | 56 EXPECT_TRUE(base::Value(availability).Equals(value)); |
| 57 } | 57 } |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 // The following testcases verify that if the obsolete IncognitoEnabled | 60 // The following testcases verify that if the obsolete IncognitoEnabled |
| 61 // policy is not set, the IncognitoModeAvailability values should be copied | 61 // policy is not set, the IncognitoModeAvailability values should be copied |
| 62 // from IncognitoModeAvailability policy to pref "as is". | 62 // from IncognitoModeAvailability policy to pref "as is". |
| 63 TEST_F(IncognitoModePolicyHandlerTest, | 63 TEST_F(IncognitoModePolicyHandlerTest, |
| 64 NoObsoletePolicyAndIncognitoEnabled) { | 64 NoObsoletePolicyAndIncognitoEnabled) { |
| 65 SetPolicies(INCOGNITO_ENABLED_UNKNOWN, IncognitoModePrefs::ENABLED); | 65 SetPolicies(INCOGNITO_ENABLED_UNKNOWN, IncognitoModePrefs::ENABLED); |
| 66 VerifyValues(IncognitoModePrefs::ENABLED); | 66 VerifyValues(IncognitoModePrefs::ENABLED); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 VerifyValues(IncognitoModePrefs::ENABLED); | 106 VerifyValues(IncognitoModePrefs::ENABLED); |
| 107 } | 107 } |
| 108 | 108 |
| 109 TEST_F(IncognitoModePolicyHandlerTest, | 109 TEST_F(IncognitoModePolicyHandlerTest, |
| 110 ObsoletePolicySetsPreferenceToDisabled) { | 110 ObsoletePolicySetsPreferenceToDisabled) { |
| 111 SetPolicies(INCOGNITO_ENABLED_FALSE, kIncognitoModeAvailabilityNotSet); | 111 SetPolicies(INCOGNITO_ENABLED_FALSE, kIncognitoModeAvailabilityNotSet); |
| 112 VerifyValues(IncognitoModePrefs::DISABLED); | 112 VerifyValues(IncognitoModePrefs::DISABLED); |
| 113 } | 113 } |
| 114 | 114 |
| 115 } // namespace policy | 115 } // namespace policy |
| OLD | NEW |