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

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

Issue 5219006: Refresh policies from DM server periodically (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years, 1 month 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
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 #include "chrome/browser/policy/mock_device_management_backend.h" 5 #include "chrome/browser/policy/mock_device_management_backend.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 10
(...skipping 10 matching lines...) Expand all
21 using ::testing::Invoke; 21 using ::testing::Invoke;
22 22
23 using em::DeviceRegisterRequest; 23 using em::DeviceRegisterRequest;
24 using em::DeviceUnregisterRequest; 24 using em::DeviceUnregisterRequest;
25 using em::DevicePolicyRequest; 25 using em::DevicePolicyRequest;
26 using em::DeviceRegisterResponse; 26 using em::DeviceRegisterResponse;
27 using em::DeviceUnregisterResponse; 27 using em::DeviceUnregisterResponse;
28 using em::DevicePolicyResponse; 28 using em::DevicePolicyResponse;
29 29
30 MockDeviceManagementBackend::MockDeviceManagementBackend() 30 MockDeviceManagementBackend::MockDeviceManagementBackend()
31 : DeviceManagementBackend() { 31 : DeviceManagementBackend(),
32 policy_works_later_(false),
danno 2010/11/22 13:47:50 do you need a separate boolean to track this? the
Jakob Kummerow (corp) 2010/11/22 16:56:08 Done.
33 policy_remaining_fail_count_(0),
34 register_works_later_(false),
35 register_remaining_fail_count_(0),
36 policy_fails_later_(false),
37 policy_remaining_success_count_(0) {
32 policy_setting_ = policy_response_.add_setting(); 38 policy_setting_ = policy_response_.add_setting();
33 policy_setting_->set_policy_key("chrome-policy"); 39 policy_setting_->set_policy_key("chrome-policy");
34 policy_setting_->set_watermark("fresh"); 40 policy_setting_->set_watermark("fresh");
35 } 41 }
36 42
37 MockDeviceManagementBackend::~MockDeviceManagementBackend() { 43 MockDeviceManagementBackend::~MockDeviceManagementBackend() {
38 } 44 }
39 45
40 void MockDeviceManagementBackend::AllShouldSucceed() { 46 void MockDeviceManagementBackend::AllShouldSucceed() {
41 ON_CALL(*this, ProcessRegisterRequest(_, _, _, _)). 47 ON_CALL(*this, ProcessRegisterRequest(_, _, _, _)).
(...skipping 17 matching lines...) Expand all
59 &MockDeviceManagementBackend::SimulateFailedPolicyRequest)); 65 &MockDeviceManagementBackend::SimulateFailedPolicyRequest));
60 } 66 }
61 67
62 void MockDeviceManagementBackend::UnmanagedDevice() { 68 void MockDeviceManagementBackend::UnmanagedDevice() {
63 ON_CALL(*this, ProcessRegisterRequest(_, _, _, _)). 69 ON_CALL(*this, ProcessRegisterRequest(_, _, _, _)).
64 WillByDefault(Invoke( 70 WillByDefault(Invoke(
65 this, 71 this,
66 &MockDeviceManagementBackend::SimulateUnmanagedRegisterRequest)); 72 &MockDeviceManagementBackend::SimulateUnmanagedRegisterRequest));
67 } 73 }
68 74
75 void MockDeviceManagementBackend::RegisterFailsOncePolicyFailsTwice() {
76 register_works_later_ = true;
77 register_remaining_fail_count_ = 1;
78 policy_works_later_ = true;
79 policy_remaining_fail_count_ = 2;
80 AllShouldFail();
81 }
82
83 void MockDeviceManagementBackend::AllWorksFirstPolicyFailsLater() {
84 policy_fails_later_ = true;
85 policy_remaining_success_count_ = 3;
86 AllShouldSucceed();
87 }
88
69 void MockDeviceManagementBackend::AddBooleanPolicy(const char* policy_name, 89 void MockDeviceManagementBackend::AddBooleanPolicy(const char* policy_name,
70 bool value) { 90 bool value) {
71 em::GenericSetting* policy_value = policy_setting_->mutable_policy_value(); 91 em::GenericSetting* policy_value = policy_setting_->mutable_policy_value();
72 em::GenericNamedValue* named_value = policy_value->add_named_value(); 92 em::GenericNamedValue* named_value = policy_value->add_named_value();
73 named_value->set_name(policy_name); 93 named_value->set_name(policy_name);
74 named_value->mutable_value()->set_value_type( 94 named_value->mutable_value()->set_value_type(
75 em::GenericValue::VALUE_TYPE_BOOL); 95 em::GenericValue::VALUE_TYPE_BOOL);
76 named_value->mutable_value()->set_bool_value(value); 96 named_value->mutable_value()->set_bool_value(value);
77 } 97 }
78 98
79 void MockDeviceManagementBackend::SimulateSuccessfulRegisterRequest( 99 void MockDeviceManagementBackend::SimulateSuccessfulRegisterRequest(
80 const std::string& auth_token, 100 const std::string& auth_token,
81 const std::string& device_id, 101 const std::string& device_id,
82 const em::DeviceRegisterRequest& request, 102 const em::DeviceRegisterRequest& request,
83 DeviceRegisterResponseDelegate* delegate) { 103 DeviceRegisterResponseDelegate* delegate) {
84 DeviceRegisterResponse response; 104 DeviceRegisterResponse response;
85 std::string token(kFakeDeviceManagementToken); 105 std::string token(kFakeDeviceManagementToken);
86 token += next_token_suffix_++; 106 token += next_token_suffix_++;
87 response.set_device_management_token(token); 107 response.set_device_management_token(token);
88 delegate->HandleRegisterResponse(response); 108 delegate->HandleRegisterResponse(response);
89 } 109 }
90 110
91 void MockDeviceManagementBackend::SimulateSuccessfulPolicyRequest( 111 void MockDeviceManagementBackend::SimulateSuccessfulPolicyRequest(
92 const std::string& device_management_token, 112 const std::string& device_management_token,
93 const em::DevicePolicyRequest& request, 113 const em::DevicePolicyRequest& request,
94 DevicePolicyResponseDelegate* delegate) { 114 DevicePolicyResponseDelegate* delegate) {
115 if (policy_fails_later_) {
116 policy_remaining_success_count_--;
117 if (!policy_remaining_success_count_) {
118 ON_CALL(*this, ProcessPolicyRequest(_, _, _)).
119 WillByDefault(Invoke(
120 this,
121 &MockDeviceManagementBackend::SimulateFailedPolicyRequest));
122 }
123 }
95 delegate->HandlePolicyResponse(policy_response_); 124 delegate->HandlePolicyResponse(policy_response_);
96 } 125 }
97 126
98 void MockDeviceManagementBackend::SimulateFailedRegisterRequest( 127 void MockDeviceManagementBackend::SimulateFailedRegisterRequest(
99 const std::string& auth_token, 128 const std::string& auth_token,
100 const std::string& device_id, 129 const std::string& device_id,
101 const em::DeviceRegisterRequest& request, 130 const em::DeviceRegisterRequest& request,
102 DeviceRegisterResponseDelegate* delegate) { 131 DeviceRegisterResponseDelegate* delegate) {
132 if (register_works_later_) {
133 register_remaining_fail_count_--;
134 if (!register_remaining_fail_count_) {
135 ON_CALL(*this, ProcessRegisterRequest(_, _, _, _)).WillByDefault(Invoke(
136 this,
137 &MockDeviceManagementBackend::SimulateSuccessfulRegisterRequest));
138 }
139 }
103 delegate->OnError(kErrorRequestFailed); 140 delegate->OnError(kErrorRequestFailed);
104 } 141 }
105 142
106 void MockDeviceManagementBackend::SimulateFailedPolicyRequest( 143 void MockDeviceManagementBackend::SimulateFailedPolicyRequest(
107 const std::string& device_management_token, 144 const std::string& device_management_token,
108 const em::DevicePolicyRequest& request, 145 const em::DevicePolicyRequest& request,
109 DevicePolicyResponseDelegate* delegate) { 146 DevicePolicyResponseDelegate* delegate) {
147 if (policy_works_later_) {
148 policy_remaining_fail_count_--;
149 if (!policy_remaining_fail_count_) {
150 ON_CALL(*this, ProcessPolicyRequest(_, _, _)).
151 WillByDefault(Invoke(
152 this,
153 &MockDeviceManagementBackend::SimulateSuccessfulPolicyRequest));
154 }
155 }
110 delegate->OnError(kErrorRequestFailed); 156 delegate->OnError(kErrorRequestFailed);
111 } 157 }
112 158
113 void MockDeviceManagementBackend::SimulateUnmanagedRegisterRequest( 159 void MockDeviceManagementBackend::SimulateUnmanagedRegisterRequest(
114 const std::string& auth_token, 160 const std::string& auth_token,
115 const std::string& device_id, 161 const std::string& device_id,
116 const em::DeviceRegisterRequest& request, 162 const em::DeviceRegisterRequest& request,
117 DeviceRegisterResponseDelegate* delegate) { 163 DeviceRegisterResponseDelegate* delegate) {
118 delegate->OnError(kErrorServiceManagementNotSupported); 164 delegate->OnError(kErrorServiceManagementNotSupported);
119 } 165 }
120 166
121 } // namespace 167 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698