OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // Causes the invalidation service to fire an invalidation. Returns an ack | 110 // Causes the invalidation service to fire an invalidation. Returns an ack |
111 // handle which be used to verify that the invalidation was acknowledged. | 111 // handle which be used to verify that the invalidation was acknowledged. |
112 syncer::AckHandle FireInvalidation( | 112 syncer::AckHandle FireInvalidation( |
113 PolicyObject object, | 113 PolicyObject object, |
114 int64 version, | 114 int64 version, |
115 const std::string& payload); | 115 const std::string& payload); |
116 | 116 |
117 // Causes the invalidation service to fire an invalidation with unknown | 117 // Causes the invalidation service to fire an invalidation with unknown |
118 // version. Returns an ack handle which be used to verify that the | 118 // version. Returns an ack handle which be used to verify that the |
119 // invalidation was acknowledged. | 119 // invalidation was acknowledged. |
120 syncer::AckHandle FireInvalidation(PolicyObject object); | 120 syncer::AckHandle FireUnknownVersionInvalidation(PolicyObject object); |
121 | 121 |
122 // Checks the expected value of the currently set invalidation info. | 122 // Checks the expected value of the currently set invalidation info. |
123 bool CheckInvalidationInfo(int64 version, const std::string& payload); | 123 bool CheckInvalidationInfo(int64 version, const std::string& payload); |
124 | 124 |
125 // Checks that the policy was not refreshed due to an invalidation. | 125 // Checks that the policy was not refreshed due to an invalidation. |
126 bool CheckPolicyNotRefreshed(); | 126 bool CheckPolicyNotRefreshed(); |
127 | 127 |
128 // Checks that the policy was refreshed due to an invalidation within an | 128 // Checks that the policy was refreshed due to an invalidation within an |
129 // appropriate timeframe depending on whether the invalidation had unknown | 129 // appropriate timeframe depending on whether the invalidation had unknown |
130 // version. | 130 // version. |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 } | 298 } |
299 | 299 |
300 void CloudPolicyInvalidatorTest::EnableInvalidationService() { | 300 void CloudPolicyInvalidatorTest::EnableInvalidationService() { |
301 invalidation_service_.SetInvalidatorState(syncer::INVALIDATIONS_ENABLED); | 301 invalidation_service_.SetInvalidatorState(syncer::INVALIDATIONS_ENABLED); |
302 } | 302 } |
303 | 303 |
304 syncer::AckHandle CloudPolicyInvalidatorTest::FireInvalidation( | 304 syncer::AckHandle CloudPolicyInvalidatorTest::FireInvalidation( |
305 PolicyObject object, | 305 PolicyObject object, |
306 int64 version, | 306 int64 version, |
307 const std::string& payload) { | 307 const std::string& payload) { |
308 return invalidation_service_.EmitInvalidationForTest( | 308 syncer::Invalidation invalidation = syncer::Invalidation::Init( |
309 GetPolicyObjectId(object), | 309 GetPolicyObjectId(object), |
310 version, | 310 version, |
311 payload); | 311 payload); |
| 312 invalidation_service_.EmitInvalidationForTest(invalidation); |
| 313 return invalidation.ack_handle(); |
312 } | 314 } |
313 | 315 |
314 syncer::AckHandle CloudPolicyInvalidatorTest::FireInvalidation( | 316 syncer::AckHandle CloudPolicyInvalidatorTest::FireUnknownVersionInvalidation( |
315 PolicyObject object) { | 317 PolicyObject object) { |
316 return invalidation_service_.EmitInvalidationForTest( | 318 syncer::Invalidation invalidation = |
317 GetPolicyObjectId(object), | 319 syncer::Invalidation::InitUnknownVersion(GetPolicyObjectId(object)); |
318 syncer::Invalidation::kUnknownVersion, | 320 invalidation_service_.EmitInvalidationForTest(invalidation); |
319 std::string()); | 321 return invalidation.ack_handle(); |
320 } | 322 } |
321 | 323 |
322 bool CloudPolicyInvalidatorTest::CheckInvalidationInfo( | 324 bool CloudPolicyInvalidatorTest::CheckInvalidationInfo( |
323 int64 version, | 325 int64 version, |
324 const std::string& payload) { | 326 const std::string& payload) { |
325 MockCloudPolicyClient* client = | 327 MockCloudPolicyClient* client = |
326 static_cast<MockCloudPolicyClient*>(core_.client()); | 328 static_cast<MockCloudPolicyClient*>(core_.client()); |
327 return version == client->invalidation_version_ && | 329 return version == client->invalidation_version_ && |
328 payload == client->invalidation_payload_; | 330 payload == client->invalidation_payload_; |
329 } | 331 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 if (!histogram) | 415 if (!histogram) |
414 return scoped_ptr<base::HistogramSamples>(new base::SampleMap()); | 416 return scoped_ptr<base::HistogramSamples>(new base::SampleMap()); |
415 return histogram->SnapshotSamples(); | 417 return histogram->SnapshotSamples(); |
416 } | 418 } |
417 | 419 |
418 TEST_F(CloudPolicyInvalidatorTest, Uninitialized) { | 420 TEST_F(CloudPolicyInvalidatorTest, Uninitialized) { |
419 // No invalidations should be processed if the invalidator is not initialized. | 421 // No invalidations should be processed if the invalidator is not initialized. |
420 StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */); | 422 StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */); |
421 StorePolicy(POLICY_OBJECT_A); | 423 StorePolicy(POLICY_OBJECT_A); |
422 EXPECT_FALSE(IsInvalidatorRegistered()); | 424 EXPECT_FALSE(IsInvalidatorRegistered()); |
423 FireInvalidation(POLICY_OBJECT_A); | 425 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
424 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 426 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
425 } | 427 } |
426 | 428 |
427 TEST_F(CloudPolicyInvalidatorTest, RefreshSchedulerNotStarted) { | 429 TEST_F(CloudPolicyInvalidatorTest, RefreshSchedulerNotStarted) { |
428 // No invalidations should be processed if the refresh scheduler is not | 430 // No invalidations should be processed if the refresh scheduler is not |
429 // started. | 431 // started. |
430 StartInvalidator(true /* initialize */, false /* start_refresh_scheduler */); | 432 StartInvalidator(true /* initialize */, false /* start_refresh_scheduler */); |
431 StorePolicy(POLICY_OBJECT_A); | 433 StorePolicy(POLICY_OBJECT_A); |
432 EXPECT_FALSE(IsInvalidatorRegistered()); | 434 EXPECT_FALSE(IsInvalidatorRegistered()); |
433 FireInvalidation(POLICY_OBJECT_A); | 435 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
434 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 436 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
435 } | 437 } |
436 | 438 |
437 TEST_F(CloudPolicyInvalidatorTest, DisconnectCoreThenInitialize) { | 439 TEST_F(CloudPolicyInvalidatorTest, DisconnectCoreThenInitialize) { |
438 // No invalidations should be processed if the core is disconnected before | 440 // No invalidations should be processed if the core is disconnected before |
439 // initialization. | 441 // initialization. |
440 StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */); | 442 StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */); |
441 DisconnectCore(); | 443 DisconnectCore(); |
442 InitializeInvalidator(); | 444 InitializeInvalidator(); |
443 StorePolicy(POLICY_OBJECT_A); | 445 StorePolicy(POLICY_OBJECT_A); |
444 EXPECT_FALSE(IsInvalidatorRegistered()); | 446 EXPECT_FALSE(IsInvalidatorRegistered()); |
445 FireInvalidation(POLICY_OBJECT_A); | 447 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
446 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 448 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
447 } | 449 } |
448 | 450 |
449 TEST_F(CloudPolicyInvalidatorTest, InitializeThenStartRefreshScheduler) { | 451 TEST_F(CloudPolicyInvalidatorTest, InitializeThenStartRefreshScheduler) { |
450 // Make sure registration occurs and invalidations are processed when | 452 // Make sure registration occurs and invalidations are processed when |
451 // Initialize is called before starting the refresh scheduler. | 453 // Initialize is called before starting the refresh scheduler. |
452 // Note that the reverse case (start refresh scheduler then initialize) is | 454 // Note that the reverse case (start refresh scheduler then initialize) is |
453 // the default behavior for the test fixture, so will be tested in most other | 455 // the default behavior for the test fixture, so will be tested in most other |
454 // tests. | 456 // tests. |
455 StartInvalidator(true /* initialize */, false /* start_refresh_scheduler */); | 457 StartInvalidator(true /* initialize */, false /* start_refresh_scheduler */); |
456 ConnectCore(); | 458 ConnectCore(); |
457 StartRefreshScheduler(); | 459 StartRefreshScheduler(); |
458 StorePolicy(POLICY_OBJECT_A); | 460 StorePolicy(POLICY_OBJECT_A); |
459 EXPECT_TRUE(IsInvalidatorRegistered()); | 461 EXPECT_TRUE(IsInvalidatorRegistered()); |
460 FireInvalidation(POLICY_OBJECT_A); | 462 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
461 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 463 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
462 } | 464 } |
463 | 465 |
464 TEST_F(CloudPolicyInvalidatorTest, RegisterOnStoreLoaded) { | 466 TEST_F(CloudPolicyInvalidatorTest, RegisterOnStoreLoaded) { |
465 // No registration when store is not loaded. | 467 // No registration when store is not loaded. |
466 StartInvalidator(); | 468 StartInvalidator(); |
467 EXPECT_FALSE(IsInvalidatorRegistered()); | 469 EXPECT_FALSE(IsInvalidatorRegistered()); |
468 EXPECT_FALSE(InvalidationsEnabled()); | 470 EXPECT_FALSE(InvalidationsEnabled()); |
469 FireInvalidation(POLICY_OBJECT_A); | 471 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
470 FireInvalidation(POLICY_OBJECT_B); | 472 FireUnknownVersionInvalidation(POLICY_OBJECT_B); |
471 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 473 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
472 | 474 |
473 // No registration when store is loaded with no invalidation object id. | 475 // No registration when store is loaded with no invalidation object id. |
474 StorePolicy(POLICY_OBJECT_NONE); | 476 StorePolicy(POLICY_OBJECT_NONE); |
475 EXPECT_FALSE(IsInvalidatorRegistered()); | 477 EXPECT_FALSE(IsInvalidatorRegistered()); |
476 EXPECT_FALSE(InvalidationsEnabled()); | 478 EXPECT_FALSE(InvalidationsEnabled()); |
477 FireInvalidation(POLICY_OBJECT_A); | 479 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
478 FireInvalidation(POLICY_OBJECT_B); | 480 FireUnknownVersionInvalidation(POLICY_OBJECT_B); |
479 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 481 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
480 | 482 |
481 // Check registration when store is loaded for object A. | 483 // Check registration when store is loaded for object A. |
482 StorePolicy(POLICY_OBJECT_A); | 484 StorePolicy(POLICY_OBJECT_A); |
483 EXPECT_TRUE(IsInvalidatorRegistered()); | 485 EXPECT_TRUE(IsInvalidatorRegistered()); |
484 EXPECT_TRUE(InvalidationsEnabled()); | 486 EXPECT_TRUE(InvalidationsEnabled()); |
485 FireInvalidation(POLICY_OBJECT_A); | 487 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
486 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 488 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
487 FireInvalidation(POLICY_OBJECT_B); | 489 FireUnknownVersionInvalidation(POLICY_OBJECT_B); |
488 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 490 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
489 } | 491 } |
490 | 492 |
491 TEST_F(CloudPolicyInvalidatorTest, ChangeRegistration) { | 493 TEST_F(CloudPolicyInvalidatorTest, ChangeRegistration) { |
492 // Register for object A. | 494 // Register for object A. |
493 StartInvalidator(); | 495 StartInvalidator(); |
494 StorePolicy(POLICY_OBJECT_A); | 496 StorePolicy(POLICY_OBJECT_A); |
495 EXPECT_TRUE(IsInvalidatorRegistered()); | 497 EXPECT_TRUE(IsInvalidatorRegistered()); |
496 EXPECT_TRUE(InvalidationsEnabled()); | 498 EXPECT_TRUE(InvalidationsEnabled()); |
497 FireInvalidation(POLICY_OBJECT_A); | 499 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
498 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 500 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
499 FireInvalidation(POLICY_OBJECT_B); | 501 FireUnknownVersionInvalidation(POLICY_OBJECT_B); |
500 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 502 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
501 syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A); | 503 syncer::AckHandle ack = FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
502 | 504 |
503 // Check re-registration for object B. Make sure the pending invalidation for | 505 // Check re-registration for object B. Make sure the pending invalidation for |
504 // object A is acknowledged without making the callback. | 506 // object A is acknowledged without making the callback. |
505 StorePolicy(POLICY_OBJECT_B); | 507 StorePolicy(POLICY_OBJECT_B); |
506 EXPECT_TRUE(IsInvalidatorRegistered()); | 508 EXPECT_TRUE(IsInvalidatorRegistered()); |
507 EXPECT_TRUE(InvalidationsEnabled()); | 509 EXPECT_TRUE(InvalidationsEnabled()); |
508 EXPECT_TRUE(IsInvalidationAcknowledged(ack)); | 510 EXPECT_TRUE(IsInvalidationAcknowledged(ack)); |
509 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 511 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
510 | 512 |
511 // Make sure future invalidations for object A are ignored and for object B | 513 // Make sure future invalidations for object A are ignored and for object B |
512 // are processed. | 514 // are processed. |
513 FireInvalidation(POLICY_OBJECT_A); | 515 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
514 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 516 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
515 FireInvalidation(POLICY_OBJECT_B); | 517 FireUnknownVersionInvalidation(POLICY_OBJECT_B); |
516 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 518 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
517 } | 519 } |
518 | 520 |
519 TEST_F(CloudPolicyInvalidatorTest, UnregisterOnStoreLoaded) { | 521 TEST_F(CloudPolicyInvalidatorTest, UnregisterOnStoreLoaded) { |
520 // Register for object A. | 522 // Register for object A. |
521 StartInvalidator(); | 523 StartInvalidator(); |
522 StorePolicy(POLICY_OBJECT_A); | 524 StorePolicy(POLICY_OBJECT_A); |
523 EXPECT_TRUE(IsInvalidatorRegistered()); | 525 EXPECT_TRUE(IsInvalidatorRegistered()); |
524 EXPECT_TRUE(InvalidationsEnabled()); | 526 EXPECT_TRUE(InvalidationsEnabled()); |
525 FireInvalidation(POLICY_OBJECT_A); | 527 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
526 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 528 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
527 | 529 |
528 // Check unregistration when store is loaded with no invalidation object id. | 530 // Check unregistration when store is loaded with no invalidation object id. |
529 syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A); | 531 syncer::AckHandle ack = FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
530 EXPECT_FALSE(IsInvalidationAcknowledged(ack)); | 532 EXPECT_FALSE(IsInvalidationAcknowledged(ack)); |
531 StorePolicy(POLICY_OBJECT_NONE); | 533 StorePolicy(POLICY_OBJECT_NONE); |
532 EXPECT_FALSE(IsInvalidatorRegistered()); | 534 EXPECT_FALSE(IsInvalidatorRegistered()); |
533 EXPECT_TRUE(IsInvalidationAcknowledged(ack)); | 535 EXPECT_TRUE(IsInvalidationAcknowledged(ack)); |
534 EXPECT_FALSE(InvalidationsEnabled()); | 536 EXPECT_FALSE(InvalidationsEnabled()); |
535 FireInvalidation(POLICY_OBJECT_A); | 537 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
536 FireInvalidation(POLICY_OBJECT_B); | 538 FireUnknownVersionInvalidation(POLICY_OBJECT_B); |
537 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 539 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
538 | 540 |
539 // Check re-registration for object B. | 541 // Check re-registration for object B. |
540 StorePolicy(POLICY_OBJECT_B); | 542 StorePolicy(POLICY_OBJECT_B); |
541 EXPECT_TRUE(IsInvalidatorRegistered()); | 543 EXPECT_TRUE(IsInvalidatorRegistered()); |
542 EXPECT_TRUE(InvalidationsEnabled()); | 544 EXPECT_TRUE(InvalidationsEnabled()); |
543 FireInvalidation(POLICY_OBJECT_B); | 545 FireUnknownVersionInvalidation(POLICY_OBJECT_B); |
544 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 546 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
545 } | 547 } |
546 | 548 |
547 TEST_F(CloudPolicyInvalidatorTest, HandleInvalidation) { | 549 TEST_F(CloudPolicyInvalidatorTest, HandleInvalidation) { |
548 // Register and fire invalidation | 550 // Register and fire invalidation |
549 StorePolicy(POLICY_OBJECT_A); | 551 StorePolicy(POLICY_OBJECT_A); |
550 StartInvalidator(); | 552 StartInvalidator(); |
551 EXPECT_TRUE(InvalidationsEnabled()); | 553 EXPECT_TRUE(InvalidationsEnabled()); |
552 syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A, 12, "test_payload"); | 554 syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A, 12, "test_payload"); |
553 | 555 |
554 // Make sure client info is set as soon as the invalidation is received. | 556 // Make sure client info is set as soon as the invalidation is received. |
555 EXPECT_TRUE(CheckInvalidationInfo(12, "test_payload")); | 557 EXPECT_TRUE(CheckInvalidationInfo(12, "test_payload")); |
556 EXPECT_TRUE(CheckPolicyRefreshed()); | 558 EXPECT_TRUE(CheckPolicyRefreshed()); |
557 | 559 |
558 // Make sure invalidation is not acknowledged until the store is loaded. | 560 // Make sure invalidation is not acknowledged until the store is loaded. |
559 EXPECT_FALSE(IsInvalidationAcknowledged(ack)); | 561 EXPECT_FALSE(IsInvalidationAcknowledged(ack)); |
560 EXPECT_TRUE(CheckInvalidationInfo(12, "test_payload")); | 562 EXPECT_TRUE(CheckInvalidationInfo(12, "test_payload")); |
561 StorePolicy(POLICY_OBJECT_A, 12); | 563 StorePolicy(POLICY_OBJECT_A, 12); |
562 EXPECT_TRUE(IsInvalidationAcknowledged(ack)); | 564 EXPECT_TRUE(IsInvalidationAcknowledged(ack)); |
563 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); | 565 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
564 } | 566 } |
565 | 567 |
566 TEST_F(CloudPolicyInvalidatorTest, HandleInvalidationWithUnknownVersion) { | 568 TEST_F(CloudPolicyInvalidatorTest, HandleInvalidationWithUnknownVersion) { |
567 // Register and fire invalidation with unknown version. | 569 // Register and fire invalidation with unknown version. |
568 StorePolicy(POLICY_OBJECT_A); | 570 StorePolicy(POLICY_OBJECT_A); |
569 StartInvalidator(); | 571 StartInvalidator(); |
570 syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A); | 572 syncer::AckHandle ack = FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
571 | 573 |
572 // Make sure client info is not set until after the invalidation callback is | 574 // Make sure client info is not set until after the invalidation callback is |
573 // made. | 575 // made. |
574 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); | 576 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
575 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 577 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
576 EXPECT_TRUE(CheckInvalidationInfo(-1, std::string())); | 578 EXPECT_TRUE(CheckInvalidationInfo(-1, std::string())); |
577 | 579 |
578 // Make sure invalidation is not acknowledged until the store is loaded. | 580 // Make sure invalidation is not acknowledged until the store is loaded. |
579 EXPECT_FALSE(IsInvalidationAcknowledged(ack)); | 581 EXPECT_FALSE(IsInvalidationAcknowledged(ack)); |
580 StorePolicy(POLICY_OBJECT_A, -1); | 582 StorePolicy(POLICY_OBJECT_A, -1); |
(...skipping 28 matching lines...) Expand all Loading... |
609 StorePolicy(POLICY_OBJECT_A, 3); | 611 StorePolicy(POLICY_OBJECT_A, 3); |
610 EXPECT_TRUE(IsInvalidationAcknowledged(ack3)); | 612 EXPECT_TRUE(IsInvalidationAcknowledged(ack3)); |
611 } | 613 } |
612 | 614 |
613 TEST_F(CloudPolicyInvalidatorTest, | 615 TEST_F(CloudPolicyInvalidatorTest, |
614 HandleMultipleInvalidationsWithUnknownVersion) { | 616 HandleMultipleInvalidationsWithUnknownVersion) { |
615 // Validate that multiple invalidations with unknown version each generate | 617 // Validate that multiple invalidations with unknown version each generate |
616 // unique invalidation version numbers. | 618 // unique invalidation version numbers. |
617 StorePolicy(POLICY_OBJECT_A); | 619 StorePolicy(POLICY_OBJECT_A); |
618 StartInvalidator(); | 620 StartInvalidator(); |
619 syncer::AckHandle ack1 = FireInvalidation(POLICY_OBJECT_A); | 621 syncer::AckHandle ack1 = FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
620 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); | 622 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
621 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 623 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
622 EXPECT_TRUE(CheckInvalidationInfo(-1, std::string())); | 624 EXPECT_TRUE(CheckInvalidationInfo(-1, std::string())); |
623 syncer::AckHandle ack2 = FireInvalidation(POLICY_OBJECT_A); | 625 syncer::AckHandle ack2 = FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
624 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); | 626 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
625 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 627 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
626 EXPECT_TRUE(CheckInvalidationInfo(-2, std::string())); | 628 EXPECT_TRUE(CheckInvalidationInfo(-2, std::string())); |
627 syncer::AckHandle ack3 = FireInvalidation(POLICY_OBJECT_A); | 629 syncer::AckHandle ack3 = FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
628 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); | 630 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
629 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 631 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
630 EXPECT_TRUE(CheckInvalidationInfo(-3, std::string())); | 632 EXPECT_TRUE(CheckInvalidationInfo(-3, std::string())); |
631 | 633 |
632 // Make sure the replaced invalidations are acknowledged. | 634 // Make sure the replaced invalidations are acknowledged. |
633 EXPECT_TRUE(IsInvalidationAcknowledged(ack1)); | 635 EXPECT_TRUE(IsInvalidationAcknowledged(ack1)); |
634 EXPECT_TRUE(IsInvalidationAcknowledged(ack2)); | 636 EXPECT_TRUE(IsInvalidationAcknowledged(ack2)); |
635 | 637 |
636 // Make sure that the last invalidation is only acknowledged after the store | 638 // Make sure that the last invalidation is only acknowledged after the store |
637 // is loaded with the last unknown version. | 639 // is loaded with the last unknown version. |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS)); | 825 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS)); |
824 EXPECT_EQ(4, GetCount(METRIC_POLICY_REFRESH_UNCHANGED)); | 826 EXPECT_EQ(4, GetCount(METRIC_POLICY_REFRESH_UNCHANGED)); |
825 EXPECT_EQ(2, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED)); | 827 EXPECT_EQ(2, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED)); |
826 EXPECT_EQ(1, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED)); | 828 EXPECT_EQ(1, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED)); |
827 } | 829 } |
828 | 830 |
829 TEST_F(CloudPolicyInvalidatorTest, InvalidationMetrics) { | 831 TEST_F(CloudPolicyInvalidatorTest, InvalidationMetrics) { |
830 // Generate a mix of versioned and unknown-version invalidations. | 832 // Generate a mix of versioned and unknown-version invalidations. |
831 StorePolicy(POLICY_OBJECT_A); | 833 StorePolicy(POLICY_OBJECT_A); |
832 StartInvalidator(); | 834 StartInvalidator(); |
833 FireInvalidation(POLICY_OBJECT_B); | 835 FireUnknownVersionInvalidation(POLICY_OBJECT_B); |
834 FireInvalidation(POLICY_OBJECT_A); | 836 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
835 FireInvalidation(POLICY_OBJECT_B, 1, "test"); | 837 FireInvalidation(POLICY_OBJECT_B, 1, "test"); |
836 FireInvalidation(POLICY_OBJECT_A, 1, "test"); | 838 FireInvalidation(POLICY_OBJECT_A, 1, "test"); |
837 FireInvalidation(POLICY_OBJECT_A, 2, "test"); | 839 FireInvalidation(POLICY_OBJECT_A, 2, "test"); |
838 FireInvalidation(POLICY_OBJECT_A); | 840 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
839 FireInvalidation(POLICY_OBJECT_A); | 841 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
840 FireInvalidation(POLICY_OBJECT_A, 3, "test"); | 842 FireInvalidation(POLICY_OBJECT_A, 3, "test"); |
841 FireInvalidation(POLICY_OBJECT_A, 4, "test"); | 843 FireInvalidation(POLICY_OBJECT_A, 4, "test"); |
842 | 844 |
843 // Verify that received invalidations metrics are correct. | 845 // Verify that received invalidations metrics are correct. |
844 EXPECT_EQ(3, GetInvalidationCount(false /* with_payload */)); | 846 EXPECT_EQ(3, GetInvalidationCount(false /* with_payload */)); |
845 EXPECT_EQ(4, GetInvalidationCount(true /* with_payload */)); | 847 EXPECT_EQ(4, GetInvalidationCount(true /* with_payload */)); |
846 } | 848 } |
847 | 849 |
848 } // namespace policy | 850 } // namespace policy |
OLD | NEW |