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

Side by Side Diff: components/policy/core/common/configuration_policy_provider_test.cc

Issue 2414663002: Fix log spew for "_comment..." policies. (Closed)
Patch Set: Rename EraseGeneric() to FilterErase(). Created 4 years, 2 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 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/policy/core/common/configuration_policy_provider_test.h" 5 #include "components/policy/core/common/configuration_policy_provider_test.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "components/policy/core/common/configuration_policy_provider.h" 14 #include "components/policy/core/common/configuration_policy_provider.h"
15 #include "components/policy/core/common/external_data_fetcher.h" 15 #include "components/policy/core/common/external_data_fetcher.h"
16 #include "components/policy/core/common/mock_configuration_policy_provider.h" 16 #include "components/policy/core/common/mock_configuration_policy_provider.h"
17 #include "components/policy/core/common/policy_bundle.h" 17 #include "components/policy/core/common/policy_bundle.h"
18 #include "components/policy/core/common/policy_map.h" 18 #include "components/policy/core/common/policy_map.h"
19 #include "components/policy/core/common/policy_namespace.h" 19 #include "components/policy/core/common/policy_namespace.h"
20 #include "components/policy/core/common/policy_test_utils.h"
21 #include "components/policy/core/common/policy_types.h" 20 #include "components/policy/core/common/policy_types.h"
22 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
23 22
24 using ::testing::Mock; 23 using ::testing::Mock;
25 using ::testing::_; 24 using ::testing::_;
26 25
27 namespace { 26 namespace policy {
28 27
29 const char kTestChromeSchema[] = 28 const char kTestChromeSchema[] =
30 "{" 29 "{"
31 " \"type\": \"object\"," 30 " \"type\": \"object\","
32 " \"properties\": {" 31 " \"properties\": {"
33 " \"StringPolicy\": { \"type\": \"string\" }," 32 " \"StringPolicy\": { \"type\": \"string\" },"
34 " \"BooleanPolicy\": { \"type\": \"boolean\" }," 33 " \"BooleanPolicy\": { \"type\": \"boolean\" },"
35 " \"IntegerPolicy\": { \"type\": \"integer\" }," 34 " \"IntegerPolicy\": { \"type\": \"integer\" },"
36 " \"StringListPolicy\": {" 35 " \"StringListPolicy\": {"
37 " \"type\": \"array\"," 36 " \"type\": \"array\","
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 " }" 108 " }"
110 " }" 109 " }"
111 " }" 110 " }"
112 " }" 111 " }"
113 " }" 112 " }"
114 " }" 113 " }"
115 " }" 114 " }"
116 " }" 115 " }"
117 "}"; 116 "}";
118 117
119 } // anonymous namespace
120
121 namespace policy {
122
123 namespace test_keys { 118 namespace test_keys {
124 119
125 // These are the defaults for PolicyProviderTestHarness but they are generally
126 // available for use in other tests. Subclasses of PolicyProviderTestHarness
127 // may use different values.
128 const char kKeyString[] = "StringPolicy"; 120 const char kKeyString[] = "StringPolicy";
129 const char kKeyBoolean[] = "BooleanPolicy"; 121 const char kKeyBoolean[] = "BooleanPolicy";
130 const char kKeyInteger[] = "IntegerPolicy"; 122 const char kKeyInteger[] = "IntegerPolicy";
131 const char kKeyStringList[] = "StringListPolicy"; 123 const char kKeyStringList[] = "StringListPolicy";
132 const char kKeyDictionary[] = "DictionaryPolicy"; 124 const char kKeyDictionary[] = "DictionaryPolicy";
133 125
134 } // namespace test_keys 126 } // namespace test_keys
135 127
136 PolicyTestBase::PolicyTestBase() 128 PolicyTestBase::PolicyTestBase()
137 #if defined(OS_POSIX) 129 #if defined(OS_POSIX)
(...skipping 21 matching lines...) Expand all
159 schema_registry_.RegisterComponent(ns, schema); 151 schema_registry_.RegisterComponent(ns, schema);
160 return true; 152 return true;
161 } 153 }
162 ADD_FAILURE() << error; 154 ADD_FAILURE() << error;
163 return false; 155 return false;
164 } 156 }
165 157
166 PolicyProviderTestHarness::PolicyProviderTestHarness(PolicyLevel level, 158 PolicyProviderTestHarness::PolicyProviderTestHarness(PolicyLevel level,
167 PolicyScope scope, 159 PolicyScope scope,
168 PolicySource source) 160 PolicySource source)
169 : key_string_(test_keys::kKeyString), 161 : level_(level), scope_(scope), source_(source) {}
170 key_boolean_(test_keys::kKeyBoolean), 162
171 key_integer_(test_keys::kKeyInteger), 163 PolicyProviderTestHarness::~PolicyProviderTestHarness() {}
172 key_stringlist_(test_keys::kKeyStringList), 164
173 key_dictionary_(test_keys::kKeyDictionary), 165 PolicyLevel PolicyProviderTestHarness::policy_level() const {
174 test_schema_(kTestChromeSchema), 166 return level_;
175 level_(level),
176 scope_(scope),
177 source_(source) {
178 } 167 }
179 168
180 PolicyProviderTestHarness::~PolicyProviderTestHarness() {} 169 PolicyScope PolicyProviderTestHarness::policy_scope() const {
170 return scope_;
171 }
172
173 PolicySource PolicyProviderTestHarness::policy_source() const {
174 return source_;
175 }
181 176
182 void PolicyProviderTestHarness::Install3rdPartyPolicy( 177 void PolicyProviderTestHarness::Install3rdPartyPolicy(
183 const base::DictionaryValue* policies) { 178 const base::DictionaryValue* policies) {
184 FAIL(); 179 FAIL();
185 } 180 }
186 181
187 ConfigurationPolicyProviderTest::ConfigurationPolicyProviderTest() {} 182 ConfigurationPolicyProviderTest::ConfigurationPolicyProviderTest() {}
188 183
189 ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {} 184 ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {}
190 185
191 void ConfigurationPolicyProviderTest::SetUp() { 186 void ConfigurationPolicyProviderTest::SetUp() {
192 harness_.reset((*GetParam())()); 187 PolicyTestBase::SetUp();
193 harness_->SetUp(); 188
189 test_harness_.reset((*GetParam())());
190 test_harness_->SetUp();
194 191
195 const PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, ""); 192 const PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, "");
196 ASSERT_TRUE(RegisterSchema(chrome_ns, harness_->test_schema()));
197
198 Schema chrome_schema = *schema_registry_.schema_map()->GetSchema(chrome_ns); 193 Schema chrome_schema = *schema_registry_.schema_map()->GetSchema(chrome_ns);
199 Schema extension_schema = 194 Schema extension_schema =
200 chrome_schema.GetKnownProperty(harness_->key_dictionary()); 195 chrome_schema.GetKnownProperty(test_keys::kKeyDictionary);
201 ASSERT_TRUE(extension_schema.valid()); 196 ASSERT_TRUE(extension_schema.valid());
202 schema_registry_.RegisterComponent( 197 schema_registry_.RegisterComponent(
203 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 198 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
204 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), 199 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
205 extension_schema); 200 extension_schema);
206 schema_registry_.RegisterComponent( 201 schema_registry_.RegisterComponent(
207 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 202 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
208 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"), 203 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"),
209 extension_schema); 204 extension_schema);
210 schema_registry_.RegisterComponent( 205 schema_registry_.RegisterComponent(
211 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 206 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
212 "cccccccccccccccccccccccccccccccc"), 207 "cccccccccccccccccccccccccccccccc"),
213 extension_schema); 208 extension_schema);
214 209
215 provider_.reset( 210 provider_.reset(
216 harness_->CreateProvider(&schema_registry_, loop_.task_runner())); 211 test_harness_->CreateProvider(&schema_registry_, loop_.task_runner()));
217 provider_->Init(&schema_registry_); 212 provider_->Init(&schema_registry_);
218 // Some providers do a reload on init. Make sure any notifications generated 213 // Some providers do a reload on init. Make sure any notifications generated
219 // are fired now. 214 // are fired now.
220 base::RunLoop().RunUntilIdle(); 215 base::RunLoop().RunUntilIdle();
221 216
222 const PolicyBundle kEmptyBundle; 217 const PolicyBundle kEmptyBundle;
223 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); 218 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle));
224 } 219 }
225 220
226 void ConfigurationPolicyProviderTest::TearDown() { 221 void ConfigurationPolicyProviderTest::TearDown() {
227 // Give providers the chance to clean up after themselves on the file thread. 222 // Give providers the chance to clean up after themselves on the file thread.
228 if (provider_) { 223 provider_->Shutdown();
229 provider_->Shutdown(); 224 provider_.reset();
230 provider_.reset();
231 }
232 225
233 PolicyTestBase::TearDown(); 226 PolicyTestBase::TearDown();
234 } 227 }
235 228
236 void ConfigurationPolicyProviderTest::CheckValue( 229 void ConfigurationPolicyProviderTest::CheckValue(
237 const char* policy_name, 230 const char* policy_name,
238 const base::Value& expected_value, 231 const base::Value& expected_value,
239 base::Closure install_value) { 232 base::Closure install_value) {
240 // Install the value, reload policy and check the provider for the value. 233 // Install the value, reload policy and check the provider for the value.
241 install_value.Run(); 234 install_value.Run();
242 provider_->RefreshPolicies(); 235 provider_->RefreshPolicies();
243 base::RunLoop().RunUntilIdle(); 236 base::RunLoop().RunUntilIdle();
244 PolicyBundle expected_bundle; 237 PolicyBundle expected_bundle;
245 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 238 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
246 .Set(policy_name, harness_->policy_level(), harness_->policy_scope(), 239 .Set(policy_name, test_harness_->policy_level(),
247 harness_->policy_source(), expected_value.CreateDeepCopy(), nullptr); 240 test_harness_->policy_scope(), test_harness_->policy_source(),
248 bool match = provider_->policies().Equals(expected_bundle); 241 expected_value.CreateDeepCopy(), nullptr);
249 if (!match) { 242 EXPECT_TRUE(provider_->policies().Equals(expected_bundle));
250 LOG(ERROR) << "EXPECTED: " << expected_bundle;
251 LOG(ERROR) << "ACTUAL: " << provider_->policies();
252 }
253 EXPECT_TRUE(match);
254 // TODO(joaodasilva): set the policy in the POLICY_DOMAIN_EXTENSIONS too, 243 // TODO(joaodasilva): set the policy in the POLICY_DOMAIN_EXTENSIONS too,
255 // and extend the |expected_bundle|, once all providers are ready. 244 // and extend the |expected_bundle|, once all providers are ready.
256 } 245 }
257 246
258 TEST_P(ConfigurationPolicyProviderTest, Empty) { 247 TEST_P(ConfigurationPolicyProviderTest, Empty) {
259 provider_->RefreshPolicies(); 248 provider_->RefreshPolicies();
260 base::RunLoop().RunUntilIdle(); 249 base::RunLoop().RunUntilIdle();
261 const PolicyBundle kEmptyBundle; 250 const PolicyBundle kEmptyBundle;
262 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); 251 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle));
263 } 252 }
264 253
265 TEST_P(ConfigurationPolicyProviderTest, StringValue) { 254 TEST_P(ConfigurationPolicyProviderTest, StringValue) {
266 const char kTestString[] = "string_value"; 255 const char kTestString[] = "string_value";
267 base::StringValue expected_value(kTestString); 256 base::StringValue expected_value(kTestString);
268 CheckValue(harness_->key_string(), 257 CheckValue(test_keys::kKeyString,
269 expected_value, 258 expected_value,
270 base::Bind(&PolicyProviderTestHarness::InstallStringPolicy, 259 base::Bind(&PolicyProviderTestHarness::InstallStringPolicy,
271 base::Unretained(harness_.get()), 260 base::Unretained(test_harness_.get()),
272 harness_->key_string(), 261 test_keys::kKeyString,
273 kTestString)); 262 kTestString));
274 } 263 }
275 264
276 TEST_P(ConfigurationPolicyProviderTest, BooleanValue) { 265 TEST_P(ConfigurationPolicyProviderTest, BooleanValue) {
277 base::FundamentalValue expected_value(true); 266 base::FundamentalValue expected_value(true);
278 CheckValue(harness_->key_boolean(), 267 CheckValue(test_keys::kKeyBoolean,
279 expected_value, 268 expected_value,
280 base::Bind(&PolicyProviderTestHarness::InstallBooleanPolicy, 269 base::Bind(&PolicyProviderTestHarness::InstallBooleanPolicy,
281 base::Unretained(harness_.get()), 270 base::Unretained(test_harness_.get()),
282 harness_->key_boolean(), 271 test_keys::kKeyBoolean,
283 true)); 272 true));
284 } 273 }
285 274
286 TEST_P(ConfigurationPolicyProviderTest, IntegerValue) { 275 TEST_P(ConfigurationPolicyProviderTest, IntegerValue) {
287 base::FundamentalValue expected_value(42); 276 base::FundamentalValue expected_value(42);
288 CheckValue(harness_->key_integer(), 277 CheckValue(test_keys::kKeyInteger,
289 expected_value, 278 expected_value,
290 base::Bind(&PolicyProviderTestHarness::InstallIntegerPolicy, 279 base::Bind(&PolicyProviderTestHarness::InstallIntegerPolicy,
291 base::Unretained(harness_.get()), 280 base::Unretained(test_harness_.get()),
292 harness_->key_integer(), 281 test_keys::kKeyInteger,
293 42)); 282 42));
294 } 283 }
295 284
296 TEST_P(ConfigurationPolicyProviderTest, StringListValue) { 285 TEST_P(ConfigurationPolicyProviderTest, StringListValue) {
297 base::ListValue expected_value; 286 base::ListValue expected_value;
298 expected_value.Set(0U, new base::StringValue("first")); 287 expected_value.Set(0U, new base::StringValue("first"));
299 expected_value.Set(1U, new base::StringValue("second")); 288 expected_value.Set(1U, new base::StringValue("second"));
300 CheckValue(harness_->key_stringlist(), 289 CheckValue(test_keys::kKeyStringList,
301 expected_value, 290 expected_value,
302 base::Bind(&PolicyProviderTestHarness::InstallStringListPolicy, 291 base::Bind(&PolicyProviderTestHarness::InstallStringListPolicy,
303 base::Unretained(harness_.get()), 292 base::Unretained(test_harness_.get()),
304 harness_->key_stringlist(), 293 test_keys::kKeyStringList,
305 &expected_value)); 294 &expected_value));
306 } 295 }
307 296
308 TEST_P(ConfigurationPolicyProviderTest, DictionaryValue) { 297 TEST_P(ConfigurationPolicyProviderTest, DictionaryValue) {
309 base::DictionaryValue expected_value; 298 base::DictionaryValue expected_value;
310 expected_value.SetBoolean("bool", true); 299 expected_value.SetBoolean("bool", true);
311 expected_value.SetDouble("double", 123.456); 300 expected_value.SetDouble("double", 123.456);
312 expected_value.SetInteger("int", 123); 301 expected_value.SetInteger("int", 123);
313 expected_value.SetString("string", "omg"); 302 expected_value.SetString("string", "omg");
314 303
315 base::ListValue* list = new base::ListValue(); 304 base::ListValue* list = new base::ListValue();
316 list->Set(0U, new base::StringValue("first")); 305 list->Set(0U, new base::StringValue("first"));
317 list->Set(1U, new base::StringValue("second")); 306 list->Set(1U, new base::StringValue("second"));
318 expected_value.Set("array", list); 307 expected_value.Set("array", list);
319 308
320 base::DictionaryValue* dict = new base::DictionaryValue(); 309 base::DictionaryValue* dict = new base::DictionaryValue();
321 dict->SetString("sub", "value"); 310 dict->SetString("sub", "value");
322 list = new base::ListValue(); 311 list = new base::ListValue();
323 std::unique_ptr<base::DictionaryValue> sub(new base::DictionaryValue()); 312 std::unique_ptr<base::DictionaryValue> sub(new base::DictionaryValue());
324 sub->SetInteger("aaa", 111); 313 sub->SetInteger("aaa", 111);
325 sub->SetInteger("bbb", 222); 314 sub->SetInteger("bbb", 222);
326 list->Append(std::move(sub)); 315 list->Append(std::move(sub));
327 sub.reset(new base::DictionaryValue()); 316 sub.reset(new base::DictionaryValue());
328 sub->SetString("ccc", "333"); 317 sub->SetString("ccc", "333");
329 sub->SetString("ddd", "444"); 318 sub->SetString("ddd", "444");
330 list->Append(std::move(sub)); 319 list->Append(std::move(sub));
331 dict->Set("sublist", list); 320 dict->Set("sublist", list);
332 expected_value.Set("dictionary", dict); 321 expected_value.Set("dictionary", dict);
333 322
334 CheckValue(harness_->key_dictionary(), 323 CheckValue(test_keys::kKeyDictionary,
335 expected_value, 324 expected_value,
336 base::Bind(&PolicyProviderTestHarness::InstallDictionaryPolicy, 325 base::Bind(&PolicyProviderTestHarness::InstallDictionaryPolicy,
337 base::Unretained(harness_.get()), 326 base::Unretained(test_harness_.get()),
338 harness_->key_dictionary(), 327 test_keys::kKeyDictionary,
339 &expected_value)); 328 &expected_value));
340 } 329 }
341 330
342 TEST_P(ConfigurationPolicyProviderTest, RefreshPolicies) { 331 TEST_P(ConfigurationPolicyProviderTest, RefreshPolicies) {
343 PolicyBundle bundle; 332 PolicyBundle bundle;
344 EXPECT_TRUE(provider_->policies().Equals(bundle)); 333 EXPECT_TRUE(provider_->policies().Equals(bundle));
345 334
346 // OnUpdatePolicy is called even when there are no changes. 335 // OnUpdatePolicy is called even when there are no changes.
347 MockConfigurationPolicyObserver observer; 336 MockConfigurationPolicyObserver observer;
348 provider_->AddObserver(&observer); 337 provider_->AddObserver(&observer);
349 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); 338 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1);
350 provider_->RefreshPolicies(); 339 provider_->RefreshPolicies();
351 base::RunLoop().RunUntilIdle(); 340 base::RunLoop().RunUntilIdle();
352 Mock::VerifyAndClearExpectations(&observer); 341 Mock::VerifyAndClearExpectations(&observer);
353 342
354 EXPECT_TRUE(provider_->policies().Equals(bundle)); 343 EXPECT_TRUE(provider_->policies().Equals(bundle));
355 344
356 // OnUpdatePolicy is called when there are changes. 345 // OnUpdatePolicy is called when there are changes.
357 harness_->InstallStringPolicy(harness_->key_string(), "value"); 346 test_harness_->InstallStringPolicy(test_keys::kKeyString, "value");
358 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); 347 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1);
359 provider_->RefreshPolicies(); 348 provider_->RefreshPolicies();
360 base::RunLoop().RunUntilIdle(); 349 base::RunLoop().RunUntilIdle();
361 Mock::VerifyAndClearExpectations(&observer); 350 Mock::VerifyAndClearExpectations(&observer);
362 351
363 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 352 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
364 .Set(harness_->key_string(), harness_->policy_level(), 353 .Set(test_keys::kKeyString, test_harness_->policy_level(),
365 harness_->policy_scope(), harness_->policy_source(), 354 test_harness_->policy_scope(), test_harness_->policy_source(),
366 base::MakeUnique<base::StringValue>("value"), nullptr); 355 base::MakeUnique<base::StringValue>("value"), nullptr);
367 EXPECT_TRUE(provider_->policies().Equals(bundle)); 356 EXPECT_TRUE(provider_->policies().Equals(bundle));
368 provider_->RemoveObserver(&observer); 357 provider_->RemoveObserver(&observer);
369 } 358 }
370 359
371 Configuration3rdPartyPolicyProviderTest:: 360 Configuration3rdPartyPolicyProviderTest::
372 Configuration3rdPartyPolicyProviderTest() {} 361 Configuration3rdPartyPolicyProviderTest() {}
373 362
374 Configuration3rdPartyPolicyProviderTest:: 363 Configuration3rdPartyPolicyProviderTest::
375 ~Configuration3rdPartyPolicyProviderTest() {} 364 ~Configuration3rdPartyPolicyProviderTest() {}
376 365
377 TEST_P(Configuration3rdPartyPolicyProviderTest, Load3rdParty) { 366 TEST_P(Configuration3rdPartyPolicyProviderTest, Load3rdParty) {
378 base::DictionaryValue policy_dict; 367 base::DictionaryValue policy_dict;
379 policy_dict.SetBoolean("bool", true); 368 policy_dict.SetBoolean("bool", true);
380 policy_dict.SetDouble("double", 123.456); 369 policy_dict.SetDouble("double", 123.456);
381 policy_dict.SetInteger("int", 789); 370 policy_dict.SetInteger("int", 789);
382 policy_dict.SetString("string", "string value"); 371 policy_dict.SetString("string", "string value");
383 372
384 base::ListValue* list = new base::ListValue(); 373 base::ListValue* list = new base::ListValue();
385 for (int i = 0; i < 2; ++i) { 374 for (int i = 0; i < 2; ++i) {
386 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 375 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
387 dict->SetInteger("subdictindex", i); 376 dict->SetInteger("subdictindex", i);
388 dict->Set("subdict", policy_dict.DeepCopy()); 377 dict->Set("subdict", policy_dict.DeepCopy());
389 list->Append(std::move(dict)); 378 list->Append(std::move(dict));
390 } 379 }
391 policy_dict.Set("list", list); 380 policy_dict.Set("list", list);
392 policy_dict.Set("dict", policy_dict.DeepCopy()); 381 policy_dict.Set("dict", policy_dict.DeepCopy());
393 382
394 // Install these policies as a Chrome policy. 383 // Install these policies as a Chrome policy.
395 harness_->InstallDictionaryPolicy(harness_->key_dictionary(), &policy_dict); 384 test_harness_->InstallDictionaryPolicy(test_keys::kKeyDictionary,
385 &policy_dict);
396 // Install them as 3rd party policies too. 386 // Install them as 3rd party policies too.
397 base::DictionaryValue policy_3rdparty; 387 base::DictionaryValue policy_3rdparty;
398 policy_3rdparty.Set("extensions.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 388 policy_3rdparty.Set("extensions.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
399 policy_dict.DeepCopy()); 389 policy_dict.DeepCopy());
400 policy_3rdparty.Set("extensions.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", 390 policy_3rdparty.Set("extensions.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
401 policy_dict.DeepCopy()); 391 policy_dict.DeepCopy());
402 // Install invalid 3rd party policies that shouldn't be loaded. These also 392 // Install invalid 3rd party policies that shouldn't be loaded. These also
403 // help detecting memory leaks in the code paths that detect invalid input. 393 // help detecting memory leaks in the code paths that detect invalid input.
404 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy()); 394 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy());
405 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc", 395 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc",
406 new base::StringValue("invalid-value")); 396 new base::StringValue("invalid-value"));
407 harness_->Install3rdPartyPolicy(&policy_3rdparty); 397 test_harness_->Install3rdPartyPolicy(&policy_3rdparty);
408 398
409 provider_->RefreshPolicies(); 399 provider_->RefreshPolicies();
410 base::RunLoop().RunUntilIdle(); 400 base::RunLoop().RunUntilIdle();
411 401
412 PolicyMap expected_policy; 402 PolicyMap expected_policy;
413 expected_policy.Set(harness_->key_dictionary(), harness_->policy_level(), 403 expected_policy.Set(test_keys::kKeyDictionary, test_harness_->policy_level(),
414 harness_->policy_scope(), harness_->policy_source(), 404 test_harness_->policy_scope(),
405 test_harness_->policy_source(),
415 policy_dict.CreateDeepCopy(), nullptr); 406 policy_dict.CreateDeepCopy(), nullptr);
416 PolicyBundle expected_bundle; 407 PolicyBundle expected_bundle;
417 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 408 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
418 .CopyFrom(expected_policy); 409 .CopyFrom(expected_policy);
419 expected_policy.Clear(); 410 expected_policy.Clear();
420 expected_policy.LoadFrom(&policy_dict, 411 expected_policy.LoadFrom(&policy_dict,
421 harness_->policy_level(), 412 test_harness_->policy_level(),
422 harness_->policy_scope(), 413 test_harness_->policy_scope(),
423 harness_->policy_source()); 414 test_harness_->policy_source());
424 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 415 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
425 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) 416 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
426 .CopyFrom(expected_policy); 417 .CopyFrom(expected_policy);
427 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 418 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
428 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) 419 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"))
429 .CopyFrom(expected_policy); 420 .CopyFrom(expected_policy);
430 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); 421 EXPECT_TRUE(provider_->policies().Equals(expected_bundle));
431 } 422 }
432 423
433 } // namespace policy 424 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698