| 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/cloud_policy_client.h" | 5 #include "chrome/browser/policy/cloud/cloud_policy_client.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 StrictMock<MockStatusProvider> status_provider_; | 193 StrictMock<MockStatusProvider> status_provider_; |
| 194 StrictMock<MockCloudPolicyClientObserver> observer_; | 194 StrictMock<MockCloudPolicyClientObserver> observer_; |
| 195 StrictMock<MockUploadCertificateObserver> upload_certificate_observer_; | 195 StrictMock<MockUploadCertificateObserver> upload_certificate_observer_; |
| 196 scoped_ptr<CloudPolicyClient> client_; | 196 scoped_ptr<CloudPolicyClient> client_; |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 TEST_F(CloudPolicyClientTest, Init) { | 199 TEST_F(CloudPolicyClientTest, Init) { |
| 200 EXPECT_CALL(service_, CreateJob(_)).Times(0); | 200 EXPECT_CALL(service_, CreateJob(_)).Times(0); |
| 201 EXPECT_FALSE(client_->is_registered()); | 201 EXPECT_FALSE(client_->is_registered()); |
| 202 EXPECT_FALSE(client_->GetPolicyFor(policy_ns_key_)); | 202 EXPECT_FALSE(client_->GetPolicyFor(policy_ns_key_)); |
| 203 EXPECT_EQ(0, client_->fetched_invalidation_version()); |
| 203 } | 204 } |
| 204 | 205 |
| 205 TEST_F(CloudPolicyClientTest, SetupRegistrationAndPolicyFetch) { | 206 TEST_F(CloudPolicyClientTest, SetupRegistrationAndPolicyFetch) { |
| 206 EXPECT_CALL(service_, CreateJob(_)).Times(0); | 207 EXPECT_CALL(service_, CreateJob(_)).Times(0); |
| 207 EXPECT_CALL(observer_, OnRegistrationStateChanged(_)); | 208 EXPECT_CALL(observer_, OnRegistrationStateChanged(_)); |
| 208 client_->SetupRegistration(kDMToken, client_id_); | 209 client_->SetupRegistration(kDMToken, client_id_); |
| 209 EXPECT_TRUE(client_->is_registered()); | 210 EXPECT_TRUE(client_->is_registered()); |
| 210 EXPECT_FALSE(client_->GetPolicyFor(policy_ns_key_)); | 211 EXPECT_FALSE(client_->GetPolicyFor(policy_ns_key_)); |
| 211 | 212 |
| 212 ExpectPolicyFetch(kDMToken, dm_protocol::kValueUserAffiliationNone); | 213 ExpectPolicyFetch(kDMToken, dm_protocol::kValueUserAffiliationNone); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 (timestamp - base::Time::UnixEpoch()).InMilliseconds()); | 339 (timestamp - base::Time::UnixEpoch()).InMilliseconds()); |
| 339 policy_fetch_request->set_public_key_version(42); | 340 policy_fetch_request->set_public_key_version(42); |
| 340 | 341 |
| 341 ExpectPolicyFetch(kDMToken, dm_protocol::kValueUserAffiliationNone); | 342 ExpectPolicyFetch(kDMToken, dm_protocol::kValueUserAffiliationNone); |
| 342 EXPECT_CALL(observer_, OnPolicyFetched(_)); | 343 EXPECT_CALL(observer_, OnPolicyFetched(_)); |
| 343 EXPECT_CALL(status_provider_, OnSubmittedSuccessfully()); | 344 EXPECT_CALL(status_provider_, OnSubmittedSuccessfully()); |
| 344 client_->FetchPolicy(); | 345 client_->FetchPolicy(); |
| 345 CheckPolicyResponse(); | 346 CheckPolicyResponse(); |
| 346 } | 347 } |
| 347 | 348 |
| 349 TEST_F(CloudPolicyClientTest, PolicyFetchWithInvalidation) { |
| 350 Register(); |
| 351 |
| 352 int64 previous_version = client_->fetched_invalidation_version(); |
| 353 client_->SetInvalidationInfo(12345, "12345"); |
| 354 EXPECT_EQ(previous_version, client_->fetched_invalidation_version()); |
| 355 em::PolicyFetchRequest* policy_fetch_request = |
| 356 policy_request_.mutable_policy_request()->mutable_request(0); |
| 357 policy_fetch_request->set_invalidation_version(12345); |
| 358 policy_fetch_request->set_invalidation_payload("12345"); |
| 359 |
| 360 ExpectPolicyFetch(kDMToken, dm_protocol::kValueUserAffiliationNone); |
| 361 EXPECT_CALL(observer_, OnPolicyFetched(_)); |
| 362 EXPECT_CALL(status_provider_, OnSubmittedSuccessfully()); |
| 363 client_->FetchPolicy(); |
| 364 CheckPolicyResponse(); |
| 365 EXPECT_EQ(12345, client_->fetched_invalidation_version()); |
| 366 } |
| 367 |
| 368 TEST_F(CloudPolicyClientTest, PolicyFetchWithInvalidationNoPayload) { |
| 369 Register(); |
| 370 |
| 371 int64 previous_version = client_->fetched_invalidation_version(); |
| 372 client_->SetInvalidationInfo(-12345, std::string()); |
| 373 EXPECT_EQ(previous_version, client_->fetched_invalidation_version()); |
| 374 |
| 375 ExpectPolicyFetch(kDMToken, dm_protocol::kValueUserAffiliationNone); |
| 376 EXPECT_CALL(observer_, OnPolicyFetched(_)); |
| 377 EXPECT_CALL(status_provider_, OnSubmittedSuccessfully()); |
| 378 client_->FetchPolicy(); |
| 379 CheckPolicyResponse(); |
| 380 EXPECT_EQ(-12345, client_->fetched_invalidation_version()); |
| 381 } |
| 382 |
| 348 TEST_F(CloudPolicyClientTest, BadPolicyResponse) { | 383 TEST_F(CloudPolicyClientTest, BadPolicyResponse) { |
| 349 Register(); | 384 Register(); |
| 350 | 385 |
| 351 policy_response_.clear_policy_response(); | 386 policy_response_.clear_policy_response(); |
| 352 ExpectPolicyFetch(kDMToken, dm_protocol::kValueUserAffiliationNone); | 387 ExpectPolicyFetch(kDMToken, dm_protocol::kValueUserAffiliationNone); |
| 353 EXPECT_CALL(observer_, OnClientError(_)); | 388 EXPECT_CALL(observer_, OnClientError(_)); |
| 354 client_->FetchPolicy(); | 389 client_->FetchPolicy(); |
| 355 EXPECT_FALSE(client_->GetPolicyFor(policy_ns_key_)); | 390 EXPECT_FALSE(client_->GetPolicyFor(policy_ns_key_)); |
| 356 EXPECT_EQ(DM_STATUS_RESPONSE_DECODING_ERROR, client_->status()); | 391 EXPECT_EQ(DM_STATUS_RESPONSE_DECODING_ERROR, client_->status()); |
| 357 | 392 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 EXPECT_CALL(service_, StartJob(_, _, _, _, _, _, _)); | 560 EXPECT_CALL(service_, StartJob(_, _, _, _, _, _, _)); |
| 526 EXPECT_CALL(observer_, OnClientError(_)); | 561 EXPECT_CALL(observer_, OnClientError(_)); |
| 527 CloudPolicyClient::StatusCallback callback = base::Bind( | 562 CloudPolicyClient::StatusCallback callback = base::Bind( |
| 528 &MockUploadCertificateObserver::OnUploadComplete, | 563 &MockUploadCertificateObserver::OnUploadComplete, |
| 529 base::Unretained(&upload_certificate_observer_)); | 564 base::Unretained(&upload_certificate_observer_)); |
| 530 client_->UploadCertificate(kDeviceCertificate, callback); | 565 client_->UploadCertificate(kDeviceCertificate, callback); |
| 531 EXPECT_EQ(DM_STATUS_REQUEST_FAILED, client_->status()); | 566 EXPECT_EQ(DM_STATUS_REQUEST_FAILED, client_->status()); |
| 532 } | 567 } |
| 533 | 568 |
| 534 } // namespace policy | 569 } // namespace policy |
| OLD | NEW |