• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, net::URLRequestContextGetter*);
51 
52   MOCK_METHOD2(CreateJob, CreateJobFunction);
53   MOCK_METHOD7(
54       StartJob,
55       void(const std::string& request_type,
56            const std::string& gaia_token,
57            const std::string& oauth_token,
58            const std::string& dm_token,
59            const std::string& user_affiliation,
60            const std::string& client_id,
61            const enterprise_management::DeviceManagementRequest& request));
62 
63   // Creates a gmock action that will make the job succeed.
64   testing::Action<CreateJobFunction> SucceedJob(
65       const enterprise_management::DeviceManagementResponse& response);
66 
67   // Creates a gmock action which will fail the job with the given error.
68   testing::Action<CreateJobFunction> FailJob(DeviceManagementStatus status);
69 
70   // Creates a gmock action which will capture the job so the test code can
71   // delay job completion.
72   testing::Action<CreateJobFunction> CreateAsyncJob(
73       MockDeviceManagementJob** job);
74 
75  private:
76   DISALLOW_COPY_AND_ASSIGN(MockDeviceManagementService);
77 };
78 
79 }  // namespace policy
80 
81 #endif  // COMPONENTS_POLICY_CORE_COMMON_CLOUD_MOCK_DEVICE_MANAGEMENT_SERVICE_H_
82