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

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

Issue 9911029: Refactored the CloudPolicyProvider so that it becomes initialized once and stays initialized. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Updated expectations in failing browser_tests Created 8 years, 9 months 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/device_policy_cache_test_base.cc
diff --git a/chrome/browser/policy/device_policy_cache_test_base.cc b/chrome/browser/policy/device_policy_cache_test_base.cc
new file mode 100644
index 0000000000000000000000000000000000000000..81dd6ecdc60146f3c232b3e631db212731c991dc
--- /dev/null
+++ b/chrome/browser/policy/device_policy_cache_test_base.cc
@@ -0,0 +1,110 @@
+// Copyright (c) 2012 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/device_policy_cache_test_base.h"
+
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace em = enterprise_management;
+
+using ::chromeos::SignedSettings;
+using ::testing::_;
+
+namespace policy {
+
+const char DevicePolicyCacheTestHelper::kTestUser[] = "test@example.com";
+
+DevicePolicyCacheTestHelper::DevicePolicyCacheTestHelper()
+ : cryptohome_(chromeos::CryptohomeLibrary::GetImpl(true)),
+ install_attributes_(cryptohome_.get()),
+ data_store_(CloudPolicyDataStore::CreateForDevicePolicies()),
+ scoped_cache_(new DevicePolicyCache(data_store_.get(),
+ &install_attributes_,
+ &signed_settings_helper_)),
+ cache_(scoped_cache_.get()),
+ username_(kTestUser) {}
+
+DevicePolicyCacheTestHelper::~DevicePolicyCacheTestHelper() {}
+
+bool DevicePolicyCacheTestHelper::MakeEnterpriseDevice() {
+ return EnterpriseInstallAttributes::LOCK_SUCCESS ==
+ install_attributes_.LockDevice(kTestUser, DEVICE_MODE_ENTERPRISE, "");
+}
+
+void DevicePolicyCacheTestHelper::ResetPolicy() {
+ settings_.Clear();
+ username_ = kTestUser;
+}
+
+void DevicePolicyCacheTestHelper::SetRefreshRatePolicy(int refresh_rate) {
+ settings_.mutable_device_policy_refresh_rate()->
+ set_device_policy_refresh_rate(refresh_rate);
+}
+
+void DevicePolicyCacheTestHelper::SetProxyPolicy(
+ const std::string& proxy_mode,
+ const std::string& proxy_server,
+ const std::string& proxy_pac_url,
+ const std::string& proxy_bypass_list) {
+ em::DeviceProxySettingsProto* proxy_settings =
+ settings_.mutable_device_proxy_settings();
+ proxy_settings->set_proxy_mode(proxy_mode);
+ proxy_settings->set_proxy_server(proxy_server);
+ proxy_settings->set_proxy_pac_url(proxy_pac_url);
+ proxy_settings->set_proxy_bypass_list(proxy_bypass_list);
+}
+
+void DevicePolicyCacheTestHelper::SetSettings(
+ const enterprise_management::ChromeDeviceSettingsProto& proto) {
+ settings_.CopyFrom(proto);
+}
+
+bool DevicePolicyCacheTestHelper::LoadPolicy() {
+ if (!SerializePolicy())
+ return false;
+
+ EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
+ MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
+ policy_));
+
+ cache_->Load();
+ return testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
+}
+
+bool DevicePolicyCacheTestHelper::SetPolicy(bool expect_store) {
+ if (!SerializePolicy())
+ return false;
+
+ if (expect_store) {
+ EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).WillOnce(
+ MockSignedSettingsHelperStorePolicy(chromeos::SignedSettings::SUCCESS));
+ EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
+ MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
+ policy_));
+ }
+
+ bool result = cache_->SetPolicy(policy_);
+ cache_->SetFetchingDone();
+ if (!result)
+ return false;
+ return testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
+}
+
+bool DevicePolicyCacheTestHelper::SerializePolicy() {
+ // This method omits a few fields which currently aren't needed by tests:
+ // timestamp, machine_name, public key info.
+ em::PolicyData signed_response;
+ signed_response.set_username(username_);
+ signed_response.set_request_token("dmtoken");
+ signed_response.set_device_id("deviceid");
+ if (!settings_.SerializeToString(signed_response.mutable_policy_value()))
+ return false;
+ std::string serialized_signed_response;
+ if (!signed_response.SerializeToString(&serialized_signed_response))
+ return false;
+ policy_.set_policy_data(serialized_signed_response);
+ return true;
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698