| 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..bb9454602b233f7f9368857b03d8b8ca1d31ad78 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 {
|
| ¬ifier_, 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, DontSetFetchingDone0) {
|
| + 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, DontSetFetchingDone1) {
|
| + 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, SetFetchingDone0) {
|
| + 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, SetFetchingDone1) {
|
| + 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, SetFetchingDone2) {
|
| + 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
|
|
|