| Index: chrome/browser/policy/asynchronous_policy_provider_unittest.cc
|
| diff --git a/chrome/browser/policy/asynchronous_policy_provider_unittest.cc b/chrome/browser/policy/asynchronous_policy_provider_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..cf09616288df5411f7319fff82bc28aadd8dcf09
|
| --- /dev/null
|
| +++ b/chrome/browser/policy/asynchronous_policy_provider_unittest.cc
|
| @@ -0,0 +1,83 @@
|
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "base/message_loop.h"
|
| +#include "chrome/browser/policy/asynchronous_policy_provider.h"
|
| +#include "chrome/browser/policy/asynchronous_policy_test_base.h"
|
| +#include "chrome/browser/policy/configuration_policy_pref_store.h"
|
| +#include "chrome/browser/policy/mock_configuration_policy_store.h"
|
| +#include "chrome/common/policy_constants.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +using ::testing::_;
|
| +using ::testing::InSequence;
|
| +using ::testing::Return;
|
| +
|
| +namespace policy {
|
| +
|
| +class AsynchronousPolicyProviderTest : public AsynchronousPolicyTestBase {
|
| + public:
|
| + AsynchronousPolicyProviderTest() {}
|
| + virtual ~AsynchronousPolicyProviderTest() {}
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyProviderTest);
|
| +};
|
| +
|
| +ACTION(DestroyPolicyChangeObserver) {
|
| + delete arg0;
|
| +}
|
| +
|
| +ACTION(RefreshAndDestroyPolicyChangeObserver) {
|
| + arg0->OnPolicyChange();
|
| + delete arg0;
|
| +}
|
| +
|
| +ACTION_P(ReturnDictionaryAndQuitMessageLoop, dict) {
|
| + MessageLoop::current()->PostTask(FROM_HERE, NewRunnableFunction(
|
| + &MessageLoopQuitNow));
|
| + return dict;
|
| +}
|
| +
|
| +TEST_F(AsynchronousPolicyProviderTest, Provide) {
|
| + EXPECT_CALL(*delegate_, Init(_)).WillOnce(
|
| + DestroyPolicyChangeObserver());
|
| + InSequence s;
|
| + DictionaryValue* policies = new DictionaryValue();
|
| + policies->SetBoolean(policy::key::kSyncDisabled, true);
|
| + EXPECT_CALL(*delegate_, Load()).WillOnce(Return(policies));
|
| + EXPECT_CALL(*store_, Apply(policy::kPolicySyncDisabled, _)).Times(1);
|
| + EXPECT_CALL(*delegate_, Stop()).Times(1);
|
| + provider_.reset(new AsynchronousPolicyProvider(
|
| + ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
|
| + delegate_.release()));
|
| + provider_->Provide(store_.get());
|
| +}
|
| +
|
| +TEST_F(AsynchronousPolicyProviderTest, ProvideAfterRefresh) {
|
| + EXPECT_CALL(*delegate_, IsSafeToReloadPolicy(_, _)).WillRepeatedly(
|
| + Return(true));
|
| + EXPECT_CALL(*delegate_, Init(_)).WillOnce(
|
| + RefreshAndDestroyPolicyChangeObserver());
|
| + InSequence s;
|
| + DictionaryValue* original_policies = new DictionaryValue();
|
| + original_policies->SetBoolean(policy::key::kSyncDisabled, true);
|
| + EXPECT_CALL(*delegate_, Load()).WillOnce(Return(original_policies));
|
| + DictionaryValue* refresh_policies = new DictionaryValue();
|
| + refresh_policies->SetBoolean(
|
| + policy::key::kJavascriptEnabled,
|
| + true);
|
| + EXPECT_CALL(*delegate_, Load()).WillOnce(
|
| + ReturnDictionaryAndQuitMessageLoop(refresh_policies));
|
| + EXPECT_CALL(*store_, Apply(policy::kPolicyJavascriptEnabled, _)).Times(1);
|
| + EXPECT_CALL(*delegate_, Stop()).Times(1);
|
| + provider_.reset(new AsynchronousPolicyProvider(
|
| + ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
|
| + delegate_.release()));
|
| + loop_.RunAllPending();
|
| + provider_->Provide(store_.get());
|
| +}
|
| +
|
| +} // namespace policy
|
|
|