| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/asynchronous_policy_loader.h" | 5 #include "chrome/browser/policy/asynchronous_policy_loader.h" |
| 6 #include "chrome/browser/policy/asynchronous_policy_test_base.h" | 6 #include "chrome/browser/policy/asynchronous_policy_test_base.h" |
| 7 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 7 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 8 #include "chrome/browser/policy/file_based_policy_provider.h" | 8 #include "chrome/browser/policy/file_based_policy_provider.h" |
| 9 #include "chrome/browser/policy/policy_map.h" | 9 #include "chrome/browser/policy/policy_map.h" |
| 10 #include "policy/policy_constants.h" | 10 #include "policy/policy_constants.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 Return(last_modified)); | 34 Return(last_modified)); |
| 35 InSequence s; | 35 InSequence s; |
| 36 EXPECT_CALL(*provider_delegate, Load()).WillOnce(Return( | 36 EXPECT_CALL(*provider_delegate, Load()).WillOnce(Return( |
| 37 new DictionaryValue)); | 37 new DictionaryValue)); |
| 38 DictionaryValue* policies = new DictionaryValue(); | 38 DictionaryValue* policies = new DictionaryValue(); |
| 39 policies->SetBoolean(policy::key::kSyncDisabled, true); | 39 policies->SetBoolean(policy::key::kSyncDisabled, true); |
| 40 // A second call to Load gets triggered during the provider's construction | 40 // A second call to Load gets triggered during the provider's construction |
| 41 // when the file watcher is initialized, since this file may have changed | 41 // when the file watcher is initialized, since this file may have changed |
| 42 // between the initial load and creating watcher. | 42 // between the initial load and creating watcher. |
| 43 EXPECT_CALL(*provider_delegate, Load()).WillOnce(Return(policies)); | 43 EXPECT_CALL(*provider_delegate, Load()).WillOnce(Return(policies)); |
| 44 FileBasedPolicyProvider provider( | 44 FileBasedPolicyProvider provider(GetChromePolicyDefinitionList(), |
| 45 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), | 45 provider_delegate); |
| 46 provider_delegate); | |
| 47 loop_.RunAllPending(); | 46 loop_.RunAllPending(); |
| 48 PolicyMap policy_map; | 47 PolicyMap policy_map; |
| 49 provider.Provide(&policy_map); | 48 provider.Provide(&policy_map); |
| 50 EXPECT_TRUE(policy_map.Get(policy::kPolicySyncDisabled)); | 49 EXPECT_TRUE(policy_map.Get(policy::kPolicySyncDisabled)); |
| 51 EXPECT_EQ(1U, policy_map.size()); | 50 EXPECT_EQ(1U, policy_map.size()); |
| 52 } | 51 } |
| 53 | 52 |
| 54 TEST_F(AsynchronousPolicyTestBase, ProviderRefresh) { | 53 TEST_F(AsynchronousPolicyTestBase, ProviderRefresh) { |
| 55 base::Time last_modified; | 54 base::Time last_modified; |
| 56 FileBasedPolicyProviderDelegateMock* provider_delegate = | 55 FileBasedPolicyProviderDelegateMock* provider_delegate = |
| 57 new FileBasedPolicyProviderDelegateMock(); | 56 new FileBasedPolicyProviderDelegateMock(); |
| 58 EXPECT_CALL(*provider_delegate, GetLastModification()).WillRepeatedly( | 57 EXPECT_CALL(*provider_delegate, GetLastModification()).WillRepeatedly( |
| 59 Return(last_modified)); | 58 Return(last_modified)); |
| 60 InSequence s; | 59 InSequence s; |
| 61 EXPECT_CALL(*provider_delegate, Load()).WillOnce(Return( | 60 EXPECT_CALL(*provider_delegate, Load()).WillOnce(Return( |
| 62 new DictionaryValue)); | 61 new DictionaryValue)); |
| 63 FileBasedPolicyProvider file_based_provider( | 62 FileBasedPolicyProvider file_based_provider(GetChromePolicyDefinitionList(), |
| 64 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), | 63 provider_delegate); |
| 65 provider_delegate); | |
| 66 // A second call to Load gets triggered during the provider's construction | 64 // A second call to Load gets triggered during the provider's construction |
| 67 // when the file watcher is initialized, since this file may have changed | 65 // when the file watcher is initialized, since this file may have changed |
| 68 // between the initial load and creating watcher. | 66 // between the initial load and creating watcher. |
| 69 EXPECT_CALL(*provider_delegate, Load()).WillOnce(Return( | 67 EXPECT_CALL(*provider_delegate, Load()).WillOnce(Return( |
| 70 new DictionaryValue)); | 68 new DictionaryValue)); |
| 71 loop_.RunAllPending(); | 69 loop_.RunAllPending(); |
| 72 // A third and final call to Load is made by the explicit Reload. This | 70 // A third and final call to Load is made by the explicit Reload. This |
| 73 // should be the one that provides the current policy. | 71 // should be the one that provides the current policy. |
| 74 DictionaryValue* policies = new DictionaryValue(); | 72 DictionaryValue* policies = new DictionaryValue(); |
| 75 policies->SetBoolean(policy::key::kSyncDisabled, true); | 73 policies->SetBoolean(policy::key::kSyncDisabled, true); |
| 76 EXPECT_CALL(*provider_delegate, Load()).WillOnce(Return(policies)); | 74 EXPECT_CALL(*provider_delegate, Load()).WillOnce(Return(policies)); |
| 77 file_based_provider.loader()->Reload(); | 75 file_based_provider.loader()->Reload(); |
| 78 loop_.RunAllPending(); | 76 loop_.RunAllPending(); |
| 79 PolicyMap policy_map; | 77 PolicyMap policy_map; |
| 80 file_based_provider.Provide(&policy_map); | 78 file_based_provider.Provide(&policy_map); |
| 81 EXPECT_TRUE(policy_map.Get(policy::kPolicySyncDisabled)); | 79 EXPECT_TRUE(policy_map.Get(policy::kPolicySyncDisabled)); |
| 82 EXPECT_EQ(1U, policy_map.size()); | 80 EXPECT_EQ(1U, policy_map.size()); |
| 83 } | 81 } |
| 84 | 82 |
| 85 } // namespace policy | 83 } // namespace policy |
| OLD | NEW |