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

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: 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
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);
}

Powered by Google App Engine
This is Rietveld 408576698