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 613022f7c27fa0eb91d76f854b84a788bfbdbe92..d0c8668710d3fb8c909bd5c7a6109af356a7932d 100644 |
--- a/chrome/browser/policy/mock_device_management_backend.cc |
+++ b/chrome/browser/policy/mock_device_management_backend.cc |
@@ -28,7 +28,13 @@ using em::DeviceUnregisterResponse; |
using em::DevicePolicyResponse; |
MockDeviceManagementBackend::MockDeviceManagementBackend() |
- : DeviceManagementBackend() { |
+ : DeviceManagementBackend(), |
+ 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.
|
+ policy_remaining_fail_count_(0), |
+ register_works_later_(false), |
+ register_remaining_fail_count_(0), |
+ policy_fails_later_(false), |
+ 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 +72,20 @@ void MockDeviceManagementBackend::UnmanagedDevice() { |
&MockDeviceManagementBackend::SimulateUnmanagedRegisterRequest)); |
} |
+void MockDeviceManagementBackend::RegisterFailsOncePolicyFailsTwice() { |
+ register_works_later_ = true; |
+ register_remaining_fail_count_ = 1; |
+ policy_works_later_ = true; |
+ policy_remaining_fail_count_ = 2; |
+ AllShouldFail(); |
+} |
+ |
+void MockDeviceManagementBackend::AllWorksFirstPolicyFailsLater() { |
+ policy_fails_later_ = true; |
+ policy_remaining_success_count_ = 3; |
+ AllShouldSucceed(); |
+} |
+ |
void MockDeviceManagementBackend::AddBooleanPolicy(const char* policy_name, |
bool value) { |
em::GenericSetting* policy_value = policy_setting_->mutable_policy_value(); |
@@ -92,6 +112,15 @@ void MockDeviceManagementBackend::SimulateSuccessfulPolicyRequest( |
const std::string& device_management_token, |
const em::DevicePolicyRequest& request, |
DevicePolicyResponseDelegate* delegate) { |
+ if (policy_fails_later_) { |
+ policy_remaining_success_count_--; |
+ if (!policy_remaining_success_count_) { |
+ ON_CALL(*this, ProcessPolicyRequest(_, _, _)). |
+ WillByDefault(Invoke( |
+ this, |
+ &MockDeviceManagementBackend::SimulateFailedPolicyRequest)); |
+ } |
+ } |
delegate->HandlePolicyResponse(policy_response_); |
} |
@@ -100,6 +129,14 @@ void MockDeviceManagementBackend::SimulateFailedRegisterRequest( |
const std::string& device_id, |
const em::DeviceRegisterRequest& request, |
DeviceRegisterResponseDelegate* delegate) { |
+ if (register_works_later_) { |
+ register_remaining_fail_count_--; |
+ if (!register_remaining_fail_count_) { |
+ ON_CALL(*this, ProcessRegisterRequest(_, _, _, _)).WillByDefault(Invoke( |
+ this, |
+ &MockDeviceManagementBackend::SimulateSuccessfulRegisterRequest)); |
+ } |
+ } |
delegate->OnError(kErrorRequestFailed); |
} |
@@ -107,6 +144,15 @@ void MockDeviceManagementBackend::SimulateFailedPolicyRequest( |
const std::string& device_management_token, |
const em::DevicePolicyRequest& request, |
DevicePolicyResponseDelegate* delegate) { |
+ if (policy_works_later_) { |
+ policy_remaining_fail_count_--; |
+ if (!policy_remaining_fail_count_) { |
+ ON_CALL(*this, ProcessPolicyRequest(_, _, _)). |
+ WillByDefault(Invoke( |
+ this, |
+ &MockDeviceManagementBackend::SimulateSuccessfulPolicyRequest)); |
+ } |
+ } |
delegate->OnError(kErrorRequestFailed); |
} |