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.
5 #ifndef CHROME_BROWSER_POLICY_CLOUD_MOCK_DEVICE_MANAGEMENT_SERVICE_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_MOCK_DEVICE_MANAGEMENT_SERVICE_H_
10 #include "base/basictypes.h"
11 #include "chrome/browser/policy/cloud/device_management_service.h"
12 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h"
13 #include "testing/gmock/include/gmock/gmock.h"
17 class MockDeviceManagementJob {
19 virtual ~MockDeviceManagementJob();
20 virtual void RetryJob() = 0;
21 virtual void SendResponse(
22 DeviceManagementStatus status,
23 const enterprise_management::DeviceManagementResponse& response) = 0;
26 class MockDeviceManagementServiceConfiguration
27 : public DeviceManagementService::Configuration {
29 MockDeviceManagementServiceConfiguration();
30 explicit MockDeviceManagementServiceConfiguration(
31 const std::string& server_url);
32 virtual ~MockDeviceManagementServiceConfiguration();
34 virtual std::string GetServerUrl() OVERRIDE;
35 virtual std::string GetUserAgent() OVERRIDE;
36 virtual std::string GetAgentParameter() OVERRIDE;
37 virtual std::string GetPlatformParameter() OVERRIDE;
40 const std::string server_url_;
42 DISALLOW_COPY_AND_ASSIGN(MockDeviceManagementServiceConfiguration);
45 class MockDeviceManagementService : public DeviceManagementService {
47 MockDeviceManagementService();
48 virtual ~MockDeviceManagementService();
50 typedef DeviceManagementRequestJob* CreateJobFunction(
51 DeviceManagementRequestJob::JobType);
53 MOCK_METHOD1(CreateJob, CreateJobFunction);
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));
64 // Creates a gmock action that will make the job succeed.
65 testing::Action<CreateJobFunction> SucceedJob(
66 const enterprise_management::DeviceManagementResponse& response);
68 // Creates a gmock action which will fail the job with the given error.
69 testing::Action<CreateJobFunction> FailJob(DeviceManagementStatus status);
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);
77 DISALLOW_COPY_AND_ASSIGN(MockDeviceManagementService);
82 #endif // CHROME_BROWSER_POLICY_CLOUD_MOCK_DEVICE_MANAGEMENT_SERVICE_H_