| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/values.h" | |
| 6 #include "chrome/browser/policy/asynchronous_policy_loader.h" | |
| 7 #include "chrome/browser/policy/asynchronous_policy_provider.h" | |
| 8 #include "chrome/browser/policy/asynchronous_policy_test_base.h" | |
| 9 #include "chrome/browser/policy/configuration_policy_pref_store.h" | |
| 10 #include "chrome/browser/policy/configuration_policy_provider.h" | |
| 11 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | |
| 12 #include "chrome/browser/policy/policy_map.h" | |
| 13 #include "policy/policy_constants.h" | |
| 14 #include "testing/gmock/include/gmock/gmock.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 | |
| 17 using ::testing::InSequence; | |
| 18 using ::testing::Return; | |
| 19 using ::testing::_; | |
| 20 | |
| 21 namespace policy { | |
| 22 | |
| 23 // Creating the provider should provide initial policy. | |
| 24 TEST_F(AsynchronousPolicyTestBase, Provide) { | |
| 25 InSequence s; | |
| 26 PolicyBundle bundle; | |
| 27 bundle.Get(POLICY_DOMAIN_CHROME, "") | |
| 28 .Set(key::kSyncDisabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | |
| 29 base::Value::CreateBooleanValue(true)); | |
| 30 ProviderDelegateMock* delegate = new ProviderDelegateMock(); | |
| 31 EXPECT_CALL(*delegate, MockLoad()).WillOnce(Return(&bundle)); | |
| 32 AsynchronousPolicyProvider provider( | |
| 33 GetChromePolicyDefinitionList(), | |
| 34 new AsynchronousPolicyLoader(delegate, 10)); | |
| 35 EXPECT_TRUE(provider.policies().Equals(bundle)); | |
| 36 } | |
| 37 | |
| 38 // Trigger a refresh manually and ensure that policy gets reloaded. | |
| 39 TEST_F(AsynchronousPolicyTestBase, ProvideAfterRefresh) { | |
| 40 InSequence s; | |
| 41 PolicyBundle original_policies; | |
| 42 original_policies.Get(POLICY_DOMAIN_CHROME, "") | |
| 43 .Set(key::kSyncDisabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | |
| 44 base::Value::CreateBooleanValue(true)); | |
| 45 ProviderDelegateMock* delegate = new ProviderDelegateMock(); | |
| 46 EXPECT_CALL(*delegate, MockLoad()).WillOnce(Return(&original_policies)); | |
| 47 PolicyBundle refresh_policies; | |
| 48 refresh_policies.Get(POLICY_DOMAIN_CHROME, "") | |
| 49 .Set(key::kJavascriptEnabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | |
| 50 base::Value::CreateBooleanValue(true)); | |
| 51 EXPECT_CALL(*delegate, MockLoad()).WillOnce(Return(&refresh_policies)); | |
| 52 AsynchronousPolicyLoader* loader = new AsynchronousPolicyLoader(delegate, 10); | |
| 53 AsynchronousPolicyProvider provider(GetChromePolicyDefinitionList(), loader); | |
| 54 // The original policies have been loaded. | |
| 55 EXPECT_TRUE(provider.policies().Equals(original_policies)); | |
| 56 | |
| 57 MockConfigurationPolicyObserver observer; | |
| 58 ConfigurationPolicyObserverRegistrar registrar; | |
| 59 registrar.Init(&provider, &observer); | |
| 60 EXPECT_CALL(observer, OnUpdatePolicy(&provider)).Times(1); | |
| 61 provider.RefreshPolicies(); | |
| 62 loop_.RunAllPending(); | |
| 63 // The refreshed policies are now provided. | |
| 64 EXPECT_TRUE(provider.policies().Equals(refresh_policies)); | |
| 65 } | |
| 66 | |
| 67 } // namespace policy | |
| OLD | NEW |