| 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 "components/sync_driver/sync_policy_handler.h" | 5 #include "components/sync_driver/sync_policy_handler.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
| 7 #include "base/values.h" | 8 #include "base/values.h" |
| 8 #include "components/policy/core/common/policy_map.h" | 9 #include "components/policy/core/common/policy_map.h" |
| 9 #include "components/policy/core/common/policy_types.h" | 10 #include "components/policy/core/common/policy_types.h" |
| 10 #include "components/prefs/pref_value_map.h" | 11 #include "components/prefs/pref_value_map.h" |
| 11 #include "components/sync_driver/pref_names.h" | 12 #include "components/sync_driver/pref_names.h" |
| 12 #include "policy/policy_constants.h" | 13 #include "policy/policy_constants.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace sync_driver { | 16 namespace sync_driver { |
| 16 | 17 |
| 17 // Test cases for the Sync policy setting. | 18 // Test cases for the Sync policy setting. |
| 18 class SyncPolicyHandlerTest : public testing::Test {}; | 19 class SyncPolicyHandlerTest : public testing::Test {}; |
| 19 | 20 |
| 20 TEST_F(SyncPolicyHandlerTest, Default) { | 21 TEST_F(SyncPolicyHandlerTest, Default) { |
| 21 policy::PolicyMap policy; | 22 policy::PolicyMap policy; |
| 22 SyncPolicyHandler handler; | 23 SyncPolicyHandler handler; |
| 23 PrefValueMap prefs; | 24 PrefValueMap prefs; |
| 24 handler.ApplyPolicySettings(policy, &prefs); | 25 handler.ApplyPolicySettings(policy, &prefs); |
| 25 EXPECT_FALSE(prefs.GetValue(sync_driver::prefs::kSyncManaged, NULL)); | 26 EXPECT_FALSE(prefs.GetValue(sync_driver::prefs::kSyncManaged, NULL)); |
| 26 } | 27 } |
| 27 | 28 |
| 28 TEST_F(SyncPolicyHandlerTest, Enabled) { | 29 TEST_F(SyncPolicyHandlerTest, Enabled) { |
| 29 policy::PolicyMap policy; | 30 policy::PolicyMap policy; |
| 30 policy.Set(policy::key::kSyncDisabled, | 31 policy.Set(policy::key::kSyncDisabled, policy::POLICY_LEVEL_MANDATORY, |
| 31 policy::POLICY_LEVEL_MANDATORY, | 32 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, |
| 32 policy::POLICY_SCOPE_USER, | 33 base::WrapUnique(new base::FundamentalValue(false)), nullptr); |
| 33 policy::POLICY_SOURCE_CLOUD, | |
| 34 new base::FundamentalValue(false), | |
| 35 NULL); | |
| 36 SyncPolicyHandler handler; | 34 SyncPolicyHandler handler; |
| 37 PrefValueMap prefs; | 35 PrefValueMap prefs; |
| 38 handler.ApplyPolicySettings(policy, &prefs); | 36 handler.ApplyPolicySettings(policy, &prefs); |
| 39 | 37 |
| 40 // Enabling Sync should not set the pref. | 38 // Enabling Sync should not set the pref. |
| 41 EXPECT_FALSE(prefs.GetValue(sync_driver::prefs::kSyncManaged, NULL)); | 39 EXPECT_FALSE(prefs.GetValue(sync_driver::prefs::kSyncManaged, NULL)); |
| 42 } | 40 } |
| 43 | 41 |
| 44 TEST_F(SyncPolicyHandlerTest, Disabled) { | 42 TEST_F(SyncPolicyHandlerTest, Disabled) { |
| 45 policy::PolicyMap policy; | 43 policy::PolicyMap policy; |
| 46 policy.Set(policy::key::kSyncDisabled, | 44 policy.Set(policy::key::kSyncDisabled, policy::POLICY_LEVEL_MANDATORY, |
| 47 policy::POLICY_LEVEL_MANDATORY, | 45 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, |
| 48 policy::POLICY_SCOPE_USER, | 46 base::WrapUnique(new base::FundamentalValue(true)), nullptr); |
| 49 policy::POLICY_SOURCE_CLOUD, | |
| 50 new base::FundamentalValue(true), | |
| 51 NULL); | |
| 52 SyncPolicyHandler handler; | 47 SyncPolicyHandler handler; |
| 53 PrefValueMap prefs; | 48 PrefValueMap prefs; |
| 54 handler.ApplyPolicySettings(policy, &prefs); | 49 handler.ApplyPolicySettings(policy, &prefs); |
| 55 | 50 |
| 56 // Sync should be flagged as managed. | 51 // Sync should be flagged as managed. |
| 57 const base::Value* value = NULL; | 52 const base::Value* value = NULL; |
| 58 EXPECT_TRUE(prefs.GetValue(sync_driver::prefs::kSyncManaged, &value)); | 53 EXPECT_TRUE(prefs.GetValue(sync_driver::prefs::kSyncManaged, &value)); |
| 59 ASSERT_TRUE(value); | 54 ASSERT_TRUE(value); |
| 60 bool sync_managed = false; | 55 bool sync_managed = false; |
| 61 bool result = value->GetAsBoolean(&sync_managed); | 56 bool result = value->GetAsBoolean(&sync_managed); |
| 62 ASSERT_TRUE(result); | 57 ASSERT_TRUE(result); |
| 63 EXPECT_TRUE(sync_managed); | 58 EXPECT_TRUE(sync_managed); |
| 64 } | 59 } |
| 65 | 60 |
| 66 } // namespace sync_driver | 61 } // namespace sync_driver |
| OLD | NEW |