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_policy_controller.h" | 5 #include "chrome/browser/policy/cloud_policy_controller.h" |
6 | 6 |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "chrome/browser/policy/cloud_policy_data_store.h" | 10 #include "chrome/browser/policy/cloud_policy_data_store.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 ¬ifier_, new DummyWorkScheduler)); | 92 ¬ifier_, new DummyWorkScheduler)); |
93 } | 93 } |
94 | 94 |
95 void CreateNewWaitingCache() { | 95 void CreateNewWaitingCache() { |
96 cache_.reset(new UserPolicyCache( | 96 cache_.reset(new UserPolicyCache( |
97 temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest"), | 97 temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest"), |
98 true /* wait_for_policy_fetch */)); | 98 true /* wait_for_policy_fetch */)); |
99 // Make this cache's disk cache ready, but have it still waiting for a | 99 // Make this cache's disk cache ready, but have it still waiting for a |
100 // policy fetch. | 100 // policy fetch. |
101 cache_->Load(); | 101 cache_->Load(); |
102 loop_.RunAllPending(); | 102 loop_.RunUntilIdle(); |
103 ASSERT_TRUE(cache_->last_policy_refresh_time().is_null()); | 103 ASSERT_TRUE(cache_->last_policy_refresh_time().is_null()); |
104 ASSERT_FALSE(cache_->IsReady()); | 104 ASSERT_FALSE(cache_->IsReady()); |
105 } | 105 } |
106 | 106 |
107 void ExpectHasSpdyPolicy() { | 107 void ExpectHasSpdyPolicy() { |
108 base::FundamentalValue expected(true); | 108 base::FundamentalValue expected(true); |
109 ASSERT_TRUE(Value::Equals(&expected, | 109 ASSERT_TRUE(Value::Equals(&expected, |
110 cache_->policy()->GetValue(key::kDisableSpdy))); | 110 cache_->policy()->GetValue(key::kDisableSpdy))); |
111 } | 111 } |
112 | 112 |
(...skipping 18 matching lines...) Expand all Loading... |
131 // 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 |
132 // fetch and apply policy. | 132 // fetch and apply policy. |
133 TEST_F(CloudPolicyControllerTest, StartupWithDeviceToken) { | 133 TEST_F(CloudPolicyControllerTest, StartupWithDeviceToken) { |
134 data_store_->SetupForTesting("fake_device_token", "device_id", "", "", | 134 data_store_->SetupForTesting("fake_device_token", "device_id", "", "", |
135 true); | 135 true); |
136 EXPECT_CALL(service_, | 136 EXPECT_CALL(service_, |
137 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) | 137 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) |
138 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow), | 138 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow), |
139 service_.SucceedJob(spdy_policy_response_))); | 139 service_.SucceedJob(spdy_policy_response_))); |
140 CreateNewController(); | 140 CreateNewController(); |
141 loop_.RunAllPending(); | 141 loop_.RunUntilIdle(); |
142 ExpectHasSpdyPolicy(); | 142 ExpectHasSpdyPolicy(); |
143 } | 143 } |
144 | 144 |
145 // 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 |
146 // instruct the token_fetcher_ to fetch one. | 146 // instruct the token_fetcher_ to fetch one. |
147 TEST_F(CloudPolicyControllerTest, StartupWithoutDeviceToken) { | 147 TEST_F(CloudPolicyControllerTest, StartupWithoutDeviceToken) { |
148 data_store_->SetupForTesting("", "device_id", "a@b.com", "auth_token", | 148 data_store_->SetupForTesting("", "device_id", "a@b.com", "auth_token", |
149 true); | 149 true); |
150 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1); | 150 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1); |
151 CreateNewController(); | 151 CreateNewController(); |
152 loop_.RunAllPending(); | 152 loop_.RunUntilIdle(); |
153 } | 153 } |
154 | 154 |
155 // If the current user belongs to a known non-managed domain, no token fetch | 155 // If the current user belongs to a known non-managed domain, no token fetch |
156 // should be initiated. | 156 // should be initiated. |
157 TEST_F(CloudPolicyControllerTest, StartupUnmanagedUser) { | 157 TEST_F(CloudPolicyControllerTest, StartupUnmanagedUser) { |
158 data_store_->SetupForTesting("", "device_id", "DannoHelper@gmail.com", | 158 data_store_->SetupForTesting("", "device_id", "DannoHelper@gmail.com", |
159 "auth_token", true); | 159 "auth_token", true); |
160 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(0); | 160 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(0); |
161 CreateNewController(); | 161 CreateNewController(); |
162 loop_.RunAllPending(); | 162 loop_.RunUntilIdle(); |
163 } | 163 } |
164 | 164 |
165 // 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 |
166 // after the refresh interval has timed out. | 166 // after the refresh interval has timed out. |
167 TEST_F(CloudPolicyControllerTest, RefreshAfterSuccessfulPolicy) { | 167 TEST_F(CloudPolicyControllerTest, RefreshAfterSuccessfulPolicy) { |
168 data_store_->SetupForTesting("device_token", "device_id", | 168 data_store_->SetupForTesting("device_token", "device_id", |
169 "DannoHelperDelegate@b.com", | 169 "DannoHelperDelegate@b.com", |
170 "auth_token", true); | 170 "auth_token", true); |
171 { | 171 { |
172 InSequence s; | 172 InSequence s; |
173 EXPECT_CALL(service_, | 173 EXPECT_CALL(service_, |
174 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) | 174 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) |
175 .WillOnce(service_.SucceedJob(spdy_policy_response_)); | 175 .WillOnce(service_.SucceedJob(spdy_policy_response_)); |
176 EXPECT_CALL(service_, | 176 EXPECT_CALL(service_, |
177 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) | 177 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) |
178 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow), | 178 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow), |
179 service_.FailJob(DM_STATUS_REQUEST_FAILED))); | 179 service_.FailJob(DM_STATUS_REQUEST_FAILED))); |
180 } | 180 } |
181 CreateNewController(); | 181 CreateNewController(); |
182 loop_.RunAllPending(); | 182 loop_.RunUntilIdle(); |
183 ExpectHasSpdyPolicy(); | 183 ExpectHasSpdyPolicy(); |
184 } | 184 } |
185 | 185 |
186 // If policy fetching failed, it should be retried. | 186 // If policy fetching failed, it should be retried. |
187 TEST_F(CloudPolicyControllerTest, RefreshAfterError) { | 187 TEST_F(CloudPolicyControllerTest, RefreshAfterError) { |
188 data_store_->SetupForTesting("device_token", "device_id", | 188 data_store_->SetupForTesting("device_token", "device_id", |
189 "DannoHelperDelegateImpl@b.com", | 189 "DannoHelperDelegateImpl@b.com", |
190 "auth_token", true); | 190 "auth_token", true); |
191 { | 191 { |
192 InSequence s; | 192 InSequence s; |
193 EXPECT_CALL(service_, | 193 EXPECT_CALL(service_, |
194 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) | 194 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) |
195 .WillOnce(service_.FailJob(DM_STATUS_REQUEST_FAILED)); | 195 .WillOnce(service_.FailJob(DM_STATUS_REQUEST_FAILED)); |
196 EXPECT_CALL(service_, | 196 EXPECT_CALL(service_, |
197 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) | 197 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) |
198 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow), | 198 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow), |
199 service_.SucceedJob(spdy_policy_response_))); | 199 service_.SucceedJob(spdy_policy_response_))); |
200 } | 200 } |
201 CreateNewController(); | 201 CreateNewController(); |
202 loop_.RunAllPending(); | 202 loop_.RunUntilIdle(); |
203 ExpectHasSpdyPolicy(); | 203 ExpectHasSpdyPolicy(); |
204 } | 204 } |
205 | 205 |
206 // 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 |
207 // should instruct the token fetcher to fetch a new token. | 207 // should instruct the token fetcher to fetch a new token. |
208 TEST_F(CloudPolicyControllerTest, InvalidToken) { | 208 TEST_F(CloudPolicyControllerTest, InvalidToken) { |
209 data_store_->SetupForTesting("device_token", "device_id", | 209 data_store_->SetupForTesting("device_token", "device_id", |
210 "standup@ten.am", "auth", true); | 210 "standup@ten.am", "auth", true); |
211 EXPECT_CALL(service_, | 211 EXPECT_CALL(service_, |
212 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) | 212 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) |
213 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_MANAGEMENT_TOKEN_INVALID)); | 213 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_MANAGEMENT_TOKEN_INVALID)); |
214 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1); | 214 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1); |
215 CreateNewController(); | 215 CreateNewController(); |
216 loop_.RunAllPending(); | 216 loop_.RunUntilIdle(); |
217 } | 217 } |
218 | 218 |
219 // 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 |
220 // controller should instruct the token fetcher to fetch a new token. | 220 // controller should instruct the token fetcher to fetch a new token. |
221 TEST_F(CloudPolicyControllerTest, DeviceNotFound) { | 221 TEST_F(CloudPolicyControllerTest, DeviceNotFound) { |
222 data_store_->SetupForTesting("device_token", "device_id", | 222 data_store_->SetupForTesting("device_token", "device_id", |
223 "me@you.com", "auth", true); | 223 "me@you.com", "auth", true); |
224 EXPECT_CALL(service_, | 224 EXPECT_CALL(service_, |
225 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) | 225 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) |
226 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_DEVICE_NOT_FOUND)); | 226 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_DEVICE_NOT_FOUND)); |
227 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1); | 227 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1); |
228 CreateNewController(); | 228 CreateNewController(); |
229 loop_.RunAllPending(); | 229 loop_.RunUntilIdle(); |
230 } | 230 } |
231 | 231 |
232 // 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 |
233 // controller should instruct the token fetcher to fetch a new token. | 233 // controller should instruct the token fetcher to fetch a new token. |
234 TEST_F(CloudPolicyControllerTest, DeviceIdConflict) { | 234 TEST_F(CloudPolicyControllerTest, DeviceIdConflict) { |
235 data_store_->SetupForTesting("device_token", "device_id", | 235 data_store_->SetupForTesting("device_token", "device_id", |
236 "me@you.com", "auth", true); | 236 "me@you.com", "auth", true); |
237 EXPECT_CALL(service_, | 237 EXPECT_CALL(service_, |
238 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) | 238 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) |
239 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_DEVICE_ID_CONFLICT)); | 239 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_DEVICE_ID_CONFLICT)); |
240 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1); | 240 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1); |
241 CreateNewController(); | 241 CreateNewController(); |
242 loop_.RunAllPending(); | 242 loop_.RunUntilIdle(); |
243 } | 243 } |
244 | 244 |
245 // 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 |
246 // 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 |
247 // set and persist the correct 'unmanaged' state). | 247 // set and persist the correct 'unmanaged' state). |
248 TEST_F(CloudPolicyControllerTest, NoLongerManaged) { | 248 TEST_F(CloudPolicyControllerTest, NoLongerManaged) { |
249 data_store_->SetupForTesting("device_token", "device_id", | 249 data_store_->SetupForTesting("device_token", "device_id", |
250 "who@what.com", "auth", true); | 250 "who@what.com", "auth", true); |
251 EXPECT_CALL(service_, | 251 EXPECT_CALL(service_, |
252 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) | 252 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) |
253 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_MANAGEMENT_NOT_SUPPORTED)); | 253 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_MANAGEMENT_NOT_SUPPORTED)); |
254 EXPECT_CALL(*token_fetcher_.get(), SetUnmanagedState()).Times(1); | 254 EXPECT_CALL(*token_fetcher_.get(), SetUnmanagedState()).Times(1); |
255 CreateNewController(); | 255 CreateNewController(); |
256 loop_.RunAllPending(); | 256 loop_.RunUntilIdle(); |
257 } | 257 } |
258 | 258 |
259 // 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 |
260 // 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 |
261 // (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). |
262 TEST_F(CloudPolicyControllerTest, InvalidSerialNumber) { | 262 TEST_F(CloudPolicyControllerTest, InvalidSerialNumber) { |
263 data_store_->SetupForTesting("device_token", "device_id", | 263 data_store_->SetupForTesting("device_token", "device_id", |
264 "who@what.com", "auth", true); | 264 "who@what.com", "auth", true); |
265 EXPECT_CALL(service_, | 265 EXPECT_CALL(service_, |
266 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) | 266 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) |
267 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_INVALID_SERIAL_NUMBER)); | 267 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_INVALID_SERIAL_NUMBER)); |
268 EXPECT_CALL(*token_fetcher_.get(), SetSerialNumberInvalidState()).Times(1); | 268 EXPECT_CALL(*token_fetcher_.get(), SetSerialNumberInvalidState()).Times(1); |
269 CreateNewController(); | 269 CreateNewController(); |
270 loop_.RunAllPending(); | 270 loop_.RunUntilIdle(); |
271 } | 271 } |
272 | 272 |
273 // If the backend reports that the domain has run out of licenses, the | 273 // If the backend reports that the domain has run out of licenses, the |
274 // controller should instruct the token fetcher not to fetch a new token | 274 // controller should instruct the token fetcher not to fetch a new token |
275 // (which will in turn set and persist the correct 'missing licenses' state). | 275 // (which will in turn set and persist the correct 'missing licenses' state). |
276 TEST_F(CloudPolicyControllerTest, MissingLicenses) { | 276 TEST_F(CloudPolicyControllerTest, MissingLicenses) { |
277 data_store_->SetupForTesting("device_token", "device_id", | 277 data_store_->SetupForTesting("device_token", "device_id", |
278 "who@what.com", "auth", true); | 278 "who@what.com", "auth", true); |
279 EXPECT_CALL(service_, | 279 EXPECT_CALL(service_, |
280 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) | 280 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) |
281 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_MISSING_LICENSES)); | 281 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_MISSING_LICENSES)); |
282 EXPECT_CALL(*token_fetcher_.get(), SetMissingLicensesState()).Times(1); | 282 EXPECT_CALL(*token_fetcher_.get(), SetMissingLicensesState()).Times(1); |
283 CreateNewController(); | 283 CreateNewController(); |
284 loop_.RunAllPending(); | 284 loop_.RunUntilIdle(); |
285 } | 285 } |
286 | 286 |
287 TEST_F(CloudPolicyControllerTest, DontSetFetchingDoneWithoutTokens) { | 287 TEST_F(CloudPolicyControllerTest, DontSetFetchingDoneWithoutTokens) { |
288 CreateNewWaitingCache(); | 288 CreateNewWaitingCache(); |
289 CreateNewController(); | 289 CreateNewController(); |
290 // Initialized without an oauth token, goes into TOKEN_UNAVAILABLE state. | 290 // Initialized without an oauth token, goes into TOKEN_UNAVAILABLE state. |
291 // This means the controller is still waiting for an oauth token fetch. | 291 // This means the controller is still waiting for an oauth token fetch. |
292 loop_.RunAllPending(); | 292 loop_.RunUntilIdle(); |
293 EXPECT_FALSE(cache_->IsReady()); | 293 EXPECT_FALSE(cache_->IsReady()); |
294 | 294 |
295 controller_->OnDeviceTokenChanged(); | 295 controller_->OnDeviceTokenChanged(); |
296 loop_.RunAllPending(); | 296 loop_.RunUntilIdle(); |
297 EXPECT_FALSE(cache_->IsReady()); | 297 EXPECT_FALSE(cache_->IsReady()); |
298 } | 298 } |
299 | 299 |
300 TEST_F(CloudPolicyControllerTest, RefreshPoliciesWithoutMaterial) { | 300 TEST_F(CloudPolicyControllerTest, RefreshPoliciesWithoutMaterial) { |
301 CreateNewWaitingCache(); | 301 CreateNewWaitingCache(); |
302 CreateNewController(); | 302 CreateNewController(); |
303 loop_.RunAllPending(); | 303 loop_.RunUntilIdle(); |
304 EXPECT_FALSE(cache_->IsReady()); | 304 EXPECT_FALSE(cache_->IsReady()); |
305 | 305 |
306 // Same scenario as the last test, but the RefreshPolicies call must always | 306 // Same scenario as the last test, but the RefreshPolicies call must always |
307 // notify the cache. | 307 // notify the cache. |
308 controller_->RefreshPolicies(false); | 308 controller_->RefreshPolicies(false); |
309 loop_.RunAllPending(); | 309 loop_.RunUntilIdle(); |
310 EXPECT_TRUE(cache_->IsReady()); | 310 EXPECT_TRUE(cache_->IsReady()); |
311 } | 311 } |
312 | 312 |
313 TEST_F(CloudPolicyControllerTest, DontSetFetchingDoneWithoutFetching) { | 313 TEST_F(CloudPolicyControllerTest, DontSetFetchingDoneWithoutFetching) { |
314 CreateNewWaitingCache(); | 314 CreateNewWaitingCache(); |
315 data_store_->SetupForTesting("device_token", "device_id", | 315 data_store_->SetupForTesting("device_token", "device_id", |
316 "who@what.com", "auth", true); | 316 "who@what.com", "auth", true); |
317 CreateNewController(); | 317 CreateNewController(); |
318 // Initialized with an oauth token, goes into TOKEN_VALID state. | 318 // Initialized with an oauth token, goes into TOKEN_VALID state. |
319 // This means the controller has an oauth token and should fetch the next | 319 // This means the controller has an oauth token and should fetch the next |
320 // token, which is the dm server register token. | 320 // token, which is the dm server register token. |
321 EXPECT_FALSE(cache_->IsReady()); | 321 EXPECT_FALSE(cache_->IsReady()); |
322 } | 322 } |
323 | 323 |
324 TEST_F(CloudPolicyControllerTest, SetFetchingDoneForUnmanagedUsers) { | 324 TEST_F(CloudPolicyControllerTest, SetFetchingDoneForUnmanagedUsers) { |
325 CreateNewWaitingCache(); | 325 CreateNewWaitingCache(); |
326 data_store_->SetupForTesting("", "device_id", | 326 data_store_->SetupForTesting("", "device_id", |
327 "user@gmail.com", "auth", true); | 327 "user@gmail.com", "auth", true); |
328 CreateNewController(); | 328 CreateNewController(); |
329 loop_.RunAllPending(); | 329 loop_.RunUntilIdle(); |
330 // User is in an unmanaged domain. | 330 // User is in an unmanaged domain. |
331 EXPECT_TRUE(cache_->IsReady()); | 331 EXPECT_TRUE(cache_->IsReady()); |
332 EXPECT_TRUE(cache_->last_policy_refresh_time().is_null()); | 332 EXPECT_TRUE(cache_->last_policy_refresh_time().is_null()); |
333 } | 333 } |
334 | 334 |
335 TEST_F(CloudPolicyControllerTest, SetFetchingDoneAfterPolicyFetch) { | 335 TEST_F(CloudPolicyControllerTest, SetFetchingDoneAfterPolicyFetch) { |
336 CreateNewWaitingCache(); | 336 CreateNewWaitingCache(); |
337 data_store_->SetupForTesting("device_token", "device_id", | 337 data_store_->SetupForTesting("device_token", "device_id", |
338 "user@enterprise.com", "auth", true); | 338 "user@enterprise.com", "auth", true); |
339 EXPECT_CALL(service_, | 339 EXPECT_CALL(service_, |
340 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) | 340 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) |
341 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow), | 341 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow), |
342 service_.SucceedJob(spdy_policy_response_))); | 342 service_.SucceedJob(spdy_policy_response_))); |
343 CreateNewController(); | 343 CreateNewController(); |
344 loop_.RunAllPending(); | 344 loop_.RunUntilIdle(); |
345 EXPECT_TRUE(cache_->IsReady()); | 345 EXPECT_TRUE(cache_->IsReady()); |
346 EXPECT_FALSE(cache_->last_policy_refresh_time().is_null()); | 346 EXPECT_FALSE(cache_->last_policy_refresh_time().is_null()); |
347 } | 347 } |
348 | 348 |
349 TEST_F(CloudPolicyControllerTest, SetFetchingDoneAfterPolicyFetchFails) { | 349 TEST_F(CloudPolicyControllerTest, SetFetchingDoneAfterPolicyFetchFails) { |
350 CreateNewWaitingCache(); | 350 CreateNewWaitingCache(); |
351 data_store_->SetupForTesting("device_token", "device_id", | 351 data_store_->SetupForTesting("device_token", "device_id", |
352 "user@enterprise.com", "auth", true); | 352 "user@enterprise.com", "auth", true); |
353 EXPECT_CALL(service_, | 353 EXPECT_CALL(service_, |
354 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) | 354 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) |
355 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow), | 355 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow), |
356 service_.FailJob(DM_STATUS_REQUEST_FAILED))); | 356 service_.FailJob(DM_STATUS_REQUEST_FAILED))); |
357 CreateNewController(); | 357 CreateNewController(); |
358 loop_.RunAllPending(); | 358 loop_.RunUntilIdle(); |
359 EXPECT_TRUE(cache_->IsReady()); | 359 EXPECT_TRUE(cache_->IsReady()); |
360 EXPECT_TRUE(cache_->last_policy_refresh_time().is_null()); | 360 EXPECT_TRUE(cache_->last_policy_refresh_time().is_null()); |
361 } | 361 } |
362 | 362 |
363 TEST_F(CloudPolicyControllerTest, DelayRefreshesIfPolicyIsInvalid) { | 363 TEST_F(CloudPolicyControllerTest, DelayRefreshesIfPolicyIsInvalid) { |
364 // Reply with a protobuf whose timestamp is too far in the future. The policy | 364 // Reply with a protobuf whose timestamp is too far in the future. The policy |
365 // cache will reject it, and the controller should detect that and go into | 365 // cache will reject it, and the controller should detect that and go into |
366 // STATE_POLICY_ERROR instead of STATE_POLICY_VALID. | 366 // STATE_POLICY_ERROR instead of STATE_POLICY_VALID. |
367 | 367 |
368 // Build the |response|. | 368 // Build the |response|. |
(...skipping 13 matching lines...) Expand all Loading... |
382 | 382 |
383 data_store_->SetupForTesting("device_token", "device_id", | 383 data_store_->SetupForTesting("device_token", "device_id", |
384 "madmax@managedchrome.com", | 384 "madmax@managedchrome.com", |
385 "auth_token", true); | 385 "auth_token", true); |
386 | 386 |
387 EXPECT_CALL(service_, | 387 EXPECT_CALL(service_, |
388 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) | 388 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) |
389 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow), | 389 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow), |
390 service_.SucceedJob(response))); | 390 service_.SucceedJob(response))); |
391 CreateNewController(); | 391 CreateNewController(); |
392 loop_.RunAllPending(); | 392 loop_.RunUntilIdle(); |
393 EXPECT_EQ(CloudPolicySubsystem::NETWORK_ERROR, notifier_.state()); | 393 EXPECT_EQ(CloudPolicySubsystem::NETWORK_ERROR, notifier_.state()); |
394 EXPECT_EQ(CloudPolicySubsystem::POLICY_NETWORK_ERROR, | 394 EXPECT_EQ(CloudPolicySubsystem::POLICY_NETWORK_ERROR, |
395 notifier_.error_details()); | 395 notifier_.error_details()); |
396 } | 396 } |
397 | 397 |
398 } // namespace policy | 398 } // namespace policy |
OLD | NEW |