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

Unified 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: address comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/policy/mock_device_management_backend.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/policy/mock_device_management_backend.cc
diff --git a/chrome/browser/policy/mock_device_management_backend.cc b/chrome/browser/policy/mock_device_management_backend.cc
index 05d2c3cf8da464b5d1faf2d17250a66e10dad9ed..ca61feb5e26540b09c06b6dd70b8c2d790800511 100644
--- a/chrome/browser/policy/mock_device_management_backend.cc
+++ b/chrome/browser/policy/mock_device_management_backend.cc
@@ -28,7 +28,10 @@ using em::DeviceUnregisterResponse;
using em::DevicePolicyResponse;
MockDeviceManagementBackend::MockDeviceManagementBackend()
- : DeviceManagementBackend() {
+ : DeviceManagementBackend(),
+ policy_remaining_fail_count_(0),
+ register_remaining_fail_count_(0),
+ policy_remaining_success_count_(0) {
policy_setting_ = policy_response_.add_setting();
policy_setting_->set_policy_key("chrome-policy");
policy_setting_->set_watermark("fresh");
@@ -66,6 +69,17 @@ void MockDeviceManagementBackend::UnmanagedDevice() {
&MockDeviceManagementBackend::SimulateUnmanagedRegisterRequest));
}
+void MockDeviceManagementBackend::RegisterFailsOncePolicyFailsTwice() {
+ register_remaining_fail_count_ = 1;
+ policy_remaining_fail_count_ = 2;
+ AllShouldFail();
+}
+
+void MockDeviceManagementBackend::AllWorksFirstPolicyFailsLater() {
+ policy_remaining_success_count_ = 3;
+ AllShouldSucceed();
+}
+
void MockDeviceManagementBackend::AddBooleanPolicy(const char* policy_name,
bool value) {
em::GenericSetting* policy_value = policy_setting_->mutable_policy_value();
@@ -93,6 +107,15 @@ void MockDeviceManagementBackend::SimulateSuccessfulPolicyRequest(
const std::string& device_id,
const em::DevicePolicyRequest& request,
DevicePolicyResponseDelegate* delegate) {
+ if (policy_remaining_success_count_) {
+ policy_remaining_success_count_--;
+ if (!policy_remaining_success_count_) {
+ ON_CALL(*this, ProcessPolicyRequest(_, _, _, _)).
+ WillByDefault(Invoke(
+ this,
+ &MockDeviceManagementBackend::SimulateFailedPolicyRequest));
+ }
+ }
delegate->HandlePolicyResponse(policy_response_);
}
@@ -101,6 +124,14 @@ void MockDeviceManagementBackend::SimulateFailedRegisterRequest(
const std::string& device_id,
const em::DeviceRegisterRequest& request,
DeviceRegisterResponseDelegate* delegate) {
+ if (register_remaining_fail_count_) {
+ register_remaining_fail_count_--;
+ if (!register_remaining_fail_count_) {
+ ON_CALL(*this, ProcessRegisterRequest(_, _, _, _)).WillByDefault(Invoke(
+ this,
+ &MockDeviceManagementBackend::SimulateSuccessfulRegisterRequest));
+ }
+ }
delegate->OnError(kErrorRequestFailed);
}
@@ -109,6 +140,15 @@ void MockDeviceManagementBackend::SimulateFailedPolicyRequest(
const std::string& device_id,
const em::DevicePolicyRequest& request,
DevicePolicyResponseDelegate* delegate) {
+ if (policy_remaining_fail_count_) {
+ policy_remaining_fail_count_--;
+ if (!policy_remaining_fail_count_) {
+ ON_CALL(*this, ProcessPolicyRequest(_, _, _, _)).
+ WillByDefault(Invoke(
+ this,
+ &MockDeviceManagementBackend::SimulateSuccessfulPolicyRequest));
+ }
+ }
delegate->OnError(kErrorRequestFailed);
}
« no previous file with comments | « chrome/browser/policy/mock_device_management_backend.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698