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

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

Issue 12209070: Fix cloud policy duplicate registrations issue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 7 years, 10 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_client.h" 5 #include "chrome/browser/policy/cloud_policy_client.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/policy/mock_device_management_service.h" 12 #include "chrome/browser/policy/mock_device_management_service.h"
13 #include "chrome/browser/policy/proto/device_management_backend.pb.h" 13 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 using testing::Mock;
17 using testing::Return; 18 using testing::Return;
18 using testing::SaveArg; 19 using testing::SaveArg;
19 using testing::StrictMock; 20 using testing::StrictMock;
20 using testing::_; 21 using testing::_;
21 22
22 namespace em = enterprise_management; 23 namespace em = enterprise_management;
23 24
24 namespace policy { 25 namespace policy {
25 26
26 namespace { 27 namespace {
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 .WillOnce(service_.FailJob(DM_STATUS_REQUEST_FAILED)); 247 .WillOnce(service_.FailJob(DM_STATUS_REQUEST_FAILED));
247 EXPECT_CALL(service_, StartJob(_, _, _, _, _, _, _)); 248 EXPECT_CALL(service_, StartJob(_, _, _, _, _, _, _));
248 EXPECT_CALL(observer_, OnClientError(_)); 249 EXPECT_CALL(observer_, OnClientError(_));
249 client_->Register(em::DeviceRegisterRequest::USER, 250 client_->Register(em::DeviceRegisterRequest::USER,
250 kOAuthToken, std::string(), false); 251 kOAuthToken, std::string(), false);
251 EXPECT_FALSE(client_->is_registered()); 252 EXPECT_FALSE(client_->is_registered());
252 EXPECT_FALSE(client_->GetPolicyFor(policy_ns_key_)); 253 EXPECT_FALSE(client_->GetPolicyFor(policy_ns_key_));
253 EXPECT_EQ(DM_STATUS_REQUEST_FAILED, client_->status()); 254 EXPECT_EQ(DM_STATUS_REQUEST_FAILED, client_->status());
254 } 255 }
255 256
257 TEST_F(CloudPolicyClientTest, RetryRegistration) {
258 // First registration does not set the re-register flag.
259 EXPECT_FALSE(
260 registration_request_.mutable_register_request()->has_reregister());
261 MockDeviceManagementJob* register_job = NULL;
262 EXPECT_CALL(service_,
263 CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION))
264 .WillOnce(service_.CreateAsyncJob(&register_job));
265 EXPECT_CALL(service_, StartJob(dm_protocol::kValueRequestRegister,
266 "", kOAuthToken, "", "", _,
267 MatchProto(registration_request_)));
268 client_->Register(em::DeviceRegisterRequest::USER,
269 kOAuthToken, std::string(), false);
270 EXPECT_FALSE(client_->is_registered());
271 Mock::VerifyAndClearExpectations(&service_);
272
273 // Simulate a retry callback before proceeding; the re-register flag is set.
274 registration_request_.mutable_register_request()->set_reregister(true);
275 EXPECT_CALL(service_, StartJob(dm_protocol::kValueRequestRegister,
276 "", kOAuthToken, "", "", _,
277 MatchProto(registration_request_)));
278 register_job->RetryJob();
279 Mock::VerifyAndClearExpectations(&service_);
280
281 // Subsequent retries keep the flag set.
282 EXPECT_CALL(service_, StartJob(dm_protocol::kValueRequestRegister,
283 "", kOAuthToken, "", "", _,
284 MatchProto(registration_request_)));
285 register_job->RetryJob();
286 Mock::VerifyAndClearExpectations(&service_);
287 }
288
256 TEST_F(CloudPolicyClientTest, PolicyUpdate) { 289 TEST_F(CloudPolicyClientTest, PolicyUpdate) {
257 Register(); 290 Register();
258 291
259 ExpectPolicyFetch(kDMToken, dm_protocol::kValueUserAffiliationNone); 292 ExpectPolicyFetch(kDMToken, dm_protocol::kValueUserAffiliationNone);
260 EXPECT_CALL(observer_, OnPolicyFetched(_)); 293 EXPECT_CALL(observer_, OnPolicyFetched(_));
261 EXPECT_CALL(status_provider_, OnSubmittedSuccessfully()); 294 EXPECT_CALL(status_provider_, OnSubmittedSuccessfully());
262 client_->FetchPolicy(); 295 client_->FetchPolicy();
263 CheckPolicyResponse(); 296 CheckPolicyResponse();
264 297
265 policy_response_.mutable_policy_response()->clear_response(); 298 policy_response_.mutable_policy_response()->clear_response();
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 // Verify that the client got all the responses mapped to their namespaces. 467 // Verify that the client got all the responses mapped to their namespaces.
435 for (ResponseMap::iterator it = expected_responses.begin(); 468 for (ResponseMap::iterator it = expected_responses.begin();
436 it != expected_responses.end(); ++it) { 469 it != expected_responses.end(); ++it) {
437 const em::PolicyFetchResponse* response = client_->GetPolicyFor(it->first); 470 const em::PolicyFetchResponse* response = client_->GetPolicyFor(it->first);
438 ASSERT_TRUE(response); 471 ASSERT_TRUE(response);
439 EXPECT_EQ(it->second.SerializeAsString(), response->SerializeAsString()); 472 EXPECT_EQ(it->second.SerializeAsString(), response->SerializeAsString());
440 } 473 }
441 } 474 }
442 475
443 } // namespace policy 476 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698