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

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: 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..630d1565f2c0f62ef3e171d852dcd42876d90a8b 100644
--- a/chrome/browser/policy/device_management_policy_provider_unittest.cc
+++ b/chrome/browser/policy/device_management_policy_provider_unittest.cc
@@ -2,6 +2,7 @@
// 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"
@@ -34,8 +35,13 @@ class DeviceManagementPolicyProviderTest : public testing::Test {
virtual void SetUp() {
EXPECT_TRUE(storage_dir_.CreateUniqueTempDir());
+ device_management_dir_ =
+ DeviceManagementPolicyProvider::GetOrCreateDeviceManagementDir(
+ storage_dir_.path());
CreateNewBackend();
- CreateNewProvider();
+ CreateNewProviderDontRunPending();
+ EXPECT_TRUE(provider_->WaitingForInitialPolicies());
+ loop_.RunAllPending();
}
void CreateNewBackend() {
@@ -43,13 +49,17 @@ class DeviceManagementPolicyProviderTest : public testing::Test {
}
void CreateNewProvider() {
danno 2010/11/25 16:35:01 Probably would be clearer to have: CreateNewProvid
Jakob Kummerow 2010/11/25 16:54:24 Done. See Mattias' comment and my reply.
+ CreateNewProviderDontRunPending();
+ loop_.RunAllPending();
+ }
+
+ void CreateNewProviderDontRunPending() {
Mattias Nissler (ping if slow) 2010/11/25 16:12:36 Hm, maybe it's worth to just have one of them and
Jakob Kummerow 2010/11/25 16:28:45 Done. I went for the first option -- only provide
token_service_.reset(new TokenService);
provider_.reset(new DeviceManagementPolicyProvider(
ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
backend_,
token_service_.get(),
storage_dir_.path()));
- loop_.RunAllPending();
}
void SimulateSuccessfulLoginAndRunPending() {
@@ -67,6 +77,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());
@@ -74,6 +85,12 @@ class DeviceManagementPolicyProviderTest : public testing::Test {
Mock::VerifyAndClearExpectations(&store);
}
+ void OverwriteUnmanagedDeviceTimestamp(const FilePath& storage_dir,
+ const base::Time& timestamp) {
+ DeviceManagementPolicyProvider::CreateUnmanagedDeviceMarker(
+ storage_dir, timestamp);
+ }
+
virtual void TearDown() {
loop_.RunAllPending();
}
@@ -93,11 +110,13 @@ class DeviceManagementPolicyProviderTest : public testing::Test {
provider->set_token_fetch_error_delay_ms(token_fetch_error_delay_ms);
}
- 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 +129,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();
}
@@ -210,4 +231,35 @@ 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) Since the backend call returned "unmanaged", the corresponding marker
+ // file should have been created.
+ FilePath path(device_management_dir_.Append("UnmanagedDevice"));
+ EXPECT_TRUE(file_util::PathExists(path));
+ // Manipulate the timestamp to trick the restarted provider into re-checking
+ // immediately.
+ OverwriteUnmanagedDeviceTimestamp(
+ device_management_dir_,
+ base::Time::NowFromSystemTime() - base::TimeDelta::FromDays(2));
+ CreateNewBackend();
+ CreateNewProviderDontRunPending();
+ // (2) On restart, the provider should detect that this is not the first
+ // login.
+ 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(file_util::PathExists(path));
+}
+
} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698