| 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 "net/url_request/url_request_status.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 |
| 55 // If backend is set, this mock will just provide proxies for it on calls |
| 56 // to CreateBackend(). |
| 53 void set_backend(DeviceManagementBackend* backend) { | 57 void set_backend(DeviceManagementBackend* backend) { |
| 54 backend_ = backend; | 58 backend_ = backend; |
| 55 } | 59 } |
| 56 | 60 |
| 57 virtual DeviceManagementBackend* CreateBackend(); | 61 virtual DeviceManagementBackend* CreateBackend() OVERRIDE; |
| 62 |
| 63 // If the backend is set, this method will pass-through to the super class. |
| 64 // Otherwise, this method will use the parameters stored and complete the |
| 65 // job immediately. |
| 66 virtual void StartJob(DeviceManagementJob* job) OVERRIDE; |
| 67 |
| 68 void set_url_request_status(const net::URLRequestStatus& status) { |
| 69 status_ = status; |
| 70 } |
| 71 |
| 72 void set_response_code(int response_code) { |
| 73 response_code_ = response_code; |
| 74 } |
| 75 |
| 76 void set_cookies(const net::ResponseCookies& cookies) { |
| 77 cookies_ = cookies; |
| 78 } |
| 79 |
| 80 void set_data(const std::string& data) { |
| 81 data_ = data; |
| 82 } |
| 58 | 83 |
| 59 private: | 84 private: |
| 60 DeviceManagementBackend* backend_; // weak | 85 DeviceManagementBackend* backend_; // weak |
| 86 net::URLRequestStatus status_; |
| 87 int response_code_; |
| 88 net::ResponseCookies cookies_; |
| 89 std::string data_; |
| 61 DISALLOW_COPY_AND_ASSIGN(MockDeviceManagementService); | 90 DISALLOW_COPY_AND_ASSIGN(MockDeviceManagementService); |
| 62 }; | 91 }; |
| 63 | 92 |
| 64 } // namespace policy | 93 } // namespace policy |
| 65 | 94 |
| 66 #endif // CHROME_BROWSER_POLICY_MOCK_DEVICE_MANAGEMENT_SERVICE_H_ | 95 #endif // CHROME_BROWSER_POLICY_MOCK_DEVICE_MANAGEMENT_SERVICE_H_ |
| OLD | NEW |