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

Side by Side Diff: remoting/host/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
« no previous file with comments | « remoting/host/policy_watcher.cc ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 24 matching lines...) Expand all
35 35
36 class PolicyWatcherTest : public testing::Test { 36 class PolicyWatcherTest : public testing::Test {
37 public: 37 public:
38 PolicyWatcherTest() : message_loop_(base::MessageLoop::TYPE_IO) {} 38 PolicyWatcherTest() : message_loop_(base::MessageLoop::TYPE_IO) {}
39 39
40 void SetUp() override { 40 void SetUp() override {
41 message_loop_proxy_ = base::MessageLoopProxy::current(); 41 message_loop_proxy_ = base::MessageLoopProxy::current();
42 42
43 // Retaining a raw pointer to keep control over policy contents. 43 // Retaining a raw pointer to keep control over policy contents.
44 policy_loader_ = new policy::FakeAsyncPolicyLoader(message_loop_proxy_); 44 policy_loader_ = new policy::FakeAsyncPolicyLoader(message_loop_proxy_);
45 policy_watcher_ = PolicyWatcher::CreateFromPolicyLoader( 45 policy_watcher_ =
46 message_loop_proxy_, make_scoped_ptr(policy_loader_)); 46 PolicyWatcher::CreateFromPolicyLoader(make_scoped_ptr(policy_loader_));
47 47
48 nat_true_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, true); 48 nat_true_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, true);
49 nat_false_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, 49 nat_false_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal,
50 false); 50 false);
51 nat_one_.SetInteger(policy::key::kRemoteAccessHostFirewallTraversal, 1); 51 nat_one_.SetInteger(policy::key::kRemoteAccessHostFirewallTraversal, 1);
52 domain_empty_.SetString(policy::key::kRemoteAccessHostDomain, 52 domain_empty_.SetString(policy::key::kRemoteAccessHostDomain,
53 std::string()); 53 std::string());
54 domain_full_.SetString(policy::key::kRemoteAccessHostDomain, kHostDomain); 54 domain_full_.SetString(policy::key::kRemoteAccessHostDomain, kHostDomain);
55 SetDefaults(nat_true_others_default_); 55 SetDefaults(nat_true_others_default_);
56 nat_true_others_default_.SetBoolean( 56 nat_true_others_default_.SetBoolean(
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 protected: 131 protected:
132 void StartWatching() { 132 void StartWatching() {
133 policy_watcher_->StartWatching( 133 policy_watcher_->StartWatching(
134 base::Bind(&MockPolicyCallback::OnPolicyUpdate, 134 base::Bind(&MockPolicyCallback::OnPolicyUpdate,
135 base::Unretained(&mock_policy_callback_)), 135 base::Unretained(&mock_policy_callback_)),
136 base::Bind(&MockPolicyCallback::OnPolicyError, 136 base::Bind(&MockPolicyCallback::OnPolicyError,
137 base::Unretained(&mock_policy_callback_))); 137 base::Unretained(&mock_policy_callback_)));
138 base::RunLoop().RunUntilIdle(); 138 base::RunLoop().RunUntilIdle();
139 } 139 }
140 140
141 void StopWatching() {
142 EXPECT_CALL(*this, PostPolicyWatcherShutdown()).Times(1);
143 policy_watcher_->StopWatching(base::Bind(
144 &PolicyWatcherTest::PostPolicyWatcherShutdown, base::Unretained(this)));
145 base::RunLoop().RunUntilIdle();
146 }
147
148 void SetPolicies(const base::DictionaryValue& dict) { 141 void SetPolicies(const base::DictionaryValue& dict) {
149 // Copy |dict| into |policy_bundle|. 142 // Copy |dict| into |policy_bundle|.
150 policy::PolicyNamespace policy_namespace = 143 policy::PolicyNamespace policy_namespace =
151 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string()); 144 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string());
152 policy::PolicyBundle policy_bundle; 145 policy::PolicyBundle policy_bundle;
153 policy::PolicyMap& policy_map = policy_bundle.Get(policy_namespace); 146 policy::PolicyMap& policy_map = policy_bundle.Get(policy_namespace);
154 policy_map.LoadFrom(&dict, policy::POLICY_LEVEL_MANDATORY, 147 policy_map.LoadFrom(&dict, policy::POLICY_LEVEL_MANDATORY,
155 policy::POLICY_SCOPE_MACHINE); 148 policy::POLICY_SCOPE_MACHINE);
156 149
157 // Simulate a policy file/registry/preference update. 150 // Simulate a policy file/registry/preference update.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 } 243 }
251 return equal; 244 return equal;
252 } 245 }
253 246
254 TEST_F(PolicyWatcherTest, None) { 247 TEST_F(PolicyWatcherTest, None) {
255 EXPECT_CALL(mock_policy_callback_, 248 EXPECT_CALL(mock_policy_callback_,
256 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 249 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
257 250
258 SetPolicies(empty_); 251 SetPolicies(empty_);
259 StartWatching(); 252 StartWatching();
260 StopWatching();
261 } 253 }
262 254
263 TEST_F(PolicyWatcherTest, NatTrue) { 255 TEST_F(PolicyWatcherTest, NatTrue) {
264 EXPECT_CALL(mock_policy_callback_, 256 EXPECT_CALL(mock_policy_callback_,
265 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 257 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
266 258
267 SetPolicies(nat_true_); 259 SetPolicies(nat_true_);
268 StartWatching(); 260 StartWatching();
269 StopWatching();
270 } 261 }
271 262
272 TEST_F(PolicyWatcherTest, NatFalse) { 263 TEST_F(PolicyWatcherTest, NatFalse) {
273 EXPECT_CALL(mock_policy_callback_, 264 EXPECT_CALL(mock_policy_callback_,
274 OnPolicyUpdatePtr(IsPolicies(&nat_false_others_default_))); 265 OnPolicyUpdatePtr(IsPolicies(&nat_false_others_default_)));
275 266
276 SetPolicies(nat_false_); 267 SetPolicies(nat_false_);
277 StartWatching(); 268 StartWatching();
278 StopWatching();
279 } 269 }
280 270
281 TEST_F(PolicyWatcherTest, NatOne) { 271 TEST_F(PolicyWatcherTest, NatOne) {
282 EXPECT_CALL(mock_policy_callback_, 272 EXPECT_CALL(mock_policy_callback_,
283 OnPolicyUpdatePtr(IsPolicies(&nat_false_others_default_))); 273 OnPolicyUpdatePtr(IsPolicies(&nat_false_others_default_)));
284 274
285 SetPolicies(nat_one_); 275 SetPolicies(nat_one_);
286 StartWatching(); 276 StartWatching();
287 StopWatching();
288 } 277 }
289 278
290 TEST_F(PolicyWatcherTest, DomainEmpty) { 279 TEST_F(PolicyWatcherTest, DomainEmpty) {
291 EXPECT_CALL(mock_policy_callback_, 280 EXPECT_CALL(mock_policy_callback_,
292 OnPolicyUpdatePtr(IsPolicies(&domain_empty_others_default_))); 281 OnPolicyUpdatePtr(IsPolicies(&domain_empty_others_default_)));
293 282
294 SetPolicies(domain_empty_); 283 SetPolicies(domain_empty_);
295 StartWatching(); 284 StartWatching();
296 StopWatching();
297 } 285 }
298 286
299 TEST_F(PolicyWatcherTest, DomainFull) { 287 TEST_F(PolicyWatcherTest, DomainFull) {
300 EXPECT_CALL(mock_policy_callback_, 288 EXPECT_CALL(mock_policy_callback_,
301 OnPolicyUpdatePtr(IsPolicies(&domain_full_others_default_))); 289 OnPolicyUpdatePtr(IsPolicies(&domain_full_others_default_)));
302 290
303 SetPolicies(domain_full_); 291 SetPolicies(domain_full_);
304 StartWatching(); 292 StartWatching();
305 StopWatching();
306 } 293 }
307 294
308 TEST_F(PolicyWatcherTest, NatNoneThenTrue) { 295 TEST_F(PolicyWatcherTest, NatNoneThenTrue) {
309 EXPECT_CALL(mock_policy_callback_, 296 EXPECT_CALL(mock_policy_callback_,
310 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 297 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
311 298
312 SetPolicies(empty_); 299 SetPolicies(empty_);
313 StartWatching(); 300 StartWatching();
314 SetPolicies(nat_true_); 301 SetPolicies(nat_true_);
315 StopWatching();
316 } 302 }
317 303
318 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrue) { 304 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrue) {
319 EXPECT_CALL(mock_policy_callback_, 305 EXPECT_CALL(mock_policy_callback_,
320 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 306 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
321 307
322 SetPolicies(empty_); 308 SetPolicies(empty_);
323 StartWatching(); 309 StartWatching();
324 SetPolicies(nat_true_); 310 SetPolicies(nat_true_);
325 SetPolicies(nat_true_); 311 SetPolicies(nat_true_);
326 StopWatching();
327 } 312 }
328 313
329 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrueThenFalse) { 314 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrueThenFalse) {
330 testing::InSequence sequence; 315 testing::InSequence sequence;
331 EXPECT_CALL(mock_policy_callback_, 316 EXPECT_CALL(mock_policy_callback_,
332 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 317 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
333 EXPECT_CALL(mock_policy_callback_, 318 EXPECT_CALL(mock_policy_callback_,
334 OnPolicyUpdatePtr(IsPolicies(&nat_false_))); 319 OnPolicyUpdatePtr(IsPolicies(&nat_false_)));
335 320
336 SetPolicies(empty_); 321 SetPolicies(empty_);
337 StartWatching(); 322 StartWatching();
338 SetPolicies(nat_true_); 323 SetPolicies(nat_true_);
339 SetPolicies(nat_true_); 324 SetPolicies(nat_true_);
340 SetPolicies(nat_false_); 325 SetPolicies(nat_false_);
341 StopWatching();
342 } 326 }
343 327
344 TEST_F(PolicyWatcherTest, NatNoneThenFalse) { 328 TEST_F(PolicyWatcherTest, NatNoneThenFalse) {
345 testing::InSequence sequence; 329 testing::InSequence sequence;
346 EXPECT_CALL(mock_policy_callback_, 330 EXPECT_CALL(mock_policy_callback_,
347 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 331 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
348 EXPECT_CALL(mock_policy_callback_, 332 EXPECT_CALL(mock_policy_callback_,
349 OnPolicyUpdatePtr(IsPolicies(&nat_false_))); 333 OnPolicyUpdatePtr(IsPolicies(&nat_false_)));
350 334
351 SetPolicies(empty_); 335 SetPolicies(empty_);
352 StartWatching(); 336 StartWatching();
353 SetPolicies(nat_false_); 337 SetPolicies(nat_false_);
354 StopWatching();
355 } 338 }
356 339
357 TEST_F(PolicyWatcherTest, NatNoneThenFalseThenTrue) { 340 TEST_F(PolicyWatcherTest, NatNoneThenFalseThenTrue) {
358 testing::InSequence sequence; 341 testing::InSequence sequence;
359 EXPECT_CALL(mock_policy_callback_, 342 EXPECT_CALL(mock_policy_callback_,
360 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 343 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
361 EXPECT_CALL(mock_policy_callback_, 344 EXPECT_CALL(mock_policy_callback_,
362 OnPolicyUpdatePtr(IsPolicies(&nat_false_))); 345 OnPolicyUpdatePtr(IsPolicies(&nat_false_)));
363 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true_))); 346 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true_)));
364 347
365 SetPolicies(empty_); 348 SetPolicies(empty_);
366 StartWatching(); 349 StartWatching();
367 SetPolicies(nat_false_); 350 SetPolicies(nat_false_);
368 SetPolicies(nat_true_); 351 SetPolicies(nat_true_);
369 StopWatching();
370 } 352 }
371 353
372 TEST_F(PolicyWatcherTest, ChangeOneRepeatedlyThenTwo) { 354 TEST_F(PolicyWatcherTest, ChangeOneRepeatedlyThenTwo) {
373 testing::InSequence sequence; 355 testing::InSequence sequence;
374 EXPECT_CALL( 356 EXPECT_CALL(
375 mock_policy_callback_, 357 mock_policy_callback_,
376 OnPolicyUpdatePtr(IsPolicies(&nat_true_domain_empty_others_default_))); 358 OnPolicyUpdatePtr(IsPolicies(&nat_true_domain_empty_others_default_)));
377 EXPECT_CALL(mock_policy_callback_, 359 EXPECT_CALL(mock_policy_callback_,
378 OnPolicyUpdatePtr(IsPolicies(&domain_full_))); 360 OnPolicyUpdatePtr(IsPolicies(&domain_full_)));
379 EXPECT_CALL(mock_policy_callback_, 361 EXPECT_CALL(mock_policy_callback_,
380 OnPolicyUpdatePtr(IsPolicies(&nat_false_))); 362 OnPolicyUpdatePtr(IsPolicies(&nat_false_)));
381 EXPECT_CALL(mock_policy_callback_, 363 EXPECT_CALL(mock_policy_callback_,
382 OnPolicyUpdatePtr(IsPolicies(&domain_empty_))); 364 OnPolicyUpdatePtr(IsPolicies(&domain_empty_)));
383 EXPECT_CALL(mock_policy_callback_, 365 EXPECT_CALL(mock_policy_callback_,
384 OnPolicyUpdatePtr(IsPolicies(&nat_true_domain_full_))); 366 OnPolicyUpdatePtr(IsPolicies(&nat_true_domain_full_)));
385 367
386 SetPolicies(nat_true_domain_empty_); 368 SetPolicies(nat_true_domain_empty_);
387 StartWatching(); 369 StartWatching();
388 SetPolicies(nat_true_domain_full_); 370 SetPolicies(nat_true_domain_full_);
389 SetPolicies(nat_false_domain_full_); 371 SetPolicies(nat_false_domain_full_);
390 SetPolicies(nat_false_domain_empty_); 372 SetPolicies(nat_false_domain_empty_);
391 SetPolicies(nat_true_domain_full_); 373 SetPolicies(nat_true_domain_full_);
392 StopWatching();
393 } 374 }
394 375
395 TEST_F(PolicyWatcherTest, FilterUnknownPolicies) { 376 TEST_F(PolicyWatcherTest, FilterUnknownPolicies) {
396 testing::InSequence sequence; 377 testing::InSequence sequence;
397 EXPECT_CALL(mock_policy_callback_, 378 EXPECT_CALL(mock_policy_callback_,
398 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 379 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
399 380
400 SetPolicies(empty_); 381 SetPolicies(empty_);
401 StartWatching(); 382 StartWatching();
402 SetPolicies(unknown_policies_); 383 SetPolicies(unknown_policies_);
403 SetPolicies(empty_); 384 SetPolicies(empty_);
404 StopWatching();
405 } 385 }
406 386
407 TEST_F(PolicyWatcherTest, DebugOverrideNatPolicy) { 387 TEST_F(PolicyWatcherTest, DebugOverrideNatPolicy) {
408 #if !defined(NDEBUG) 388 #if !defined(NDEBUG)
409 EXPECT_CALL( 389 EXPECT_CALL(
410 mock_policy_callback_, 390 mock_policy_callback_,
411 OnPolicyUpdatePtr(IsPolicies(&nat_false_overridden_others_default_))); 391 OnPolicyUpdatePtr(IsPolicies(&nat_false_overridden_others_default_)));
412 #else 392 #else
413 EXPECT_CALL(mock_policy_callback_, 393 EXPECT_CALL(mock_policy_callback_,
414 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 394 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
415 #endif 395 #endif
416 396
417 SetPolicies(nat_true_and_overridden_); 397 SetPolicies(nat_true_and_overridden_);
418 StartWatching(); 398 StartWatching();
419 StopWatching();
420 } 399 }
421 400
422 TEST_F(PolicyWatcherTest, PairingFalseThenTrue) { 401 TEST_F(PolicyWatcherTest, PairingFalseThenTrue) {
423 testing::InSequence sequence; 402 testing::InSequence sequence;
424 EXPECT_CALL(mock_policy_callback_, 403 EXPECT_CALL(mock_policy_callback_,
425 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 404 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
426 EXPECT_CALL(mock_policy_callback_, 405 EXPECT_CALL(mock_policy_callback_,
427 OnPolicyUpdatePtr(IsPolicies(&pairing_false_))); 406 OnPolicyUpdatePtr(IsPolicies(&pairing_false_)));
428 EXPECT_CALL(mock_policy_callback_, 407 EXPECT_CALL(mock_policy_callback_,
429 OnPolicyUpdatePtr(IsPolicies(&pairing_true_))); 408 OnPolicyUpdatePtr(IsPolicies(&pairing_true_)));
430 409
431 SetPolicies(empty_); 410 SetPolicies(empty_);
432 StartWatching(); 411 StartWatching();
433 SetPolicies(pairing_false_); 412 SetPolicies(pairing_false_);
434 SetPolicies(pairing_true_); 413 SetPolicies(pairing_true_);
435 StopWatching();
436 } 414 }
437 415
438 TEST_F(PolicyWatcherTest, GnubbyAuth) { 416 TEST_F(PolicyWatcherTest, GnubbyAuth) {
439 testing::InSequence sequence; 417 testing::InSequence sequence;
440 EXPECT_CALL(mock_policy_callback_, 418 EXPECT_CALL(mock_policy_callback_,
441 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 419 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
442 EXPECT_CALL(mock_policy_callback_, 420 EXPECT_CALL(mock_policy_callback_,
443 OnPolicyUpdatePtr(IsPolicies(&gnubby_auth_false_))); 421 OnPolicyUpdatePtr(IsPolicies(&gnubby_auth_false_)));
444 EXPECT_CALL(mock_policy_callback_, 422 EXPECT_CALL(mock_policy_callback_,
445 OnPolicyUpdatePtr(IsPolicies(&gnubby_auth_true_))); 423 OnPolicyUpdatePtr(IsPolicies(&gnubby_auth_true_)));
446 424
447 SetPolicies(empty_); 425 SetPolicies(empty_);
448 StartWatching(); 426 StartWatching();
449 SetPolicies(gnubby_auth_false_); 427 SetPolicies(gnubby_auth_false_);
450 SetPolicies(gnubby_auth_true_); 428 SetPolicies(gnubby_auth_true_);
451 StopWatching();
452 } 429 }
453 430
454 TEST_F(PolicyWatcherTest, Relay) { 431 TEST_F(PolicyWatcherTest, Relay) {
455 testing::InSequence sequence; 432 testing::InSequence sequence;
456 EXPECT_CALL(mock_policy_callback_, 433 EXPECT_CALL(mock_policy_callback_,
457 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 434 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
458 EXPECT_CALL(mock_policy_callback_, 435 EXPECT_CALL(mock_policy_callback_,
459 OnPolicyUpdatePtr(IsPolicies(&relay_false_))); 436 OnPolicyUpdatePtr(IsPolicies(&relay_false_)));
460 EXPECT_CALL(mock_policy_callback_, 437 EXPECT_CALL(mock_policy_callback_,
461 OnPolicyUpdatePtr(IsPolicies(&relay_true_))); 438 OnPolicyUpdatePtr(IsPolicies(&relay_true_)));
462 439
463 SetPolicies(empty_); 440 SetPolicies(empty_);
464 StartWatching(); 441 StartWatching();
465 SetPolicies(relay_false_); 442 SetPolicies(relay_false_);
466 SetPolicies(relay_true_); 443 SetPolicies(relay_true_);
467 StopWatching();
468 } 444 }
469 445
470 TEST_F(PolicyWatcherTest, UdpPortRange) { 446 TEST_F(PolicyWatcherTest, UdpPortRange) {
471 testing::InSequence sequence; 447 testing::InSequence sequence;
472 EXPECT_CALL(mock_policy_callback_, 448 EXPECT_CALL(mock_policy_callback_,
473 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 449 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
474 EXPECT_CALL(mock_policy_callback_, 450 EXPECT_CALL(mock_policy_callback_,
475 OnPolicyUpdatePtr(IsPolicies(&port_range_full_))); 451 OnPolicyUpdatePtr(IsPolicies(&port_range_full_)));
476 EXPECT_CALL(mock_policy_callback_, 452 EXPECT_CALL(mock_policy_callback_,
477 OnPolicyUpdatePtr(IsPolicies(&port_range_empty_))); 453 OnPolicyUpdatePtr(IsPolicies(&port_range_empty_)));
478 454
479 SetPolicies(empty_); 455 SetPolicies(empty_);
480 StartWatching(); 456 StartWatching();
481 SetPolicies(port_range_full_); 457 SetPolicies(port_range_full_);
482 SetPolicies(port_range_empty_); 458 SetPolicies(port_range_empty_);
483 StopWatching();
484 } 459 }
485 460
486 const int kMaxTransientErrorRetries = 5; 461 const int kMaxTransientErrorRetries = 5;
487 462
488 TEST_F(PolicyWatcherTest, SingleTransientErrorDoesntTriggerErrorCallback) { 463 TEST_F(PolicyWatcherTest, SingleTransientErrorDoesntTriggerErrorCallback) {
489 EXPECT_CALL(mock_policy_callback_, OnPolicyError()).Times(0); 464 EXPECT_CALL(mock_policy_callback_, OnPolicyError()).Times(0);
490 465
491 StartWatching(); 466 StartWatching();
492 SignalTransientErrorForTest(); 467 SignalTransientErrorForTest();
493 StopWatching();
494 } 468 }
495 469
496 TEST_F(PolicyWatcherTest, MultipleTransientErrorsTriggerErrorCallback) { 470 TEST_F(PolicyWatcherTest, MultipleTransientErrorsTriggerErrorCallback) {
497 EXPECT_CALL(mock_policy_callback_, OnPolicyError()); 471 EXPECT_CALL(mock_policy_callback_, OnPolicyError());
498 472
499 StartWatching(); 473 StartWatching();
500 for (int i = 0; i < kMaxTransientErrorRetries; i++) { 474 for (int i = 0; i < kMaxTransientErrorRetries; i++) {
501 SignalTransientErrorForTest(); 475 SignalTransientErrorForTest();
502 } 476 }
503 StopWatching();
504 } 477 }
505 478
506 TEST_F(PolicyWatcherTest, PolicyUpdateResetsTransientErrorsCounter) { 479 TEST_F(PolicyWatcherTest, PolicyUpdateResetsTransientErrorsCounter) {
507 testing::InSequence s; 480 testing::InSequence s;
508 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(testing::_)); 481 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(testing::_));
509 EXPECT_CALL(mock_policy_callback_, OnPolicyError()).Times(0); 482 EXPECT_CALL(mock_policy_callback_, OnPolicyError()).Times(0);
510 483
511 StartWatching(); 484 StartWatching();
512 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) { 485 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) {
513 SignalTransientErrorForTest(); 486 SignalTransientErrorForTest();
514 } 487 }
515 SetPolicies(nat_true_); 488 SetPolicies(nat_true_);
516 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) { 489 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) {
517 SignalTransientErrorForTest(); 490 SignalTransientErrorForTest();
518 } 491 }
519 StopWatching();
520 } 492 }
521 493
522 // Unit tests cannot instantiate PolicyWatcher on ChromeOS 494 // Unit tests cannot instantiate PolicyWatcher on ChromeOS
523 // (as this requires running inside a browser process). 495 // (as this requires running inside a browser process).
524 #ifndef OS_CHROMEOS 496 #ifndef OS_CHROMEOS
525 497
526 namespace { 498 namespace {
527 499
528 void OnPolicyUpdatedDumpPolicy(scoped_ptr<base::DictionaryValue> policies) { 500 void OnPolicyUpdatedDumpPolicy(scoped_ptr<base::DictionaryValue> policies) {
529 VLOG(1) << "OnPolicyUpdated callback received the following policies:"; 501 VLOG(1) << "OnPolicyUpdated callback received the following policies:";
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 scoped_ptr<PolicyWatcher> policy_watcher( 536 scoped_ptr<PolicyWatcher> policy_watcher(
565 PolicyWatcher::Create(nullptr, task_runner)); 537 PolicyWatcher::Create(nullptr, task_runner));
566 538
567 { 539 {
568 base::RunLoop run_loop; 540 base::RunLoop run_loop;
569 policy_watcher->StartWatching(base::Bind(OnPolicyUpdatedDumpPolicy), 541 policy_watcher->StartWatching(base::Bind(OnPolicyUpdatedDumpPolicy),
570 base::Bind(base::DoNothing)); 542 base::Bind(base::DoNothing));
571 run_loop.RunUntilIdle(); 543 run_loop.RunUntilIdle();
572 } 544 }
573 545
574 {
575 base::RunLoop run_loop;
576 PolicyWatcher* raw_policy_watcher = policy_watcher.release();
577 raw_policy_watcher->StopWatching(
578 base::Bind(base::IgnoreResult(
579 &base::SequencedTaskRunner::DeleteSoon<PolicyWatcher>),
580 task_runner, FROM_HERE, raw_policy_watcher));
581 run_loop.RunUntilIdle();
582 }
583
584 // Today, the only verification offered by this test is: 546 // Today, the only verification offered by this test is:
585 // - Manual verification of policy values dumped by OnPolicyUpdatedDumpPolicy 547 // - Manual verification of policy values dumped by OnPolicyUpdatedDumpPolicy
586 // - Automated verification that nothing crashed 548 // - Automated verification that nothing crashed
587 } 549 }
588 550
589 #endif 551 #endif
590 552
591 } // namespace remoting 553 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/policy_watcher.cc ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698