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/memory/scoped_temp_dir.h" | 7 #include "base/memory/scoped_temp_dir.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.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" | |
12 #include "chrome/browser/policy/mock_configuration_policy_store.h" | 10 #include "chrome/browser/policy/mock_configuration_policy_store.h" |
13 #include "chrome/browser/policy/mock_device_management_backend.h" | 11 #include "chrome/browser/policy/mock_device_management_backend.h" |
| 12 #include "chrome/browser/policy/proto/device_management_backend.pb.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 MOCK_METHOD0(SetUnmanagedState, void()); | 65 MOCK_METHOD0(SetUnmanagedState, void()); |
66 | 66 |
67 private: | 67 private: |
68 DISALLOW_COPY_AND_ASSIGN(MockDeviceTokenFetcher); | 68 DISALLOW_COPY_AND_ASSIGN(MockDeviceTokenFetcher); |
69 }; | 69 }; |
70 | 70 |
71 class CloudPolicyControllerTest : public testing::Test { | 71 class CloudPolicyControllerTest : public testing::Test { |
72 public: | 72 public: |
73 CloudPolicyControllerTest() | 73 CloudPolicyControllerTest() |
74 : ui_thread_(BrowserThread::UI, &loop_), | 74 : ui_thread_(BrowserThread::UI, &loop_), |
75 file_thread_(BrowserThread::FILE, &loop_) {} | 75 file_thread_(BrowserThread::FILE, &loop_) {} |
76 | 76 |
77 virtual ~CloudPolicyControllerTest() {} | 77 virtual ~CloudPolicyControllerTest() {} |
78 | 78 |
79 virtual void SetUp() { | 79 virtual void SetUp() { |
80 ASSERT_TRUE(temp_user_data_dir_.CreateUniqueTempDir()); | 80 ASSERT_TRUE(temp_user_data_dir_.CreateUniqueTempDir()); |
81 cache_.reset(new CloudPolicyCache( | 81 cache_.reset(new UserPolicyCache( |
82 temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest"))); | 82 temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest"))); |
83 token_fetcher_.reset(new MockDeviceTokenFetcher(cache_.get())); | 83 token_fetcher_.reset(new MockDeviceTokenFetcher(cache_.get())); |
84 } | 84 } |
85 | 85 |
86 virtual void TearDown() { | 86 virtual void TearDown() { |
87 controller_.reset(); // Unregisters observers. | 87 controller_.reset(); // Unregisters observers. |
88 } | 88 } |
89 | 89 |
90 // Takes ownership of |backend|. | 90 // Takes ownership of |backend|. |
91 void CreateNewController(DeviceManagementBackend* backend) { | 91 void CreateNewController(DeviceManagementBackend* backend) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 Return(policy_type)); | 133 Return(policy_type)); |
134 EXPECT_CALL(identity_strategy_, GetPolicyRegisterType()).WillRepeatedly( | 134 EXPECT_CALL(identity_strategy_, GetPolicyRegisterType()).WillRepeatedly( |
135 Return(policy_register_type)); | 135 Return(policy_register_type)); |
136 if (!user_name.empty()) { | 136 if (!user_name.empty()) { |
137 EXPECT_CALL(identity_strategy_, GetCredentials(_, _)).WillRepeatedly( | 137 EXPECT_CALL(identity_strategy_, GetCredentials(_, _)).WillRepeatedly( |
138 MockCloudPolicyIdentityStrategyGetCredentials(user_name, auth_token)); | 138 MockCloudPolicyIdentityStrategyGetCredentials(user_name, auth_token)); |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 protected: | 142 protected: |
143 scoped_ptr<CloudPolicyCache> cache_; | 143 scoped_ptr<CloudPolicyCacheBase> cache_; |
144 scoped_ptr<CloudPolicyController> controller_; | 144 scoped_ptr<CloudPolicyController> controller_; |
145 scoped_ptr<MockDeviceTokenFetcher> token_fetcher_; | 145 scoped_ptr<MockDeviceTokenFetcher> token_fetcher_; |
146 MockCloudPolicyIdentityStrategy identity_strategy_; | 146 MockCloudPolicyIdentityStrategy identity_strategy_; |
147 ScopedTempDir temp_user_data_dir_; | 147 ScopedTempDir temp_user_data_dir_; |
148 MessageLoop loop_; | 148 MessageLoop loop_; |
149 | 149 |
150 private: | 150 private: |
151 BrowserThread ui_thread_; | 151 BrowserThread ui_thread_; |
152 BrowserThread file_thread_; | 152 BrowserThread file_thread_; |
153 | 153 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 MockDeviceManagementBackend* backend = new MockDeviceManagementBackend(); | 261 MockDeviceManagementBackend* backend = new MockDeviceManagementBackend(); |
262 EXPECT_CALL(*backend, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 262 EXPECT_CALL(*backend, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
263 MockDeviceManagementBackendFailPolicy( | 263 MockDeviceManagementBackendFailPolicy( |
264 DeviceManagementBackend::kErrorServiceManagementNotSupported)); | 264 DeviceManagementBackend::kErrorServiceManagementNotSupported)); |
265 EXPECT_CALL(*token_fetcher_.get(), SetUnmanagedState()).Times(1); | 265 EXPECT_CALL(*token_fetcher_.get(), SetUnmanagedState()).Times(1); |
266 CreateNewController(backend, 0, 0, 0, 1000 * 1000); | 266 CreateNewController(backend, 0, 0, 0, 1000 * 1000); |
267 loop_.RunAllPending(); | 267 loop_.RunAllPending(); |
268 } | 268 } |
269 | 269 |
270 } // namespace policy | 270 } // namespace policy |
OLD | NEW |