| Index: chrome/browser/policy/policy_service_unittest.cc
|
| diff --git a/chrome/browser/policy/policy_service_unittest.cc b/chrome/browser/policy/policy_service_unittest.cc
|
| index 1c9baf16b97cfee76b0c708a517409a1c00d2ea7..39478cc855ee8a7afb6a5b7c9ba921c6761c2800 100644
|
| --- a/chrome/browser/policy/policy_service_unittest.cc
|
| +++ b/chrome/browser/policy/policy_service_unittest.cc
|
| @@ -7,8 +7,11 @@
|
| #include "base/bind.h"
|
| #include "base/bind_helpers.h"
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "base/message_loop.h"
|
| #include "base/values.h"
|
| #include "chrome/browser/policy/mock_configuration_policy_provider.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "content/test/test_browser_thread.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -62,6 +65,8 @@ class PolicyServiceTest : public testing::Test {
|
| MOCK_METHOD2(OnPolicyValueUpdated, void(const base::Value*,
|
| const base::Value*));
|
|
|
| + MOCK_METHOD0(OnPolicyRefresh, void());
|
| +
|
| // Returns true if the policies for |domain|, |component_id| match |expected|.
|
| bool VerifyPolicies(PolicyDomain domain,
|
| const std::string& component_id,
|
| @@ -232,4 +237,75 @@ TEST_F(PolicyServiceTest, PolicyChangeRegistrar) {
|
| Mock::VerifyAndClearExpectations(this);
|
| }
|
|
|
| +TEST_F(PolicyServiceTest, RefreshPolicies) {
|
| + MessageLoop loop;
|
| + content::TestBrowserThread ui_thread(content::BrowserThread::UI, &loop);
|
| + content::TestBrowserThread file_thread(content::BrowserThread::FILE, &loop);
|
| + content::TestBrowserThread io_thread(content::BrowserThread::IO, &loop);
|
| +
|
| + provider0_.SetNotifyOnRefresh(false);
|
| + provider1_.SetNotifyOnRefresh(false);
|
| + provider2_.SetNotifyOnRefresh(false);
|
| +
|
| + EXPECT_CALL(*this, OnPolicyRefresh()).Times(0);
|
| + policy_service_->RefreshPolicies(base::Bind(
|
| + &PolicyServiceTest::OnPolicyRefresh,
|
| + base::Unretained(this)));
|
| + loop.RunAllPending();
|
| + Mock::VerifyAndClearExpectations(this);
|
| +
|
| + EXPECT_CALL(*this, OnPolicyRefresh()).Times(0);
|
| + base::FundamentalValue kValue0(0);
|
| + provider0_.AddMandatoryPolicy("aaa", kValue0.DeepCopy());
|
| + provider0_.NotifyPolicyUpdated();
|
| + loop.RunAllPending();
|
| + Mock::VerifyAndClearExpectations(this);
|
| +
|
| + EXPECT_CALL(*this, OnPolicyRefresh()).Times(0);
|
| + base::FundamentalValue kValue1(1);
|
| + provider1_.AddRecommendedPolicy("aaa", kValue1.DeepCopy());
|
| + provider1_.NotifyPolicyUpdated();
|
| + loop.RunAllPending();
|
| + Mock::VerifyAndClearExpectations(this);
|
| +
|
| + // A provider can refresh more than once after a RefreshPolicies call, but
|
| + // OnPolicyRefresh should be triggered only after all providers are
|
| + // refreshed.
|
| + EXPECT_CALL(*this, OnPolicyRefresh()).Times(0);
|
| + provider1_.AddRecommendedPolicy("bbb", kValue1.DeepCopy());
|
| + provider1_.NotifyPolicyUpdated();
|
| + loop.RunAllPending();
|
| + Mock::VerifyAndClearExpectations(this);
|
| +
|
| + // If another RefreshPolicies() call happens while waiting for a previous
|
| + // one to complete, then all providers must refresh again.
|
| + EXPECT_CALL(*this, OnPolicyRefresh()).Times(0);
|
| + policy_service_->RefreshPolicies(base::Bind(
|
| + &PolicyServiceTest::OnPolicyRefresh,
|
| + base::Unretained(this)));
|
| + loop.RunAllPending();
|
| + Mock::VerifyAndClearExpectations(this);
|
| +
|
| + EXPECT_CALL(*this, OnPolicyRefresh()).Times(0);
|
| + provider2_.AddMandatoryPolicy("bbb", kValue0.DeepCopy());
|
| + provider2_.NotifyPolicyUpdated();
|
| + loop.RunAllPending();
|
| + Mock::VerifyAndClearExpectations(this);
|
| +
|
| + // Providers 0 and 1 must reload again.
|
| + EXPECT_CALL(*this, OnPolicyRefresh()).Times(2);
|
| + base::FundamentalValue kValue2(2);
|
| + provider0_.AddMandatoryPolicy("aaa", kValue2.DeepCopy());
|
| + provider0_.NotifyPolicyUpdated();
|
| + provider1_.NotifyPolicyUpdated();
|
| + loop.RunAllPending();
|
| + Mock::VerifyAndClearExpectations(this);
|
| +
|
| + const PolicyMap* policies = policy_service_->GetPolicies(
|
| + POLICY_DOMAIN_CHROME, "");
|
| + ASSERT_TRUE(policies);
|
| + EXPECT_TRUE(base::Value::Equals(&kValue2, policies->GetValue("aaa")));
|
| + EXPECT_TRUE(base::Value::Equals(&kValue0, policies->GetValue("bbb")));
|
| +}
|
| +
|
| } // namespace policy
|
|
|