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