| OLD | NEW |
| 1 // Copyright (c) 2010 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_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/time.h" | 12 #include "base/time.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/policy/device_management_backend.h" | 14 #include "chrome/browser/policy/device_management_backend.h" |
| 15 #include "chrome/browser/policy/proto/cloud_policy.pb.h" |
| 16 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| 15 #include "chrome/browser/policy/proto/device_management_constants.h" | 17 #include "chrome/browser/policy/proto/device_management_constants.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 20 |
| 19 namespace policy { | 21 namespace policy { |
| 20 | 22 |
| 21 namespace em = enterprise_management; | 23 namespace em = enterprise_management; |
| 22 | 24 |
| 23 // Useful for unit testing when a server-based backend isn't | 25 // Useful for unit testing when a server-based backend isn't |
| 24 // available. Simulates both successful and failed requests to the device | 26 // available. Simulates both successful and failed requests to the device |
| (...skipping 15 matching lines...) Expand all Loading... |
| 40 const std::string& device_id, | 42 const std::string& device_id, |
| 41 const em::DeviceUnregisterRequest& request, | 43 const em::DeviceUnregisterRequest& request, |
| 42 DeviceUnregisterResponseDelegate* delegate)); | 44 DeviceUnregisterResponseDelegate* delegate)); |
| 43 | 45 |
| 44 MOCK_METHOD4(ProcessPolicyRequest, void( | 46 MOCK_METHOD4(ProcessPolicyRequest, void( |
| 45 const std::string& device_management_token, | 47 const std::string& device_management_token, |
| 46 const std::string& device_id, | 48 const std::string& device_id, |
| 47 const em::DevicePolicyRequest& request, | 49 const em::DevicePolicyRequest& request, |
| 48 DevicePolicyResponseDelegate* delegate)); | 50 DevicePolicyResponseDelegate* delegate)); |
| 49 | 51 |
| 50 MOCK_METHOD4(ProcessCloudPolicyRequest, void( | |
| 51 const std::string& device_management_token, | |
| 52 const std::string& device_id, | |
| 53 const em::CloudPolicyRequest& request, | |
| 54 DevicePolicyResponseDelegate* delegate)); | |
| 55 | |
| 56 private: | 52 private: |
| 57 DISALLOW_COPY_AND_ASSIGN(MockDeviceManagementBackend); | 53 DISALLOW_COPY_AND_ASSIGN(MockDeviceManagementBackend); |
| 58 }; | 54 }; |
| 59 | 55 |
| 60 ACTION(MockDeviceManagementBackendSucceedRegister) { | 56 ACTION(MockDeviceManagementBackendSucceedRegister) { |
| 61 em::DeviceRegisterResponse response; | 57 em::DeviceRegisterResponse response; |
| 62 std::string token("FAKE_DEVICE_TOKEN_"); | 58 std::string token("FAKE_DEVICE_TOKEN_"); |
| 63 static int next_token_suffix; | 59 static int next_token_suffix; |
| 64 token += next_token_suffix++; | 60 token += next_token_suffix++; |
| 65 response.set_device_management_token(token); | 61 response.set_device_management_token(token); |
| 66 arg3->HandleRegisterResponse(response); | 62 arg3->HandleRegisterResponse(response); |
| 67 } | 63 } |
| 68 | 64 |
| 69 ACTION_P2(MockDeviceManagementBackendSucceedBooleanPolicy, name, value) { | 65 ACTION_P2(MockDeviceManagementBackendSucceedBooleanPolicy, name, value) { |
| 70 em::DevicePolicyResponse response; | 66 em::DevicePolicyResponse response; |
| 71 em::DevicePolicySetting* setting = response.add_setting(); | 67 em::DevicePolicySetting* setting = response.add_setting(); |
| 72 setting->set_policy_key(kChromeDevicePolicySettingKey); | 68 setting->set_policy_key(kChromeDevicePolicySettingKey); |
| 73 setting->set_watermark("fresh"); | 69 setting->set_watermark("fresh"); |
| 74 em::GenericSetting* policy_value = setting->mutable_policy_value(); | 70 em::GenericSetting* policy_value = setting->mutable_policy_value(); |
| 75 em::GenericNamedValue* named_value = policy_value->add_named_value(); | 71 em::GenericNamedValue* named_value = policy_value->add_named_value(); |
| 76 named_value->set_name(name); | 72 named_value->set_name(name); |
| 77 named_value->mutable_value()->set_value_type( | 73 named_value->mutable_value()->set_value_type( |
| 78 em::GenericValue::VALUE_TYPE_BOOL); | 74 em::GenericValue::VALUE_TYPE_BOOL); |
| 79 named_value->mutable_value()->set_bool_value(value); | 75 named_value->mutable_value()->set_bool_value(value); |
| 80 arg3->HandlePolicyResponse(response); | 76 arg3->HandlePolicyResponse(response); |
| 81 } | 77 } |
| 82 | 78 |
| 83 ACTION(MockDeviceManagementBackendSucceedSpdyCloudPolicy) { | 79 ACTION(MockDeviceManagementBackendSucceedSpdyCloudPolicy) { |
| 84 em::SignedCloudPolicyResponse signed_response; | 80 em::PolicyData signed_response; |
| 85 em::CloudPolicySettings* settings = signed_response.mutable_settings(); | 81 em::CloudPolicySettings settings; |
| 86 em::DisableSpdyProto* spdy_proto = settings->mutable_disablespdy(); | 82 em::DisableSpdyProto* spdy_proto = settings.mutable_disablespdy(); |
| 87 spdy_proto->set_disablespdy(true); | 83 spdy_proto->set_disablespdy(true); |
| 88 spdy_proto->mutable_policy_options()->set_mode(em::PolicyOptions::MANDATORY); | 84 spdy_proto->mutable_policy_options()->set_mode(em::PolicyOptions::MANDATORY); |
| 89 signed_response.set_timestamp(base::Time::NowFromSystemTime().ToTimeT()); | 85 EXPECT_TRUE( |
| 86 settings.SerializeToString(signed_response.mutable_policy_value())); |
| 87 base::TimeDelta timestamp = |
| 88 base::Time::NowFromSystemTime() - base::Time::UnixEpoch(); |
| 89 signed_response.set_timestamp(timestamp.InMilliseconds()); |
| 90 std::string serialized_signed_response; | 90 std::string serialized_signed_response; |
| 91 EXPECT_TRUE(signed_response.SerializeToString(&serialized_signed_response)); | 91 EXPECT_TRUE(signed_response.SerializeToString(&serialized_signed_response)); |
| 92 em::CloudPolicyResponse response; | 92 em::DevicePolicyResponse response; |
| 93 response.set_signed_response(serialized_signed_response); | 93 em::PolicyFetchResponse* fetch_response = response.add_response(); |
| 94 fetch_response->set_policy_data(serialized_signed_response); |
| 94 // TODO(jkummerow): Set proper certificate_chain and signature (when | 95 // TODO(jkummerow): Set proper certificate_chain and signature (when |
| 95 // implementing support for signature verification). | 96 // implementing support for signature verification). |
| 96 response.set_signature("TODO"); | 97 fetch_response->set_policy_data_signature("TODO"); |
| 97 response.add_certificate_chain("TODO"); | 98 fetch_response->add_certificate_chain("TODO"); |
| 98 arg3->HandleCloudPolicyResponse(response); | 99 arg3->HandlePolicyResponse(response); |
| 99 } | 100 } |
| 100 | 101 |
| 101 ACTION_P(MockDeviceManagementBackendFailRegister, error) { | 102 ACTION_P(MockDeviceManagementBackendFailRegister, error) { |
| 102 arg3->OnError(error); | 103 arg3->OnError(error); |
| 103 } | 104 } |
| 104 | 105 |
| 105 ACTION_P(MockDeviceManagementBackendFailPolicy, error) { | 106 ACTION_P(MockDeviceManagementBackendFailPolicy, error) { |
| 106 arg3->OnError(error); | 107 arg3->OnError(error); |
| 107 } | 108 } |
| 108 | 109 |
| 109 } // namespace policy | 110 } // namespace policy |
| 110 | 111 |
| 111 #endif // CHROME_BROWSER_POLICY_MOCK_DEVICE_MANAGEMENT_BACKEND_H_ | 112 #endif // CHROME_BROWSER_POLICY_MOCK_DEVICE_MANAGEMENT_BACKEND_H_ |
| OLD | NEW |