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

Side by Side Diff: components/policy/core/common/cloud/cloud_policy_manager_unittest.cc

Issue 1940153002: Use std::unique_ptr to express ownership of base::Value in PolicyMap::Entry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another-fix Created 4 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/policy/core/common/cloud/cloud_policy_manager.h" 5 #include "components/policy/core/common/cloud/cloud_policy_manager.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h"
12 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 13 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
13 #include "components/policy/core/common/cloud/mock_cloud_policy_client.h" 14 #include "components/policy/core/common/cloud/mock_cloud_policy_client.h"
14 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" 15 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h"
15 #include "components/policy/core/common/cloud/policy_builder.h" 16 #include "components/policy/core/common/cloud/policy_builder.h"
16 #include "components/policy/core/common/configuration_policy_provider_test.h" 17 #include "components/policy/core/common/configuration_policy_provider_test.h"
17 #include "components/policy/core/common/external_data_fetcher.h" 18 #include "components/policy/core/common/external_data_fetcher.h"
18 #include "components/policy/core/common/mock_configuration_policy_provider.h" 19 #include "components/policy/core/common/mock_configuration_policy_provider.h"
19 #include "components/policy/core/common/policy_types.h" 20 #include "components/policy/core/common/policy_types.h"
20 #include "components/policy/core/common/schema_registry.h" 21 #include "components/policy/core/common/schema_registry.h"
21 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 new CloudPolicyManager(dm_protocol::kChromeUserPolicyType, std::string(), 81 new CloudPolicyManager(dm_protocol::kChromeUserPolicyType, std::string(),
81 &store_, task_runner, task_runner, task_runner); 82 &store_, task_runner, task_runner, task_runner);
82 Mock::VerifyAndClearExpectations(&store_); 83 Mock::VerifyAndClearExpectations(&store_);
83 return provider; 84 return provider;
84 } 85 }
85 86
86 void TestHarness::InstallEmptyPolicy() {} 87 void TestHarness::InstallEmptyPolicy() {}
87 88
88 void TestHarness::InstallStringPolicy(const std::string& policy_name, 89 void TestHarness::InstallStringPolicy(const std::string& policy_name,
89 const std::string& policy_value) { 90 const std::string& policy_value) {
90 store_.policy_map_.Set(policy_name, 91 store_.policy_map_.Set(
91 policy_level(), 92 policy_name, policy_level(), policy_scope(), POLICY_SOURCE_CLOUD,
92 policy_scope(), 93 base::WrapUnique(new base::StringValue(policy_value)), nullptr);
93 POLICY_SOURCE_CLOUD,
94 new base::StringValue(policy_value),
95 nullptr);
96 } 94 }
97 95
98 void TestHarness::InstallIntegerPolicy(const std::string& policy_name, 96 void TestHarness::InstallIntegerPolicy(const std::string& policy_name,
99 int policy_value) { 97 int policy_value) {
100 store_.policy_map_.Set(policy_name, 98 store_.policy_map_.Set(
101 policy_level(), 99 policy_name, policy_level(), policy_scope(), POLICY_SOURCE_CLOUD,
102 policy_scope(), 100 base::WrapUnique(new base::FundamentalValue(policy_value)), nullptr);
103 POLICY_SOURCE_CLOUD,
104 new base::
105 FundamentalValue(policy_value),
106 nullptr);
107 } 101 }
108 102
109 void TestHarness::InstallBooleanPolicy(const std::string& policy_name, 103 void TestHarness::InstallBooleanPolicy(const std::string& policy_name,
110 bool policy_value) { 104 bool policy_value) {
111 store_.policy_map_.Set(policy_name, 105 store_.policy_map_.Set(
112 policy_level(), 106 policy_name, policy_level(), policy_scope(), POLICY_SOURCE_CLOUD,
113 policy_scope(), 107 base::WrapUnique(new base::FundamentalValue(policy_value)), nullptr);
114 POLICY_SOURCE_CLOUD,
115 new base::
116 FundamentalValue(policy_value),
117 nullptr);
118 } 108 }
119 109
120 void TestHarness::InstallStringListPolicy(const std::string& policy_name, 110 void TestHarness::InstallStringListPolicy(const std::string& policy_name,
121 const base::ListValue* policy_value) { 111 const base::ListValue* policy_value) {
122 store_.policy_map_.Set(policy_name, 112 store_.policy_map_.Set(policy_name, policy_level(), policy_scope(),
123 policy_level(), 113 POLICY_SOURCE_CLOUD, policy_value->CreateDeepCopy(),
124 policy_scope(),
125 POLICY_SOURCE_CLOUD,
126 policy_value->DeepCopy(),
127 nullptr); 114 nullptr);
128 } 115 }
129 116
130 void TestHarness::InstallDictionaryPolicy( 117 void TestHarness::InstallDictionaryPolicy(
131 const std::string& policy_name, 118 const std::string& policy_name,
132 const base::DictionaryValue* policy_value) { 119 const base::DictionaryValue* policy_value) {
133 store_.policy_map_.Set(policy_name, 120 store_.policy_map_.Set(policy_name, policy_level(), policy_scope(),
134 policy_level(), 121 POLICY_SOURCE_CLOUD, policy_value->CreateDeepCopy(),
135 policy_scope(),
136 POLICY_SOURCE_CLOUD,
137 policy_value->DeepCopy(),
138 nullptr); 122 nullptr);
139 } 123 }
140 124
141 // static 125 // static
142 PolicyProviderTestHarness* TestHarness::CreateMandatory() { 126 PolicyProviderTestHarness* TestHarness::CreateMandatory() {
143 return new TestHarness(POLICY_LEVEL_MANDATORY); 127 return new TestHarness(POLICY_LEVEL_MANDATORY);
144 } 128 }
145 129
146 // static 130 // static
147 PolicyProviderTestHarness* TestHarness::CreateRecommended() { 131 PolicyProviderTestHarness* TestHarness::CreateRecommended() {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 return arg.SerializePartialAsString() == proto.SerializePartialAsString(); 166 return arg.SerializePartialAsString() == proto.SerializePartialAsString();
183 } 167 }
184 168
185 class CloudPolicyManagerTest : public testing::Test { 169 class CloudPolicyManagerTest : public testing::Test {
186 protected: 170 protected:
187 CloudPolicyManagerTest() 171 CloudPolicyManagerTest()
188 : policy_type_(dm_protocol::kChromeUserPolicyType) {} 172 : policy_type_(dm_protocol::kChromeUserPolicyType) {}
189 173
190 void SetUp() override { 174 void SetUp() override {
191 // Set up a policy map for testing. 175 // Set up a policy map for testing.
192 policy_map_.Set("key", 176 policy_map_.Set("key", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
193 POLICY_LEVEL_MANDATORY,
194 POLICY_SCOPE_USER,
195 POLICY_SOURCE_CLOUD, 177 POLICY_SOURCE_CLOUD,
196 new base::StringValue("value"), 178 base::WrapUnique(new base::StringValue("value")), nullptr);
197 nullptr);
198 expected_bundle_.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 179 expected_bundle_.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
199 .CopyFrom(policy_map_); 180 .CopyFrom(policy_map_);
200 181
201 policy_.payload().mutable_passwordmanagerenabled()->set_value(false); 182 policy_.payload().mutable_passwordmanagerenabled()->set_value(false);
202 policy_.Build(); 183 policy_.Build();
203 184
204 EXPECT_CALL(store_, Load()); 185 EXPECT_CALL(store_, Load());
205 manager_.reset(new TestCloudPolicyManager(&store_, loop_.task_runner())); 186 manager_.reset(new TestCloudPolicyManager(&store_, loop_.task_runner()));
206 manager_->Init(&schema_registry_); 187 manager_->Init(&schema_registry_);
207 Mock::VerifyAndClearExpectations(&store_); 188 Mock::VerifyAndClearExpectations(&store_);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 store_.policy_.reset(new em::PolicyData(policy_.policy_data())); 348 store_.policy_.reset(new em::PolicyData(policy_.policy_data()));
368 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); 349 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get()));
369 store_.NotifyStoreError(); 350 store_.NotifyStoreError();
370 Mock::VerifyAndClearExpectations(&observer_); 351 Mock::VerifyAndClearExpectations(&observer_);
371 352
372 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 353 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
373 } 354 }
374 355
375 } // namespace 356 } // namespace
376 } // namespace policy 357 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698