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

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

Issue 10664017: Introduce a new error code from the DM server - 402 - missing licenses. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 5 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"
(...skipping 22 matching lines...) Expand all
33 33
34 class MockDeviceTokenFetcher : public DeviceTokenFetcher { 34 class MockDeviceTokenFetcher : public DeviceTokenFetcher {
35 public: 35 public:
36 explicit MockDeviceTokenFetcher(CloudPolicyCacheBase* cache) 36 explicit MockDeviceTokenFetcher(CloudPolicyCacheBase* cache)
37 : DeviceTokenFetcher(NULL, cache, NULL, NULL) {} 37 : DeviceTokenFetcher(NULL, cache, NULL, NULL) {}
38 virtual ~MockDeviceTokenFetcher() {} 38 virtual ~MockDeviceTokenFetcher() {}
39 39
40 MOCK_METHOD0(FetchToken, void()); 40 MOCK_METHOD0(FetchToken, void());
41 MOCK_METHOD0(SetUnmanagedState, void()); 41 MOCK_METHOD0(SetUnmanagedState, void());
42 MOCK_METHOD0(SetSerialNumberInvalidState, void()); 42 MOCK_METHOD0(SetSerialNumberInvalidState, void());
43 MOCK_METHOD0(SetMissingLicensesState, void());
43 44
44 private: 45 private:
45 DISALLOW_COPY_AND_ASSIGN(MockDeviceTokenFetcher); 46 DISALLOW_COPY_AND_ASSIGN(MockDeviceTokenFetcher);
46 }; 47 };
47 48
48 class CloudPolicyControllerTest : public testing::Test { 49 class CloudPolicyControllerTest : public testing::Test {
49 public: 50 public:
50 CloudPolicyControllerTest() 51 CloudPolicyControllerTest()
51 : ui_thread_(BrowserThread::UI, &loop_), 52 : ui_thread_(BrowserThread::UI, &loop_),
52 file_thread_(BrowserThread::FILE, &loop_) { 53 file_thread_(BrowserThread::FILE, &loop_) {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 data_store_->SetupForTesting("device_token", "device_id", 263 data_store_->SetupForTesting("device_token", "device_id",
263 "who@what.com", "auth", true); 264 "who@what.com", "auth", true);
264 EXPECT_CALL(service_, 265 EXPECT_CALL(service_,
265 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) 266 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
266 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_INVALID_SERIAL_NUMBER)); 267 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_INVALID_SERIAL_NUMBER));
267 EXPECT_CALL(*token_fetcher_.get(), SetSerialNumberInvalidState()).Times(1); 268 EXPECT_CALL(*token_fetcher_.get(), SetSerialNumberInvalidState()).Times(1);
268 CreateNewController(); 269 CreateNewController();
269 loop_.RunAllPending(); 270 loop_.RunAllPending();
270 } 271 }
271 272
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
275 // (which will in turn set and persist the correct 'missing licenses' state).
276 TEST_F(CloudPolicyControllerTest, MissingLicenses) {
277 data_store_->SetupForTesting("device_token", "device_id",
278 "who@what.com", "auth", true);
279 EXPECT_CALL(service_,
280 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
281 .WillOnce(service_.FailJob(DM_STATUS_MISSING_LICENSES));
282 EXPECT_CALL(*token_fetcher_.get(), SetMissingLicensesState()).Times(1);
283 CreateNewController();
284 loop_.RunAllPending();
285 }
286
272 TEST_F(CloudPolicyControllerTest, DontSetFetchingDoneWithoutTokens) { 287 TEST_F(CloudPolicyControllerTest, DontSetFetchingDoneWithoutTokens) {
273 CreateNewWaitingCache(); 288 CreateNewWaitingCache();
274 CreateNewController(); 289 CreateNewController();
275 // Initialized without an oauth token, goes into TOKEN_UNAVAILABLE state. 290 // Initialized without an oauth token, goes into TOKEN_UNAVAILABLE state.
276 // 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.
277 loop_.RunAllPending(); 292 loop_.RunAllPending();
278 EXPECT_FALSE(cache_->IsReady()); 293 EXPECT_FALSE(cache_->IsReady());
279 294
280 controller_->OnDeviceTokenChanged(); 295 controller_->OnDeviceTokenChanged();
281 loop_.RunAllPending(); 296 loop_.RunAllPending();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow), 389 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow),
375 service_.SucceedJob(response))); 390 service_.SucceedJob(response)));
376 CreateNewController(); 391 CreateNewController();
377 loop_.RunAllPending(); 392 loop_.RunAllPending();
378 EXPECT_EQ(CloudPolicySubsystem::NETWORK_ERROR, notifier_.state()); 393 EXPECT_EQ(CloudPolicySubsystem::NETWORK_ERROR, notifier_.state());
379 EXPECT_EQ(CloudPolicySubsystem::POLICY_NETWORK_ERROR, 394 EXPECT_EQ(CloudPolicySubsystem::POLICY_NETWORK_ERROR,
380 notifier_.error_details()); 395 notifier_.error_details());
381 } 396 }
382 397
383 } // namespace policy 398 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698