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

Side by Side Diff: chrome/browser/policy/cloud_policy_controller_unittest.cc

Issue 9064006: Convert DeviceTokenFetcher and CloudPolicyController response callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: another nit. Created 8 years, 11 months 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/cloud_policy_controller.h" 5 #include "chrome/browser/policy/cloud_policy_controller.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "chrome/browser/policy/cloud_policy_data_store.h" 10 #include "chrome/browser/policy/cloud_policy_data_store.h"
11 #include "chrome/browser/policy/device_token_fetcher.h" 11 #include "chrome/browser/policy/device_token_fetcher.h"
12 #include "chrome/browser/policy/logging_work_scheduler.h" 12 #include "chrome/browser/policy/logging_work_scheduler.h"
13 #include "chrome/browser/policy/mock_device_management_backend.h" 13 #include "chrome/browser/policy/mock_device_management_service.h"
14 #include "chrome/browser/policy/mock_device_management_service_old.h"
15 #include "chrome/browser/policy/policy_notifier.h" 14 #include "chrome/browser/policy/policy_notifier.h"
15 #include "chrome/browser/policy/proto/cloud_policy.pb.h"
16 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
16 #include "chrome/browser/policy/user_policy_cache.h" 17 #include "chrome/browser/policy/user_policy_cache.h"
17 #include "content/test/test_browser_thread.h" 18 #include "content/test/test_browser_thread.h"
18 #include "policy/policy_constants.h" 19 #include "policy/policy_constants.h"
19 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 namespace em = enterprise_management; 23 namespace em = enterprise_management;
23 24
24 namespace policy { 25 namespace policy {
25 26
26 using ::testing::AnyNumber; 27 using ::testing::AnyNumber;
27 using ::testing::InSequence; 28 using ::testing::InSequence;
Joao da Silva 2012/01/03 08:19:02 Nit: using DoAll
Mattias Nissler (ping if slow) 2012/01/03 10:02:45 Done.
29 using ::testing::InvokeWithoutArgs;
28 using ::testing::_; 30 using ::testing::_;
29 using content::BrowserThread; 31 using content::BrowserThread;
30 32
31 class MockDeviceTokenFetcher : public DeviceTokenFetcher { 33 class MockDeviceTokenFetcher : public DeviceTokenFetcher {
32 public: 34 public:
33 explicit MockDeviceTokenFetcher(CloudPolicyCacheBase* cache) 35 explicit MockDeviceTokenFetcher(CloudPolicyCacheBase* cache)
34 : DeviceTokenFetcher(NULL, cache, NULL, NULL) {} 36 : DeviceTokenFetcher(NULL, cache, NULL, NULL) {}
35 virtual ~MockDeviceTokenFetcher() {} 37 virtual ~MockDeviceTokenFetcher() {}
36 38
37 MOCK_METHOD0(FetchToken, void()); 39 MOCK_METHOD0(FetchToken, void());
38 MOCK_METHOD0(SetUnmanagedState, void()); 40 MOCK_METHOD0(SetUnmanagedState, void());
39 MOCK_METHOD0(SetSerialNumberInvalidState, void()); 41 MOCK_METHOD0(SetSerialNumberInvalidState, void());
40 42
41 private: 43 private:
42 DISALLOW_COPY_AND_ASSIGN(MockDeviceTokenFetcher); 44 DISALLOW_COPY_AND_ASSIGN(MockDeviceTokenFetcher);
43 }; 45 };
44 46
45 class CloudPolicyControllerTest : public testing::Test { 47 class CloudPolicyControllerTest : public testing::Test {
46 public: 48 public:
47 CloudPolicyControllerTest() 49 CloudPolicyControllerTest()
48 : ui_thread_(BrowserThread::UI, &loop_), 50 : ui_thread_(BrowserThread::UI, &loop_),
49 file_thread_(BrowserThread::FILE, &loop_) {} 51 file_thread_(BrowserThread::FILE, &loop_) {
52 em::PolicyData signed_response;
53 em::CloudPolicySettings settings;
54 em::DisableSpdyProto* spdy_proto = settings.mutable_disablespdy();
55 spdy_proto->set_disablespdy(true);
56 spdy_proto->mutable_policy_options()->set_mode(
57 em::PolicyOptions::MANDATORY);
58 EXPECT_TRUE(
59 settings.SerializeToString(signed_response.mutable_policy_value()));
60 base::TimeDelta timestamp =
61 base::Time::NowFromSystemTime() - base::Time::UnixEpoch();
62 signed_response.set_timestamp(timestamp.InMilliseconds());
63 std::string serialized_signed_response;
64 EXPECT_TRUE(signed_response.SerializeToString(&serialized_signed_response));
65 em::PolicyFetchResponse* fetch_response =
66 spdy_policy_response_.mutable_policy_response()->add_response();
67 fetch_response->set_policy_data(serialized_signed_response);
68 }
50 69
51 virtual ~CloudPolicyControllerTest() {} 70 virtual ~CloudPolicyControllerTest() {}
52 71
53 virtual void SetUp() { 72 virtual void SetUp() {
54 ASSERT_TRUE(temp_user_data_dir_.CreateUniqueTempDir()); 73 ASSERT_TRUE(temp_user_data_dir_.CreateUniqueTempDir());
55 cache_.reset(new UserPolicyCache( 74 cache_.reset(new UserPolicyCache(
56 temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest"), 75 temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest"),
57 false /* wait_for_policy_fetch */)); 76 false /* wait_for_policy_fetch */));
58 token_fetcher_.reset(new MockDeviceTokenFetcher(cache_.get())); 77 token_fetcher_.reset(new MockDeviceTokenFetcher(cache_.get()));
59 EXPECT_CALL(service_, CreateBackend()) 78 EXPECT_CALL(service_, StartJob(_)).Times(AnyNumber());
60 .Times(AnyNumber())
61 .WillRepeatedly(MockDeviceManagementServiceProxyBackend(&backend_));
62 data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); 79 data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies());
63 } 80 }
64 81
65 virtual void TearDown() { 82 virtual void TearDown() {
66 controller_.reset(); // Unregisters observers. 83 controller_.reset(); // Unregisters observers.
67 data_store_.reset(); 84 data_store_.reset();
68 } 85 }
69 86
70 void CreateNewController() { 87 void CreateNewController() {
71 controller_.reset(new CloudPolicyController( 88 controller_.reset(new CloudPolicyController(
(...skipping 13 matching lines...) Expand all
85 ASSERT_FALSE(cache_->IsReady()); 102 ASSERT_FALSE(cache_->IsReady());
86 } 103 }
87 104
88 void ExpectHasSpdyPolicy() { 105 void ExpectHasSpdyPolicy() {
89 base::FundamentalValue expected(true); 106 base::FundamentalValue expected(true);
90 const PolicyMap* policy_map = cache_->policy( 107 const PolicyMap* policy_map = cache_->policy(
91 CloudPolicyCacheBase::POLICY_LEVEL_MANDATORY); 108 CloudPolicyCacheBase::POLICY_LEVEL_MANDATORY);
92 ASSERT_TRUE(Value::Equals(&expected, policy_map->Get(kPolicyDisableSpdy))); 109 ASSERT_TRUE(Value::Equals(&expected, policy_map->Get(kPolicyDisableSpdy)));
93 } 110 }
94 111
95 void StopMessageLoop() {
96 loop_.QuitNow();
97 }
98
99 protected: 112 protected:
100 scoped_ptr<CloudPolicyCacheBase> cache_; 113 scoped_ptr<CloudPolicyCacheBase> cache_;
101 scoped_ptr<CloudPolicyController> controller_; 114 scoped_ptr<CloudPolicyController> controller_;
102 scoped_ptr<MockDeviceTokenFetcher> token_fetcher_; 115 scoped_ptr<MockDeviceTokenFetcher> token_fetcher_;
103 scoped_ptr<CloudPolicyDataStore> data_store_; 116 scoped_ptr<CloudPolicyDataStore> data_store_;
104 MockDeviceManagementBackend backend_; 117 MockDeviceManagementService service_;
105 MockDeviceManagementServiceOld service_;
106 PolicyNotifier notifier_; 118 PolicyNotifier notifier_;
107 ScopedTempDir temp_user_data_dir_; 119 ScopedTempDir temp_user_data_dir_;
108 MessageLoop loop_; 120 MessageLoop loop_;
121 em::DeviceManagementResponse spdy_policy_response_;
109 122
110 private: 123 private:
111 content::TestBrowserThread ui_thread_; 124 content::TestBrowserThread ui_thread_;
112 content::TestBrowserThread file_thread_; 125 content::TestBrowserThread file_thread_;
113 126
114 DISALLOW_COPY_AND_ASSIGN(CloudPolicyControllerTest); 127 DISALLOW_COPY_AND_ASSIGN(CloudPolicyControllerTest);
115 }; 128 };
116 129
117 // If a device token is present when the controller starts up, it should 130 // If a device token is present when the controller starts up, it should
118 // fetch and apply policy. 131 // fetch and apply policy.
119 TEST_F(CloudPolicyControllerTest, StartupWithDeviceToken) { 132 TEST_F(CloudPolicyControllerTest, StartupWithDeviceToken) {
120 data_store_->SetupForTesting("fake_device_token", "device_id", "", "", 133 data_store_->SetupForTesting("fake_device_token", "device_id", "", "",
121 true); 134 true);
122 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(DoAll( 135 EXPECT_CALL(service_,
123 InvokeWithoutArgs(this, &CloudPolicyControllerTest::StopMessageLoop), 136 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
124 MockDeviceManagementBackendSucceedSpdyCloudPolicy())); 137 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow),
138 service_.SucceedJob(spdy_policy_response_)));
125 CreateNewController(); 139 CreateNewController();
126 loop_.RunAllPending(); 140 loop_.RunAllPending();
127 ExpectHasSpdyPolicy(); 141 ExpectHasSpdyPolicy();
128 } 142 }
129 143
130 // If no device token is present when the controller starts up, it should 144 // If no device token is present when the controller starts up, it should
131 // instruct the token_fetcher_ to fetch one. 145 // instruct the token_fetcher_ to fetch one.
132 TEST_F(CloudPolicyControllerTest, StartupWithoutDeviceToken) { 146 TEST_F(CloudPolicyControllerTest, StartupWithoutDeviceToken) {
133 data_store_->SetupForTesting("", "device_id", "a@b.com", "auth_token", 147 data_store_->SetupForTesting("", "device_id", "a@b.com", "auth_token",
134 true); 148 true);
(...skipping 13 matching lines...) Expand all
148 } 162 }
149 163
150 // After policy has been fetched successfully, a new fetch should be triggered 164 // After policy has been fetched successfully, a new fetch should be triggered
151 // after the refresh interval has timed out. 165 // after the refresh interval has timed out.
152 TEST_F(CloudPolicyControllerTest, RefreshAfterSuccessfulPolicy) { 166 TEST_F(CloudPolicyControllerTest, RefreshAfterSuccessfulPolicy) {
153 data_store_->SetupForTesting("device_token", "device_id", 167 data_store_->SetupForTesting("device_token", "device_id",
154 "DannoHelperDelegate@b.com", 168 "DannoHelperDelegate@b.com",
155 "auth_token", true); 169 "auth_token", true);
156 { 170 {
157 InSequence s; 171 InSequence s;
158 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce( 172 EXPECT_CALL(service_,
159 MockDeviceManagementBackendSucceedSpdyCloudPolicy()); 173 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
160 EXPECT_CALL(backend_, 174 .WillOnce(service_.SucceedJob(spdy_policy_response_));
161 ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(DoAll( 175 EXPECT_CALL(service_,
162 InvokeWithoutArgs(this, &CloudPolicyControllerTest::StopMessageLoop), 176 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
163 MockDeviceManagementBackendFailPolicy( 177 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow),
164 DeviceManagementBackend::kErrorRequestFailed))); 178 service_.FailJob(DM_STATUS_REQUEST_FAILED)));
165 } 179 }
166 CreateNewController(); 180 CreateNewController();
167 loop_.RunAllPending(); 181 loop_.RunAllPending();
168 ExpectHasSpdyPolicy(); 182 ExpectHasSpdyPolicy();
169 } 183 }
170 184
171 // If policy fetching failed, it should be retried. 185 // If policy fetching failed, it should be retried.
172 TEST_F(CloudPolicyControllerTest, RefreshAfterError) { 186 TEST_F(CloudPolicyControllerTest, RefreshAfterError) {
173 data_store_->SetupForTesting("device_token", "device_id", 187 data_store_->SetupForTesting("device_token", "device_id",
174 "DannoHelperDelegateImpl@b.com", 188 "DannoHelperDelegateImpl@b.com",
175 "auth_token", true); 189 "auth_token", true);
176 { 190 {
177 InSequence s; 191 InSequence s;
178 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce( 192 EXPECT_CALL(service_,
179 MockDeviceManagementBackendFailPolicy( 193 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
180 DeviceManagementBackend::kErrorRequestFailed)); 194 .WillOnce(service_.FailJob(DM_STATUS_REQUEST_FAILED));
181 EXPECT_CALL(backend_, 195 EXPECT_CALL(service_,
182 ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(DoAll( 196 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
183 InvokeWithoutArgs(this, 197 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow),
184 &CloudPolicyControllerTest::StopMessageLoop), 198 service_.SucceedJob(spdy_policy_response_)));
185 MockDeviceManagementBackendSucceedSpdyCloudPolicy()));
186 } 199 }
187 CreateNewController(); 200 CreateNewController();
188 loop_.RunAllPending(); 201 loop_.RunAllPending();
189 ExpectHasSpdyPolicy(); 202 ExpectHasSpdyPolicy();
190 } 203 }
191 204
192 // If the backend reports that the device token was invalid, the controller 205 // If the backend reports that the device token was invalid, the controller
193 // should instruct the token fetcher to fetch a new token. 206 // should instruct the token fetcher to fetch a new token.
194 TEST_F(CloudPolicyControllerTest, InvalidToken) { 207 TEST_F(CloudPolicyControllerTest, InvalidToken) {
195 data_store_->SetupForTesting("device_token", "device_id", 208 data_store_->SetupForTesting("device_token", "device_id",
196 "standup@ten.am", "auth", true); 209 "standup@ten.am", "auth", true);
197 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce( 210 EXPECT_CALL(service_,
198 MockDeviceManagementBackendFailPolicy( 211 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
199 DeviceManagementBackend::kErrorServiceManagementTokenInvalid)); 212 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_MANAGEMENT_TOKEN_INVALID));
200 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1); 213 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1);
201 CreateNewController(); 214 CreateNewController();
202 loop_.RunAllPending(); 215 loop_.RunAllPending();
203 } 216 }
204 217
205 // If the backend reports that the device is unknown to the server, the 218 // If the backend reports that the device is unknown to the server, the
206 // controller should instruct the token fetcher to fetch a new token. 219 // controller should instruct the token fetcher to fetch a new token.
207 TEST_F(CloudPolicyControllerTest, DeviceNotFound) { 220 TEST_F(CloudPolicyControllerTest, DeviceNotFound) {
208 data_store_->SetupForTesting("device_token", "device_id", 221 data_store_->SetupForTesting("device_token", "device_id",
209 "me@you.com", "auth", true); 222 "me@you.com", "auth", true);
210 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce( 223 EXPECT_CALL(service_,
211 MockDeviceManagementBackendFailPolicy( 224 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
212 DeviceManagementBackend::kErrorServiceDeviceNotFound)); 225 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_DEVICE_NOT_FOUND));
213 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1); 226 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1);
214 CreateNewController(); 227 CreateNewController();
215 loop_.RunAllPending(); 228 loop_.RunAllPending();
216 } 229 }
217 230
218 // If the backend reports that the device-id is already existing, the 231 // If the backend reports that the device-id is already existing, the
219 // controller should instruct the token fetcher to fetch a new token. 232 // controller should instruct the token fetcher to fetch a new token.
220 TEST_F(CloudPolicyControllerTest, DeviceIdConflict) { 233 TEST_F(CloudPolicyControllerTest, DeviceIdConflict) {
221 data_store_->SetupForTesting("device_token", "device_id", 234 data_store_->SetupForTesting("device_token", "device_id",
222 "me@you.com", "auth", true); 235 "me@you.com", "auth", true);
223 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce( 236 EXPECT_CALL(service_,
224 MockDeviceManagementBackendFailPolicy( 237 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
225 DeviceManagementBackend::kErrorServiceDeviceIdConflict)); 238 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_DEVICE_ID_CONFLICT));
226 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1); 239 EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1);
227 CreateNewController(); 240 CreateNewController();
228 loop_.RunAllPending(); 241 loop_.RunAllPending();
229 } 242 }
230 243
231 // If the backend reports that the device is no longer managed, the controller 244 // If the backend reports that the device is no longer managed, the controller
232 // should instruct the token fetcher to fetch a new token (which will in turn 245 // should instruct the token fetcher to fetch a new token (which will in turn
233 // set and persist the correct 'unmanaged' state). 246 // set and persist the correct 'unmanaged' state).
234 TEST_F(CloudPolicyControllerTest, NoLongerManaged) { 247 TEST_F(CloudPolicyControllerTest, NoLongerManaged) {
235 data_store_->SetupForTesting("device_token", "device_id", 248 data_store_->SetupForTesting("device_token", "device_id",
236 "who@what.com", "auth", true); 249 "who@what.com", "auth", true);
237 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce( 250 EXPECT_CALL(service_,
238 MockDeviceManagementBackendFailPolicy( 251 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
239 DeviceManagementBackend::kErrorServiceManagementNotSupported)); 252 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_MANAGEMENT_NOT_SUPPORTED));
240 EXPECT_CALL(*token_fetcher_.get(), SetUnmanagedState()).Times(1); 253 EXPECT_CALL(*token_fetcher_.get(), SetUnmanagedState()).Times(1);
241 CreateNewController(); 254 CreateNewController();
242 loop_.RunAllPending(); 255 loop_.RunAllPending();
243 } 256 }
244 257
245 // If the backend reports that the device has invalid serial number, the 258 // If the backend reports that the device has invalid serial number, the
246 // controller should instruct the token fetcher not to fetch a new token 259 // controller should instruct the token fetcher not to fetch a new token
247 // (which will in turn set and persist the correct 'sn invalid' state). 260 // (which will in turn set and persist the correct 'sn invalid' state).
248 TEST_F(CloudPolicyControllerTest, InvalidSerialNumber) { 261 TEST_F(CloudPolicyControllerTest, InvalidSerialNumber) {
249 data_store_->SetupForTesting("device_token", "device_id", 262 data_store_->SetupForTesting("device_token", "device_id",
250 "who@what.com", "auth", true); 263 "who@what.com", "auth", true);
251 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce( 264 EXPECT_CALL(service_,
252 MockDeviceManagementBackendFailPolicy( 265 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
253 DeviceManagementBackend::kErrorServiceInvalidSerialNumber)); 266 .WillOnce(service_.FailJob(DM_STATUS_SERVICE_INVALID_SERIAL_NUMBER));
254 EXPECT_CALL(*token_fetcher_.get(), SetSerialNumberInvalidState()).Times(1); 267 EXPECT_CALL(*token_fetcher_.get(), SetSerialNumberInvalidState()).Times(1);
255 CreateNewController(); 268 CreateNewController();
256 loop_.RunAllPending(); 269 loop_.RunAllPending();
257 } 270 }
258 271
259 TEST_F(CloudPolicyControllerTest, DontSetFetchingDoneWithoutTokens) { 272 TEST_F(CloudPolicyControllerTest, DontSetFetchingDoneWithoutTokens) {
260 CreateNewWaitingCache(); 273 CreateNewWaitingCache();
261 CreateNewController(); 274 CreateNewController();
262 // Initialized without an oauth token, goes into TOKEN_UNAVAILABLE state. 275 // Initialized without an oauth token, goes into TOKEN_UNAVAILABLE state.
263 // This means the controller is still waiting for an oauth token fetch. 276 // This means the controller is still waiting for an oauth token fetch.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 loop_.RunAllPending(); 314 loop_.RunAllPending();
302 // User is in an unmanaged domain. 315 // User is in an unmanaged domain.
303 EXPECT_TRUE(cache_->IsReady()); 316 EXPECT_TRUE(cache_->IsReady());
304 EXPECT_TRUE(cache_->last_policy_refresh_time().is_null()); 317 EXPECT_TRUE(cache_->last_policy_refresh_time().is_null());
305 } 318 }
306 319
307 TEST_F(CloudPolicyControllerTest, SetFetchingDoneAfterPolicyFetch) { 320 TEST_F(CloudPolicyControllerTest, SetFetchingDoneAfterPolicyFetch) {
308 CreateNewWaitingCache(); 321 CreateNewWaitingCache();
309 data_store_->SetupForTesting("device_token", "device_id", 322 data_store_->SetupForTesting("device_token", "device_id",
310 "user@enterprise.com", "auth", true); 323 "user@enterprise.com", "auth", true);
311 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(DoAll( 324 EXPECT_CALL(service_,
312 InvokeWithoutArgs(this, &CloudPolicyControllerTest::StopMessageLoop), 325 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
313 MockDeviceManagementBackendSucceedSpdyCloudPolicy())); 326 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow),
327 service_.SucceedJob(spdy_policy_response_)));
314 CreateNewController(); 328 CreateNewController();
315 loop_.RunAllPending(); 329 loop_.RunAllPending();
316 EXPECT_TRUE(cache_->IsReady()); 330 EXPECT_TRUE(cache_->IsReady());
317 EXPECT_FALSE(cache_->last_policy_refresh_time().is_null()); 331 EXPECT_FALSE(cache_->last_policy_refresh_time().is_null());
318 } 332 }
319 333
320 TEST_F(CloudPolicyControllerTest, SetFetchingDoneAfterPolicyFetchFails) { 334 TEST_F(CloudPolicyControllerTest, SetFetchingDoneAfterPolicyFetchFails) {
321 CreateNewWaitingCache(); 335 CreateNewWaitingCache();
322 data_store_->SetupForTesting("device_token", "device_id", 336 data_store_->SetupForTesting("device_token", "device_id",
323 "user@enterprise.com", "auth", true); 337 "user@enterprise.com", "auth", true);
324 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(DoAll( 338 EXPECT_CALL(service_,
325 InvokeWithoutArgs(this, &CloudPolicyControllerTest::StopMessageLoop), 339 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
326 MockDeviceManagementBackendFailPolicy( 340 .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow),
327 DeviceManagementBackend::kErrorRequestFailed))); 341 service_.FailJob(DM_STATUS_REQUEST_FAILED)));
328 CreateNewController(); 342 CreateNewController();
329 loop_.RunAllPending(); 343 loop_.RunAllPending();
330 EXPECT_TRUE(cache_->IsReady()); 344 EXPECT_TRUE(cache_->IsReady());
331 EXPECT_TRUE(cache_->last_policy_refresh_time().is_null()); 345 EXPECT_TRUE(cache_->last_policy_refresh_time().is_null());
332 } 346 }
333 347
334 } // namespace policy 348 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698