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

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

Issue 2211473003: Remove calls to deprecated MessageLoop methods on Windows and Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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 <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/run_loop.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "components/policy/core/common/configuration_policy_provider.h" 15 #include "components/policy/core/common/configuration_policy_provider.h"
15 #include "components/policy/core/common/external_data_fetcher.h" 16 #include "components/policy/core/common/external_data_fetcher.h"
16 #include "components/policy/core/common/mock_configuration_policy_provider.h" 17 #include "components/policy/core/common/mock_configuration_policy_provider.h"
17 #include "components/policy/core/common/policy_bundle.h" 18 #include "components/policy/core/common/policy_bundle.h"
18 #include "components/policy/core/common/policy_map.h" 19 #include "components/policy/core/common/policy_map.h"
19 #include "components/policy/core/common/policy_namespace.h" 20 #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_test_utils.h"
21 #include "components/policy/core/common/policy_types.h" 22 #include "components/policy/core/common/policy_types.h"
22 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 PolicyTestBase::PolicyTestBase() {} 137 PolicyTestBase::PolicyTestBase() {}
137 138
138 PolicyTestBase::~PolicyTestBase() {} 139 PolicyTestBase::~PolicyTestBase() {}
139 140
140 void PolicyTestBase::SetUp() { 141 void PolicyTestBase::SetUp() {
141 const PolicyNamespace ns(POLICY_DOMAIN_CHROME, ""); 142 const PolicyNamespace ns(POLICY_DOMAIN_CHROME, "");
142 ASSERT_TRUE(RegisterSchema(ns, kTestChromeSchema)); 143 ASSERT_TRUE(RegisterSchema(ns, kTestChromeSchema));
143 } 144 }
144 145
145 void PolicyTestBase::TearDown() { 146 void PolicyTestBase::TearDown() {
146 loop_.RunUntilIdle(); 147 base::RunLoop().RunUntilIdle();
147 } 148 }
148 149
149 bool PolicyTestBase::RegisterSchema(const PolicyNamespace& ns, 150 bool PolicyTestBase::RegisterSchema(const PolicyNamespace& ns,
150 const std::string& schema_string) { 151 const std::string& schema_string) {
151 std::string error; 152 std::string error;
152 Schema schema = Schema::Parse(schema_string, &error); 153 Schema schema = Schema::Parse(schema_string, &error);
153 if (schema.valid()) { 154 if (schema.valid()) {
154 schema_registry_.RegisterComponent(ns, schema); 155 schema_registry_.RegisterComponent(ns, schema);
155 return true; 156 return true;
156 } 157 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 schema_registry_.RegisterComponent( 206 schema_registry_.RegisterComponent(
206 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 207 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
207 "cccccccccccccccccccccccccccccccc"), 208 "cccccccccccccccccccccccccccccccc"),
208 extension_schema); 209 extension_schema);
209 210
210 provider_.reset( 211 provider_.reset(
211 harness_->CreateProvider(&schema_registry_, loop_.task_runner())); 212 harness_->CreateProvider(&schema_registry_, loop_.task_runner()));
212 provider_->Init(&schema_registry_); 213 provider_->Init(&schema_registry_);
213 // Some providers do a reload on init. Make sure any notifications generated 214 // Some providers do a reload on init. Make sure any notifications generated
214 // are fired now. 215 // are fired now.
215 loop_.RunUntilIdle(); 216 base::RunLoop().RunUntilIdle();
216 217
217 const PolicyBundle kEmptyBundle; 218 const PolicyBundle kEmptyBundle;
218 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); 219 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle));
219 } 220 }
220 221
221 void ConfigurationPolicyProviderTest::TearDown() { 222 void ConfigurationPolicyProviderTest::TearDown() {
222 // Give providers the chance to clean up after themselves on the file thread. 223 // Give providers the chance to clean up after themselves on the file thread.
223 if (provider_) { 224 if (provider_) {
224 provider_->Shutdown(); 225 provider_->Shutdown();
225 provider_.reset(); 226 provider_.reset();
226 } 227 }
227 228
228 PolicyTestBase::TearDown(); 229 PolicyTestBase::TearDown();
229 } 230 }
230 231
231 void ConfigurationPolicyProviderTest::CheckValue( 232 void ConfigurationPolicyProviderTest::CheckValue(
232 const char* policy_name, 233 const char* policy_name,
233 const base::Value& expected_value, 234 const base::Value& expected_value,
234 base::Closure install_value) { 235 base::Closure install_value) {
235 // Install the value, reload policy and check the provider for the value. 236 // Install the value, reload policy and check the provider for the value.
236 install_value.Run(); 237 install_value.Run();
237 provider_->RefreshPolicies(); 238 provider_->RefreshPolicies();
238 loop_.RunUntilIdle(); 239 base::RunLoop().RunUntilIdle();
239 PolicyBundle expected_bundle; 240 PolicyBundle expected_bundle;
240 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 241 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
241 .Set(policy_name, harness_->policy_level(), harness_->policy_scope(), 242 .Set(policy_name, harness_->policy_level(), harness_->policy_scope(),
242 harness_->policy_source(), expected_value.CreateDeepCopy(), nullptr); 243 harness_->policy_source(), expected_value.CreateDeepCopy(), nullptr);
243 bool match = provider_->policies().Equals(expected_bundle); 244 bool match = provider_->policies().Equals(expected_bundle);
244 if (!match) { 245 if (!match) {
245 LOG(ERROR) << "EXPECTED: " << expected_bundle; 246 LOG(ERROR) << "EXPECTED: " << expected_bundle;
246 LOG(ERROR) << "ACTUAL: " << provider_->policies(); 247 LOG(ERROR) << "ACTUAL: " << provider_->policies();
247 } 248 }
248 EXPECT_TRUE(match); 249 EXPECT_TRUE(match);
249 // TODO(joaodasilva): set the policy in the POLICY_DOMAIN_EXTENSIONS too, 250 // TODO(joaodasilva): set the policy in the POLICY_DOMAIN_EXTENSIONS too,
250 // and extend the |expected_bundle|, once all providers are ready. 251 // and extend the |expected_bundle|, once all providers are ready.
251 } 252 }
252 253
253 TEST_P(ConfigurationPolicyProviderTest, Empty) { 254 TEST_P(ConfigurationPolicyProviderTest, Empty) {
254 provider_->RefreshPolicies(); 255 provider_->RefreshPolicies();
255 loop_.RunUntilIdle(); 256 base::RunLoop().RunUntilIdle();
256 const PolicyBundle kEmptyBundle; 257 const PolicyBundle kEmptyBundle;
257 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); 258 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle));
258 } 259 }
259 260
260 TEST_P(ConfigurationPolicyProviderTest, StringValue) { 261 TEST_P(ConfigurationPolicyProviderTest, StringValue) {
261 const char kTestString[] = "string_value"; 262 const char kTestString[] = "string_value";
262 base::StringValue expected_value(kTestString); 263 base::StringValue expected_value(kTestString);
263 CheckValue(harness_->key_string(), 264 CheckValue(harness_->key_string(),
264 expected_value, 265 expected_value,
265 base::Bind(&PolicyProviderTestHarness::InstallStringPolicy, 266 base::Bind(&PolicyProviderTestHarness::InstallStringPolicy,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 337
337 TEST_P(ConfigurationPolicyProviderTest, RefreshPolicies) { 338 TEST_P(ConfigurationPolicyProviderTest, RefreshPolicies) {
338 PolicyBundle bundle; 339 PolicyBundle bundle;
339 EXPECT_TRUE(provider_->policies().Equals(bundle)); 340 EXPECT_TRUE(provider_->policies().Equals(bundle));
340 341
341 // OnUpdatePolicy is called even when there are no changes. 342 // OnUpdatePolicy is called even when there are no changes.
342 MockConfigurationPolicyObserver observer; 343 MockConfigurationPolicyObserver observer;
343 provider_->AddObserver(&observer); 344 provider_->AddObserver(&observer);
344 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); 345 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1);
345 provider_->RefreshPolicies(); 346 provider_->RefreshPolicies();
346 loop_.RunUntilIdle(); 347 base::RunLoop().RunUntilIdle();
347 Mock::VerifyAndClearExpectations(&observer); 348 Mock::VerifyAndClearExpectations(&observer);
348 349
349 EXPECT_TRUE(provider_->policies().Equals(bundle)); 350 EXPECT_TRUE(provider_->policies().Equals(bundle));
350 351
351 // OnUpdatePolicy is called when there are changes. 352 // OnUpdatePolicy is called when there are changes.
352 harness_->InstallStringPolicy(harness_->key_string(), "value"); 353 harness_->InstallStringPolicy(harness_->key_string(), "value");
353 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); 354 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1);
354 provider_->RefreshPolicies(); 355 provider_->RefreshPolicies();
355 loop_.RunUntilIdle(); 356 base::RunLoop().RunUntilIdle();
356 Mock::VerifyAndClearExpectations(&observer); 357 Mock::VerifyAndClearExpectations(&observer);
357 358
358 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 359 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
359 .Set(harness_->key_string(), harness_->policy_level(), 360 .Set(harness_->key_string(), harness_->policy_level(),
360 harness_->policy_scope(), harness_->policy_source(), 361 harness_->policy_scope(), harness_->policy_source(),
361 base::WrapUnique(new base::StringValue("value")), nullptr); 362 base::WrapUnique(new base::StringValue("value")), nullptr);
362 EXPECT_TRUE(provider_->policies().Equals(bundle)); 363 EXPECT_TRUE(provider_->policies().Equals(bundle));
363 provider_->RemoveObserver(&observer); 364 provider_->RemoveObserver(&observer);
364 } 365 }
365 366
(...skipping 29 matching lines...) Expand all
395 policy_3rdparty.Set("extensions.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", 396 policy_3rdparty.Set("extensions.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
396 policy_dict.DeepCopy()); 397 policy_dict.DeepCopy());
397 // Install invalid 3rd party policies that shouldn't be loaded. These also 398 // Install invalid 3rd party policies that shouldn't be loaded. These also
398 // help detecting memory leaks in the code paths that detect invalid input. 399 // help detecting memory leaks in the code paths that detect invalid input.
399 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy()); 400 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy());
400 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc", 401 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc",
401 new base::StringValue("invalid-value")); 402 new base::StringValue("invalid-value"));
402 harness_->Install3rdPartyPolicy(&policy_3rdparty); 403 harness_->Install3rdPartyPolicy(&policy_3rdparty);
403 404
404 provider_->RefreshPolicies(); 405 provider_->RefreshPolicies();
405 loop_.RunUntilIdle(); 406 base::RunLoop().RunUntilIdle();
406 407
407 PolicyMap expected_policy; 408 PolicyMap expected_policy;
408 expected_policy.Set(harness_->key_dictionary(), harness_->policy_level(), 409 expected_policy.Set(harness_->key_dictionary(), harness_->policy_level(),
409 harness_->policy_scope(), harness_->policy_source(), 410 harness_->policy_scope(), harness_->policy_source(),
410 policy_dict.CreateDeepCopy(), nullptr); 411 policy_dict.CreateDeepCopy(), nullptr);
411 PolicyBundle expected_bundle; 412 PolicyBundle expected_bundle;
412 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 413 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
413 .CopyFrom(expected_policy); 414 .CopyFrom(expected_policy);
414 expected_policy.Clear(); 415 expected_policy.Clear();
415 expected_policy.LoadFrom(&policy_dict, 416 expected_policy.LoadFrom(&policy_dict,
416 harness_->policy_level(), 417 harness_->policy_level(),
417 harness_->policy_scope(), 418 harness_->policy_scope(),
418 harness_->policy_source()); 419 harness_->policy_source());
419 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 420 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
420 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) 421 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
421 .CopyFrom(expected_policy); 422 .CopyFrom(expected_policy);
422 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 423 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
423 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) 424 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"))
424 .CopyFrom(expected_policy); 425 .CopyFrom(expected_policy);
425 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); 426 EXPECT_TRUE(provider_->policies().Equals(expected_bundle));
426 } 427 }
427 428
428 } // namespace policy 429 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698