Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1335)

Side by Side Diff: chrome/browser/policy/cloud_policy_controller_unittest.cc

Issue 9064006: Convert DeviceTokenFetcher and CloudPolicyController response callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address nits Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_policy_controller.h" 5 #include "chrome/browser/policy/cloud_policy_controller.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "chrome/browser/policy/cloud_policy_data_store.h" 10 #include "chrome/browser/policy/cloud_policy_data_store.h"
11 #include "chrome/browser/policy/device_token_fetcher.h" 11 #include "chrome/browser/policy/device_token_fetcher.h"
12 #include "chrome/browser/policy/logging_work_scheduler.h" 12 #include "chrome/browser/policy/logging_work_scheduler.h"
13 #include "chrome/browser/policy/mock_device_management_backend.h" 13 #include "chrome/browser/policy/mock_device_management_service.h"
14 #include "chrome/browser/policy/mock_device_management_service_old.h"
15 #include "chrome/browser/policy/policy_notifier.h" 14 #include "chrome/browser/policy/policy_notifier.h"
15 #include "chrome/browser/policy/proto/cloud_policy.pb.h"
16 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
16 #include "chrome/browser/policy/user_policy_cache.h" 17 #include "chrome/browser/policy/user_policy_cache.h"
17 #include "content/test/test_browser_thread.h" 18 #include "content/test/test_browser_thread.h"
18 #include "policy/policy_constants.h" 19 #include "policy/policy_constants.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 namespace em = enterprise_management; 23 namespace em = enterprise_management;
23 24
24 namespace policy { 25 namespace policy {
25 26
26 using ::testing::AnyNumber; 27 using ::testing::AnyNumber;
28 using ::testing::DoAll;
27 using ::testing::InSequence; 29 using ::testing::InSequence;
30 using ::testing::InvokeWithoutArgs;
28 using ::testing::_; 31 using ::testing::_;
29 using content::BrowserThread; 32 using content::BrowserThread;
30 33
31 class MockDeviceTokenFetcher : public DeviceTokenFetcher { 34 class MockDeviceTokenFetcher : public DeviceTokenFetcher {
32 public: 35 public:
33 explicit MockDeviceTokenFetcher(CloudPolicyCacheBase* cache) 36 explicit MockDeviceTokenFetcher(CloudPolicyCacheBase* cache)
34 : DeviceTokenFetcher(NULL, cache, NULL, NULL) {} 37 : DeviceTokenFetcher(NULL, cache, NULL, NULL) {}
35 virtual ~MockDeviceTokenFetcher() {} 38 virtual ~MockDeviceTokenFetcher() {}
36 39
37 MOCK_METHOD0(FetchToken, void()); 40 MOCK_METHOD0(FetchToken, void());
38 MOCK_METHOD0(SetUnmanagedState, void()); 41 MOCK_METHOD0(SetUnmanagedState, void());
39 MOCK_METHOD0(SetSerialNumberInvalidState, void()); 42 MOCK_METHOD0(SetSerialNumberInvalidState, void());
40 43
41 private: 44 private:
42 DISALLOW_COPY_AND_ASSIGN(MockDeviceTokenFetcher); 45 DISALLOW_COPY_AND_ASSIGN(MockDeviceTokenFetcher);
43 }; 46 };
44 47
45 class CloudPolicyControllerTest : public testing::Test { 48 class CloudPolicyControllerTest : public testing::Test {
46 public: 49 public:
47 CloudPolicyControllerTest() 50 CloudPolicyControllerTest()
48 : ui_thread_(BrowserThread::UI, &loop_), 51 : ui_thread_(BrowserThread::UI, &loop_),
49 file_thread_(BrowserThread::FILE, &loop_) {} 52 file_thread_(BrowserThread::FILE, &loop_) {
53 em::PolicyData signed_response;
54 em::CloudPolicySettings settings;
55 em::DisableSpdyProto* spdy_proto = settings.mutable_disablespdy();
56 spdy_proto->set_disablespdy(true);
57 spdy_proto->mutable_policy_options()->set_mode(
58 em::PolicyOptions::MANDATORY);
59 EXPECT_TRUE(
60 settings.SerializeToString(signed_response.mutable_policy_value()));
61 base::TimeDelta timestamp =
62 base::Time::NowFromSystemTime() - base::Time::UnixEpoch();
63 signed_response.set_timestamp(timestamp.InMilliseconds());
64 std::string serialized_signed_response;
65 EXPECT_TRUE(signed_response.SerializeToString(&serialized_signed_response));
66 em::PolicyFetchResponse* fetch_response =
67 spdy_policy_response_.mutable_policy_response()->add_response();
68 fetch_response->set_policy_data(serialized_signed_response);
69 }
50 70
51 virtual ~CloudPolicyControllerTest() {} 71 virtual ~CloudPolicyControllerTest() {}
52 72
53 virtual void SetUp() { 73 virtual void SetUp() {
54 ASSERT_TRUE(temp_user_data_dir_.CreateUniqueTempDir()); 74 ASSERT_TRUE(temp_user_data_dir_.CreateUniqueTempDir());
55 cache_.reset(new UserPolicyCache( 75 cache_.reset(new UserPolicyCache(
56 temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest"), 76 temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest"),
57 false /* wait_for_policy_fetch */)); 77 false /* wait_for_policy_fetch */));
58 token_fetcher_.reset(new MockDeviceTokenFetcher(cache_.get())); 78 token_fetcher_.reset(new MockDeviceTokenFetcher(cache_.get()));
59 EXPECT_CALL(service_, CreateBackend()) 79 EXPECT_CALL(service_, StartJob(_)).Times(AnyNumber());
60 .Times(AnyNumber())
61 .WillRepeatedly(MockDeviceManagementServiceProxyBackend(&backend_));
62 data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); 80 data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies());
63 } 81 }
64 82
65 virtual void TearDown() { 83 virtual void TearDown() {
66 controller_.reset(); // Unregisters observers. 84 controller_.reset(); // Unregisters observers.
67 data_store_.reset(); 85 data_store_.reset();
68 } 86 }
69 87
70 void CreateNewController() { 88 void CreateNewController() {
71 controller_.reset(new CloudPolicyController( 89 controller_.reset(new CloudPolicyController(
(...skipping 13 matching lines...) Expand all
85 ASSERT_FALSE(cache_->IsReady()); 103 ASSERT_FALSE(cache_->IsReady());
86 } 104 }
87 105
88 void ExpectHasSpdyPolicy() { 106 void ExpectHasSpdyPolicy() {
89 base::FundamentalValue expected(true); 107 base::FundamentalValue expected(true);
90 const PolicyMap* policy_map = cache_->policy( 108 const PolicyMap* policy_map = cache_->policy(
91 CloudPolicyCacheBase::POLICY_LEVEL_MANDATORY); 109 CloudPolicyCacheBase::POLICY_LEVEL_MANDATORY);
92 ASSERT_TRUE(Value::Equals(&expected, policy_map->Get(kPolicyDisableSpdy))); 110 ASSERT_TRUE(Value::Equals(&expected, policy_map->Get(kPolicyDisableSpdy)));
93 } 111 }
94 112
95 void StopMessageLoop() {
96 loop_.QuitNow();
97 }
98
99 protected: 113 protected:
100 scoped_ptr<CloudPolicyCacheBase> cache_; 114 scoped_ptr<CloudPolicyCacheBase> cache_;
101 scoped_ptr<CloudPolicyController> controller_; 115 scoped_ptr<CloudPolicyController> controller_;
102 scoped_ptr<MockDeviceTokenFetcher> token_fetcher_; 116 scoped_ptr<MockDeviceTokenFetcher> token_fetcher_;
103 scoped_ptr<CloudPolicyDataStore> data_store_; 117 scoped_ptr<CloudPolicyDataStore> data_store_;
104 MockDeviceManagementBackend backend_; 118 MockDeviceManagementService service_;
105 MockDeviceManagementServiceOld service_;
106 PolicyNotifier notifier_; 119 PolicyNotifier notifier_;
107 ScopedTempDir temp_user_data_dir_; 120 ScopedTempDir temp_user_data_dir_;
108 MessageLoop loop_; 121 MessageLoop loop_;
122 em::DeviceManagementResponse spdy_policy_response_;
109 123
110 private: 124 private:
111 content::TestBrowserThread ui_thread_; 125 content::TestBrowserThread ui_thread_;
112 content::TestBrowserThread file_thread_; 126 content::TestBrowserThread file_thread_;
113 127
114 DISALLOW_COPY_AND_ASSIGN(CloudPolicyControllerTest); 128 DISALLOW_COPY_AND_ASSIGN(CloudPolicyControllerTest);
115 }; 129 };
116 130
117 // If a device token is present when the controller starts up, it should 131 // If a device token is present when the controller starts up, it should
118 // fetch and apply policy. 132 // fetch and apply policy.
119 TEST_F(CloudPolicyControllerTest, StartupWithDeviceToken) { 133 TEST_F(CloudPolicyControllerTest, StartupWithDeviceToken) {
120 data_store_->SetupForTesting("fake_device_token", "device_id", "", "", 134 data_store_->SetupForTesting("fake_device_token", "device_id", "", "",
121 true); 135 true);
122 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(DoAll( 136 EXPECT_CALL(service_,
123 InvokeWithoutArgs(this, &CloudPolicyControllerTest::StopMessageLoop), 137 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
124 MockDeviceManagementBackendSucceedSpdyCloudPolicy())); 138 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow),
139 service_.SucceedJob(spdy_policy_response_)));
125 CreateNewController(); 140 CreateNewController();
126 loop_.RunAllPending(); 141 loop_.RunAllPending();
127 ExpectHasSpdyPolicy(); 142 ExpectHasSpdyPolicy();
128 } 143 }
129 144
130 // If no device token is present when the controller starts up, it should 145 // If no device token is present when the controller starts up, it should
131 // instruct the token_fetcher_ to fetch one. 146 // instruct the token_fetcher_ to fetch one.
132 TEST_F(CloudPolicyControllerTest, StartupWithoutDeviceToken) { 147 TEST_F(CloudPolicyControllerTest, StartupWithoutDeviceToken) {
133 data_store_->SetupForTesting("", "device_id", "a@b.com", "auth_token", 148 data_store_->SetupForTesting("", "device_id", "a@b.com", "auth_token",
134 true); 149 true);
(...skipping 13 matching lines...) Expand all
148 } 163 }
149 164
150 // After policy has been fetched successfully, a new fetch should be triggered 165 // After policy has been fetched successfully, a new fetch should be triggered
151 // after the refresh interval has timed out. 166 // after the refresh interval has timed out.
152 TEST_F(CloudPolicyControllerTest, RefreshAfterSuccessfulPolicy) { 167 TEST_F(CloudPolicyControllerTest, RefreshAfterSuccessfulPolicy) {
153 data_store_->SetupForTesting("device_token", "device_id", 168 data_store_->SetupForTesting("device_token", "device_id",
154 "DannoHelperDelegate@b.com", 169 "DannoHelperDelegate@b.com",
155 "auth_token", true); 170 "auth_token", true);
156 { 171 {
157 InSequence s; 172 InSequence s;
158 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce( 173 EXPECT_CALL(service_,
159 MockDeviceManagementBackendSucceedSpdyCloudPolicy()); 174 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
160 EXPECT_CALL(backend_, 175 .WillOnce(service_.SucceedJob(spdy_policy_response_));
161 ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(DoAll( 176 EXPECT_CALL(service_,
162 InvokeWithoutArgs(this, &CloudPolicyControllerTest::StopMessageLoop), 177 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
163 MockDeviceManagementBackendFailPolicy( 178 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow),
164 DeviceManagementBackend::kErrorRequestFailed))); 179 service_.FailJob(DM_STATUS_REQUEST_FAILED)));
165 } 180 }
166 CreateNewController(); 181 CreateNewController();
167 loop_.RunAllPending(); 182 loop_.RunAllPending();
168 ExpectHasSpdyPolicy(); 183 ExpectHasSpdyPolicy();
169 } 184 }
170 185
171 // If policy fetching failed, it should be retried. 186 // If policy fetching failed, it should be retried.
172 TEST_F(CloudPolicyControllerTest, RefreshAfterError) { 187 TEST_F(CloudPolicyControllerTest, RefreshAfterError) {
173 data_store_->SetupForTesting("device_token", "device_id", 188 data_store_->SetupForTesting("device_token", "device_id",
174 "DannoHelperDelegateImpl@b.com", 189 "DannoHelperDelegateImpl@b.com",
175 "auth_token", true); 190 "auth_token", true);
176 { 191 {
177 InSequence s; 192 InSequence s;
178 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce( 193 EXPECT_CALL(service_,
179 MockDeviceManagementBackendFailPolicy( 194 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
180 DeviceManagementBackend::kErrorRequestFailed)); 195 .WillOnce(service_.FailJob(DM_STATUS_REQUEST_FAILED));
181 EXPECT_CALL(backend_, 196 EXPECT_CALL(service_,
182 ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(DoAll( 197 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
183 InvokeWithoutArgs(this, 198 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow),
184 &CloudPolicyControllerTest::StopMessageLoop), 199 service_.SucceedJob(spdy_policy_response_)));
185 MockDeviceManagementBackendSucceedSpdyCloudPolicy()));
186 } 200 }
187 CreateNewController(); 201 CreateNewController();
188 loop_.RunAllPending(); 202 loop_.RunAllPending();
189 ExpectHasSpdyPolicy(); 203 ExpectHasSpdyPolicy();
190 } 204 }
191 205
192 // If the backend reports that the device token was invalid, the controller 206 // If the backend reports that the device token was invalid, the controller
193 // should instruct the token fetcher to fetch a new token. 207 // should instruct the token fetcher to fetch a new token.
194 TEST_F(CloudPolicyControllerTest, InvalidToken) { 208 TEST_F(CloudPolicyControllerTest, InvalidToken) {
195 data_store_->SetupForTesting("device_token", "device_id", 209 data_store_->SetupForTesting("device_token", "device_id",
196 "standup@ten.am", "auth", true); 210 "standup@ten.am", "auth", true);
197 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce( 211 EXPECT_CALL(service_,
198 MockDeviceManagementBackendFailPolicy( 212 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
199 DeviceManagementBackend::kErrorServiceManagementTokenInvalid)); 213 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_MANAGEMENT_TOKEN_INVALID));
200 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1); 214 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1);
201 CreateNewController(); 215 CreateNewController();
202 loop_.RunAllPending(); 216 loop_.RunAllPending();
203 } 217 }
204 218
205 // If the backend reports that the device is unknown to the server, the 219 // If the backend reports that the device is unknown to the server, the
206 // controller should instruct the token fetcher to fetch a new token. 220 // controller should instruct the token fetcher to fetch a new token.
207 TEST_F(CloudPolicyControllerTest, DeviceNotFound) { 221 TEST_F(CloudPolicyControllerTest, DeviceNotFound) {
208 data_store_->SetupForTesting("device_token", "device_id", 222 data_store_->SetupForTesting("device_token", "device_id",
209 "me@you.com", "auth", true); 223 "me@you.com", "auth", true);
210 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce( 224 EXPECT_CALL(service_,
211 MockDeviceManagementBackendFailPolicy( 225 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
212 DeviceManagementBackend::kErrorServiceDeviceNotFound)); 226 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_DEVICE_NOT_FOUND));
213 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1); 227 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1);
214 CreateNewController(); 228 CreateNewController();
215 loop_.RunAllPending(); 229 loop_.RunAllPending();
216 } 230 }
217 231
218 // If the backend reports that the device-id is already existing, the 232 // If the backend reports that the device-id is already existing, the
219 // controller should instruct the token fetcher to fetch a new token. 233 // controller should instruct the token fetcher to fetch a new token.
220 TEST_F(CloudPolicyControllerTest, DeviceIdConflict) { 234 TEST_F(CloudPolicyControllerTest, DeviceIdConflict) {
221 data_store_->SetupForTesting("device_token", "device_id", 235 data_store_->SetupForTesting("device_token", "device_id",
222 "me@you.com", "auth", true); 236 "me@you.com", "auth", true);
223 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce( 237 EXPECT_CALL(service_,
224 MockDeviceManagementBackendFailPolicy( 238 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
225 DeviceManagementBackend::kErrorServiceDeviceIdConflict)); 239 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_DEVICE_ID_CONFLICT));
226 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1); 240 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1);
227 CreateNewController(); 241 CreateNewController();
228 loop_.RunAllPending(); 242 loop_.RunAllPending();
229 } 243 }
230 244
231 // If the backend reports that the device is no longer managed, the controller 245 // If the backend reports that the device is no longer managed, the controller
232 // should instruct the token fetcher to fetch a new token (which will in turn 246 // should instruct the token fetcher to fetch a new token (which will in turn
233 // set and persist the correct 'unmanaged' state). 247 // set and persist the correct 'unmanaged' state).
234 TEST_F(CloudPolicyControllerTest, NoLongerManaged) { 248 TEST_F(CloudPolicyControllerTest, NoLongerManaged) {
235 data_store_->SetupForTesting("device_token", "device_id", 249 data_store_->SetupForTesting("device_token", "device_id",
236 "who@what.com", "auth", true); 250 "who@what.com", "auth", true);
237 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce( 251 EXPECT_CALL(service_,
238 MockDeviceManagementBackendFailPolicy( 252 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
239 DeviceManagementBackend::kErrorServiceManagementNotSupported)); 253 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_MANAGEMENT_NOT_SUPPORTED));
240 EXPECT_CALL(*token_fetcher_.get(), SetUnmanagedState()).Times(1); 254 EXPECT_CALL(*token_fetcher_.get(), SetUnmanagedState()).Times(1);
241 CreateNewController(); 255 CreateNewController();
242 loop_.RunAllPending(); 256 loop_.RunAllPending();
243 } 257 }
244 258
245 // If the backend reports that the device has invalid serial number, the 259 // If the backend reports that the device has invalid serial number, the
246 // controller should instruct the token fetcher not to fetch a new token 260 // controller should instruct the token fetcher not to fetch a new token
247 // (which will in turn set and persist the correct 'sn invalid' state). 261 // (which will in turn set and persist the correct 'sn invalid' state).
248 TEST_F(CloudPolicyControllerTest, InvalidSerialNumber) { 262 TEST_F(CloudPolicyControllerTest, InvalidSerialNumber) {
249 data_store_->SetupForTesting("device_token", "device_id", 263 data_store_->SetupForTesting("device_token", "device_id",
250 "who@what.com", "auth", true); 264 "who@what.com", "auth", true);
251 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce( 265 EXPECT_CALL(service_,
252 MockDeviceManagementBackendFailPolicy( 266 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
253 DeviceManagementBackend::kErrorServiceInvalidSerialNumber)); 267 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_INVALID_SERIAL_NUMBER));
254 EXPECT_CALL(*token_fetcher_.get(), SetSerialNumberInvalidState()).Times(1); 268 EXPECT_CALL(*token_fetcher_.get(), SetSerialNumberInvalidState()).Times(1);
255 CreateNewController(); 269 CreateNewController();
256 loop_.RunAllPending(); 270 loop_.RunAllPending();
257 } 271 }
258 272
259 TEST_F(CloudPolicyControllerTest, DontSetFetchingDoneWithoutTokens) { 273 TEST_F(CloudPolicyControllerTest, DontSetFetchingDoneWithoutTokens) {
260 CreateNewWaitingCache(); 274 CreateNewWaitingCache();
261 CreateNewController(); 275 CreateNewController();
262 // Initialized without an oauth token, goes into TOKEN_UNAVAILABLE state. 276 // Initialized without an oauth token, goes into TOKEN_UNAVAILABLE state.
263 // This means the controller is still waiting for an oauth token fetch. 277 // This means the controller is still waiting for an oauth token fetch.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 loop_.RunAllPending(); 315 loop_.RunAllPending();
302 // User is in an unmanaged domain. 316 // User is in an unmanaged domain.
303 EXPECT_TRUE(cache_->IsReady()); 317 EXPECT_TRUE(cache_->IsReady());
304 EXPECT_TRUE(cache_->last_policy_refresh_time().is_null()); 318 EXPECT_TRUE(cache_->last_policy_refresh_time().is_null());
305 } 319 }
306 320
307 TEST_F(CloudPolicyControllerTest, SetFetchingDoneAfterPolicyFetch) { 321 TEST_F(CloudPolicyControllerTest, SetFetchingDoneAfterPolicyFetch) {
308 CreateNewWaitingCache(); 322 CreateNewWaitingCache();
309 data_store_->SetupForTesting("device_token", "device_id", 323 data_store_->SetupForTesting("device_token", "device_id",
310 "user@enterprise.com", "auth", true); 324 "user@enterprise.com", "auth", true);
311 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(DoAll( 325 EXPECT_CALL(service_,
312 InvokeWithoutArgs(this, &CloudPolicyControllerTest::StopMessageLoop), 326 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
313 MockDeviceManagementBackendSucceedSpdyCloudPolicy())); 327 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow),
328 service_.SucceedJob(spdy_policy_response_)));
314 CreateNewController(); 329 CreateNewController();
315 loop_.RunAllPending(); 330 loop_.RunAllPending();
316 EXPECT_TRUE(cache_->IsReady()); 331 EXPECT_TRUE(cache_->IsReady());
317 EXPECT_FALSE(cache_->last_policy_refresh_time().is_null()); 332 EXPECT_FALSE(cache_->last_policy_refresh_time().is_null());
318 } 333 }
319 334
320 TEST_F(CloudPolicyControllerTest, SetFetchingDoneAfterPolicyFetchFails) { 335 TEST_F(CloudPolicyControllerTest, SetFetchingDoneAfterPolicyFetchFails) {
321 CreateNewWaitingCache(); 336 CreateNewWaitingCache();
322 data_store_->SetupForTesting("device_token", "device_id", 337 data_store_->SetupForTesting("device_token", "device_id",
323 "user@enterprise.com", "auth", true); 338 "user@enterprise.com", "auth", true);
324 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(DoAll( 339 EXPECT_CALL(service_,
325 InvokeWithoutArgs(this, &CloudPolicyControllerTest::StopMessageLoop), 340 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
326 MockDeviceManagementBackendFailPolicy( 341 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow),
327 DeviceManagementBackend::kErrorRequestFailed))); 342 service_.FailJob(DM_STATUS_REQUEST_FAILED)));
328 CreateNewController(); 343 CreateNewController();
329 loop_.RunAllPending(); 344 loop_.RunAllPending();
330 EXPECT_TRUE(cache_->IsReady()); 345 EXPECT_TRUE(cache_->IsReady());
331 EXPECT_TRUE(cache_->last_policy_refresh_time().is_null()); 346 EXPECT_TRUE(cache_->last_policy_refresh_time().is_null());
332 } 347 }
333 348
334 } // namespace policy 349 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_controller.cc ('k') | chrome/browser/policy/cloud_policy_data_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698