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

Side by Side Diff: chrome/browser/policy/policy_service_impl_unittest.cc

Issue 11413050: chrome/browser: Update calls from RunAllPending() to RunUntilIdle(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
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 "chrome/browser/policy/policy_service_impl.h" 5 #include "chrome/browser/policy/policy_service_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 content::TestBrowserThread io_thread(content::BrowserThread::IO, &loop); 369 content::TestBrowserThread io_thread(content::BrowserThread::IO, &loop);
370 370
371 EXPECT_CALL(provider0_, RefreshPolicies()).Times(AnyNumber()); 371 EXPECT_CALL(provider0_, RefreshPolicies()).Times(AnyNumber());
372 EXPECT_CALL(provider1_, RefreshPolicies()).Times(AnyNumber()); 372 EXPECT_CALL(provider1_, RefreshPolicies()).Times(AnyNumber());
373 EXPECT_CALL(provider2_, RefreshPolicies()).Times(AnyNumber()); 373 EXPECT_CALL(provider2_, RefreshPolicies()).Times(AnyNumber());
374 374
375 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); 375 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0);
376 policy_service_->RefreshPolicies(base::Bind( 376 policy_service_->RefreshPolicies(base::Bind(
377 &PolicyServiceTest::OnPolicyRefresh, 377 &PolicyServiceTest::OnPolicyRefresh,
378 base::Unretained(this))); 378 base::Unretained(this)));
379 loop.RunAllPending(); 379 loop.RunUntilIdle();
380 Mock::VerifyAndClearExpectations(this); 380 Mock::VerifyAndClearExpectations(this);
381 381
382 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); 382 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0);
383 base::FundamentalValue kValue0(0); 383 base::FundamentalValue kValue0(0);
384 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 384 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
385 kValue0.DeepCopy()); 385 kValue0.DeepCopy());
386 provider0_.UpdateChromePolicy(policy0_); 386 provider0_.UpdateChromePolicy(policy0_);
387 loop.RunAllPending(); 387 loop.RunUntilIdle();
388 Mock::VerifyAndClearExpectations(this); 388 Mock::VerifyAndClearExpectations(this);
389 389
390 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); 390 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0);
391 base::FundamentalValue kValue1(1); 391 base::FundamentalValue kValue1(1);
392 policy1_.Set("aaa", POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, 392 policy1_.Set("aaa", POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER,
393 kValue1.DeepCopy()); 393 kValue1.DeepCopy());
394 provider1_.UpdateChromePolicy(policy1_); 394 provider1_.UpdateChromePolicy(policy1_);
395 loop.RunAllPending(); 395 loop.RunUntilIdle();
396 Mock::VerifyAndClearExpectations(this); 396 Mock::VerifyAndClearExpectations(this);
397 397
398 // A provider can refresh more than once after a RefreshPolicies call, but 398 // A provider can refresh more than once after a RefreshPolicies call, but
399 // OnPolicyRefresh should be triggered only after all providers are 399 // OnPolicyRefresh should be triggered only after all providers are
400 // refreshed. 400 // refreshed.
401 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); 401 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0);
402 policy1_.Set("bbb", POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, 402 policy1_.Set("bbb", POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER,
403 kValue1.DeepCopy()); 403 kValue1.DeepCopy());
404 provider1_.UpdateChromePolicy(policy1_); 404 provider1_.UpdateChromePolicy(policy1_);
405 loop.RunAllPending(); 405 loop.RunUntilIdle();
406 Mock::VerifyAndClearExpectations(this); 406 Mock::VerifyAndClearExpectations(this);
407 407
408 // If another RefreshPolicies() call happens while waiting for a previous 408 // If another RefreshPolicies() call happens while waiting for a previous
409 // one to complete, then all providers must refresh again. 409 // one to complete, then all providers must refresh again.
410 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); 410 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0);
411 policy_service_->RefreshPolicies(base::Bind( 411 policy_service_->RefreshPolicies(base::Bind(
412 &PolicyServiceTest::OnPolicyRefresh, 412 &PolicyServiceTest::OnPolicyRefresh,
413 base::Unretained(this))); 413 base::Unretained(this)));
414 loop.RunAllPending(); 414 loop.RunUntilIdle();
415 Mock::VerifyAndClearExpectations(this); 415 Mock::VerifyAndClearExpectations(this);
416 416
417 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); 417 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0);
418 policy2_.Set("bbb", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 418 policy2_.Set("bbb", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
419 kValue0.DeepCopy()); 419 kValue0.DeepCopy());
420 provider2_.UpdateChromePolicy(policy2_); 420 provider2_.UpdateChromePolicy(policy2_);
421 loop.RunAllPending(); 421 loop.RunUntilIdle();
422 Mock::VerifyAndClearExpectations(this); 422 Mock::VerifyAndClearExpectations(this);
423 423
424 // Providers 0 and 1 must reload again. 424 // Providers 0 and 1 must reload again.
425 EXPECT_CALL(*this, OnPolicyRefresh()).Times(2); 425 EXPECT_CALL(*this, OnPolicyRefresh()).Times(2);
426 base::FundamentalValue kValue2(2); 426 base::FundamentalValue kValue2(2);
427 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 427 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
428 kValue2.DeepCopy()); 428 kValue2.DeepCopy());
429 provider0_.UpdateChromePolicy(policy0_); 429 provider0_.UpdateChromePolicy(policy0_);
430 provider1_.UpdateChromePolicy(policy1_); 430 provider1_.UpdateChromePolicy(policy1_);
431 loop.RunAllPending(); 431 loop.RunUntilIdle();
432 Mock::VerifyAndClearExpectations(this); 432 Mock::VerifyAndClearExpectations(this);
433 433
434 const PolicyMap& policies = policy_service_->GetPolicies( 434 const PolicyMap& policies = policy_service_->GetPolicies(
435 POLICY_DOMAIN_CHROME, ""); 435 POLICY_DOMAIN_CHROME, "");
436 EXPECT_TRUE(base::Value::Equals(&kValue2, policies.GetValue("aaa"))); 436 EXPECT_TRUE(base::Value::Equals(&kValue2, policies.GetValue("aaa")));
437 EXPECT_TRUE(base::Value::Equals(&kValue0, policies.GetValue("bbb"))); 437 EXPECT_TRUE(base::Value::Equals(&kValue0, policies.GetValue("bbb")));
438 } 438 }
439 439
440 TEST_F(PolicyServiceTest, NamespaceMerge) { 440 TEST_F(PolicyServiceTest, NamespaceMerge) {
441 scoped_ptr<PolicyBundle> bundle0(new PolicyBundle()); 441 scoped_ptr<PolicyBundle> bundle0(new PolicyBundle());
(...skipping 20 matching lines...) Expand all
462 // level/scope combination takes precedence, on every namespace. 462 // level/scope combination takes precedence, on every namespace.
463 expected.Set(kDiffLevelPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 463 expected.Set(kDiffLevelPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
464 base::Value::CreateStringValue("bundle2")); 464 base::Value::CreateStringValue("bundle2"));
465 EXPECT_TRUE(policy_service_->GetPolicies(POLICY_DOMAIN_CHROME, "") 465 EXPECT_TRUE(policy_service_->GetPolicies(POLICY_DOMAIN_CHROME, "")
466 .Equals(expected)); 466 .Equals(expected));
467 EXPECT_TRUE(policy_service_->GetPolicies(POLICY_DOMAIN_EXTENSIONS, kExtension) 467 EXPECT_TRUE(policy_service_->GetPolicies(POLICY_DOMAIN_EXTENSIONS, kExtension)
468 .Equals(expected)); 468 .Equals(expected));
469 } 469 }
470 470
471 } // namespace policy 471 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_loader_mac_unittest.cc ('k') | chrome/browser/policy/url_blacklist_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698