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

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

Issue 9109009: Introduce CloudPolicyClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 8 years, 8 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/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 using testing::AllOf;
11 using testing::Matcher;
Joao da Silva 2012/04/16 23:45:00 These 2 are not used
Mattias Nissler (ping if slow) 2012/05/22 14:05:26 Done.
12
7 namespace em = enterprise_management; 13 namespace em = enterprise_management;
8 14
9 namespace policy { 15 namespace policy {
10 16
11 class MockDeviceManagementRequestJob : public DeviceManagementRequestJob { 17 class MockDeviceManagementRequestJob : public DeviceManagementRequestJob {
12 public: 18 public:
13 MockDeviceManagementRequestJob( 19 MockDeviceManagementRequestJob(
14 JobType type, 20 JobType type,
15 MockDeviceManagementService* service, 21 MockDeviceManagementService* service,
16 DeviceManagementStatus status, 22 DeviceManagementStatus status,
17 const enterprise_management::DeviceManagementResponse& response) 23 const enterprise_management::DeviceManagementResponse& response)
18 : DeviceManagementRequestJob(type), 24 : DeviceManagementRequestJob(type),
19 service_(service), 25 service_(service),
20 status_(status), 26 status_(status),
21 response_(response) {} 27 response_(response) {}
28 virtual ~MockDeviceManagementRequestJob() {}
22 29
23 protected: 30 protected:
24 virtual void Run() OVERRIDE { 31 virtual void Run() OVERRIDE {
25 service_->StartJob(this); 32 service_->StartJob(ExtractParameter(dm_protocol::kParamRequest),
33 gaia_token_,
34 ExtractParameter(dm_protocol::kParamOAuthToken),
35 dm_token_,
36 ExtractParameter(dm_protocol::kParamUserAffiliation),
37 ExtractParameter(dm_protocol::kParamDeviceID),
38 request_);
26 callback_.Run(status_, response_); 39 callback_.Run(status_, response_);
27 } 40 }
28 41
29 private: 42 private:
43 // Searches for a query parameter and returns the associated value.
44 const std::string& ExtractParameter(const std::string& name) const {
45 for (ParameterMap::const_iterator entry(query_params_.begin());
46 entry != query_params_.end();
47 ++entry) {
48 if (name == entry->first)
49 return entry->second;
50 }
51
52 return EmptyString();
53 }
54
30 MockDeviceManagementService* service_; 55 MockDeviceManagementService* service_;
31 DeviceManagementStatus status_; 56 DeviceManagementStatus status_;
32 enterprise_management::DeviceManagementResponse response_; 57 enterprise_management::DeviceManagementResponse response_;
33 58
34 DISALLOW_COPY_AND_ASSIGN(MockDeviceManagementRequestJob); 59 DISALLOW_COPY_AND_ASSIGN(MockDeviceManagementRequestJob);
35 }; 60 };
36 61
37 ACTION_P3(CreateMockDeviceManagementRequestJob, service, status, response) { 62 ACTION_P3(CreateMockDeviceManagementRequestJob, service, status, response) {
38 return new MockDeviceManagementRequestJob(arg0, service, status, response); 63 return new MockDeviceManagementRequestJob(arg0, service, status, response);
39 } 64 }
40 65
41 MockDeviceManagementService::MockDeviceManagementService() 66 MockDeviceManagementService::MockDeviceManagementService()
42 : DeviceManagementService("") {} 67 : DeviceManagementService("") {}
43 68
44 MockDeviceManagementService::~MockDeviceManagementService() {} 69 MockDeviceManagementService::~MockDeviceManagementService() {}
45 70
46 testing::Action<MockDeviceManagementService::CreateJobFunction> 71 Action<MockDeviceManagementService::CreateJobFunction>
47 MockDeviceManagementService::SucceedJob( 72 MockDeviceManagementService::SucceedJob(
48 const enterprise_management::DeviceManagementResponse& response) { 73 const enterprise_management::DeviceManagementResponse& response) {
49 return CreateMockDeviceManagementRequestJob(this, DM_STATUS_SUCCESS, 74 return CreateMockDeviceManagementRequestJob(this, DM_STATUS_SUCCESS,
50 response); 75 response);
51 } 76 }
52 77
53 testing::Action<MockDeviceManagementService::CreateJobFunction> 78 Action<MockDeviceManagementService::CreateJobFunction>
54 MockDeviceManagementService::FailJob(DeviceManagementStatus status) { 79 MockDeviceManagementService::FailJob(DeviceManagementStatus status) {
55 const enterprise_management::DeviceManagementResponse dummy_response; 80 const enterprise_management::DeviceManagementResponse dummy_response;
56 return CreateMockDeviceManagementRequestJob(this, status, dummy_response); 81 return CreateMockDeviceManagementRequestJob(this, status, dummy_response);
57 } 82 }
58 83
59 } // namespace policy 84 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698