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

Unified Diff: chrome/browser/policy/mock_device_management_backend.cc

Issue 5338004: Cleanup mock device management backend (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge with latest 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') | chrome/chrome_tests.gypi » ('j') | 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
deleted file mode 100644
index ca61feb5e26540b09c06b6dd70b8c2d790800511..0000000000000000000000000000000000000000
--- a/chrome/browser/policy/mock_device_management_backend.cc
+++ /dev/null
@@ -1,163 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/policy/mock_device_management_backend.h"
-
-#include "base/basictypes.h"
-#include "base/logging.h"
-#include "base/stl_util-inl.h"
-
-namespace {
-
-static const char kFakeDeviceManagementToken[] = "FAKE_DEVICE_TOKEN_";
-static char next_token_suffix_ = '0';
-
-} // namespace
-
-namespace policy {
-
-using ::testing::_;
-using ::testing::Invoke;
-
-using em::DeviceRegisterRequest;
-using em::DeviceUnregisterRequest;
-using em::DevicePolicyRequest;
-using em::DeviceRegisterResponse;
-using em::DeviceUnregisterResponse;
-using em::DevicePolicyResponse;
-
-MockDeviceManagementBackend::MockDeviceManagementBackend()
- : 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");
-}
-
-MockDeviceManagementBackend::~MockDeviceManagementBackend() {
-}
-
-void MockDeviceManagementBackend::AllShouldSucceed() {
- ON_CALL(*this, ProcessRegisterRequest(_, _, _, _)).
- WillByDefault(Invoke(
- this,
- &MockDeviceManagementBackend::SimulateSuccessfulRegisterRequest));
- ON_CALL(*this, ProcessPolicyRequest(_, _, _, _)).
- WillByDefault(Invoke(
- this,
- &MockDeviceManagementBackend::SimulateSuccessfulPolicyRequest));
-}
-
-void MockDeviceManagementBackend::AllShouldFail() {
- ON_CALL(*this, ProcessRegisterRequest(_, _, _, _)).
- WillByDefault(Invoke(
- this,
- &MockDeviceManagementBackend::SimulateFailedRegisterRequest));
- ON_CALL(*this, ProcessPolicyRequest(_, _, _, _)).
- WillByDefault(Invoke(
- this,
- &MockDeviceManagementBackend::SimulateFailedPolicyRequest));
-}
-
-void MockDeviceManagementBackend::UnmanagedDevice() {
- ON_CALL(*this, ProcessRegisterRequest(_, _, _, _)).
- WillByDefault(Invoke(
- this,
- &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();
- em::GenericNamedValue* named_value = policy_value->add_named_value();
- named_value->set_name(policy_name);
- named_value->mutable_value()->set_value_type(
- em::GenericValue::VALUE_TYPE_BOOL);
- named_value->mutable_value()->set_bool_value(value);
-}
-
-void MockDeviceManagementBackend::SimulateSuccessfulRegisterRequest(
- const std::string& auth_token,
- const std::string& device_id,
- const em::DeviceRegisterRequest& request,
- DeviceRegisterResponseDelegate* delegate) {
- DeviceRegisterResponse response;
- std::string token(kFakeDeviceManagementToken);
- token += next_token_suffix_++;
- response.set_device_management_token(token);
- delegate->HandleRegisterResponse(response);
-}
-
-void MockDeviceManagementBackend::SimulateSuccessfulPolicyRequest(
- const std::string& device_management_token,
- 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_);
-}
-
-void MockDeviceManagementBackend::SimulateFailedRegisterRequest(
- const std::string& auth_token,
- 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);
-}
-
-void MockDeviceManagementBackend::SimulateFailedPolicyRequest(
- const std::string& device_management_token,
- 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);
-}
-
-void MockDeviceManagementBackend::SimulateUnmanagedRegisterRequest(
- const std::string& auth_token,
- const std::string& device_id,
- const em::DeviceRegisterRequest& request,
- DeviceRegisterResponseDelegate* delegate) {
- delegate->OnError(kErrorServiceManagementNotSupported);
-}
-
-} // namespace
« no previous file with comments | « chrome/browser/policy/mock_device_management_backend.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698