Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: chrome/browser/policy/cloud/mock_device_management_service.cc

Issue 25690003: Refactored the DeviceManagementService to get its parameters from a delegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 const char kUserAgent[] = "Chrome 1.2.3(456)";
21 const char kPlatform[] = "Test|Unit|1.2.3";
22
19 // Common mock request job functionality. 23 // Common mock request job functionality.
20 class MockRequestJobBase : public DeviceManagementRequestJob { 24 class MockRequestJobBase : public DeviceManagementRequestJob {
21 public: 25 public:
22 MockRequestJobBase(JobType type, 26 MockRequestJobBase(JobType type,
23 MockDeviceManagementService* service) 27 MockDeviceManagementService* service)
24 : DeviceManagementRequestJob(type, std::string(), std::string()), 28 : DeviceManagementRequestJob(type, std::string(), std::string()),
25 service_(service) {} 29 service_(service) {}
26 virtual ~MockRequestJobBase() {} 30 virtual ~MockRequestJobBase() {}
27 31
28 protected: 32 protected:
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 115 }
112 116
113 ACTION_P2(CreateAsyncMockDeviceManagementJob, service, mock_job) { 117 ACTION_P2(CreateAsyncMockDeviceManagementJob, service, mock_job) {
114 AsyncRequestJob* job = new AsyncRequestJob(arg0, service); 118 AsyncRequestJob* job = new AsyncRequestJob(arg0, service);
115 *mock_job = job; 119 *mock_job = job;
116 return job; 120 return job;
117 } 121 }
118 122
119 MockDeviceManagementJob::~MockDeviceManagementJob() {} 123 MockDeviceManagementJob::~MockDeviceManagementJob() {}
120 124
125 MockDeviceManagementServiceConfiguration::
126 MockDeviceManagementServiceConfiguration()
127 : server_url_(kServerUrl) {}
128
129 MockDeviceManagementServiceConfiguration::
130 MockDeviceManagementServiceConfiguration(const std::string& server_url)
131 : server_url_(server_url) {}
132
133 MockDeviceManagementServiceConfiguration::
134 ~MockDeviceManagementServiceConfiguration() {}
135
136 std::string MockDeviceManagementServiceConfiguration::GetServerUrl() {
137 return server_url_;
138 }
139
140 std::string MockDeviceManagementServiceConfiguration::GetUserAgent() {
141 return kUserAgent;
142 }
143
144 std::string MockDeviceManagementServiceConfiguration::GetAgentParameter() {
145 return kUserAgent;
146 }
147
148 std::string MockDeviceManagementServiceConfiguration::GetPlatformParameter() {
149 return kPlatform;
150 }
151
121 MockDeviceManagementService::MockDeviceManagementService() 152 MockDeviceManagementService::MockDeviceManagementService()
122 : DeviceManagementService( 153 : DeviceManagementService(scoped_ptr<Configuration>(
123 new net::TestURLRequestContextGetter( 154 new MockDeviceManagementServiceConfiguration),
124 base::MessageLoopProxy::current()), 155 new net::TestURLRequestContextGetter(
125 std::string(), 156 base::MessageLoopProxy::current())) {}
126 std::string(),
127 std::string(),
128 std::string()) {}
129 157
130 MockDeviceManagementService::~MockDeviceManagementService() {} 158 MockDeviceManagementService::~MockDeviceManagementService() {}
131 159
132 Action<MockDeviceManagementService::CreateJobFunction> 160 Action<MockDeviceManagementService::CreateJobFunction>
133 MockDeviceManagementService::SucceedJob( 161 MockDeviceManagementService::SucceedJob(
134 const em::DeviceManagementResponse& response) { 162 const em::DeviceManagementResponse& response) {
135 return CreateSyncMockDeviceManagementJob(this, DM_STATUS_SUCCESS, response); 163 return CreateSyncMockDeviceManagementJob(this, DM_STATUS_SUCCESS, response);
136 } 164 }
137 165
138 Action<MockDeviceManagementService::CreateJobFunction> 166 Action<MockDeviceManagementService::CreateJobFunction>
139 MockDeviceManagementService::FailJob(DeviceManagementStatus status) { 167 MockDeviceManagementService::FailJob(DeviceManagementStatus status) {
140 const em::DeviceManagementResponse dummy_response; 168 const em::DeviceManagementResponse dummy_response;
141 return CreateSyncMockDeviceManagementJob(this, status, dummy_response); 169 return CreateSyncMockDeviceManagementJob(this, status, dummy_response);
142 } 170 }
143 171
144 Action<MockDeviceManagementService::CreateJobFunction> 172 Action<MockDeviceManagementService::CreateJobFunction>
145 MockDeviceManagementService::CreateAsyncJob(MockDeviceManagementJob** job) { 173 MockDeviceManagementService::CreateAsyncJob(MockDeviceManagementJob** job) {
146 return CreateAsyncMockDeviceManagementJob(this, job); 174 return CreateAsyncMockDeviceManagementJob(this, job);
147 } 175 }
148 176
149 } // namespace policy 177 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud/mock_device_management_service.h ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698