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

Unified Diff: chrome/browser/policy/device_policy_cache_unittest.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_unittest.cc
diff --git a/chrome/browser/policy/device_policy_cache_unittest.cc b/chrome/browser/policy/device_policy_cache_unittest.cc
index 3a62009fea40d97f236d997fb6039cf896420645..67920b59a0951d4b02990691b5e6363c8a1c8d7e 100644
--- a/chrome/browser/policy/device_policy_cache_unittest.cc
+++ b/chrome/browser/policy/device_policy_cache_unittest.cc
@@ -4,10 +4,8 @@
#include "chrome/browser/policy/device_policy_cache.h"
-#include "chrome/browser/chromeos/cros/cryptohome_library.h"
-#include "chrome/browser/chromeos/login/mock_signed_settings_helper.h"
-#include "chrome/browser/policy/cloud_policy_data_store.h"
-#include "chrome/browser/policy/enterprise_install_attributes.h"
+#include "base/message_loop.h"
+#include "chrome/browser/policy/device_policy_cache_test_base.h"
#include "content/test/test_browser_thread.h"
#include "policy/policy_constants.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -15,171 +13,79 @@
namespace em = enterprise_management;
-namespace policy {
-
-namespace {
-
-// Test registration user name.
-const char kTestUser[] = "test@example.com";
-
-using ::chromeos::SignedSettings;
using ::testing::InSequence;
-using ::testing::_;
-
-void CreatePolicy(em::PolicyFetchResponse* policy,
- const std::string& user,
- em::ChromeDeviceSettingsProto& settings) {
- // 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(user);
- signed_response.set_request_token("dmtoken");
- signed_response.set_device_id("deviceid");
- EXPECT_TRUE(
- settings.SerializeToString(signed_response.mutable_policy_value()));
- std::string serialized_signed_response;
- EXPECT_TRUE(signed_response.SerializeToString(&serialized_signed_response));
- policy->set_policy_data(serialized_signed_response);
-}
-
-void CreateRefreshRatePolicy(em::PolicyFetchResponse* policy,
- const std::string& user,
- int refresh_rate) {
- em::ChromeDeviceSettingsProto settings;
- settings.mutable_device_policy_refresh_rate()->
- set_device_policy_refresh_rate(refresh_rate);
- CreatePolicy(policy, user, settings);
-}
-
-void CreateProxyPolicy(em::PolicyFetchResponse* policy,
- const std::string& user,
- const std::string& proxy_mode,
- const std::string& proxy_server,
- const std::string& proxy_pac_url,
- const std::string& proxy_bypass_list) {
- em::ChromeDeviceSettingsProto settings;
- 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);
- CreatePolicy(policy, user, settings);
-}
-} // namespace
+namespace policy {
class DevicePolicyCacheTest : public testing::Test {
protected:
DevicePolicyCacheTest()
- : cryptohome_(chromeos::CryptohomeLibrary::GetImpl(true)),
- install_attributes_(cryptohome_.get()),
- message_loop_(MessageLoop::TYPE_UI),
+ : message_loop_(MessageLoop::TYPE_UI),
ui_thread_(content::BrowserThread::UI, &message_loop_),
file_thread_(content::BrowserThread::FILE, &message_loop_) {}
- virtual void SetUp() {
- data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies());
- cache_.reset(new DevicePolicyCache(data_store_.get(),
- &install_attributes_,
- &signed_settings_helper_));
- }
-
- virtual void TearDown() {
- cache_.reset();
+ virtual void SetUp() OVERRIDE {
+ cache_helper_.reset(new DevicePolicyCacheTestHelper());
+ cache_ = cache_helper_->cache();
+ ASSERT_TRUE(cache_);
}
- void MakeEnterpriseDevice(const char* registration_user) {
- ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
- install_attributes_.LockDevice(
- registration_user,
- DEVICE_MODE_ENTERPRISE,
- std::string()));
+ virtual void TearDown() OVERRIDE {
+ cache_helper_.reset();
}
const Value* GetPolicy(const char* policy_name) {
return cache_->policy()->GetValue(policy_name);
}
- scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_;
- EnterpriseInstallAttributes install_attributes_;
- scoped_ptr<CloudPolicyDataStore> data_store_;
- chromeos::MockSignedSettingsHelper signed_settings_helper_;
- scoped_ptr<DevicePolicyCache> cache_;
-
MessageLoop message_loop_;
content::TestBrowserThread ui_thread_;
content::TestBrowserThread file_thread_;
+ scoped_ptr<DevicePolicyCacheTestHelper> cache_helper_;
+ DevicePolicyCache* cache_;
+
private:
DISALLOW_COPY_AND_ASSIGN(DevicePolicyCacheTest);
};
TEST_F(DevicePolicyCacheTest, Startup) {
- em::PolicyFetchResponse policy;
- CreateRefreshRatePolicy(&policy, kTestUser, 120);
- EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
- MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
- policy));
- cache_->Load();
- testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
+ cache_helper_->SetRefreshRatePolicy(120);
+ EXPECT_TRUE(cache_helper_->LoadPolicy());
base::FundamentalValue expected(120);
EXPECT_TRUE(Value::Equals(&expected,
GetPolicy(key::kDevicePolicyRefreshRate)));
}
TEST_F(DevicePolicyCacheTest, SetPolicy) {
- InSequence s;
-
- MakeEnterpriseDevice(kTestUser);
+ cache_helper_->MakeEnterpriseDevice();
// Startup.
- em::PolicyFetchResponse policy;
- CreateRefreshRatePolicy(&policy, kTestUser, 120);
- EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
- MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
- policy));
- cache_->Load();
- testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
+ cache_helper_->SetRefreshRatePolicy(120);
+ EXPECT_TRUE(cache_helper_->LoadPolicy());
base::FundamentalValue expected(120);
EXPECT_TRUE(Value::Equals(&expected,
GetPolicy(key::kDevicePolicyRefreshRate)));
// Set new policy information.
- em::PolicyFetchResponse new_policy;
- CreateRefreshRatePolicy(&new_policy, kTestUser, 300);
- EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).WillOnce(
- MockSignedSettingsHelperStorePolicy(chromeos::SignedSettings::SUCCESS));
- EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
- MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
- new_policy));
- EXPECT_TRUE(cache_->SetPolicy(new_policy));
- testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
+ cache_helper_->SetRefreshRatePolicy(300);
+ EXPECT_TRUE(cache_helper_->SetPolicy(true));
base::FundamentalValue updated_expected(300);
EXPECT_TRUE(Value::Equals(&updated_expected,
GetPolicy(key::kDevicePolicyRefreshRate)));
}
TEST_F(DevicePolicyCacheTest, SetPolicyWrongUser) {
- InSequence s;
-
- MakeEnterpriseDevice(kTestUser);
+ cache_helper_->MakeEnterpriseDevice();
// Startup.
- em::PolicyFetchResponse policy;
- CreateRefreshRatePolicy(&policy, kTestUser, 120);
- EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
- MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
- policy));
- cache_->Load();
- testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
+ cache_helper_->SetRefreshRatePolicy(120);
+ EXPECT_TRUE(cache_helper_->LoadPolicy());
// Set new policy information. This should fail due to invalid user.
- em::PolicyFetchResponse new_policy;
- CreateRefreshRatePolicy(&new_policy, "foreign_user@example.com", 300);
- EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0);
- EXPECT_FALSE(cache_->SetPolicy(new_policy));
- testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
+ cache_helper_->SetUsername("foreign_user@example.com");
+ cache_helper_->SetRefreshRatePolicy(300);
+ EXPECT_FALSE(cache_helper_->SetPolicy(false));
base::FundamentalValue expected(120);
EXPECT_TRUE(Value::Equals(&expected,
@@ -187,23 +93,14 @@ TEST_F(DevicePolicyCacheTest, SetPolicyWrongUser) {
}
TEST_F(DevicePolicyCacheTest, SetPolicyNonEnterpriseDevice) {
- InSequence s;
-
// Startup.
- em::PolicyFetchResponse policy;
- CreateRefreshRatePolicy(&policy, kTestUser, 120);
- EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
- MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
- policy));
- cache_->Load();
- testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
+ cache_helper_->SetRefreshRatePolicy(120);
+ EXPECT_TRUE(cache_helper_->LoadPolicy());
- // Set new policy information. This should fail due to invalid user.
- em::PolicyFetchResponse new_policy;
- CreateRefreshRatePolicy(&new_policy, kTestUser, 120);
- EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0);
- EXPECT_FALSE(cache_->SetPolicy(new_policy));
- testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
+ // Set new policy information. This should fail because the device is not
+ // enrolled.
+ cache_helper_->SetRefreshRatePolicy(300);
+ EXPECT_FALSE(cache_helper_->SetPolicy(false));
base::FundamentalValue expected(120);
EXPECT_TRUE(Value::Equals(&expected,
@@ -211,17 +108,14 @@ TEST_F(DevicePolicyCacheTest, SetPolicyNonEnterpriseDevice) {
}
TEST_F(DevicePolicyCacheTest, SetProxyPolicy) {
- MakeEnterpriseDevice(kTestUser);
+ cache_helper_->MakeEnterpriseDevice();
// Startup.
- em::PolicyFetchResponse policy;
- CreateProxyPolicy(&policy, kTestUser, "direct", "http://proxy:8080",
- "http://proxy:8080/pac.js", "127.0.0.1,example.com");
- EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
- MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
- policy));
- cache_->Load();
- testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
+ cache_helper_->SetProxyPolicy("direct", "http://proxy:8080",
+ "http://proxy:8080/pac.js",
+ "127.0.0.1,example.com");
+ EXPECT_TRUE(cache_helper_->LoadPolicy());
+
DictionaryValue expected;
expected.SetString(key::kProxyMode, "direct");
expected.SetString(key::kProxyServer, "http://proxy:8080");
@@ -232,24 +126,18 @@ TEST_F(DevicePolicyCacheTest, SetProxyPolicy) {
}
TEST_F(DevicePolicyCacheTest, SetDeviceNetworkConfigurationPolicy) {
- MakeEnterpriseDevice(kTestUser);
+ cache_helper_->MakeEnterpriseDevice();
// Startup.
std::string fake_config("{ 'NetworkConfigurations': [] }");
- em::PolicyFetchResponse policy;
em::ChromeDeviceSettingsProto settings;
settings.mutable_open_network_configuration()->set_open_network_configuration(
fake_config);
- CreatePolicy(&policy, kTestUser, settings);
- EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
- MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
- policy));
- cache_->Load();
- testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
+ cache_helper_->SetSettings(settings);
+ EXPECT_TRUE(cache_helper_->LoadPolicy());
StringValue expected_config(fake_config);
- EXPECT_TRUE(
- Value::Equals(&expected_config,
- GetPolicy(key::kDeviceOpenNetworkConfiguration)));
+ EXPECT_TRUE(Value::Equals(&expected_config,
+ GetPolicy(key::kDeviceOpenNetworkConfiguration)));
}
} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698