- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / policy / cloud / mock_device_management_service.h
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 CHROME_BROWSER_POLICY_CLOUD_MOCK_DEVICE_MANAGEMENT_SERVICE_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_MOCK_DEVICE_MANAGEMENT_SERVICE_H_
7
8 #include <string>
9
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"
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 GetUserAgent() OVERRIDE;
36   virtual std::string GetAgentParameter() OVERRIDE;
37   virtual std::string GetPlatformParameter() OVERRIDE;
38
39  private:
40   const std::string server_url_;
41
42   DISALLOW_COPY_AND_ASSIGN(MockDeviceManagementServiceConfiguration);
43 };
44
45 class MockDeviceManagementService : public DeviceManagementService {
46  public:
47   MockDeviceManagementService();
48   virtual ~MockDeviceManagementService();
49
50   typedef DeviceManagementRequestJob* CreateJobFunction(
51       DeviceManagementRequestJob::JobType);
52
53   MOCK_METHOD1(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  // CHROME_BROWSER_POLICY_CLOUD_MOCK_DEVICE_MANAGEMENT_SERVICE_H_