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/cloud_policy_controller.h" | 5 #include "chrome/browser/policy/cloud_policy_controller.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
9 #include "chrome/browser/policy/cloud_policy_cache.h" | |
10 #include "chrome/browser/policy/device_token_fetcher.h" | 9 #include "chrome/browser/policy/device_token_fetcher.h" |
11 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 10 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
12 #include "chrome/browser/policy/mock_configuration_policy_store.h" | 11 #include "chrome/browser/policy/mock_configuration_policy_store.h" |
13 #include "chrome/browser/policy/mock_device_management_backend.h" | 12 #include "chrome/browser/policy/mock_device_management_backend.h" |
| 13 #include "chrome/browser/policy/user_policy_cache.h" |
14 #include "content/browser/browser_thread.h" | 14 #include "content/browser/browser_thread.h" |
15 #include "policy/policy_constants.h" | 15 #include "policy/policy_constants.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 const char kTestToken[] = "cloud_policy_controller_test_auth_token"; | 19 const char kTestToken[] = "cloud_policy_controller_test_auth_token"; |
20 | 20 |
21 namespace policy { | 21 namespace policy { |
22 | 22 |
23 namespace em = enterprise_management; | 23 namespace em = enterprise_management; |
(...skipping 23 matching lines...) Expand all Loading... |
47 }; | 47 }; |
48 | 48 |
49 ACTION_P2(MockCloudPolicyIdentityStrategyGetCredentials, username, auth_token) { | 49 ACTION_P2(MockCloudPolicyIdentityStrategyGetCredentials, username, auth_token) { |
50 *arg0 = username; | 50 *arg0 = username; |
51 *arg1 = auth_token; | 51 *arg1 = auth_token; |
52 return true; | 52 return true; |
53 } | 53 } |
54 | 54 |
55 class MockDeviceTokenFetcher : public DeviceTokenFetcher { | 55 class MockDeviceTokenFetcher : public DeviceTokenFetcher { |
56 public: | 56 public: |
57 explicit MockDeviceTokenFetcher(CloudPolicyCache* cache) | 57 explicit MockDeviceTokenFetcher(CloudPolicyCacheBase* cache) |
58 : DeviceTokenFetcher(NULL, cache) {} | 58 : DeviceTokenFetcher(NULL, cache) {} |
59 virtual ~MockDeviceTokenFetcher() {} | 59 virtual ~MockDeviceTokenFetcher() {} |
60 | 60 |
61 MOCK_METHOD0(GetDeviceToken, const std::string&()); | 61 MOCK_METHOD0(GetDeviceToken, const std::string&()); |
62 MOCK_METHOD4(FetchToken, | 62 MOCK_METHOD4(FetchToken, |
63 void(const std::string&, const std::string&, | 63 void(const std::string&, const std::string&, |
64 em::DeviceRegisterRequest_Type, const std::string&)); | 64 em::DeviceRegisterRequest_Type, const std::string&)); |
65 | 65 |
66 private: | 66 private: |
67 DISALLOW_COPY_AND_ASSIGN(MockDeviceTokenFetcher); | 67 DISALLOW_COPY_AND_ASSIGN(MockDeviceTokenFetcher); |
68 }; | 68 }; |
69 | 69 |
70 class CloudPolicyControllerTest : public testing::Test { | 70 class CloudPolicyControllerTest : public testing::Test { |
71 public: | 71 public: |
72 CloudPolicyControllerTest() | 72 CloudPolicyControllerTest() |
73 : ui_thread_(BrowserThread::UI, &loop_), | 73 : ui_thread_(BrowserThread::UI, &loop_), |
74 file_thread_(BrowserThread::FILE, &loop_) {} | 74 file_thread_(BrowserThread::FILE, &loop_) {} |
75 | 75 |
76 virtual ~CloudPolicyControllerTest() {} | 76 virtual ~CloudPolicyControllerTest() {} |
77 | 77 |
78 virtual void SetUp() { | 78 virtual void SetUp() { |
79 ASSERT_TRUE(temp_user_data_dir_.CreateUniqueTempDir()); | 79 ASSERT_TRUE(temp_user_data_dir_.CreateUniqueTempDir()); |
80 cache_.reset(new CloudPolicyCache( | 80 cache_.reset(new UserPolicyCache( |
81 temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest"))); | 81 temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest"))); |
82 token_fetcher_.reset(new MockDeviceTokenFetcher(cache_.get())); | 82 token_fetcher_.reset(new MockDeviceTokenFetcher(cache_.get())); |
83 } | 83 } |
84 | 84 |
85 virtual void TearDown() { | 85 virtual void TearDown() { |
86 controller_.reset(); // Unregisters observers. | 86 controller_.reset(); // Unregisters observers. |
87 } | 87 } |
88 | 88 |
89 // Takes ownership of |backend|. | 89 // Takes ownership of |backend|. |
90 void CreateNewController(DeviceManagementBackend* backend) { | 90 void CreateNewController(DeviceManagementBackend* backend) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 Return(policy_type)); | 132 Return(policy_type)); |
133 EXPECT_CALL(identity_strategy_, GetPolicyRegisterType()).WillRepeatedly( | 133 EXPECT_CALL(identity_strategy_, GetPolicyRegisterType()).WillRepeatedly( |
134 Return(policy_register_type)); | 134 Return(policy_register_type)); |
135 if (!user_name.empty()) { | 135 if (!user_name.empty()) { |
136 EXPECT_CALL(identity_strategy_, GetCredentials(_, _)).WillRepeatedly( | 136 EXPECT_CALL(identity_strategy_, GetCredentials(_, _)).WillRepeatedly( |
137 MockCloudPolicyIdentityStrategyGetCredentials(user_name, auth_token)); | 137 MockCloudPolicyIdentityStrategyGetCredentials(user_name, auth_token)); |
138 } | 138 } |
139 } | 139 } |
140 | 140 |
141 protected: | 141 protected: |
142 scoped_ptr<CloudPolicyCache> cache_; | 142 scoped_ptr<CloudPolicyCacheBase> cache_; |
143 scoped_ptr<CloudPolicyController> controller_; | 143 scoped_ptr<CloudPolicyController> controller_; |
144 scoped_ptr<MockDeviceTokenFetcher> token_fetcher_; | 144 scoped_ptr<MockDeviceTokenFetcher> token_fetcher_; |
145 MockCloudPolicyIdentityStrategy identity_strategy_; | 145 MockCloudPolicyIdentityStrategy identity_strategy_; |
146 ScopedTempDir temp_user_data_dir_; | 146 ScopedTempDir temp_user_data_dir_; |
147 MessageLoop loop_; | 147 MessageLoop loop_; |
148 | 148 |
149 private: | 149 private: |
150 BrowserThread ui_thread_; | 150 BrowserThread ui_thread_; |
151 BrowserThread file_thread_; | 151 BrowserThread file_thread_; |
152 | 152 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 MockDeviceManagementBackend* backend = new MockDeviceManagementBackend(); | 260 MockDeviceManagementBackend* backend = new MockDeviceManagementBackend(); |
261 EXPECT_CALL(*backend, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 261 EXPECT_CALL(*backend, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
262 MockDeviceManagementBackendFailPolicy( | 262 MockDeviceManagementBackendFailPolicy( |
263 DeviceManagementBackend::kErrorServiceManagementNotSupported)); | 263 DeviceManagementBackend::kErrorServiceManagementNotSupported)); |
264 EXPECT_CALL(*token_fetcher_.get(), FetchToken(_, _, _, _)).Times(1); | 264 EXPECT_CALL(*token_fetcher_.get(), FetchToken(_, _, _, _)).Times(1); |
265 CreateNewController(backend); | 265 CreateNewController(backend); |
266 loop_.RunAllPending(); | 266 loop_.RunAllPending(); |
267 } | 267 } |
268 | 268 |
269 } // namespace policy | 269 } // namespace policy |
OLD | NEW |