| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/cloud/cloud_policy_manager.h" | 5 #include "chrome/browser/policy/cloud/cloud_policy_manager.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" | 12 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
| 13 #include "chrome/browser/policy/cloud/mock_cloud_policy_client.h" | 13 #include "chrome/browser/policy/cloud/mock_cloud_policy_client.h" |
| 14 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h" | 14 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h" |
| 15 #include "chrome/browser/policy/cloud/policy_builder.h" | 15 #include "chrome/browser/policy/cloud/policy_builder.h" |
| 16 #include "chrome/browser/policy/configuration_policy_provider_test.h" | 16 #include "chrome/browser/policy/configuration_policy_provider_test.h" |
| 17 #include "chrome/browser/policy/external_data_fetcher.h" | 17 #include "chrome/browser/policy/external_data_fetcher.h" |
| 18 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 18 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| 19 #include "chrome/browser/policy/schema_registry.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 using testing::Mock; | 23 using testing::Mock; |
| 23 using testing::_; | 24 using testing::_; |
| 24 | 25 |
| 25 namespace em = enterprise_management; | 26 namespace em = enterprise_management; |
| 26 | 27 |
| 27 namespace policy { | 28 namespace policy { |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 class TestHarness : public PolicyProviderTestHarness { | 31 class TestHarness : public PolicyProviderTestHarness { |
| 31 public: | 32 public: |
| 32 explicit TestHarness(PolicyLevel level); | 33 explicit TestHarness(PolicyLevel level); |
| 33 virtual ~TestHarness(); | 34 virtual ~TestHarness(); |
| 34 | 35 |
| 35 virtual void SetUp() OVERRIDE; | 36 virtual void SetUp() OVERRIDE; |
| 36 | 37 |
| 37 virtual ConfigurationPolicyProvider* CreateProvider( | 38 virtual ConfigurationPolicyProvider* CreateProvider( |
| 39 SchemaRegistry* registry, |
| 38 scoped_refptr<base::SequencedTaskRunner> task_runner, | 40 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 39 const PolicyDefinitionList* policy_definition_list) OVERRIDE; | 41 const PolicyDefinitionList* policy_definition_list) OVERRIDE; |
| 40 | 42 |
| 41 virtual void InstallEmptyPolicy() OVERRIDE; | 43 virtual void InstallEmptyPolicy() OVERRIDE; |
| 42 virtual void InstallStringPolicy(const std::string& policy_name, | 44 virtual void InstallStringPolicy(const std::string& policy_name, |
| 43 const std::string& policy_value) OVERRIDE; | 45 const std::string& policy_value) OVERRIDE; |
| 44 virtual void InstallIntegerPolicy(const std::string& policy_name, | 46 virtual void InstallIntegerPolicy(const std::string& policy_name, |
| 45 int policy_value) OVERRIDE; | 47 int policy_value) OVERRIDE; |
| 46 virtual void InstallBooleanPolicy(const std::string& policy_name, | 48 virtual void InstallBooleanPolicy(const std::string& policy_name, |
| 47 bool policy_value) OVERRIDE; | 49 bool policy_value) OVERRIDE; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 63 }; | 65 }; |
| 64 | 66 |
| 65 TestHarness::TestHarness(PolicyLevel level) | 67 TestHarness::TestHarness(PolicyLevel level) |
| 66 : PolicyProviderTestHarness(level, POLICY_SCOPE_USER) {} | 68 : PolicyProviderTestHarness(level, POLICY_SCOPE_USER) {} |
| 67 | 69 |
| 68 TestHarness::~TestHarness() {} | 70 TestHarness::~TestHarness() {} |
| 69 | 71 |
| 70 void TestHarness::SetUp() {} | 72 void TestHarness::SetUp() {} |
| 71 | 73 |
| 72 ConfigurationPolicyProvider* TestHarness::CreateProvider( | 74 ConfigurationPolicyProvider* TestHarness::CreateProvider( |
| 75 SchemaRegistry* registry, |
| 73 scoped_refptr<base::SequencedTaskRunner> task_runner, | 76 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 74 const PolicyDefinitionList* policy_definition_list) { | 77 const PolicyDefinitionList* policy_definition_list) { |
| 75 // Create and initialize the store. | 78 // Create and initialize the store. |
| 76 store_.NotifyStoreLoaded(); | 79 store_.NotifyStoreLoaded(); |
| 77 ConfigurationPolicyProvider* provider = new CloudPolicyManager( | 80 ConfigurationPolicyProvider* provider = new CloudPolicyManager( |
| 78 PolicyNamespaceKey(dm_protocol::kChromeUserPolicyType, std::string()), | 81 PolicyNamespaceKey(dm_protocol::kChromeUserPolicyType, std::string()), |
| 79 &store_, | 82 &store_, |
| 80 task_runner); | 83 task_runner); |
| 81 Mock::VerifyAndClearExpectations(&store_); | 84 Mock::VerifyAndClearExpectations(&store_); |
| 82 return provider; | 85 return provider; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 base::Value::CreateStringValue("value"), NULL); | 172 base::Value::CreateStringValue("value"), NULL); |
| 170 expected_bundle_.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 173 expected_bundle_.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 171 .CopyFrom(policy_map_); | 174 .CopyFrom(policy_map_); |
| 172 | 175 |
| 173 policy_.payload().mutable_passwordmanagerenabled()->set_value(false); | 176 policy_.payload().mutable_passwordmanagerenabled()->set_value(false); |
| 174 policy_.Build(); | 177 policy_.Build(); |
| 175 | 178 |
| 176 EXPECT_CALL(store_, Load()); | 179 EXPECT_CALL(store_, Load()); |
| 177 manager_.reset(new TestCloudPolicyManager(&store_, | 180 manager_.reset(new TestCloudPolicyManager(&store_, |
| 178 loop_.message_loop_proxy())); | 181 loop_.message_loop_proxy())); |
| 179 manager_->Init(); | 182 manager_->Init(&schema_registry_); |
| 180 Mock::VerifyAndClearExpectations(&store_); | 183 Mock::VerifyAndClearExpectations(&store_); |
| 181 manager_->AddObserver(&observer_); | 184 manager_->AddObserver(&observer_); |
| 182 } | 185 } |
| 183 | 186 |
| 184 virtual void TearDown() OVERRIDE { | 187 virtual void TearDown() OVERRIDE { |
| 185 manager_->RemoveObserver(&observer_); | 188 manager_->RemoveObserver(&observer_); |
| 186 manager_->Shutdown(); | 189 manager_->Shutdown(); |
| 187 } | 190 } |
| 188 | 191 |
| 189 // Required by the refresh scheduler that's created by the manager. | 192 // Required by the refresh scheduler that's created by the manager. |
| 190 base::MessageLoop loop_; | 193 base::MessageLoop loop_; |
| 191 | 194 |
| 192 // Testing policy. | 195 // Testing policy. |
| 193 const PolicyNamespaceKey policy_ns_key_; | 196 const PolicyNamespaceKey policy_ns_key_; |
| 194 UserPolicyBuilder policy_; | 197 UserPolicyBuilder policy_; |
| 195 PolicyMap policy_map_; | 198 PolicyMap policy_map_; |
| 196 PolicyBundle expected_bundle_; | 199 PolicyBundle expected_bundle_; |
| 197 | 200 |
| 198 // Policy infrastructure. | 201 // Policy infrastructure. |
| 202 SchemaRegistry schema_registry_; |
| 199 MockConfigurationPolicyObserver observer_; | 203 MockConfigurationPolicyObserver observer_; |
| 200 MockCloudPolicyStore store_; | 204 MockCloudPolicyStore store_; |
| 201 scoped_ptr<TestCloudPolicyManager> manager_; | 205 scoped_ptr<TestCloudPolicyManager> manager_; |
| 202 | 206 |
| 203 private: | 207 private: |
| 204 DISALLOW_COPY_AND_ASSIGN(CloudPolicyManagerTest); | 208 DISALLOW_COPY_AND_ASSIGN(CloudPolicyManagerTest); |
| 205 }; | 209 }; |
| 206 | 210 |
| 207 TEST_F(CloudPolicyManagerTest, InitAndShutdown) { | 211 TEST_F(CloudPolicyManagerTest, InitAndShutdown) { |
| 208 PolicyBundle empty_bundle; | 212 PolicyBundle empty_bundle; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 store_.policy_.reset(new em::PolicyData(policy_.policy_data())); | 343 store_.policy_.reset(new em::PolicyData(policy_.policy_data())); |
| 340 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); | 344 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); |
| 341 store_.NotifyStoreError(); | 345 store_.NotifyStoreError(); |
| 342 Mock::VerifyAndClearExpectations(&observer_); | 346 Mock::VerifyAndClearExpectations(&observer_); |
| 343 | 347 |
| 344 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); | 348 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); |
| 345 } | 349 } |
| 346 | 350 |
| 347 } // namespace | 351 } // namespace |
| 348 } // namespace policy | 352 } // namespace policy |
| OLD | NEW |