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_client.h" | 5 #include "chrome/browser/policy/cloud_policy_client.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "chrome/browser/policy/mock_device_management_service.h" | 9 #include "chrome/browser/policy/mock_device_management_service.h" |
10 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 10 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 80 |
81 unregistration_request_.mutable_unregister_request(); | 81 unregistration_request_.mutable_unregister_request(); |
82 unregistration_response_.mutable_unregister_response(); | 82 unregistration_response_.mutable_unregister_response(); |
83 } | 83 } |
84 | 84 |
85 virtual void SetUp() OVERRIDE { | 85 virtual void SetUp() OVERRIDE { |
86 EXPECT_CALL(status_provider_, GetDeviceStatus(_)) | 86 EXPECT_CALL(status_provider_, GetDeviceStatus(_)) |
87 .WillRepeatedly(Return(false)); | 87 .WillRepeatedly(Return(false)); |
88 EXPECT_CALL(status_provider_, GetSessionStatus(_)) | 88 EXPECT_CALL(status_provider_, GetSessionStatus(_)) |
89 .WillRepeatedly(Return(false)); | 89 .WillRepeatedly(Return(false)); |
90 CreateClient(USER_AFFILIATION_NONE, POLICY_SCOPE_USER); | 90 CreateClient(USER_AFFILIATION_NONE, CloudPolicyClient::POLICY_TYPE_USER); |
91 } | 91 } |
92 | 92 |
93 virtual void TearDown() OVERRIDE { | 93 virtual void TearDown() OVERRIDE { |
94 client_->RemoveObserver(&observer_); | 94 client_->RemoveObserver(&observer_); |
95 } | 95 } |
96 | 96 |
97 void Register() { | 97 void Register() { |
98 EXPECT_CALL(observer_, OnRegistrationStateChanged(_)); | 98 EXPECT_CALL(observer_, OnRegistrationStateChanged(_)); |
99 client_->SetupRegistration(kDMToken, client_id_); | 99 client_->SetupRegistration(kDMToken, client_id_); |
100 } | 100 } |
101 | 101 |
102 void CreateClient(UserAffiliation user_affiliation, PolicyScope scope) { | 102 void CreateClient(UserAffiliation user_affiliation, |
| 103 CloudPolicyClient::PolicyType type) { |
103 if (client_.get()) | 104 if (client_.get()) |
104 client_->RemoveObserver(&observer_); | 105 client_->RemoveObserver(&observer_); |
105 | 106 |
106 client_.reset(new CloudPolicyClient(kMachineID, kMachineModel, | 107 client_.reset(new CloudPolicyClient(kMachineID, kMachineModel, |
107 user_affiliation, scope, | 108 user_affiliation, type, |
108 &status_provider_, &service_)); | 109 &status_provider_, &service_)); |
109 client_->AddObserver(&observer_); | 110 client_->AddObserver(&observer_); |
110 } | 111 } |
111 | 112 |
112 void ExpectRegistration(const std::string& oauth_token) { | 113 void ExpectRegistration(const std::string& oauth_token) { |
113 EXPECT_CALL(service_, | 114 EXPECT_CALL(service_, |
114 CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION)) | 115 CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION)) |
115 .WillOnce(service_.SucceedJob(registration_response_)); | 116 .WillOnce(service_.SucceedJob(registration_response_)); |
116 EXPECT_CALL(service_, StartJob(dm_protocol::kValueRequestRegister, | 117 EXPECT_CALL(service_, StartJob(dm_protocol::kValueRequestRegister, |
117 "", oauth_token, "", "", _, | 118 "", oauth_token, "", "", _, |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION)) | 332 CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION)) |
332 .WillOnce(service_.FailJob(DM_STATUS_REQUEST_FAILED)); | 333 .WillOnce(service_.FailJob(DM_STATUS_REQUEST_FAILED)); |
333 EXPECT_CALL(service_, StartJob(_, _, _, _, _, _, _)); | 334 EXPECT_CALL(service_, StartJob(_, _, _, _, _, _, _)); |
334 EXPECT_CALL(observer_, OnClientError(_)); | 335 EXPECT_CALL(observer_, OnClientError(_)); |
335 client_->Unregister(); | 336 client_->Unregister(); |
336 EXPECT_TRUE(client_->is_registered()); | 337 EXPECT_TRUE(client_->is_registered()); |
337 EXPECT_EQ(DM_STATUS_REQUEST_FAILED, client_->status()); | 338 EXPECT_EQ(DM_STATUS_REQUEST_FAILED, client_->status()); |
338 } | 339 } |
339 | 340 |
340 } // namespace policy | 341 } // namespace policy |
OLD | NEW |