OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_BACKEND_H_ | 5 #ifndef CHROME_BROWSER_POLICY_MOCK_DEVICE_MANAGEMENT_BACKEND_H_ |
6 #define CHROME_BROWSER_POLICY_MOCK_DEVICE_MANAGEMENT_BACKEND_H_ | 6 #define CHROME_BROWSER_POLICY_MOCK_DEVICE_MANAGEMENT_BACKEND_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/policy/device_management_backend.h" | 13 #include "chrome/browser/policy/device_management_backend.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 namespace policy { | 17 namespace policy { |
18 | 18 |
19 namespace em = enterprise_management; | 19 namespace em = enterprise_management; |
20 | 20 |
21 // Useful for unit testing when a server-based backend isn't | 21 // Useful for unit testing when a server-based backend isn't |
22 // available. Simulates both successful and failed requests to the device | 22 // available. Simulates both successful and failed requests to the device |
23 // management server. | 23 // management server. |
24 class MockDeviceManagementBackend | 24 class MockDeviceManagementBackend |
25 : public DeviceManagementBackend { | 25 : public DeviceManagementBackend { |
26 public: | 26 public: |
27 MockDeviceManagementBackend(); | 27 MockDeviceManagementBackend() {} |
28 virtual ~MockDeviceManagementBackend(); | 28 virtual ~MockDeviceManagementBackend() {} |
29 | 29 |
30 // DeviceManagementBackend method overrides: | 30 // DeviceManagementBackend method overrides: |
31 MOCK_METHOD4(ProcessRegisterRequest, void( | 31 MOCK_METHOD4(ProcessRegisterRequest, void( |
32 const std::string& auth_token, | 32 const std::string& auth_token, |
33 const std::string& device_id, | 33 const std::string& device_id, |
34 const em::DeviceRegisterRequest& request, | 34 const em::DeviceRegisterRequest& request, |
35 DeviceRegisterResponseDelegate* delegate)); | 35 DeviceRegisterResponseDelegate* delegate)); |
36 | 36 |
37 MOCK_METHOD4(ProcessUnregisterRequest, void( | 37 MOCK_METHOD4(ProcessUnregisterRequest, void( |
38 const std::string& device_management_token, | 38 const std::string& device_management_token, |
39 const std::string& device_id, | 39 const std::string& device_id, |
40 const em::DeviceUnregisterRequest& request, | 40 const em::DeviceUnregisterRequest& request, |
41 DeviceUnregisterResponseDelegate* delegate)); | 41 DeviceUnregisterResponseDelegate* delegate)); |
42 | 42 |
43 MOCK_METHOD4(ProcessPolicyRequest, void( | 43 MOCK_METHOD4(ProcessPolicyRequest, void( |
44 const std::string& device_management_token, | 44 const std::string& device_management_token, |
45 const std::string& device_id, | 45 const std::string& device_id, |
46 const em::DevicePolicyRequest& request, | 46 const em::DevicePolicyRequest& request, |
47 DevicePolicyResponseDelegate* delegate)); | 47 DevicePolicyResponseDelegate* delegate)); |
48 | 48 |
49 void AllShouldSucceed(); | |
50 void AllShouldFail(); | |
51 void UnmanagedDevice(); | |
52 void RegisterFailsOncePolicyFailsTwice(); | |
53 void AllWorksFirstPolicyFailsLater(); | |
54 | |
55 void SimulateSuccessfulRegisterRequest( | |
56 const std::string& auth_token, | |
57 const std::string& device_id, | |
58 const em::DeviceRegisterRequest& request, | |
59 DeviceRegisterResponseDelegate* delegate); | |
60 | |
61 void SimulateSuccessfulPolicyRequest( | |
62 const std::string& device_management_token, | |
63 const std::string& device_id, | |
64 const em::DevicePolicyRequest& request, | |
65 DevicePolicyResponseDelegate* delegate); | |
66 | |
67 void SimulateFailedRegisterRequest( | |
68 const std::string& auth_token, | |
69 const std::string& device_id, | |
70 const em::DeviceRegisterRequest& request, | |
71 DeviceRegisterResponseDelegate* delegate); | |
72 | |
73 void SimulateFailedPolicyRequest( | |
74 const std::string& device_management_token, | |
75 const std::string& device_id, | |
76 const em::DevicePolicyRequest& request, | |
77 DevicePolicyResponseDelegate* delegate); | |
78 | |
79 void SimulateUnmanagedRegisterRequest( | |
80 const std::string& auth_token, | |
81 const std::string& device_id, | |
82 const em::DeviceRegisterRequest& request, | |
83 DeviceRegisterResponseDelegate* delegate); | |
84 | |
85 void AddBooleanPolicy(const char* policy_name, bool value); | |
86 | |
87 private: | 49 private: |
88 em::DevicePolicyResponse policy_response_; | |
89 em::DevicePolicySetting* policy_setting_; | |
90 | |
91 int policy_remaining_fail_count_; | |
92 int register_remaining_fail_count_; | |
93 int policy_remaining_success_count_; | |
94 | |
95 DISALLOW_COPY_AND_ASSIGN(MockDeviceManagementBackend); | 50 DISALLOW_COPY_AND_ASSIGN(MockDeviceManagementBackend); |
96 }; | 51 }; |
97 | 52 |
53 ACTION(SucceedRegister) { | |
Mattias Nissler (ping if slow)
2010/11/24 09:51:21
Hm, so we're putting these actions into the policy
| |
54 em::DeviceRegisterResponse response; | |
55 std::string token("FAKE_DEVICE_TOKEN_"); | |
56 static int next_token_suffix; | |
57 token += next_token_suffix++; | |
58 response.set_device_management_token(token); | |
59 arg3->HandleRegisterResponse(response); | |
60 } | |
61 | |
62 ACTION_P2(SucceedBooleanPolicy, name, value) { | |
63 em::DevicePolicyResponse response; | |
64 em::DevicePolicySetting* setting = response.add_setting(); | |
65 setting->set_policy_key("chrome-policy"); | |
66 setting->set_watermark("fresh"); | |
67 em::GenericSetting* policy_value = setting->mutable_policy_value(); | |
68 em::GenericNamedValue* named_value = policy_value->add_named_value(); | |
69 named_value->set_name(name); | |
70 named_value->mutable_value()->set_value_type( | |
71 em::GenericValue::VALUE_TYPE_BOOL); | |
72 named_value->mutable_value()->set_bool_value(value); | |
73 arg3->HandlePolicyResponse(response); | |
74 } | |
75 | |
76 ACTION_P(FailRegister, error) { | |
77 arg3->OnError(error); | |
78 } | |
79 | |
80 ACTION_P(FailPolicy, error) { | |
81 arg3->OnError(error); | |
82 } | |
83 | |
98 } // namespace policy | 84 } // namespace policy |
99 | 85 |
100 #endif // CHROME_BROWSER_POLICY_MOCK_DEVICE_MANAGEMENT_BACKEND_H_ | 86 #endif // CHROME_BROWSER_POLICY_MOCK_DEVICE_MANAGEMENT_BACKEND_H_ |
OLD | NEW |