| 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 "components/policy/core/common/cloud/cloud_policy_client.h" | 5 #include "components/policy/core/common/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" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "components/policy/core/common/cloud/mock_cloud_policy_client.h" | 15 #include "components/policy/core/common/cloud/mock_cloud_policy_client.h" |
| 15 #include "components/policy/core/common/cloud/mock_device_management_service.h" | 16 #include "components/policy/core/common/cloud/mock_device_management_service.h" |
| 16 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
| 17 #include "net/url_request/url_request_test_util.h" | 18 #include "net/url_request/url_request_test_util.h" |
| 18 #include "policy/proto/device_management_backend.pb.h" | 19 #include "policy/proto/device_management_backend.pb.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 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 em::DeviceManagementResponse upload_certificate_response_; | 198 em::DeviceManagementResponse upload_certificate_response_; |
| 198 | 199 |
| 199 base::MessageLoop loop_; | 200 base::MessageLoop loop_; |
| 200 std::string client_id_; | 201 std::string client_id_; |
| 201 PolicyNamespaceKey policy_ns_key_; | 202 PolicyNamespaceKey policy_ns_key_; |
| 202 MockDeviceManagementService service_; | 203 MockDeviceManagementService service_; |
| 203 StrictMock<MockStatusProvider> status_provider_; | 204 StrictMock<MockStatusProvider> status_provider_; |
| 204 StrictMock<MockCloudPolicyClientObserver> observer_; | 205 StrictMock<MockCloudPolicyClientObserver> observer_; |
| 205 StrictMock<MockUploadCertificateObserver> upload_certificate_observer_; | 206 StrictMock<MockUploadCertificateObserver> upload_certificate_observer_; |
| 206 scoped_ptr<CloudPolicyClient> client_; | 207 scoped_ptr<CloudPolicyClient> client_; |
| 207 // Cached weak pointer to the client's request context. | 208 // Pointer to the client's request context. |
| 208 net::URLRequestContextGetter* request_context_; | 209 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 209 }; | 210 }; |
| 210 | 211 |
| 211 TEST_F(CloudPolicyClientTest, Init) { | 212 TEST_F(CloudPolicyClientTest, Init) { |
| 212 EXPECT_CALL(service_, CreateJob(_, _)).Times(0); | 213 EXPECT_CALL(service_, CreateJob(_, _)).Times(0); |
| 213 EXPECT_FALSE(client_->is_registered()); | 214 EXPECT_FALSE(client_->is_registered()); |
| 214 EXPECT_FALSE(client_->GetPolicyFor(policy_ns_key_)); | 215 EXPECT_FALSE(client_->GetPolicyFor(policy_ns_key_)); |
| 215 EXPECT_EQ(0, client_->fetched_invalidation_version()); | 216 EXPECT_EQ(0, client_->fetched_invalidation_version()); |
| 216 } | 217 } |
| 217 | 218 |
| 218 TEST_F(CloudPolicyClientTest, SetupRegistrationAndPolicyFetch) { | 219 TEST_F(CloudPolicyClientTest, SetupRegistrationAndPolicyFetch) { |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 EXPECT_CALL(service_, StartJob(_, _, _, _, _, _, _)); | 582 EXPECT_CALL(service_, StartJob(_, _, _, _, _, _, _)); |
| 582 EXPECT_CALL(observer_, OnClientError(_)); | 583 EXPECT_CALL(observer_, OnClientError(_)); |
| 583 CloudPolicyClient::StatusCallback callback = base::Bind( | 584 CloudPolicyClient::StatusCallback callback = base::Bind( |
| 584 &MockUploadCertificateObserver::OnUploadComplete, | 585 &MockUploadCertificateObserver::OnUploadComplete, |
| 585 base::Unretained(&upload_certificate_observer_)); | 586 base::Unretained(&upload_certificate_observer_)); |
| 586 client_->UploadCertificate(kDeviceCertificate, callback); | 587 client_->UploadCertificate(kDeviceCertificate, callback); |
| 587 EXPECT_EQ(DM_STATUS_REQUEST_FAILED, client_->status()); | 588 EXPECT_EQ(DM_STATUS_REQUEST_FAILED, client_->status()); |
| 588 } | 589 } |
| 589 | 590 |
| 590 } // namespace policy | 591 } // namespace policy |
| OLD | NEW |