• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2010 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 "chrome/browser/policy/asynchronous_policy_loader.h"
6 #include "chrome/browser/policy/asynchronous_policy_provider.h"
7 #include "chrome/browser/policy/asynchronous_policy_test_base.h"
8 #include "chrome/browser/policy/configuration_policy_pref_store.h"
9 #include "chrome/browser/policy/mock_configuration_policy_store.h"
10 #include "policy/policy_constants.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 
14 using ::testing::_;
15 using ::testing::InSequence;
16 using ::testing::Return;
17 
18 namespace policy {
19 
20 // Creating the provider should provide initial policy.
TEST_F(AsynchronousPolicyTestBase,Provide)21 TEST_F(AsynchronousPolicyTestBase, Provide) {
22   InSequence s;
23   DictionaryValue* policies = new DictionaryValue();
24   policies->SetBoolean(policy::key::kSyncDisabled, true);
25   EXPECT_CALL(*delegate_, Load()).WillOnce(Return(policies));
26   EXPECT_CALL(*store_, Apply(policy::kPolicySyncDisabled, _)).Times(1);
27   AsynchronousPolicyProvider provider(
28       ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
29       new AsynchronousPolicyLoader(delegate_.release(), 10));
30   provider.Provide(store_.get());
31 }
32 
33 
34 // Trigger a refresh manually and ensure that policy gets reloaded.
TEST_F(AsynchronousPolicyTestBase,ProvideAfterRefresh)35 TEST_F(AsynchronousPolicyTestBase, ProvideAfterRefresh) {
36   InSequence s;
37   DictionaryValue* original_policies = new DictionaryValue();
38   original_policies->SetBoolean(policy::key::kSyncDisabled, true);
39   EXPECT_CALL(*delegate_, Load()).WillOnce(Return(original_policies));
40   DictionaryValue* refresh_policies = new DictionaryValue();
41   refresh_policies->SetBoolean(
42       policy::key::kJavascriptEnabled,
43       true);
44   EXPECT_CALL(*delegate_, Load()).WillOnce(Return(refresh_policies));
45   AsynchronousPolicyLoader* loader =
46       new AsynchronousPolicyLoader(delegate_.release(), 10);
47   AsynchronousPolicyProvider provider(
48       ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
49       loader);
50   loop_.RunAllPending();
51   loader->Reload();
52   loop_.RunAllPending();
53   EXPECT_CALL(*store_, Apply(policy::kPolicyJavascriptEnabled, _)).Times(1);
54   provider.Provide(store_.get());
55 }
56 
57 }  // namespace policy
58