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 17 matching lines...) Expand all Loading... |
28 enum ObsoleteIncognitoEnabledValue { | 28 enum ObsoleteIncognitoEnabledValue { |
29 INCOGNITO_ENABLED_UNKNOWN, | 29 INCOGNITO_ENABLED_UNKNOWN, |
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, | 38 policy.Set(key::kIncognitoEnabled, POLICY_LEVEL_MANDATORY, |
39 POLICY_LEVEL_MANDATORY, | 39 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
40 POLICY_SCOPE_USER, | 40 base::WrapUnique(new base::FundamentalValue( |
41 POLICY_SOURCE_CLOUD, | 41 incognito_enabled == INCOGNITO_ENABLED_TRUE)), |
42 new base::FundamentalValue(incognito_enabled == | 42 nullptr); |
43 INCOGNITO_ENABLED_TRUE), | |
44 NULL); | |
45 } | 43 } |
46 if (availability >= 0) { | 44 if (availability >= 0) { |
47 policy.Set(key::kIncognitoModeAvailability, | 45 policy.Set(key::kIncognitoModeAvailability, POLICY_LEVEL_MANDATORY, |
48 POLICY_LEVEL_MANDATORY, | 46 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
49 POLICY_SCOPE_USER, | 47 base::WrapUnique(new base::FundamentalValue(availability)), |
50 POLICY_SOURCE_CLOUD, | 48 nullptr); |
51 new base::FundamentalValue(availability), | |
52 NULL); | |
53 } | 49 } |
54 UpdateProviderPolicy(policy); | 50 UpdateProviderPolicy(policy); |
55 } | 51 } |
56 | 52 |
57 void VerifyValues(IncognitoModePrefs::Availability availability) { | 53 void VerifyValues(IncognitoModePrefs::Availability availability) { |
58 const base::Value* value = NULL; | 54 const base::Value* value = NULL; |
59 EXPECT_TRUE(store_->GetValue(prefs::kIncognitoModeAvailability, &value)); | 55 EXPECT_TRUE(store_->GetValue(prefs::kIncognitoModeAvailability, &value)); |
60 EXPECT_TRUE(base::FundamentalValue(availability).Equals(value)); | 56 EXPECT_TRUE(base::FundamentalValue(availability).Equals(value)); |
61 } | 57 } |
62 }; | 58 }; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 VerifyValues(IncognitoModePrefs::ENABLED); | 106 VerifyValues(IncognitoModePrefs::ENABLED); |
111 } | 107 } |
112 | 108 |
113 TEST_F(IncognitoModePolicyHandlerTest, | 109 TEST_F(IncognitoModePolicyHandlerTest, |
114 ObsoletePolicySetsPreferenceToDisabled) { | 110 ObsoletePolicySetsPreferenceToDisabled) { |
115 SetPolicies(INCOGNITO_ENABLED_FALSE, kIncognitoModeAvailabilityNotSet); | 111 SetPolicies(INCOGNITO_ENABLED_FALSE, kIncognitoModeAvailabilityNotSet); |
116 VerifyValues(IncognitoModePrefs::DISABLED); | 112 VerifyValues(IncognitoModePrefs::DISABLED); |
117 } | 113 } |
118 | 114 |
119 } // namespace policy | 115 } // namespace policy |
OLD | NEW |