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

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

Issue 5331008: Persist 'this device is not managed' information (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move 'unmanaged' timestamp into DMPCache's file; introduce private DMPProvider constructor 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/device_management_policy_provider_unittest.cc
diff --git a/chrome/browser/policy/device_management_policy_provider_unittest.cc b/chrome/browser/policy/device_management_policy_provider_unittest.cc
index 1761e80ea60cd7b72cd0418f1f26421cd38aa2cc..62c75ab6d6e491c0b1e300d6dd4ccc7fe0851dc3 100644
--- a/chrome/browser/policy/device_management_policy_provider_unittest.cc
+++ b/chrome/browser/policy/device_management_policy_provider_unittest.cc
@@ -2,14 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/file_util.h"
#include "base/message_loop.h"
#include "base/scoped_temp_dir.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/net/gaia/token_service.h"
#include "chrome/browser/policy/configuration_policy_pref_store.h"
+#include "chrome/browser/policy/device_management_policy_cache.h"
#include "chrome/browser/policy/device_management_policy_provider.h"
#include "chrome/browser/policy/mock_configuration_policy_store.h"
#include "chrome/browser/policy/mock_device_management_backend.h"
+#include "chrome/browser/policy/proto/device_management_local.pb.h"
Mattias Nissler (ping if slow) 2010/11/26 10:37:45 What do you need this header for?
Jakob Kummerow 2010/11/26 11:07:42 Done. (Leftover from the earlier ugly workaround m
#include "chrome/common/net/gaia/gaia_constants.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/policy_constants.h"
@@ -34,22 +37,41 @@ class DeviceManagementPolicyProviderTest : public testing::Test {
virtual void SetUp() {
EXPECT_TRUE(storage_dir_.CreateUniqueTempDir());
- CreateNewBackend();
+ device_management_dir_ =
+ DeviceManagementPolicyProvider::GetOrCreateDeviceManagementDir(
+ storage_dir_.path());
CreateNewProvider();
+ EXPECT_TRUE(provider_->WaitingForInitialPolicies());
+ loop_.RunAllPending();
}
- void CreateNewBackend() {
+ void CreateNewProvider() {
backend_ = new MockDeviceManagementBackend;
+ token_service_.reset(new TokenService);
+ provider_.reset(new DeviceManagementPolicyProvider(
+ ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
+ backend_,
+ token_service_.get(),
+ storage_dir_.path()));
}
- void CreateNewProvider() {
+ void CreateNewProvider(int64 policy_refresh_rate_ms,
+ int64 policy_refresh_max_earlier_ms,
+ int64 policy_refresh_error_delay_ms,
+ int64 token_fetch_error_delay_ms,
+ int64 unmanaged_device_refresh_rate_ms) {
+ backend_ = new MockDeviceManagementBackend;
token_service_.reset(new TokenService);
provider_.reset(new DeviceManagementPolicyProvider(
ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
backend_,
token_service_.get(),
- storage_dir_.path()));
- loop_.RunAllPending();
+ storage_dir_.path(),
+ policy_refresh_rate_ms,
+ policy_refresh_max_earlier_ms,
+ policy_refresh_error_delay_ms,
+ token_fetch_error_delay_ms,
+ unmanaged_device_refresh_rate_ms));
}
void SimulateSuccessfulLoginAndRunPending() {
@@ -67,6 +89,7 @@ class DeviceManagementPolicyProviderTest : public testing::Test {
MockDeviceManagementBackendSucceedBooleanPolicy(
key::kDisableSpdy, true));
SimulateSuccessfulLoginAndRunPending();
+ EXPECT_FALSE(provider_->WaitingForInitialPolicies());
EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1);
provider_->Provide(&store);
ASSERT_EQ(1U, store.policy_map().size());
@@ -82,22 +105,17 @@ class DeviceManagementPolicyProviderTest : public testing::Test {
scoped_ptr<DeviceManagementPolicyProvider> provider_;
protected:
- void SetRefreshDelays(DeviceManagementPolicyProvider* provider,
- int64 policy_refresh_rate_ms,
- int64 policy_refresh_max_earlier_ms,
- int64 policy_refresh_error_delay_ms,
- int64 token_fetch_error_delay_ms) {
- provider->set_policy_refresh_rate_ms(policy_refresh_rate_ms);
- provider->set_policy_refresh_max_earlier_ms(policy_refresh_max_earlier_ms);
- provider->set_policy_refresh_error_delay_ms(policy_refresh_error_delay_ms);
- provider->set_token_fetch_error_delay_ms(token_fetch_error_delay_ms);
+ DeviceManagementPolicyCache* cache(DeviceManagementPolicyProvider* provider) {
+ return provider->cache_.get();
}
- private:
MessageLoop loop_;
+ ScopedTempDir storage_dir_;
+ FilePath device_management_dir_;
+
+ private:
BrowserThread ui_thread_;
BrowserThread file_thread_;
- ScopedTempDir storage_dir_;
scoped_ptr<TokenService> token_service_;
DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProviderTest);
@@ -110,12 +128,14 @@ TEST_F(DeviceManagementPolicyProviderTest, InitialProvideNoLogin) {
EXPECT_CALL(store, Apply(_, _)).Times(0);
provider_->Provide(&store);
EXPECT_TRUE(store.policy_map().empty());
+ EXPECT_TRUE(provider_->WaitingForInitialPolicies());
}
// If the login is successful and there's no previously-fetched policy, the
// policy should be fetched from the server and should be available the first
// time the Provide method is called.
TEST_F(DeviceManagementPolicyProviderTest, InitialProvideWithLogin) {
+ EXPECT_TRUE(provider_->WaitingForInitialPolicies());
SimulateSuccessfulInitialPolicyFetch();
}
@@ -141,21 +161,21 @@ TEST_F(DeviceManagementPolicyProviderTest, SecondProvide) {
// Simulate a app relaunch by constructing a new provider. Policy should be
// refreshed (since that might be the purpose of the app relaunch).
- CreateNewBackend();
+ CreateNewProvider();
EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
MockDeviceManagementBackendSucceedBooleanPolicy(
key::kDisableSpdy, true));
- CreateNewProvider();
+ loop_.RunAllPending();
Mock::VerifyAndClearExpectations(backend_);
// Simulate another app relaunch, this time against a failing backend.
// Cached policy should still be available.
- CreateNewBackend();
MockConfigurationPolicyStore store;
+ CreateNewProvider();
EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
MockDeviceManagementBackendFailPolicy(
DeviceManagementBackend::kErrorRequestFailed));
- CreateNewProvider();
+ loop_.RunAllPending();
SimulateSuccessfulLoginAndRunPending();
EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1);
provider_->Provide(&store);
@@ -176,7 +196,7 @@ TEST_F(DeviceManagementPolicyProviderTest, FetchTriggersRefresh) {
TEST_F(DeviceManagementPolicyProviderTest, ErrorCausesNewRequest) {
InSequence s;
- SetRefreshDelays(provider_.get(), 1000 * 1000, 0, 0, 0);
+ CreateNewProvider(1000 * 1000, 0, 0, 0, 0);
EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
MockDeviceManagementBackendFailRegister(
DeviceManagementBackend::kErrorRequestFailed));
@@ -195,7 +215,7 @@ TEST_F(DeviceManagementPolicyProviderTest, ErrorCausesNewRequest) {
TEST_F(DeviceManagementPolicyProviderTest, RefreshPolicies) {
InSequence s;
- SetRefreshDelays(provider_.get(), 0, 0, 1000 * 1000, 1000);
+ CreateNewProvider(0, 0, 1000 * 1000, 1000, 0);
EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
MockDeviceManagementBackendSucceedRegister());
EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
@@ -210,4 +230,28 @@ TEST_F(DeviceManagementPolicyProviderTest, RefreshPolicies) {
SimulateSuccessfulLoginAndRunPending();
}
+// This test tests three things (see numbered comments below):
+TEST_F(DeviceManagementPolicyProviderTest, UnmanagedDevice) {
+ InSequence s;
+ EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
+ MockDeviceManagementBackendFailRegister(
+ DeviceManagementBackend::kErrorServiceManagementNotSupported));
+ SimulateSuccessfulLoginAndRunPending();
+ // (1) The provider's DMPolicyCache should know that the device is not
+ // managed.
+ EXPECT_TRUE(cache(provider_.get())->is_device_unmanaged());
+ // (2) On restart, the provider should detect that this is not the first
+ // login.
+ CreateNewProvider(1000*1000, 0, 0, 0, 0);
+ EXPECT_FALSE(provider_->WaitingForInitialPolicies());
+ EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
+ MockDeviceManagementBackendSucceedRegister());
+ EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
+ MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true));
+ SimulateSuccessfulLoginAndRunPending();
+ // (3) Since the backend call this time returned a device id, the "unmanaged"
+ // marker should have been deleted.
+ EXPECT_FALSE(cache(provider_.get())->is_device_unmanaged());
+}
+
} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698