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

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

Issue 8499021: UserPolicyCache only becomes ready after policy has been fetched. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 9 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/cloud_policy_controller_unittest.cc
diff --git a/chrome/browser/policy/cloud_policy_controller_unittest.cc b/chrome/browser/policy/cloud_policy_controller_unittest.cc
index 68d57bd4bac64fc2651284ca0049c1e5ecfa44cd..8636c5c7db455b212d22c1b2e839dd491eaf75d5 100644
--- a/chrome/browser/policy/cloud_policy_controller_unittest.cc
+++ b/chrome/browser/policy/cloud_policy_controller_unittest.cc
@@ -51,7 +51,8 @@ class CloudPolicyControllerTest : public testing::Test {
virtual void SetUp() {
ASSERT_TRUE(temp_user_data_dir_.CreateUniqueTempDir());
cache_.reset(new UserPolicyCache(
- temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest")));
+ temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest"),
+ false /* wait_for_policy_fetch */));
token_fetcher_.reset(new MockDeviceTokenFetcher(cache_.get()));
EXPECT_CALL(service_, CreateBackend())
.Times(AnyNumber())
@@ -70,6 +71,18 @@ class CloudPolicyControllerTest : public testing::Test {
&notifier_, new DummyWorkScheduler));
}
+ void CreateNewWaitingCache() {
+ cache_.reset(new UserPolicyCache(
+ temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest"),
+ true /* wait_for_policy_fetch */));
+ // Make this cache's disk cache ready, but have it still waiting for a
+ // policy fetch.
+ cache_->Load();
+ loop_.RunAllPending();
+ ASSERT_TRUE(cache_->last_policy_refresh_time().is_null());
+ ASSERT_FALSE(cache_->IsReady());
+ }
+
void ExpectHasSpdyPolicy() {
base::FundamentalValue expected(true);
const PolicyMap* policy_map = cache_->policy(
@@ -239,4 +252,61 @@ TEST_F(CloudPolicyControllerTest, InvalidSerialNumber) {
loop_.RunAllPending();
}
+TEST_F(CloudPolicyControllerTest, DontSetFetchingDoneWithoutTokens) {
+ CreateNewWaitingCache();
+ CreateNewController();
+ // Initialized without an oauth token, goes into TOKEN_UNAVAILABLE state.
+ // This means the controller is still waiting for an oauth token fetch.
+ EXPECT_FALSE(cache_->IsReady());
+}
+
+TEST_F(CloudPolicyControllerTest, DontSetFetchingDoneWithoutFetching) {
+ CreateNewWaitingCache();
+ data_store_->SetupForTesting("device_token", "device_id",
+ "who@what.com", "auth", true);
+ CreateNewController();
+ // Initialized with an oauth token, goes into TOKEN_VALID state.
+ // This means the controller has an oauth token and should fetch the next
+ // token, which is the dm server register token.
+ EXPECT_FALSE(cache_->IsReady());
+}
+
+TEST_F(CloudPolicyControllerTest, SetFetchingDoneForUnmanagedUsers) {
+ CreateNewWaitingCache();
+ data_store_->SetupForTesting("", "device_id",
+ "user@gmail.com", "auth", true);
+ CreateNewController();
+ loop_.RunAllPending();
+ // User is in an unmanaged domain.
+ EXPECT_TRUE(cache_->IsReady());
+ EXPECT_TRUE(cache_->last_policy_refresh_time().is_null());
+}
+
+TEST_F(CloudPolicyControllerTest, SetFetchingDoneAfterPolicyFetch) {
+ CreateNewWaitingCache();
+ data_store_->SetupForTesting("device_token", "device_id",
+ "user@enterprise.com", "auth", true);
+ EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _)).WillOnce(DoAll(
+ InvokeWithoutArgs(this, &CloudPolicyControllerTest::StopMessageLoop),
+ MockDeviceManagementBackendSucceedSpdyCloudPolicy()));
+ CreateNewController();
+ loop_.RunAllPending();
+ EXPECT_TRUE(cache_->IsReady());
+ EXPECT_FALSE(cache_->last_policy_refresh_time().is_null());
+}
+
+TEST_F(CloudPolicyControllerTest, SetFetchingDoneAfterPolicyFetchFails) {
+ CreateNewWaitingCache();
+ data_store_->SetupForTesting("device_token", "device_id",
+ "user@enterprise.com", "auth", true);
+ EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _)).WillOnce(DoAll(
+ InvokeWithoutArgs(this, &CloudPolicyControllerTest::StopMessageLoop),
+ MockDeviceManagementBackendFailPolicy(
+ DeviceManagementBackend::kErrorRequestFailed)));
+ CreateNewController();
+ loop_.RunAllPending();
+ EXPECT_TRUE(cache_->IsReady());
+ EXPECT_TRUE(cache_->last_policy_refresh_time().is_null());
+}
+
} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698