| 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/mock_device_management_service.h" | 5 #include "chrome/browser/policy/mock_device_management_service.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" |
| 8 |
| 9 using testing::Action; |
| 10 |
| 7 namespace em = enterprise_management; | 11 namespace em = enterprise_management; |
| 8 | 12 |
| 9 namespace policy { | 13 namespace policy { |
| 10 | 14 |
| 11 class MockDeviceManagementRequestJob : public DeviceManagementRequestJob { | 15 class MockDeviceManagementRequestJob : public DeviceManagementRequestJob { |
| 12 public: | 16 public: |
| 13 MockDeviceManagementRequestJob( | 17 MockDeviceManagementRequestJob( |
| 14 JobType type, | 18 JobType type, |
| 15 MockDeviceManagementService* service, | 19 MockDeviceManagementService* service, |
| 16 DeviceManagementStatus status, | 20 DeviceManagementStatus status, |
| 17 const enterprise_management::DeviceManagementResponse& response) | 21 const enterprise_management::DeviceManagementResponse& response) |
| 18 : DeviceManagementRequestJob(type), | 22 : DeviceManagementRequestJob(type), |
| 19 service_(service), | 23 service_(service), |
| 20 status_(status), | 24 status_(status), |
| 21 response_(response) {} | 25 response_(response) {} |
| 26 virtual ~MockDeviceManagementRequestJob() {} |
| 22 | 27 |
| 23 protected: | 28 protected: |
| 24 virtual void Run() OVERRIDE { | 29 virtual void Run() OVERRIDE { |
| 25 service_->StartJob(this); | 30 service_->StartJob(ExtractParameter(dm_protocol::kParamRequest), |
| 31 gaia_token_, |
| 32 ExtractParameter(dm_protocol::kParamOAuthToken), |
| 33 dm_token_, |
| 34 ExtractParameter(dm_protocol::kParamUserAffiliation), |
| 35 ExtractParameter(dm_protocol::kParamDeviceID), |
| 36 request_); |
| 26 callback_.Run(status_, response_); | 37 callback_.Run(status_, response_); |
| 27 } | 38 } |
| 28 | 39 |
| 29 private: | 40 private: |
| 41 // Searches for a query parameter and returns the associated value. |
| 42 const std::string& ExtractParameter(const std::string& name) const { |
| 43 for (ParameterMap::const_iterator entry(query_params_.begin()); |
| 44 entry != query_params_.end(); |
| 45 ++entry) { |
| 46 if (name == entry->first) |
| 47 return entry->second; |
| 48 } |
| 49 |
| 50 return EmptyString(); |
| 51 } |
| 52 |
| 30 MockDeviceManagementService* service_; | 53 MockDeviceManagementService* service_; |
| 31 DeviceManagementStatus status_; | 54 DeviceManagementStatus status_; |
| 32 enterprise_management::DeviceManagementResponse response_; | 55 enterprise_management::DeviceManagementResponse response_; |
| 33 | 56 |
| 34 DISALLOW_COPY_AND_ASSIGN(MockDeviceManagementRequestJob); | 57 DISALLOW_COPY_AND_ASSIGN(MockDeviceManagementRequestJob); |
| 35 }; | 58 }; |
| 36 | 59 |
| 37 ACTION_P3(CreateMockDeviceManagementRequestJob, service, status, response) { | 60 ACTION_P3(CreateMockDeviceManagementRequestJob, service, status, response) { |
| 38 return new MockDeviceManagementRequestJob(arg0, service, status, response); | 61 return new MockDeviceManagementRequestJob(arg0, service, status, response); |
| 39 } | 62 } |
| 40 | 63 |
| 41 MockDeviceManagementService::MockDeviceManagementService() | 64 MockDeviceManagementService::MockDeviceManagementService() |
| 42 : DeviceManagementService("") {} | 65 : DeviceManagementService("") {} |
| 43 | 66 |
| 44 MockDeviceManagementService::~MockDeviceManagementService() {} | 67 MockDeviceManagementService::~MockDeviceManagementService() {} |
| 45 | 68 |
| 46 testing::Action<MockDeviceManagementService::CreateJobFunction> | 69 Action<MockDeviceManagementService::CreateJobFunction> |
| 47 MockDeviceManagementService::SucceedJob( | 70 MockDeviceManagementService::SucceedJob( |
| 48 const enterprise_management::DeviceManagementResponse& response) { | 71 const enterprise_management::DeviceManagementResponse& response) { |
| 49 return CreateMockDeviceManagementRequestJob(this, DM_STATUS_SUCCESS, | 72 return CreateMockDeviceManagementRequestJob(this, DM_STATUS_SUCCESS, |
| 50 response); | 73 response); |
| 51 } | 74 } |
| 52 | 75 |
| 53 testing::Action<MockDeviceManagementService::CreateJobFunction> | 76 Action<MockDeviceManagementService::CreateJobFunction> |
| 54 MockDeviceManagementService::FailJob(DeviceManagementStatus status) { | 77 MockDeviceManagementService::FailJob(DeviceManagementStatus status) { |
| 55 const enterprise_management::DeviceManagementResponse dummy_response; | 78 const enterprise_management::DeviceManagementResponse dummy_response; |
| 56 return CreateMockDeviceManagementRequestJob(this, status, dummy_response); | 79 return CreateMockDeviceManagementRequestJob(this, status, dummy_response); |
| 57 } | 80 } |
| 58 | 81 |
| 59 } // namespace policy | 82 } // namespace policy |
| OLD | NEW |