| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_POLICY_MOCK_DEVICE_MANAGEMENT_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_POLICY_MOCK_DEVICE_MANAGEMENT_SERVICE_H_ |
| 6 #define CHROME_BROWSER_POLICY_MOCK_DEVICE_MANAGEMENT_SERVICE_H_ | 6 #define CHROME_BROWSER_POLICY_MOCK_DEVICE_MANAGEMENT_SERVICE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" |
| 11 #include "chrome/browser/policy/device_management_backend.h" | 12 #include "chrome/browser/policy/device_management_backend.h" |
| 12 #include "chrome/browser/policy/device_management_service.h" | 13 #include "chrome/browser/policy/device_management_service.h" |
| 13 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 14 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" |
| 14 | 16 |
| 15 namespace policy { | 17 namespace policy { |
| 16 | 18 |
| 17 // This proxy class is used so that expectations can be defined for a single | 19 // This proxy class is used so that expectations can be defined for a single |
| 18 // persistent instance of DMBackend while the DeviceTokenFetcher under test | 20 // persistent instance of DMBackend while the DeviceTokenFetcher under test |
| 19 // merrily creates and destroys proxies. | 21 // merrily creates and destroys proxies. |
| 20 class ProxyDeviceManagementBackend : public DeviceManagementBackend { | 22 class ProxyDeviceManagementBackend : public DeviceManagementBackend { |
| 21 public: | 23 public: |
| 22 explicit ProxyDeviceManagementBackend(DeviceManagementBackend* backend); | 24 explicit ProxyDeviceManagementBackend(DeviceManagementBackend* backend); |
| 23 virtual ~ProxyDeviceManagementBackend(); | 25 virtual ~ProxyDeviceManagementBackend(); |
| 24 | 26 |
| 25 virtual void ProcessRegisterRequest( | 27 virtual void ProcessRegisterRequest( |
| 26 const std::string& auth_token, | 28 const std::string& auth_token, |
| 27 const std::string& device_id, | 29 const std::string& device_id, |
| 28 const em::DeviceRegisterRequest& request, | 30 const em::DeviceRegisterRequest& request, |
| 29 DeviceRegisterResponseDelegate* delegate); | 31 DeviceRegisterResponseDelegate* delegate) OVERRIDE; |
| 30 | 32 |
| 31 virtual void ProcessUnregisterRequest( | 33 virtual void ProcessUnregisterRequest( |
| 32 const std::string& device_management_token, | 34 const std::string& device_management_token, |
| 33 const std::string& device_id, | 35 const std::string& device_id, |
| 34 const em::DeviceUnregisterRequest& request, | 36 const em::DeviceUnregisterRequest& request, |
| 35 DeviceUnregisterResponseDelegate* delegate); | 37 DeviceUnregisterResponseDelegate* delegate) OVERRIDE; |
| 36 | 38 |
| 37 virtual void ProcessPolicyRequest( | 39 virtual void ProcessPolicyRequest( |
| 38 const std::string& device_management_token, | 40 const std::string& device_management_token, |
| 39 const std::string& device_id, | 41 const std::string& device_id, |
| 40 const em::DevicePolicyRequest& request, | 42 const em::DevicePolicyRequest& request, |
| 41 DevicePolicyResponseDelegate* delegate); | 43 DevicePolicyResponseDelegate* delegate) OVERRIDE; |
| 42 | 44 |
| 43 private: | 45 private: |
| 44 DeviceManagementBackend* backend_; // weak | 46 DeviceManagementBackend* backend_; // weak |
| 45 DISALLOW_COPY_AND_ASSIGN(ProxyDeviceManagementBackend); | 47 DISALLOW_COPY_AND_ASSIGN(ProxyDeviceManagementBackend); |
| 46 }; | 48 }; |
| 47 | 49 |
| 48 class MockDeviceManagementService : public DeviceManagementService { | 50 class MockDeviceManagementService : public DeviceManagementService { |
| 49 public: | 51 public: |
| 50 MockDeviceManagementService(); | 52 MockDeviceManagementService(); |
| 51 virtual ~MockDeviceManagementService(); | 53 virtual ~MockDeviceManagementService(); |
| 52 | 54 |
| 53 void set_backend(DeviceManagementBackend* backend) { | 55 MOCK_METHOD0(CreateBackend, DeviceManagementBackend*()); |
| 54 backend_ = backend; | 56 MOCK_METHOD1(StartJob, void(DeviceManagementJob*)); |
| 57 |
| 58 // This method bypasses the mocked version and calls the superclass' |
| 59 // CreateBackend(), returning a "real" backend. |
| 60 DeviceManagementBackend* CreateBackendNotMocked() { |
| 61 return DeviceManagementService::CreateBackend(); |
| 55 } | 62 } |
| 56 | 63 |
| 57 virtual DeviceManagementBackend* CreateBackend(); | 64 // This method bypasses the mocked version and calls the superclass' |
| 65 // StartJob. |
| 66 void StartJobNotMocked(DeviceManagementJob* job) { |
| 67 DeviceManagementService::StartJob(job); |
| 68 } |
| 58 | 69 |
| 59 private: | 70 private: |
| 60 DeviceManagementBackend* backend_; // weak | |
| 61 DISALLOW_COPY_AND_ASSIGN(MockDeviceManagementService); | 71 DISALLOW_COPY_AND_ASSIGN(MockDeviceManagementService); |
| 62 }; | 72 }; |
| 63 | 73 |
| 74 // Use this to make CreateBackend return a ProxyDeviceManagementBackend for |
| 75 // the given |backend|. |
| 76 ACTION_P(MockDeviceManagementServiceProxyBackend, backend) { |
| 77 return new ProxyDeviceManagementBackend(backend); |
| 78 } |
| 79 |
| 80 // Use this to make StartJob send a faked response to the job immediately. |
| 81 ACTION_P4(MockDeviceManagementServiceRespondToJob, status, response_code, |
| 82 cookies, data) { |
| 83 arg0->HandleResponse(status, response_code, cookies, data); |
| 84 } |
| 85 |
| 64 } // namespace policy | 86 } // namespace policy |
| 65 | 87 |
| 66 #endif // CHROME_BROWSER_POLICY_MOCK_DEVICE_MANAGEMENT_SERVICE_H_ | 88 #endif // CHROME_BROWSER_POLICY_MOCK_DEVICE_MANAGEMENT_SERVICE_H_ |
| OLD | NEW |