| 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/user_cloud_policy_manager.h" | 5 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
| 11 #include "chrome/browser/policy/cloud/cloud_external_data_manager.h" | 11 #include "chrome/browser/policy/cloud/cloud_external_data_manager.h" |
| 12 #include "chrome/browser/policy/cloud/mock_user_cloud_policy_store.h" | 12 #include "chrome/browser/policy/cloud/mock_user_cloud_policy_store.h" |
| 13 #include "chrome/browser/policy/external_data_fetcher.h" | 13 #include "chrome/browser/policy/external_data_fetcher.h" |
| 14 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 14 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| 15 #include "chrome/browser/policy/schema_registry.h" |
| 15 #include "net/url_request/url_request_context_getter.h" | 16 #include "net/url_request/url_request_context_getter.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 namespace em = enterprise_management; | 20 namespace em = enterprise_management; |
| 20 | 21 |
| 21 using testing::AnyNumber; | 22 using testing::AnyNumber; |
| 22 using testing::AtLeast; | 23 using testing::AtLeast; |
| 23 using testing::Mock; | 24 using testing::Mock; |
| 24 using testing::_; | 25 using testing::_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 46 } | 47 } |
| 47 | 48 |
| 48 void CreateManager() { | 49 void CreateManager() { |
| 49 store_ = new MockUserCloudPolicyStore(); | 50 store_ = new MockUserCloudPolicyStore(); |
| 50 EXPECT_CALL(*store_, Load()); | 51 EXPECT_CALL(*store_, Load()); |
| 51 manager_.reset(new UserCloudPolicyManager( | 52 manager_.reset(new UserCloudPolicyManager( |
| 52 NULL, | 53 NULL, |
| 53 scoped_ptr<UserCloudPolicyStore>(store_), | 54 scoped_ptr<UserCloudPolicyStore>(store_), |
| 54 scoped_ptr<CloudExternalDataManager>(), | 55 scoped_ptr<CloudExternalDataManager>(), |
| 55 loop_.message_loop_proxy())); | 56 loop_.message_loop_proxy())); |
| 56 manager_->Init(); | 57 manager_->Init(&schema_registry_); |
| 57 manager_->AddObserver(&observer_); | 58 manager_->AddObserver(&observer_); |
| 58 Mock::VerifyAndClearExpectations(store_); | 59 Mock::VerifyAndClearExpectations(store_); |
| 59 } | 60 } |
| 60 | 61 |
| 61 // Required by the refresh scheduler that's created by the manager. | 62 // Required by the refresh scheduler that's created by the manager. |
| 62 base::MessageLoop loop_; | 63 base::MessageLoop loop_; |
| 63 | 64 |
| 64 // Convenience policy objects. | 65 // Convenience policy objects. |
| 65 PolicyMap policy_map_; | 66 PolicyMap policy_map_; |
| 66 PolicyBundle expected_bundle_; | 67 PolicyBundle expected_bundle_; |
| 67 | 68 |
| 68 // Policy infrastructure. | 69 // Policy infrastructure. |
| 70 SchemaRegistry schema_registry_; |
| 69 MockConfigurationPolicyObserver observer_; | 71 MockConfigurationPolicyObserver observer_; |
| 70 MockUserCloudPolicyStore* store_; // Not owned. | 72 MockUserCloudPolicyStore* store_; // Not owned. |
| 71 scoped_ptr<UserCloudPolicyManager> manager_; | 73 scoped_ptr<UserCloudPolicyManager> manager_; |
| 72 | 74 |
| 73 private: | 75 private: |
| 74 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerTest); | 76 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerTest); |
| 75 }; | 77 }; |
| 76 | 78 |
| 77 TEST_F(UserCloudPolicyManagerTest, DisconnectAndRemovePolicy) { | 79 TEST_F(UserCloudPolicyManagerTest, DisconnectAndRemovePolicy) { |
| 78 // Load policy, make sure it goes away when DisconnectAndRemovePolicy() is | 80 // Load policy, make sure it goes away when DisconnectAndRemovePolicy() is |
| 79 // called. | 81 // called. |
| 80 CreateManager(); | 82 CreateManager(); |
| 81 store_->policy_map_.CopyFrom(policy_map_); | 83 store_->policy_map_.CopyFrom(policy_map_); |
| 82 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); | 84 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); |
| 83 store_->NotifyStoreLoaded(); | 85 store_->NotifyStoreLoaded(); |
| 84 EXPECT_TRUE(expected_bundle_.Equals(manager_->policies())); | 86 EXPECT_TRUE(expected_bundle_.Equals(manager_->policies())); |
| 85 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); | 87 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); |
| 86 EXPECT_CALL(*store_, Clear()); | 88 EXPECT_CALL(*store_, Clear()); |
| 87 manager_->DisconnectAndRemovePolicy(); | 89 manager_->DisconnectAndRemovePolicy(); |
| 88 EXPECT_FALSE(manager_->core()->service()); | 90 EXPECT_FALSE(manager_->core()->service()); |
| 89 } | 91 } |
| 90 | 92 |
| 91 } // namespace | 93 } // namespace |
| 92 } // namespace policy | 94 } // namespace policy |
| OLD | NEW |