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/mock_device_management_service.h" | 5 #include "chrome/browser/policy/cloud/mock_device_management_service.h" |
6 | 6 |
7 #include "base/message_loop/message_loop_proxy.h" | 7 #include "base/message_loop/message_loop_proxy.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/url_request/url_request_test_util.h" | 10 #include "net/url_request/url_request_test_util.h" |
11 | 11 |
12 using testing::Action; | 12 using testing::Action; |
13 | 13 |
14 namespace em = enterprise_management; | 14 namespace em = enterprise_management; |
15 | 15 |
16 namespace policy { | 16 namespace policy { |
17 namespace { | 17 namespace { |
18 | 18 |
19 const char kServerUrl[] = "https://example.com/management_service"; | |
20 | |
19 // Common mock request job functionality. | 21 // Common mock request job functionality. |
20 class MockRequestJobBase : public DeviceManagementRequestJob { | 22 class MockRequestJobBase : public DeviceManagementRequestJob { |
21 public: | 23 public: |
22 MockRequestJobBase(JobType type, | 24 MockRequestJobBase(JobType type, |
23 MockDeviceManagementService* service) | 25 MockDeviceManagementService* service) |
24 : DeviceManagementRequestJob(type, std::string(), std::string()), | 26 : DeviceManagementRequestJob(type, std::string(), std::string()), |
25 service_(service) {} | 27 service_(service) {} |
26 virtual ~MockRequestJobBase() {} | 28 virtual ~MockRequestJobBase() {} |
27 | 29 |
28 protected: | 30 protected: |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 } | 113 } |
112 | 114 |
113 ACTION_P2(CreateAsyncMockDeviceManagementJob, service, mock_job) { | 115 ACTION_P2(CreateAsyncMockDeviceManagementJob, service, mock_job) { |
114 AsyncRequestJob* job = new AsyncRequestJob(arg0, service); | 116 AsyncRequestJob* job = new AsyncRequestJob(arg0, service); |
115 *mock_job = job; | 117 *mock_job = job; |
116 return job; | 118 return job; |
117 } | 119 } |
118 | 120 |
119 MockDeviceManagementJob::~MockDeviceManagementJob() {} | 121 MockDeviceManagementJob::~MockDeviceManagementJob() {} |
120 | 122 |
123 MockDeviceManagementServiceConfiguration:: | |
124 MockDeviceManagementServiceConfiguration() | |
125 : server_url_(kServerUrl) {} | |
126 | |
127 MockDeviceManagementServiceConfiguration:: | |
128 MockDeviceManagementServiceConfiguration(const std::string& server_url) | |
129 : server_url_(server_url) {} | |
130 | |
131 MockDeviceManagementServiceConfiguration:: | |
132 ~MockDeviceManagementServiceConfiguration() {} | |
133 | |
134 std::string MockDeviceManagementServiceConfiguration::GetServerUrl() { | |
135 return server_url_; | |
136 } | |
137 | |
138 std::string MockDeviceManagementServiceConfiguration::GetUserAgent() { | |
139 return "Chrome 1.2.3(456)"; | |
pastarmovj
2013/10/02 11:14:10
nit: Can you please move those up to be named cons
Joao da Silva
2013/10/02 11:37:40
Done.
| |
140 } | |
141 | |
142 std::string MockDeviceManagementServiceConfiguration::GetAgentParameter() { | |
143 return GetUserAgent(); | |
144 } | |
145 | |
146 std::string MockDeviceManagementServiceConfiguration::GetPlatformParameter() { | |
147 return "Test|Unit|1.2.3"; | |
pastarmovj
2013/10/02 11:14:10
ditto.
Joao da Silva
2013/10/02 11:37:40
Done.
| |
148 } | |
149 | |
121 MockDeviceManagementService::MockDeviceManagementService() | 150 MockDeviceManagementService::MockDeviceManagementService() |
122 : DeviceManagementService( | 151 : DeviceManagementService(scoped_ptr<Configuration>( |
123 new net::TestURLRequestContextGetter( | 152 new MockDeviceManagementServiceConfiguration), |
124 base::MessageLoopProxy::current()), | 153 new net::TestURLRequestContextGetter( |
125 std::string(), | 154 base::MessageLoopProxy::current())) {} |
126 std::string(), | |
127 std::string(), | |
128 std::string()) {} | |
129 | 155 |
130 MockDeviceManagementService::~MockDeviceManagementService() {} | 156 MockDeviceManagementService::~MockDeviceManagementService() {} |
131 | 157 |
132 Action<MockDeviceManagementService::CreateJobFunction> | 158 Action<MockDeviceManagementService::CreateJobFunction> |
133 MockDeviceManagementService::SucceedJob( | 159 MockDeviceManagementService::SucceedJob( |
134 const em::DeviceManagementResponse& response) { | 160 const em::DeviceManagementResponse& response) { |
135 return CreateSyncMockDeviceManagementJob(this, DM_STATUS_SUCCESS, response); | 161 return CreateSyncMockDeviceManagementJob(this, DM_STATUS_SUCCESS, response); |
136 } | 162 } |
137 | 163 |
138 Action<MockDeviceManagementService::CreateJobFunction> | 164 Action<MockDeviceManagementService::CreateJobFunction> |
139 MockDeviceManagementService::FailJob(DeviceManagementStatus status) { | 165 MockDeviceManagementService::FailJob(DeviceManagementStatus status) { |
140 const em::DeviceManagementResponse dummy_response; | 166 const em::DeviceManagementResponse dummy_response; |
141 return CreateSyncMockDeviceManagementJob(this, status, dummy_response); | 167 return CreateSyncMockDeviceManagementJob(this, status, dummy_response); |
142 } | 168 } |
143 | 169 |
144 Action<MockDeviceManagementService::CreateJobFunction> | 170 Action<MockDeviceManagementService::CreateJobFunction> |
145 MockDeviceManagementService::CreateAsyncJob(MockDeviceManagementJob** job) { | 171 MockDeviceManagementService::CreateAsyncJob(MockDeviceManagementJob** job) { |
146 return CreateAsyncMockDeviceManagementJob(this, job); | 172 return CreateAsyncMockDeviceManagementJob(this, job); |
147 } | 173 } |
148 | 174 |
149 } // namespace policy | 175 } // namespace policy |
OLD | NEW |