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 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_CLOUD_MOCK_DEVICE_MANAGEMENT_SERVICE_H_ 6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_MOCK_DEVICE_MANAGEMENT_SERVICE_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "components/policy/core/common/cloud/device_management_service.h" 12 #include "policy/proto/device_management_backend.pb.h" 13 #include "testing/gmock/include/gmock/gmock.h" 14 15 namespace policy { 16 17 class MockDeviceManagementJob { 18 public: 19 virtual ~MockDeviceManagementJob(); 20 virtual void RetryJob() = 0; 21 virtual void SendResponse( 22 DeviceManagementStatus status, 23 const enterprise_management::DeviceManagementResponse& response) = 0; 24 }; 25 26 class MockDeviceManagementServiceConfiguration 27 : public DeviceManagementService::Configuration { 28 public: 29 MockDeviceManagementServiceConfiguration(); 30 explicit MockDeviceManagementServiceConfiguration( 31 const std::string& server_url); 32 virtual ~MockDeviceManagementServiceConfiguration(); 33 34 virtual std::string GetServerUrl() OVERRIDE; 35 virtual std::string GetAgentParameter() OVERRIDE; 36 virtual std::string GetPlatformParameter() OVERRIDE; 37 38 private: 39 const std::string server_url_; 40 41 DISALLOW_COPY_AND_ASSIGN(MockDeviceManagementServiceConfiguration); 42 }; 43 44 class MockDeviceManagementService : public DeviceManagementService { 45 public: 46 MockDeviceManagementService(); 47 virtual ~MockDeviceManagementService(); 48 49 typedef DeviceManagementRequestJob* CreateJobFunction( 50 DeviceManagementRequestJob::JobType, 51 const scoped_refptr<net::URLRequestContextGetter>&); 52 53 MOCK_METHOD2(CreateJob, CreateJobFunction); 54 MOCK_METHOD7( 55 StartJob, 56 void(const std::string& request_type, 57 const std::string& gaia_token, 58 const std::string& oauth_token, 59 const std::string& dm_token, 60 const std::string& user_affiliation, 61 const std::string& client_id, 62 const enterprise_management::DeviceManagementRequest& request)); 63 64 // Creates a gmock action that will make the job succeed. 65 testing::Action<CreateJobFunction> SucceedJob( 66 const enterprise_management::DeviceManagementResponse& response); 67 68 // Creates a gmock action which will fail the job with the given error. 69 testing::Action<CreateJobFunction> FailJob(DeviceManagementStatus status); 70 71 // Creates a gmock action which will capture the job so the test code can 72 // delay job completion. 73 testing::Action<CreateJobFunction> CreateAsyncJob( 74 MockDeviceManagementJob** job); 75 76 private: 77 DISALLOW_COPY_AND_ASSIGN(MockDeviceManagementService); 78 }; 79 80 } // namespace policy 81 82 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_MOCK_DEVICE_MANAGEMENT_SERVICE_H_ 83