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

Side by Side Diff: remoting/host/policy_hack/policy_watcher_unittest.cc

Issue 886913002: Always run PolicyWatcher on UI thread in It2Me host. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 16 matching lines...) Expand all
27 message_loop_proxy_ = base::MessageLoopProxy::current(); 27 message_loop_proxy_ = base::MessageLoopProxy::current();
28 policy_updated_callback_ = base::Bind( 28 policy_updated_callback_ = base::Bind(
29 &MockPolicyCallback::OnPolicyUpdate, 29 &MockPolicyCallback::OnPolicyUpdate,
30 base::Unretained(&mock_policy_callback_)); 30 base::Unretained(&mock_policy_callback_));
31 policy_error_callback_ = base::Bind( 31 policy_error_callback_ = base::Bind(
32 &MockPolicyCallback::OnPolicyError, 32 &MockPolicyCallback::OnPolicyError,
33 base::Unretained(&mock_policy_callback_)); 33 base::Unretained(&mock_policy_callback_));
34 34
35 // Retaining a raw pointer to keep control over policy contents. 35 // Retaining a raw pointer to keep control over policy contents.
36 policy_loader_ = new policy::FakeAsyncPolicyLoader(message_loop_proxy_); 36 policy_loader_ = new policy::FakeAsyncPolicyLoader(message_loop_proxy_);
37 policy_watcher_ = PolicyWatcher::CreateFromPolicyLoader( 37 policy_watcher_ =
38 message_loop_proxy_, make_scoped_ptr(policy_loader_)); 38 PolicyWatcher::CreateFromPolicyLoader(make_scoped_ptr(policy_loader_));
39 39
40 nat_true_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, true); 40 nat_true_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, true);
41 nat_false_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, 41 nat_false_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal,
42 false); 42 false);
43 nat_one_.SetInteger(policy::key::kRemoteAccessHostFirewallTraversal, 1); 43 nat_one_.SetInteger(policy::key::kRemoteAccessHostFirewallTraversal, 1);
44 domain_empty_.SetString(policy::key::kRemoteAccessHostDomain, 44 domain_empty_.SetString(policy::key::kRemoteAccessHostDomain,
45 std::string()); 45 std::string());
46 domain_full_.SetString(policy::key::kRemoteAccessHostDomain, kHostDomain); 46 domain_full_.SetString(policy::key::kRemoteAccessHostDomain, kHostDomain);
47 SetDefaults(nat_true_others_default_); 47 SetDefaults(nat_true_others_default_);
48 nat_true_others_default_.SetBoolean( 48 nat_true_others_default_.SetBoolean(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 121 }
122 122
123 protected: 123 protected:
124 void StartWatching() { 124 void StartWatching() {
125 policy_watcher_->StartWatching( 125 policy_watcher_->StartWatching(
126 policy_updated_callback_, 126 policy_updated_callback_,
127 policy_error_callback_); 127 policy_error_callback_);
128 base::RunLoop().RunUntilIdle(); 128 base::RunLoop().RunUntilIdle();
129 } 129 }
130 130
131 void StopWatching() {
132 EXPECT_CALL(*this, PostPolicyWatcherShutdown()).Times(1);
133 policy_watcher_->StopWatching(base::Bind(
134 &PolicyWatcherTest::PostPolicyWatcherShutdown, base::Unretained(this)));
135 base::RunLoop().RunUntilIdle();
136 }
137
138 void SetPolicies(const base::DictionaryValue& dict) { 131 void SetPolicies(const base::DictionaryValue& dict) {
139 // Copy |dict| into |policy_bundle|. 132 // Copy |dict| into |policy_bundle|.
140 policy::PolicyNamespace policy_namespace = 133 policy::PolicyNamespace policy_namespace =
141 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string()); 134 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string());
142 policy::PolicyBundle policy_bundle; 135 policy::PolicyBundle policy_bundle;
143 policy::PolicyMap& policy_map = policy_bundle.Get(policy_namespace); 136 policy::PolicyMap& policy_map = policy_bundle.Get(policy_namespace);
144 policy_map.LoadFrom(&dict, policy::POLICY_LEVEL_MANDATORY, 137 policy_map.LoadFrom(&dict, policy::POLICY_LEVEL_MANDATORY,
145 policy::POLICY_SCOPE_MACHINE); 138 policy::POLICY_SCOPE_MACHINE);
146 139
147 // Simulate a policy file/registry/preference update. 140 // Simulate a policy file/registry/preference update.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 } 235 }
243 return equal; 236 return equal;
244 } 237 }
245 238
246 TEST_F(PolicyWatcherTest, None) { 239 TEST_F(PolicyWatcherTest, None) {
247 EXPECT_CALL(mock_policy_callback_, 240 EXPECT_CALL(mock_policy_callback_,
248 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 241 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
249 242
250 SetPolicies(empty_); 243 SetPolicies(empty_);
251 StartWatching(); 244 StartWatching();
252 StopWatching();
253 } 245 }
254 246
255 TEST_F(PolicyWatcherTest, NatTrue) { 247 TEST_F(PolicyWatcherTest, NatTrue) {
256 EXPECT_CALL(mock_policy_callback_, 248 EXPECT_CALL(mock_policy_callback_,
257 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 249 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
258 250
259 SetPolicies(nat_true_); 251 SetPolicies(nat_true_);
260 StartWatching(); 252 StartWatching();
261 StopWatching();
262 } 253 }
263 254
264 TEST_F(PolicyWatcherTest, NatFalse) { 255 TEST_F(PolicyWatcherTest, NatFalse) {
265 EXPECT_CALL(mock_policy_callback_, 256 EXPECT_CALL(mock_policy_callback_,
266 OnPolicyUpdatePtr(IsPolicies(&nat_false_others_default_))); 257 OnPolicyUpdatePtr(IsPolicies(&nat_false_others_default_)));
267 258
268 SetPolicies(nat_false_); 259 SetPolicies(nat_false_);
269 StartWatching(); 260 StartWatching();
270 StopWatching();
271 } 261 }
272 262
273 TEST_F(PolicyWatcherTest, NatOne) { 263 TEST_F(PolicyWatcherTest, NatOne) {
274 EXPECT_CALL(mock_policy_callback_, 264 EXPECT_CALL(mock_policy_callback_,
275 OnPolicyUpdatePtr(IsPolicies(&nat_false_others_default_))); 265 OnPolicyUpdatePtr(IsPolicies(&nat_false_others_default_)));
276 266
277 SetPolicies(nat_one_); 267 SetPolicies(nat_one_);
278 StartWatching(); 268 StartWatching();
279 StopWatching();
280 } 269 }
281 270
282 TEST_F(PolicyWatcherTest, DomainEmpty) { 271 TEST_F(PolicyWatcherTest, DomainEmpty) {
283 EXPECT_CALL(mock_policy_callback_, 272 EXPECT_CALL(mock_policy_callback_,
284 OnPolicyUpdatePtr(IsPolicies(&domain_empty_others_default_))); 273 OnPolicyUpdatePtr(IsPolicies(&domain_empty_others_default_)));
285 274
286 SetPolicies(domain_empty_); 275 SetPolicies(domain_empty_);
287 StartWatching(); 276 StartWatching();
288 StopWatching();
289 } 277 }
290 278
291 TEST_F(PolicyWatcherTest, DomainFull) { 279 TEST_F(PolicyWatcherTest, DomainFull) {
292 EXPECT_CALL(mock_policy_callback_, 280 EXPECT_CALL(mock_policy_callback_,
293 OnPolicyUpdatePtr(IsPolicies(&domain_full_others_default_))); 281 OnPolicyUpdatePtr(IsPolicies(&domain_full_others_default_)));
294 282
295 SetPolicies(domain_full_); 283 SetPolicies(domain_full_);
296 StartWatching(); 284 StartWatching();
297 StopWatching();
298 } 285 }
299 286
300 TEST_F(PolicyWatcherTest, NatNoneThenTrue) { 287 TEST_F(PolicyWatcherTest, NatNoneThenTrue) {
301 EXPECT_CALL(mock_policy_callback_, 288 EXPECT_CALL(mock_policy_callback_,
302 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 289 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
303 290
304 SetPolicies(empty_); 291 SetPolicies(empty_);
305 StartWatching(); 292 StartWatching();
306 SetPolicies(nat_true_); 293 SetPolicies(nat_true_);
307 StopWatching();
308 } 294 }
309 295
310 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrue) { 296 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrue) {
311 EXPECT_CALL(mock_policy_callback_, 297 EXPECT_CALL(mock_policy_callback_,
312 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 298 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
313 299
314 SetPolicies(empty_); 300 SetPolicies(empty_);
315 StartWatching(); 301 StartWatching();
316 SetPolicies(nat_true_); 302 SetPolicies(nat_true_);
317 SetPolicies(nat_true_); 303 SetPolicies(nat_true_);
318 StopWatching();
319 } 304 }
320 305
321 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrueThenFalse) { 306 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrueThenFalse) {
322 testing::InSequence sequence; 307 testing::InSequence sequence;
323 EXPECT_CALL(mock_policy_callback_, 308 EXPECT_CALL(mock_policy_callback_,
324 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 309 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
325 EXPECT_CALL(mock_policy_callback_, 310 EXPECT_CALL(mock_policy_callback_,
326 OnPolicyUpdatePtr(IsPolicies(&nat_false_))); 311 OnPolicyUpdatePtr(IsPolicies(&nat_false_)));
327 312
328 SetPolicies(empty_); 313 SetPolicies(empty_);
329 StartWatching(); 314 StartWatching();
330 SetPolicies(nat_true_); 315 SetPolicies(nat_true_);
331 SetPolicies(nat_true_); 316 SetPolicies(nat_true_);
332 SetPolicies(nat_false_); 317 SetPolicies(nat_false_);
333 StopWatching();
334 } 318 }
335 319
336 TEST_F(PolicyWatcherTest, NatNoneThenFalse) { 320 TEST_F(PolicyWatcherTest, NatNoneThenFalse) {
337 testing::InSequence sequence; 321 testing::InSequence sequence;
338 EXPECT_CALL(mock_policy_callback_, 322 EXPECT_CALL(mock_policy_callback_,
339 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 323 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
340 EXPECT_CALL(mock_policy_callback_, 324 EXPECT_CALL(mock_policy_callback_,
341 OnPolicyUpdatePtr(IsPolicies(&nat_false_))); 325 OnPolicyUpdatePtr(IsPolicies(&nat_false_)));
342 326
343 SetPolicies(empty_); 327 SetPolicies(empty_);
344 StartWatching(); 328 StartWatching();
345 SetPolicies(nat_false_); 329 SetPolicies(nat_false_);
346 StopWatching();
347 } 330 }
348 331
349 TEST_F(PolicyWatcherTest, NatNoneThenFalseThenTrue) { 332 TEST_F(PolicyWatcherTest, NatNoneThenFalseThenTrue) {
350 testing::InSequence sequence; 333 testing::InSequence sequence;
351 EXPECT_CALL(mock_policy_callback_, 334 EXPECT_CALL(mock_policy_callback_,
352 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 335 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
353 EXPECT_CALL(mock_policy_callback_, 336 EXPECT_CALL(mock_policy_callback_,
354 OnPolicyUpdatePtr(IsPolicies(&nat_false_))); 337 OnPolicyUpdatePtr(IsPolicies(&nat_false_)));
355 EXPECT_CALL(mock_policy_callback_, 338 EXPECT_CALL(mock_policy_callback_,
356 OnPolicyUpdatePtr(IsPolicies(&nat_true_))); 339 OnPolicyUpdatePtr(IsPolicies(&nat_true_)));
357 340
358 SetPolicies(empty_); 341 SetPolicies(empty_);
359 StartWatching(); 342 StartWatching();
360 SetPolicies(nat_false_); 343 SetPolicies(nat_false_);
361 SetPolicies(nat_true_); 344 SetPolicies(nat_true_);
362 StopWatching();
363 } 345 }
364 346
365 TEST_F(PolicyWatcherTest, ChangeOneRepeatedlyThenTwo) { 347 TEST_F(PolicyWatcherTest, ChangeOneRepeatedlyThenTwo) {
366 testing::InSequence sequence; 348 testing::InSequence sequence;
367 EXPECT_CALL(mock_policy_callback_, 349 EXPECT_CALL(mock_policy_callback_,
368 OnPolicyUpdatePtr(IsPolicies( 350 OnPolicyUpdatePtr(IsPolicies(
369 &nat_true_domain_empty_others_default_))); 351 &nat_true_domain_empty_others_default_)));
370 EXPECT_CALL(mock_policy_callback_, 352 EXPECT_CALL(mock_policy_callback_,
371 OnPolicyUpdatePtr(IsPolicies(&domain_full_))); 353 OnPolicyUpdatePtr(IsPolicies(&domain_full_)));
372 EXPECT_CALL(mock_policy_callback_, 354 EXPECT_CALL(mock_policy_callback_,
373 OnPolicyUpdatePtr(IsPolicies(&nat_false_))); 355 OnPolicyUpdatePtr(IsPolicies(&nat_false_)));
374 EXPECT_CALL(mock_policy_callback_, 356 EXPECT_CALL(mock_policy_callback_,
375 OnPolicyUpdatePtr(IsPolicies(&domain_empty_))); 357 OnPolicyUpdatePtr(IsPolicies(&domain_empty_)));
376 EXPECT_CALL(mock_policy_callback_, 358 EXPECT_CALL(mock_policy_callback_,
377 OnPolicyUpdatePtr(IsPolicies(&nat_true_domain_full_))); 359 OnPolicyUpdatePtr(IsPolicies(&nat_true_domain_full_)));
378 360
379 SetPolicies(nat_true_domain_empty_); 361 SetPolicies(nat_true_domain_empty_);
380 StartWatching(); 362 StartWatching();
381 SetPolicies(nat_true_domain_full_); 363 SetPolicies(nat_true_domain_full_);
382 SetPolicies(nat_false_domain_full_); 364 SetPolicies(nat_false_domain_full_);
383 SetPolicies(nat_false_domain_empty_); 365 SetPolicies(nat_false_domain_empty_);
384 SetPolicies(nat_true_domain_full_); 366 SetPolicies(nat_true_domain_full_);
385 StopWatching();
386 } 367 }
387 368
388 TEST_F(PolicyWatcherTest, FilterUnknownPolicies) { 369 TEST_F(PolicyWatcherTest, FilterUnknownPolicies) {
389 testing::InSequence sequence; 370 testing::InSequence sequence;
390 EXPECT_CALL(mock_policy_callback_, 371 EXPECT_CALL(mock_policy_callback_,
391 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 372 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
392 373
393 SetPolicies(empty_); 374 SetPolicies(empty_);
394 StartWatching(); 375 StartWatching();
395 SetPolicies(unknown_policies_); 376 SetPolicies(unknown_policies_);
396 SetPolicies(empty_); 377 SetPolicies(empty_);
397 StopWatching();
398 } 378 }
399 379
400 TEST_F(PolicyWatcherTest, DebugOverrideNatPolicy) { 380 TEST_F(PolicyWatcherTest, DebugOverrideNatPolicy) {
401 #if !defined(NDEBUG) 381 #if !defined(NDEBUG)
402 EXPECT_CALL( 382 EXPECT_CALL(
403 mock_policy_callback_, 383 mock_policy_callback_,
404 OnPolicyUpdatePtr(IsPolicies(&nat_false_overridden_others_default_))); 384 OnPolicyUpdatePtr(IsPolicies(&nat_false_overridden_others_default_)));
405 #else 385 #else
406 EXPECT_CALL(mock_policy_callback_, 386 EXPECT_CALL(mock_policy_callback_,
407 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 387 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
408 #endif 388 #endif
409 389
410 SetPolicies(nat_true_and_overridden_); 390 SetPolicies(nat_true_and_overridden_);
411 StartWatching(); 391 StartWatching();
412 StopWatching();
413 } 392 }
414 393
415 TEST_F(PolicyWatcherTest, PairingFalseThenTrue) { 394 TEST_F(PolicyWatcherTest, PairingFalseThenTrue) {
416 testing::InSequence sequence; 395 testing::InSequence sequence;
417 EXPECT_CALL(mock_policy_callback_, 396 EXPECT_CALL(mock_policy_callback_,
418 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 397 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
419 EXPECT_CALL(mock_policy_callback_, 398 EXPECT_CALL(mock_policy_callback_,
420 OnPolicyUpdatePtr(IsPolicies(&pairing_false_))); 399 OnPolicyUpdatePtr(IsPolicies(&pairing_false_)));
421 EXPECT_CALL(mock_policy_callback_, 400 EXPECT_CALL(mock_policy_callback_,
422 OnPolicyUpdatePtr(IsPolicies(&pairing_true_))); 401 OnPolicyUpdatePtr(IsPolicies(&pairing_true_)));
423 402
424 SetPolicies(empty_); 403 SetPolicies(empty_);
425 StartWatching(); 404 StartWatching();
426 SetPolicies(pairing_false_); 405 SetPolicies(pairing_false_);
427 SetPolicies(pairing_true_); 406 SetPolicies(pairing_true_);
428 StopWatching();
429 } 407 }
430 408
431 TEST_F(PolicyWatcherTest, GnubbyAuth) { 409 TEST_F(PolicyWatcherTest, GnubbyAuth) {
432 testing::InSequence sequence; 410 testing::InSequence sequence;
433 EXPECT_CALL(mock_policy_callback_, 411 EXPECT_CALL(mock_policy_callback_,
434 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 412 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
435 EXPECT_CALL(mock_policy_callback_, 413 EXPECT_CALL(mock_policy_callback_,
436 OnPolicyUpdatePtr(IsPolicies(&gnubby_auth_false_))); 414 OnPolicyUpdatePtr(IsPolicies(&gnubby_auth_false_)));
437 EXPECT_CALL(mock_policy_callback_, 415 EXPECT_CALL(mock_policy_callback_,
438 OnPolicyUpdatePtr(IsPolicies(&gnubby_auth_true_))); 416 OnPolicyUpdatePtr(IsPolicies(&gnubby_auth_true_)));
439 417
440 SetPolicies(empty_); 418 SetPolicies(empty_);
441 StartWatching(); 419 StartWatching();
442 SetPolicies(gnubby_auth_false_); 420 SetPolicies(gnubby_auth_false_);
443 SetPolicies(gnubby_auth_true_); 421 SetPolicies(gnubby_auth_true_);
444 StopWatching();
445 } 422 }
446 423
447 TEST_F(PolicyWatcherTest, Relay) { 424 TEST_F(PolicyWatcherTest, Relay) {
448 testing::InSequence sequence; 425 testing::InSequence sequence;
449 EXPECT_CALL(mock_policy_callback_, 426 EXPECT_CALL(mock_policy_callback_,
450 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 427 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
451 EXPECT_CALL(mock_policy_callback_, 428 EXPECT_CALL(mock_policy_callback_,
452 OnPolicyUpdatePtr(IsPolicies(&relay_false_))); 429 OnPolicyUpdatePtr(IsPolicies(&relay_false_)));
453 EXPECT_CALL(mock_policy_callback_, 430 EXPECT_CALL(mock_policy_callback_,
454 OnPolicyUpdatePtr(IsPolicies(&relay_true_))); 431 OnPolicyUpdatePtr(IsPolicies(&relay_true_)));
455 432
456 SetPolicies(empty_); 433 SetPolicies(empty_);
457 StartWatching(); 434 StartWatching();
458 SetPolicies(relay_false_); 435 SetPolicies(relay_false_);
459 SetPolicies(relay_true_); 436 SetPolicies(relay_true_);
460 StopWatching();
461 } 437 }
462 438
463 TEST_F(PolicyWatcherTest, UdpPortRange) { 439 TEST_F(PolicyWatcherTest, UdpPortRange) {
464 testing::InSequence sequence; 440 testing::InSequence sequence;
465 EXPECT_CALL(mock_policy_callback_, 441 EXPECT_CALL(mock_policy_callback_,
466 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 442 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
467 EXPECT_CALL(mock_policy_callback_, 443 EXPECT_CALL(mock_policy_callback_,
468 OnPolicyUpdatePtr(IsPolicies(&port_range_full_))); 444 OnPolicyUpdatePtr(IsPolicies(&port_range_full_)));
469 EXPECT_CALL(mock_policy_callback_, 445 EXPECT_CALL(mock_policy_callback_,
470 OnPolicyUpdatePtr(IsPolicies(&port_range_empty_))); 446 OnPolicyUpdatePtr(IsPolicies(&port_range_empty_)));
471 447
472 SetPolicies(empty_); 448 SetPolicies(empty_);
473 StartWatching(); 449 StartWatching();
474 SetPolicies(port_range_full_); 450 SetPolicies(port_range_full_);
475 SetPolicies(port_range_empty_); 451 SetPolicies(port_range_empty_);
476 StopWatching();
477 } 452 }
478 453
479 const int kMaxTransientErrorRetries = 5; 454 const int kMaxTransientErrorRetries = 5;
480 455
481 TEST_F(PolicyWatcherTest, SingleTransientErrorDoesntTriggerErrorCallback) { 456 TEST_F(PolicyWatcherTest, SingleTransientErrorDoesntTriggerErrorCallback) {
482 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()).Times(0); 457 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()).Times(0);
483 458
484 StartWatching(); 459 StartWatching();
485 SignalTransientErrorForTest(); 460 SignalTransientErrorForTest();
486 StopWatching();
487 } 461 }
488 462
489 TEST_F(PolicyWatcherTest, MultipleTransientErrorsTriggerErrorCallback) { 463 TEST_F(PolicyWatcherTest, MultipleTransientErrorsTriggerErrorCallback) {
490 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()); 464 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr());
491 465
492 StartWatching(); 466 StartWatching();
493 for (int i = 0; i < kMaxTransientErrorRetries; i++) { 467 for (int i = 0; i < kMaxTransientErrorRetries; i++) {
494 SignalTransientErrorForTest(); 468 SignalTransientErrorForTest();
495 } 469 }
496 StopWatching();
497 } 470 }
498 471
499 TEST_F(PolicyWatcherTest, PolicyUpdateResetsTransientErrorsCounter) { 472 TEST_F(PolicyWatcherTest, PolicyUpdateResetsTransientErrorsCounter) {
500 testing::InSequence s; 473 testing::InSequence s;
501 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(testing::_)); 474 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(testing::_));
502 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()).Times(0); 475 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()).Times(0);
503 476
504 StartWatching(); 477 StartWatching();
505 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) { 478 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) {
506 SignalTransientErrorForTest(); 479 SignalTransientErrorForTest();
507 } 480 }
508 SetPolicies(nat_true_); 481 SetPolicies(nat_true_);
509 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) { 482 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) {
510 SignalTransientErrorForTest(); 483 SignalTransientErrorForTest();
511 } 484 }
512 StopWatching();
513 } 485 }
514 486
515 // Unit tests cannot instantiate PolicyWatcher on ChromeOS 487 // Unit tests cannot instantiate PolicyWatcher on ChromeOS
516 // (as this requires running inside a browser process). 488 // (as this requires running inside a browser process).
517 #ifndef OS_CHROMEOS 489 #ifndef OS_CHROMEOS
518 490
519 namespace { 491 namespace {
520 492
521 void OnPolicyUpdatedDumpPolicy(scoped_ptr<base::DictionaryValue> policies) { 493 void OnPolicyUpdatedDumpPolicy(scoped_ptr<base::DictionaryValue> policies) {
522 VLOG(1) << "OnPolicyUpdated callback received the following policies:"; 494 VLOG(1) << "OnPolicyUpdated callback received the following policies:";
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 scoped_ptr<PolicyWatcher> policy_watcher( 529 scoped_ptr<PolicyWatcher> policy_watcher(
558 PolicyWatcher::Create(nullptr, task_runner)); 530 PolicyWatcher::Create(nullptr, task_runner));
559 531
560 { 532 {
561 base::RunLoop run_loop; 533 base::RunLoop run_loop;
562 policy_watcher->StartWatching(base::Bind(OnPolicyUpdatedDumpPolicy), 534 policy_watcher->StartWatching(base::Bind(OnPolicyUpdatedDumpPolicy),
563 base::Bind(base::DoNothing)); 535 base::Bind(base::DoNothing));
564 run_loop.RunUntilIdle(); 536 run_loop.RunUntilIdle();
565 } 537 }
566 538
567 {
568 base::RunLoop run_loop;
569 PolicyWatcher* raw_policy_watcher = policy_watcher.release();
570 raw_policy_watcher->StopWatching(
571 base::Bind(base::IgnoreResult(
572 &base::SequencedTaskRunner::DeleteSoon<PolicyWatcher>),
573 task_runner, FROM_HERE, raw_policy_watcher));
574 run_loop.RunUntilIdle();
575 }
576
577 // Today, the only verification offered by this test is: 539 // Today, the only verification offered by this test is:
578 // - Manual verification of policy values dumped by OnPolicyUpdatedDumpPolicy 540 // - Manual verification of policy values dumped by OnPolicyUpdatedDumpPolicy
579 // - Automated verification that nothing crashed 541 // - Automated verification that nothing crashed
580 } 542 }
581 543
582 #endif 544 #endif
583 545
584 } // namespace policy_hack 546 } // namespace policy_hack
585 } // namespace remoting 547 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698