Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: chrome/browser/policy/mock_device_management_backend.h

Issue 9066005: Remove all old-style DeviceManagementService legacy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 CHROME_BROWSER_POLICY_MOCK_DEVICE_MANAGEMENT_BACKEND_H_
6 #define CHROME_BROWSER_POLICY_MOCK_DEVICE_MANAGEMENT_BACKEND_H_
7 #pragma once
8
9 #include <string>
10
11 #include "base/time.h"
12 #include "chrome/browser/policy/device_management_backend.h"
13 #include "chrome/browser/policy/proto/cloud_policy.pb.h"
14 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace policy {
19
20 // Useful for unit testing when a server-based backend isn't
21 // available. Simulates both successful and failed requests to the device
22 // management server.
23 class MockDeviceManagementBackend : public DeviceManagementBackend {
24 public:
25 MockDeviceManagementBackend();
26 virtual ~MockDeviceManagementBackend();
27
28 // DeviceManagementBackend method overrides:
29 MOCK_METHOD5(ProcessRegisterRequest, void(
30 const std::string& gaia_auth_token,
31 const std::string& oauth_token,
32 const std::string& device_id,
33 const enterprise_management::DeviceRegisterRequest& request,
34 DeviceRegisterResponseDelegate* delegate));
35
36 MOCK_METHOD4(ProcessUnregisterRequest, void(
37 const std::string& device_management_token,
38 const std::string& device_id,
39 const enterprise_management::DeviceUnregisterRequest& request,
40 DeviceUnregisterResponseDelegate* delegate));
41
42 MOCK_METHOD6(ProcessPolicyRequest, void(
43 const std::string& device_management_token,
44 const std::string& device_id,
45 CloudPolicyDataStore::UserAffiliation affiliation,
46 const enterprise_management::DevicePolicyRequest& request,
47 const enterprise_management::DeviceStatusReportRequest* device_status,
48 DevicePolicyResponseDelegate* delegate));
49
50 MOCK_METHOD3(ProcessAutoEnrollmentRequest, void(
51 const std::string& device_id,
52 const enterprise_management::DeviceAutoEnrollmentRequest& request,
53 DeviceAutoEnrollmentResponseDelegate* delegate));
54
55 private:
56 DISALLOW_COPY_AND_ASSIGN(MockDeviceManagementBackend);
57 };
58
59 ACTION(MockDeviceManagementBackendSucceedRegister) {
60 enterprise_management::DeviceRegisterResponse response;
61 std::string token("FAKE_DEVICE_TOKEN_");
62 static int next_token_suffix;
63 token += next_token_suffix++;
64 response.set_device_management_token(token);
65 arg4->HandleRegisterResponse(response);
66 }
67
68 ACTION(MockDeviceManagementBackendSucceedSpdyCloudPolicy) {
69 enterprise_management::PolicyData signed_response;
70 enterprise_management::CloudPolicySettings settings;
71 enterprise_management::DisableSpdyProto* spdy_proto =
72 settings.mutable_disablespdy();
73 spdy_proto->set_disablespdy(true);
74 spdy_proto->mutable_policy_options()->set_mode(
75 enterprise_management::PolicyOptions::MANDATORY);
76 EXPECT_TRUE(
77 settings.SerializeToString(signed_response.mutable_policy_value()));
78 base::TimeDelta timestamp =
79 base::Time::NowFromSystemTime() - base::Time::UnixEpoch();
80 signed_response.set_timestamp(timestamp.InMilliseconds());
81 std::string serialized_signed_response;
82 EXPECT_TRUE(signed_response.SerializeToString(&serialized_signed_response));
83 enterprise_management::DevicePolicyResponse response;
84 enterprise_management::PolicyFetchResponse* fetch_response =
85 response.add_response();
86 fetch_response->set_policy_data(serialized_signed_response);
87 // TODO(jkummerow): Set proper new_public_key and signature (when
88 // implementing support for signature verification).
89 fetch_response->set_policy_data_signature("TODO");
90 fetch_response->set_new_public_key("TODO");
91 arg5->HandlePolicyResponse(response);
92 }
93
94 ACTION_P(MockDeviceManagementBackendFailRegister, error) {
95 arg4->OnError(error);
96 }
97
98 ACTION_P(MockDeviceManagementBackendFailPolicy, error) {
99 arg5->OnError(error);
100 }
101
102 } // namespace policy
103
104 #endif // CHROME_BROWSER_POLICY_MOCK_DEVICE_MANAGEMENT_BACKEND_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/device_management_service.cc ('k') | chrome/browser/policy/mock_device_management_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698