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

Side by Side Diff: chrome/browser/policy/device_token_fetcher_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: Fixed build-breaking typo 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/policy/device_token_fetcher.h" 5 #include "chrome/browser/policy/device_token_fetcher.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/scoped_temp_dir.h" 8 #include "base/scoped_temp_dir.h"
9 #include "chrome/browser/policy/cloud_policy_data_store.h" 9 #include "chrome/browser/policy/cloud_policy_data_store.h"
10 #include "chrome/browser/policy/logging_work_scheduler.h" 10 #include "chrome/browser/policy/logging_work_scheduler.h"
(...skipping 18 matching lines...) Expand all
29 class DeviceTokenFetcherTest : public testing::Test { 29 class DeviceTokenFetcherTest : public testing::Test {
30 protected: 30 protected:
31 DeviceTokenFetcherTest() 31 DeviceTokenFetcherTest()
32 : ui_thread_(BrowserThread::UI, &loop_), 32 : ui_thread_(BrowserThread::UI, &loop_),
33 file_thread_(BrowserThread::FILE, &loop_) { 33 file_thread_(BrowserThread::FILE, &loop_) {
34 EXPECT_TRUE(temp_user_data_dir_.CreateUniqueTempDir()); 34 EXPECT_TRUE(temp_user_data_dir_.CreateUniqueTempDir());
35 } 35 }
36 36
37 virtual void SetUp() { 37 virtual void SetUp() {
38 cache_.reset(new UserPolicyCache( 38 cache_.reset(new UserPolicyCache(
39 temp_user_data_dir_.path().AppendASCII("DeviceTokenFetcherTest"))); 39 temp_user_data_dir_.path().AppendASCII("DeviceTokenFetcherTest"),
40 false /* wait_for_policy_fetch */));
40 EXPECT_CALL(service_, CreateBackend()) 41 EXPECT_CALL(service_, CreateBackend())
41 .Times(AnyNumber()) 42 .Times(AnyNumber())
42 .WillRepeatedly(MockDeviceManagementServiceProxyBackend(&backend_)); 43 .WillRepeatedly(MockDeviceManagementServiceProxyBackend(&backend_));
43 data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); 44 data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies());
44 data_store_->AddObserver(&observer_); 45 data_store_->AddObserver(&observer_);
45 } 46 }
46 47
47 virtual void TearDown() { 48 virtual void TearDown() {
48 loop_.RunAllPending(); 49 loop_.RunAllPending();
49 data_store_->RemoveObserver(&observer_); 50 data_store_->RemoveObserver(&observer_);
50 } 51 }
51 52
52 void FetchToken(DeviceTokenFetcher* fetcher) { 53 void FetchToken(DeviceTokenFetcher* fetcher) {
53 data_store_->SetupForTesting("", "fake_device_id", "fake_user_name", 54 data_store_->SetupForTesting("", "fake_device_id", "fake_user_name",
54 "fake_auth_token", true); 55 "fake_auth_token", true);
55 fetcher->FetchToken(); 56 fetcher->FetchToken();
56 } 57 }
57 58
59 void CreateNewWaitingCache() {
60 cache_.reset(new UserPolicyCache(
61 temp_user_data_dir_.path().AppendASCII("DeviceTokenFetcherTest"),
62 true /* wait_for_policy_fetch */));
63 // Make this cache's disk cache ready, but have it still waiting for a
64 // policy fetch.
65 cache_->Load();
66 loop_.RunAllPending();
67 ASSERT_TRUE(cache_->last_policy_refresh_time().is_null());
68 ASSERT_FALSE(cache_->IsReady());
69 }
70
58 MessageLoop loop_; 71 MessageLoop loop_;
59 MockDeviceManagementBackend backend_; 72 MockDeviceManagementBackend backend_;
60 MockDeviceManagementService service_; 73 MockDeviceManagementService service_;
61 scoped_ptr<CloudPolicyCacheBase> cache_; 74 scoped_ptr<CloudPolicyCacheBase> cache_;
62 scoped_ptr<CloudPolicyDataStore> data_store_; 75 scoped_ptr<CloudPolicyDataStore> data_store_;
63 MockCloudPolicyDataStoreObserver observer_; 76 MockCloudPolicyDataStoreObserver observer_;
64 PolicyNotifier notifier_; 77 PolicyNotifier notifier_;
65 ScopedTempDir temp_user_data_dir_; 78 ScopedTempDir temp_user_data_dir_;
66 79
67 private: 80 private:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(), 131 DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
119 &notifier_); 132 &notifier_);
120 EXPECT_CALL(observer_, OnDeviceTokenChanged()).Times(0); 133 EXPECT_CALL(observer_, OnDeviceTokenChanged()).Times(0);
121 FetchToken(&fetcher); 134 FetchToken(&fetcher);
122 loop_.RunAllPending(); 135 loop_.RunAllPending();
123 Mock::VerifyAndClearExpectations(&observer_); 136 Mock::VerifyAndClearExpectations(&observer_);
124 EXPECT_EQ("", data_store_->device_token()); 137 EXPECT_EQ("", data_store_->device_token());
125 EXPECT_TRUE(cache_->is_unmanaged()); 138 EXPECT_TRUE(cache_->is_unmanaged());
126 } 139 }
127 140
141 TEST_F(DeviceTokenFetcherTest, DontSetFetchingDone0) {
Mattias Nissler (ping if slow) 2011/11/11 14:38:50 more descriptive names.
Joao da Silva 2011/11/14 15:59:48 Done.
142 CreateNewWaitingCache();
143 DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
144 &notifier_);
145 EXPECT_FALSE(cache_->IsReady());
146 }
147
148 TEST_F(DeviceTokenFetcherTest, DontSetFetchingDone1) {
149 CreateNewWaitingCache();
150 EXPECT_CALL(backend_, ProcessRegisterRequest(_, _, _, _, _)).WillOnce(
151 MockDeviceManagementBackendSucceedRegister());
152 EXPECT_CALL(observer_, OnDeviceTokenChanged());
153 DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
154 &notifier_);
155 FetchToken(&fetcher);
156 loop_.RunAllPending();
157 // On successful token fetching the cache isn't set to ready, since the next
158 // step is to fetch policy. Only failures to fetch the token should make
159 // the cache ready.
160 EXPECT_FALSE(cache_->IsReady());
161 }
162
163 TEST_F(DeviceTokenFetcherTest, SetFetchingDone0) {
164 CreateNewWaitingCache();
165 cache_->SetUnmanaged();
166 DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
167 &notifier_);
168 EXPECT_TRUE(cache_->IsReady());
169 }
170
171 TEST_F(DeviceTokenFetcherTest, SetFetchingDone1) {
172 CreateNewWaitingCache();
173 EXPECT_CALL(backend_, ProcessRegisterRequest(_, _, _, _, _)).WillOnce(
174 MockDeviceManagementBackendFailRegister(
175 DeviceManagementBackend::kErrorRequestFailed));
176 DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
177 &notifier_);
178 FetchToken(&fetcher);
179 loop_.RunAllPending();
180 // This is the opposite case of DontSetFetchingDone1.
181 EXPECT_TRUE(cache_->IsReady());
182 }
183
128 } // namespace policy 184 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698