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

Side by Side Diff: chrome/browser/policy/cloud/cloud_policy_invalidator_unittest.cc

Issue 460573005: Pass highest handled invalidation version between invalidators (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code and tests done. Ready for review. Created 6 years, 4 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 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 POLICY_OBJECT_B 46 POLICY_OBJECT_B
47 }; 47 };
48 48
49 CloudPolicyInvalidatorTest(); 49 CloudPolicyInvalidatorTest();
50 50
51 virtual void TearDown() OVERRIDE; 51 virtual void TearDown() OVERRIDE;
52 52
53 // Starts the invalidator which will be tested. 53 // Starts the invalidator which will be tested.
54 // |initialize| determines if the invalidator should be initialized. 54 // |initialize| determines if the invalidator should be initialized.
55 // |start_refresh_scheduler| determines if the refresh scheduler should start. 55 // |start_refresh_scheduler| determines if the refresh scheduler should start.
56 void StartInvalidator(bool initialize, bool start_refresh_scheduler); 56 // |highest_handled_invalidation_version| is the highest invalidation version
57 // that was handled already before this invalidator was created.
58 void StartInvalidator(bool initialize,
59 bool start_refresh_scheduler,
60 int64 highest_handled_invalidation_version);
57 void StartInvalidator() { 61 void StartInvalidator() {
58 StartInvalidator(true /* initialize */, true /* start_refresh_scheduler */); 62 StartInvalidator(true, /* initialize */
63 true, /* start_refresh_scheduler */
64 0 /* highest_handled_invalidation_version */);
59 } 65 }
60 66
61 // Calls Initialize on the invalidator. 67 // Calls Initialize on the invalidator.
62 void InitializeInvalidator(); 68 void InitializeInvalidator();
63 69
64 // Calls Shutdown on the invalidator. Test must call DestroyInvalidator 70 // Calls Shutdown on the invalidator. Test must call DestroyInvalidator
65 // afterwards to prevent Shutdown from being called twice. 71 // afterwards to prevent Shutdown from being called twice.
66 void ShutdownInvalidator(); 72 void ShutdownInvalidator();
67 73
68 // Destroys the invalidator. 74 // Destroys the invalidator.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 bool InvalidationsEnabled(); 146 bool InvalidationsEnabled();
141 147
142 // Determines if the invalidation with the given ack handle has been 148 // Determines if the invalidation with the given ack handle has been
143 // acknowledged. 149 // acknowledged.
144 bool IsInvalidationAcknowledged(const syncer::Invalidation& invalidation); 150 bool IsInvalidationAcknowledged(const syncer::Invalidation& invalidation);
145 151
146 // Determines if the invalidator has registered for an object with the 152 // Determines if the invalidator has registered for an object with the
147 // invalidation service. 153 // invalidation service.
148 bool IsInvalidatorRegistered(); 154 bool IsInvalidatorRegistered();
149 155
156 // Returns the highest invalidation version that was handled already according
157 // to the |invalidator_|.
158 int64 GetHighestHandledInvalidationVersion() const;
159
150 // Advance the test clock. 160 // Advance the test clock.
151 void AdvanceClock(base::TimeDelta delta); 161 void AdvanceClock(base::TimeDelta delta);
152 162
153 // Get the current time on the test clock. 163 // Get the current time on the test clock.
154 base::Time Now(); 164 base::Time Now();
155 165
156 // Translate a version number into an appropriate invalidation version (which 166 // Translate a version number into an appropriate invalidation version (which
157 // is based on the current time). 167 // is based on the current time).
158 int64 V(int version); 168 int64 V(int version);
159 169
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } 228 }
219 229
220 void CloudPolicyInvalidatorTest::TearDown() { 230 void CloudPolicyInvalidatorTest::TearDown() {
221 if (invalidator_) 231 if (invalidator_)
222 invalidator_->Shutdown(); 232 invalidator_->Shutdown();
223 core_.Disconnect(); 233 core_.Disconnect();
224 } 234 }
225 235
226 void CloudPolicyInvalidatorTest::StartInvalidator( 236 void CloudPolicyInvalidatorTest::StartInvalidator(
227 bool initialize, 237 bool initialize,
228 bool start_refresh_scheduler) { 238 bool start_refresh_scheduler,
239 int64 highest_handled_invalidation_version) {
229 invalidator_.reset(new CloudPolicyInvalidator( 240 invalidator_.reset(new CloudPolicyInvalidator(
230 GetPolicyType(), 241 GetPolicyType(),
231 &core_, 242 &core_,
232 task_runner_, 243 task_runner_,
233 scoped_ptr<base::Clock>(clock_))); 244 scoped_ptr<base::Clock>(clock_),
245 highest_handled_invalidation_version));
234 if (start_refresh_scheduler) { 246 if (start_refresh_scheduler) {
235 ConnectCore(); 247 ConnectCore();
236 StartRefreshScheduler(); 248 StartRefreshScheduler();
237 } 249 }
238 if (initialize) 250 if (initialize)
239 InitializeInvalidator(); 251 InitializeInvalidator();
240 } 252 }
241 253
242 void CloudPolicyInvalidatorTest::InitializeInvalidator() { 254 void CloudPolicyInvalidatorTest::InitializeInvalidator() {
243 invalidator_->Initialize(&invalidation_service_); 255 invalidator_->Initialize(&invalidation_service_);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 376
365 EXPECT_FALSE(IsUnsent(invalidation)); 377 EXPECT_FALSE(IsUnsent(invalidation));
366 return !invalidation_service_.GetMockAckHandler()->IsUnacked(invalidation); 378 return !invalidation_service_.GetMockAckHandler()->IsUnacked(invalidation);
367 } 379 }
368 380
369 bool CloudPolicyInvalidatorTest::IsInvalidatorRegistered() { 381 bool CloudPolicyInvalidatorTest::IsInvalidatorRegistered() {
370 return !invalidation_service_.invalidator_registrar() 382 return !invalidation_service_.invalidator_registrar()
371 .GetRegisteredIds(invalidator_.get()).empty(); 383 .GetRegisteredIds(invalidator_.get()).empty();
372 } 384 }
373 385
386 int64 CloudPolicyInvalidatorTest::GetHighestHandledInvalidationVersion() const {
387 return invalidator_->highest_handled_invalidation_version();
388 }
389
374 void CloudPolicyInvalidatorTest::AdvanceClock(base::TimeDelta delta) { 390 void CloudPolicyInvalidatorTest::AdvanceClock(base::TimeDelta delta) {
375 clock_->Advance(delta); 391 clock_->Advance(delta);
376 } 392 }
377 393
378 base::Time CloudPolicyInvalidatorTest::Now() { 394 base::Time CloudPolicyInvalidatorTest::Now() {
379 return clock_->Now(); 395 return clock_->Now();
380 } 396 }
381 397
382 int64 CloudPolicyInvalidatorTest::V(int version) { 398 int64 CloudPolicyInvalidatorTest::V(int version) {
383 return GetVersion(Now()) + version; 399 return GetVersion(Now()) + version;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 440 }
425 441
426 const invalidation::ObjectId& CloudPolicyInvalidatorTest::GetPolicyObjectId( 442 const invalidation::ObjectId& CloudPolicyInvalidatorTest::GetPolicyObjectId(
427 PolicyObject object) const { 443 PolicyObject object) const {
428 EXPECT_TRUE(object == POLICY_OBJECT_A || object == POLICY_OBJECT_B); 444 EXPECT_TRUE(object == POLICY_OBJECT_A || object == POLICY_OBJECT_B);
429 return object == POLICY_OBJECT_A ? object_id_a_ : object_id_b_; 445 return object == POLICY_OBJECT_A ? object_id_a_ : object_id_b_;
430 } 446 }
431 447
432 TEST_F(CloudPolicyInvalidatorTest, Uninitialized) { 448 TEST_F(CloudPolicyInvalidatorTest, Uninitialized) {
433 // No invalidations should be processed if the invalidator is not initialized. 449 // No invalidations should be processed if the invalidator is not initialized.
434 StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */); 450 StartInvalidator(false, /* initialize */
451 true, /* start_refresh_scheduler */
452 0 /*highest_handled_invalidation_version*/);
Joao da Silva 2014/08/13 13:01:38 nit: space after /* and before */ (same below)
bartfab (slow) 2014/08/13 13:37:47 Done.
435 StorePolicy(POLICY_OBJECT_A); 453 StorePolicy(POLICY_OBJECT_A);
436 EXPECT_FALSE(IsInvalidatorRegistered()); 454 EXPECT_FALSE(IsInvalidatorRegistered());
437 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A))); 455 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A)));
438 EXPECT_TRUE(CheckPolicyNotRefreshed()); 456 EXPECT_TRUE(CheckPolicyNotRefreshed());
457 EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
439 } 458 }
440 459
441 TEST_F(CloudPolicyInvalidatorTest, RefreshSchedulerNotStarted) { 460 TEST_F(CloudPolicyInvalidatorTest, RefreshSchedulerNotStarted) {
442 // No invalidations should be processed if the refresh scheduler is not 461 // No invalidations should be processed if the refresh scheduler is not
443 // started. 462 // started.
444 StartInvalidator(true /* initialize */, false /* start_refresh_scheduler */); 463 StartInvalidator(true, /* initialize */
464 false, /* start_refresh_scheduler */
465 0 /*highest_handled_invalidation_version*/);
445 StorePolicy(POLICY_OBJECT_A); 466 StorePolicy(POLICY_OBJECT_A);
446 EXPECT_FALSE(IsInvalidatorRegistered()); 467 EXPECT_FALSE(IsInvalidatorRegistered());
447 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A))); 468 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A)));
448 EXPECT_TRUE(CheckPolicyNotRefreshed()); 469 EXPECT_TRUE(CheckPolicyNotRefreshed());
470 EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
449 } 471 }
450 472
451 TEST_F(CloudPolicyInvalidatorTest, DisconnectCoreThenInitialize) { 473 TEST_F(CloudPolicyInvalidatorTest, DisconnectCoreThenInitialize) {
452 // No invalidations should be processed if the core is disconnected before 474 // No invalidations should be processed if the core is disconnected before
453 // initialization. 475 // initialization.
454 StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */); 476 StartInvalidator(false, /* initialize */
477 true, /* start_refresh_scheduler */
478 0 /*highest_handled_invalidation_version*/);
455 DisconnectCore(); 479 DisconnectCore();
456 InitializeInvalidator(); 480 InitializeInvalidator();
457 StorePolicy(POLICY_OBJECT_A); 481 StorePolicy(POLICY_OBJECT_A);
458 EXPECT_FALSE(IsInvalidatorRegistered()); 482 EXPECT_FALSE(IsInvalidatorRegistered());
459 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A))); 483 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A)));
460 EXPECT_TRUE(CheckPolicyNotRefreshed()); 484 EXPECT_TRUE(CheckPolicyNotRefreshed());
485 EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
461 } 486 }
462 487
463 TEST_F(CloudPolicyInvalidatorTest, InitializeThenStartRefreshScheduler) { 488 TEST_F(CloudPolicyInvalidatorTest, InitializeThenStartRefreshScheduler) {
464 // Make sure registration occurs and invalidations are processed when 489 // Make sure registration occurs and invalidations are processed when
465 // Initialize is called before starting the refresh scheduler. 490 // Initialize is called before starting the refresh scheduler.
466 // Note that the reverse case (start refresh scheduler then initialize) is 491 // Note that the reverse case (start refresh scheduler then initialize) is
467 // the default behavior for the test fixture, so will be tested in most other 492 // the default behavior for the test fixture, so will be tested in most other
468 // tests. 493 // tests.
469 StartInvalidator(true /* initialize */, false /* start_refresh_scheduler */); 494 StartInvalidator(true, /* initialize */
495 false, /* start_refresh_scheduler */
496 0 /*highest_handled_invalidation_version*/);
470 ConnectCore(); 497 ConnectCore();
471 StartRefreshScheduler(); 498 StartRefreshScheduler();
472 StorePolicy(POLICY_OBJECT_A); 499 StorePolicy(POLICY_OBJECT_A);
473 EXPECT_TRUE(IsInvalidatorRegistered()); 500 EXPECT_TRUE(IsInvalidatorRegistered());
474 FireUnknownVersionInvalidation(POLICY_OBJECT_A); 501 FireUnknownVersionInvalidation(POLICY_OBJECT_A);
475 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); 502 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion());
503 EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
476 } 504 }
477 505
478 TEST_F(CloudPolicyInvalidatorTest, RegisterOnStoreLoaded) { 506 TEST_F(CloudPolicyInvalidatorTest, RegisterOnStoreLoaded) {
479 // No registration when store is not loaded. 507 // No registration when store is not loaded.
480 StartInvalidator(); 508 StartInvalidator();
481 EXPECT_FALSE(IsInvalidatorRegistered()); 509 EXPECT_FALSE(IsInvalidatorRegistered());
482 EXPECT_FALSE(InvalidationsEnabled()); 510 EXPECT_FALSE(InvalidationsEnabled());
483 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A))); 511 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A)));
484 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_B))); 512 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_B)));
485 EXPECT_TRUE(CheckPolicyNotRefreshed()); 513 EXPECT_TRUE(CheckPolicyNotRefreshed());
486 514
487 // No registration when store is loaded with no invalidation object id. 515 // No registration when store is loaded with no invalidation object id.
488 StorePolicy(POLICY_OBJECT_NONE); 516 StorePolicy(POLICY_OBJECT_NONE);
489 EXPECT_FALSE(IsInvalidatorRegistered()); 517 EXPECT_FALSE(IsInvalidatorRegistered());
490 EXPECT_FALSE(InvalidationsEnabled()); 518 EXPECT_FALSE(InvalidationsEnabled());
491 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A))); 519 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A)));
492 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_B))); 520 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_B)));
493 EXPECT_TRUE(CheckPolicyNotRefreshed()); 521 EXPECT_TRUE(CheckPolicyNotRefreshed());
494 522
495 // Check registration when store is loaded for object A. 523 // Check registration when store is loaded for object A.
496 StorePolicy(POLICY_OBJECT_A); 524 StorePolicy(POLICY_OBJECT_A);
497 EXPECT_TRUE(IsInvalidatorRegistered()); 525 EXPECT_TRUE(IsInvalidatorRegistered());
498 EXPECT_TRUE(InvalidationsEnabled()); 526 EXPECT_TRUE(InvalidationsEnabled());
499 FireUnknownVersionInvalidation(POLICY_OBJECT_A); 527 FireUnknownVersionInvalidation(POLICY_OBJECT_A);
500 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); 528 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion());
501 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_B))); 529 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_B)));
502 EXPECT_TRUE(CheckPolicyNotRefreshed()); 530 EXPECT_TRUE(CheckPolicyNotRefreshed());
531 EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
503 } 532 }
504 533
505 TEST_F(CloudPolicyInvalidatorTest, ChangeRegistration) { 534 TEST_F(CloudPolicyInvalidatorTest, ChangeRegistration) {
506 // Register for object A. 535 // Register for object A.
507 StartInvalidator(); 536 StartInvalidator();
508 StorePolicy(POLICY_OBJECT_A); 537 StorePolicy(POLICY_OBJECT_A);
509 EXPECT_TRUE(IsInvalidatorRegistered()); 538 EXPECT_TRUE(IsInvalidatorRegistered());
510 EXPECT_TRUE(InvalidationsEnabled()); 539 EXPECT_TRUE(InvalidationsEnabled());
511 FireUnknownVersionInvalidation(POLICY_OBJECT_A); 540 FireUnknownVersionInvalidation(POLICY_OBJECT_A);
512 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); 541 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion());
513 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_B))); 542 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_B)));
514 EXPECT_TRUE(CheckPolicyNotRefreshed()); 543 EXPECT_TRUE(CheckPolicyNotRefreshed());
515 syncer::Invalidation inv = FireUnknownVersionInvalidation(POLICY_OBJECT_A); 544 syncer::Invalidation inv = FireUnknownVersionInvalidation(POLICY_OBJECT_A);
516 545
517 // Check re-registration for object B. Make sure the pending invalidation for 546 // Check re-registration for object B. Make sure the pending invalidation for
518 // object A is acknowledged without making the callback. 547 // object A is acknowledged without making the callback.
519 StorePolicy(POLICY_OBJECT_B); 548 StorePolicy(POLICY_OBJECT_B);
520 EXPECT_TRUE(IsInvalidatorRegistered()); 549 EXPECT_TRUE(IsInvalidatorRegistered());
521 EXPECT_TRUE(InvalidationsEnabled()); 550 EXPECT_TRUE(InvalidationsEnabled());
522 EXPECT_TRUE(IsInvalidationAcknowledged(inv)); 551 EXPECT_TRUE(IsInvalidationAcknowledged(inv));
523 EXPECT_TRUE(CheckPolicyNotRefreshed()); 552 EXPECT_TRUE(CheckPolicyNotRefreshed());
524 553
525 // Make sure future invalidations for object A are ignored and for object B 554 // Make sure future invalidations for object A are ignored and for object B
526 // are processed. 555 // are processed.
527 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A))); 556 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A)));
528 EXPECT_TRUE(CheckPolicyNotRefreshed()); 557 EXPECT_TRUE(CheckPolicyNotRefreshed());
529 FireUnknownVersionInvalidation(POLICY_OBJECT_B); 558 FireUnknownVersionInvalidation(POLICY_OBJECT_B);
530 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); 559 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion());
560 EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
531 } 561 }
532 562
533 TEST_F(CloudPolicyInvalidatorTest, UnregisterOnStoreLoaded) { 563 TEST_F(CloudPolicyInvalidatorTest, UnregisterOnStoreLoaded) {
534 // Register for object A. 564 // Register for object A.
535 StartInvalidator(); 565 StartInvalidator();
536 StorePolicy(POLICY_OBJECT_A); 566 StorePolicy(POLICY_OBJECT_A);
537 EXPECT_TRUE(IsInvalidatorRegistered()); 567 EXPECT_TRUE(IsInvalidatorRegistered());
538 EXPECT_TRUE(InvalidationsEnabled()); 568 EXPECT_TRUE(InvalidationsEnabled());
539 FireUnknownVersionInvalidation(POLICY_OBJECT_A); 569 FireUnknownVersionInvalidation(POLICY_OBJECT_A);
540 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); 570 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion());
541 571
542 // Check unregistration when store is loaded with no invalidation object id. 572 // Check unregistration when store is loaded with no invalidation object id.
543 syncer::Invalidation inv = FireUnknownVersionInvalidation(POLICY_OBJECT_A); 573 syncer::Invalidation inv = FireUnknownVersionInvalidation(POLICY_OBJECT_A);
544 EXPECT_FALSE(IsInvalidationAcknowledged(inv)); 574 EXPECT_FALSE(IsInvalidationAcknowledged(inv));
545 StorePolicy(POLICY_OBJECT_NONE); 575 StorePolicy(POLICY_OBJECT_NONE);
546 EXPECT_FALSE(IsInvalidatorRegistered()); 576 EXPECT_FALSE(IsInvalidatorRegistered());
547 EXPECT_TRUE(IsInvalidationAcknowledged(inv)); 577 EXPECT_TRUE(IsInvalidationAcknowledged(inv));
548 EXPECT_FALSE(InvalidationsEnabled()); 578 EXPECT_FALSE(InvalidationsEnabled());
549 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A))); 579 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A)));
550 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_B))); 580 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_B)));
551 EXPECT_TRUE(CheckPolicyNotRefreshed()); 581 EXPECT_TRUE(CheckPolicyNotRefreshed());
552 582
553 // Check re-registration for object B. 583 // Check re-registration for object B.
554 StorePolicy(POLICY_OBJECT_B); 584 StorePolicy(POLICY_OBJECT_B);
555 EXPECT_TRUE(IsInvalidatorRegistered()); 585 EXPECT_TRUE(IsInvalidatorRegistered());
556 EXPECT_TRUE(InvalidationsEnabled()); 586 EXPECT_TRUE(InvalidationsEnabled());
557 FireUnknownVersionInvalidation(POLICY_OBJECT_B); 587 FireUnknownVersionInvalidation(POLICY_OBJECT_B);
558 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); 588 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion());
589 EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
559 } 590 }
560 591
561 TEST_F(CloudPolicyInvalidatorTest, HandleInvalidation) { 592 TEST_F(CloudPolicyInvalidatorTest, HandleInvalidation) {
562 // Register and fire invalidation 593 // Register and fire invalidation
563 StorePolicy(POLICY_OBJECT_A); 594 StorePolicy(POLICY_OBJECT_A);
564 StartInvalidator(); 595 StartInvalidator();
565 EXPECT_TRUE(InvalidationsEnabled()); 596 EXPECT_TRUE(InvalidationsEnabled());
566 syncer::Invalidation inv = 597 syncer::Invalidation inv =
567 FireInvalidation(POLICY_OBJECT_A, V(12), "test_payload"); 598 FireInvalidation(POLICY_OBJECT_A, V(12), "test_payload");
568 599
569 // Make sure client info is set as soon as the invalidation is received. 600 // Make sure client info is set as soon as the invalidation is received.
570 EXPECT_TRUE(CheckInvalidationInfo(V(12), "test_payload")); 601 EXPECT_TRUE(CheckInvalidationInfo(V(12), "test_payload"));
571 EXPECT_TRUE(CheckPolicyRefreshed()); 602 EXPECT_TRUE(CheckPolicyRefreshed());
572 603
573 // Make sure invalidation is not acknowledged until the store is loaded. 604 // Make sure invalidation is not acknowledged until the store is loaded.
574 EXPECT_FALSE(IsInvalidationAcknowledged(inv)); 605 EXPECT_FALSE(IsInvalidationAcknowledged(inv));
606 EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
575 EXPECT_TRUE(CheckInvalidationInfo(V(12), "test_payload")); 607 EXPECT_TRUE(CheckInvalidationInfo(V(12), "test_payload"));
576 StorePolicy(POLICY_OBJECT_A, V(12)); 608 StorePolicy(POLICY_OBJECT_A, V(12));
577 EXPECT_TRUE(IsInvalidationAcknowledged(inv)); 609 EXPECT_TRUE(IsInvalidationAcknowledged(inv));
578 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); 610 EXPECT_TRUE(CheckInvalidationInfo(0, std::string()));
611 EXPECT_EQ(V(12), GetHighestHandledInvalidationVersion());
579 } 612 }
580 613
581 TEST_F(CloudPolicyInvalidatorTest, HandleInvalidationWithUnknownVersion) { 614 TEST_F(CloudPolicyInvalidatorTest, HandleInvalidationWithUnknownVersion) {
582 // Register and fire invalidation with unknown version. 615 // Register and fire invalidation with unknown version.
583 StorePolicy(POLICY_OBJECT_A); 616 StorePolicy(POLICY_OBJECT_A);
584 StartInvalidator(); 617 StartInvalidator();
585 syncer::Invalidation inv = FireUnknownVersionInvalidation(POLICY_OBJECT_A); 618 syncer::Invalidation inv = FireUnknownVersionInvalidation(POLICY_OBJECT_A);
586 619
587 // Make sure client info is not set until after the invalidation callback is 620 // Make sure client info is not set until after the invalidation callback is
588 // made. 621 // made.
589 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); 622 EXPECT_TRUE(CheckInvalidationInfo(0, std::string()));
590 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); 623 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion());
591 EXPECT_TRUE(CheckInvalidationInfo(-1, std::string())); 624 EXPECT_TRUE(CheckInvalidationInfo(-1, std::string()));
592 625
593 // Make sure invalidation is not acknowledged until the store is loaded. 626 // Make sure invalidation is not acknowledged until the store is loaded.
594 EXPECT_FALSE(IsInvalidationAcknowledged(inv)); 627 EXPECT_FALSE(IsInvalidationAcknowledged(inv));
595 StorePolicy(POLICY_OBJECT_A, -1); 628 StorePolicy(POLICY_OBJECT_A, -1);
596 EXPECT_TRUE(IsInvalidationAcknowledged(inv)); 629 EXPECT_TRUE(IsInvalidationAcknowledged(inv));
597 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); 630 EXPECT_TRUE(CheckInvalidationInfo(0, std::string()));
631 EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
598 } 632 }
599 633
600 TEST_F(CloudPolicyInvalidatorTest, HandleMultipleInvalidations) { 634 TEST_F(CloudPolicyInvalidatorTest, HandleMultipleInvalidations) {
601 // Generate multiple invalidations. 635 // Generate multiple invalidations.
602 StorePolicy(POLICY_OBJECT_A); 636 StorePolicy(POLICY_OBJECT_A);
603 StartInvalidator(); 637 StartInvalidator();
604 syncer::Invalidation inv1 = FireInvalidation(POLICY_OBJECT_A, V(1), "test1"); 638 syncer::Invalidation inv1 = FireInvalidation(POLICY_OBJECT_A, V(1), "test1");
605 EXPECT_TRUE(CheckInvalidationInfo(V(1), "test1")); 639 EXPECT_TRUE(CheckInvalidationInfo(V(1), "test1"));
606 syncer::Invalidation inv2 = FireInvalidation(POLICY_OBJECT_A, V(2), "test2"); 640 syncer::Invalidation inv2 = FireInvalidation(POLICY_OBJECT_A, V(2), "test2");
607 EXPECT_TRUE(CheckInvalidationInfo(V(2), "test2")); 641 EXPECT_TRUE(CheckInvalidationInfo(V(2), "test2"));
608 syncer::Invalidation inv3 = FireInvalidation(POLICY_OBJECT_A, V(3), "test3"); 642 syncer::Invalidation inv3 = FireInvalidation(POLICY_OBJECT_A, V(3), "test3");
609 EXPECT_TRUE(CheckInvalidationInfo(V(3), "test3")); 643 EXPECT_TRUE(CheckInvalidationInfo(V(3), "test3"));
610 644
611 // Make sure the replaced invalidations are acknowledged. 645 // Make sure the replaced invalidations are acknowledged.
612 EXPECT_TRUE(IsInvalidationAcknowledged(inv1)); 646 EXPECT_TRUE(IsInvalidationAcknowledged(inv1));
613 EXPECT_TRUE(IsInvalidationAcknowledged(inv2)); 647 EXPECT_TRUE(IsInvalidationAcknowledged(inv2));
614 648
615 // Make sure the policy is refreshed once. 649 // Make sure the policy is refreshed once.
616 EXPECT_TRUE(CheckPolicyRefreshed()); 650 EXPECT_TRUE(CheckPolicyRefreshed());
617 651
618 // Make sure that the last invalidation is only acknowledged after the store 652 // Make sure that the last invalidation is only acknowledged after the store
619 // is loaded with the latest version. 653 // is loaded with the latest version.
654 EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
620 StorePolicy(POLICY_OBJECT_A, V(1)); 655 StorePolicy(POLICY_OBJECT_A, V(1));
621 EXPECT_FALSE(IsInvalidationAcknowledged(inv3)); 656 EXPECT_FALSE(IsInvalidationAcknowledged(inv3));
657 EXPECT_EQ(V(1), GetHighestHandledInvalidationVersion());
622 StorePolicy(POLICY_OBJECT_A, V(2)); 658 StorePolicy(POLICY_OBJECT_A, V(2));
623 EXPECT_FALSE(IsInvalidationAcknowledged(inv3)); 659 EXPECT_FALSE(IsInvalidationAcknowledged(inv3));
660 EXPECT_EQ(V(2), GetHighestHandledInvalidationVersion());
624 StorePolicy(POLICY_OBJECT_A, V(3)); 661 StorePolicy(POLICY_OBJECT_A, V(3));
625 EXPECT_TRUE(IsInvalidationAcknowledged(inv3)); 662 EXPECT_TRUE(IsInvalidationAcknowledged(inv3));
663 EXPECT_EQ(V(3), GetHighestHandledInvalidationVersion());
626 } 664 }
627 665
628 TEST_F(CloudPolicyInvalidatorTest, 666 TEST_F(CloudPolicyInvalidatorTest,
629 HandleMultipleInvalidationsWithUnknownVersion) { 667 HandleMultipleInvalidationsWithUnknownVersion) {
630 // Validate that multiple invalidations with unknown version each generate 668 // Validate that multiple invalidations with unknown version each generate
631 // unique invalidation version numbers. 669 // unique invalidation version numbers.
632 StorePolicy(POLICY_OBJECT_A); 670 StorePolicy(POLICY_OBJECT_A);
633 StartInvalidator(); 671 StartInvalidator();
634 syncer::Invalidation inv1 = FireUnknownVersionInvalidation(POLICY_OBJECT_A); 672 syncer::Invalidation inv1 = FireUnknownVersionInvalidation(POLICY_OBJECT_A);
635 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); 673 EXPECT_TRUE(CheckInvalidationInfo(0, std::string()));
(...skipping 13 matching lines...) Expand all
649 EXPECT_TRUE(IsInvalidationAcknowledged(inv2)); 687 EXPECT_TRUE(IsInvalidationAcknowledged(inv2));
650 688
651 // Make sure that the last invalidation is only acknowledged after the store 689 // Make sure that the last invalidation is only acknowledged after the store
652 // is loaded with the last unknown version. 690 // is loaded with the last unknown version.
653 StorePolicy(POLICY_OBJECT_A, -1); 691 StorePolicy(POLICY_OBJECT_A, -1);
654 EXPECT_FALSE(IsInvalidationAcknowledged(inv3)); 692 EXPECT_FALSE(IsInvalidationAcknowledged(inv3));
655 StorePolicy(POLICY_OBJECT_A, -2); 693 StorePolicy(POLICY_OBJECT_A, -2);
656 EXPECT_FALSE(IsInvalidationAcknowledged(inv3)); 694 EXPECT_FALSE(IsInvalidationAcknowledged(inv3));
657 StorePolicy(POLICY_OBJECT_A, -3); 695 StorePolicy(POLICY_OBJECT_A, -3);
658 EXPECT_TRUE(IsInvalidationAcknowledged(inv3)); 696 EXPECT_TRUE(IsInvalidationAcknowledged(inv3));
697 EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
698 }
699
700 TEST_F(CloudPolicyInvalidatorTest,
701 InitialHighestHandledInvalidationVersionNonZero) {
702 StorePolicy(POLICY_OBJECT_A);
703 StartInvalidator(true, /* initialize */
704 true, /* start_refresh_scheduler */
705 V(2) /* highest_handled_invalidation_version*/);
706
707 // Check that an invalidation whose version is lower than the highest handled
708 // so far is acknowledged but ignored otherwise.
709 syncer::Invalidation inv1 = FireInvalidation(POLICY_OBJECT_A, V(1), "test1");
710 EXPECT_TRUE(CheckPolicyNotRefreshed());
711 EXPECT_TRUE(CheckInvalidationInfo(0, std::string()));
712 EXPECT_TRUE(IsInvalidationAcknowledged(inv1));
713 EXPECT_EQ(V(2), GetHighestHandledInvalidationVersion());
714
715 // Check that an invalidation with an unknown version is handled.
716 syncer::Invalidation inv = FireUnknownVersionInvalidation(POLICY_OBJECT_A);
717 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion());
718 EXPECT_TRUE(CheckInvalidationInfo(-1, std::string()));
719 StorePolicy(POLICY_OBJECT_A, -1);
720 EXPECT_TRUE(IsInvalidationAcknowledged(inv));
721 EXPECT_EQ(V(2), GetHighestHandledInvalidationVersion());
722
723 // Check that an invalidation whose version matches the highest handled so far
724 // is acknowledged but ignored otherwise.
725 syncer::Invalidation inv2 = FireInvalidation(POLICY_OBJECT_A, V(2), "test2");
726 EXPECT_TRUE(CheckPolicyNotRefreshed());
727 EXPECT_TRUE(CheckInvalidationInfo(0, std::string()));
728 EXPECT_TRUE(IsInvalidationAcknowledged(inv2));
729 EXPECT_EQ(V(2), GetHighestHandledInvalidationVersion());
730
731 // Check that an invalidation whose version is higher than the highest handled
732 // so far is handled, causing a policy refresh.
733 syncer::Invalidation inv3 = FireInvalidation(POLICY_OBJECT_A, V(3), "test3");
734 EXPECT_TRUE(CheckPolicyRefreshed());
735 EXPECT_TRUE(CheckInvalidationInfo(V(3), "test3"));
736 StorePolicy(POLICY_OBJECT_A, V(3));
737 EXPECT_TRUE(IsInvalidationAcknowledged(inv3));
738 EXPECT_EQ(V(3), GetHighestHandledInvalidationVersion());
659 } 739 }
660 740
661 TEST_F(CloudPolicyInvalidatorTest, AcknowledgeBeforeRefresh) { 741 TEST_F(CloudPolicyInvalidatorTest, AcknowledgeBeforeRefresh) {
662 // Generate an invalidation. 742 // Generate an invalidation.
663 StorePolicy(POLICY_OBJECT_A); 743 StorePolicy(POLICY_OBJECT_A);
664 StartInvalidator(); 744 StartInvalidator();
665 syncer::Invalidation inv = FireInvalidation(POLICY_OBJECT_A, V(3), "test"); 745 syncer::Invalidation inv = FireInvalidation(POLICY_OBJECT_A, V(3), "test");
666 746
667 // Ensure that the policy is not refreshed and the invalidation is 747 // Ensure that the policy is not refreshed and the invalidation is
668 // acknowledged if the store is loaded with the latest version before the 748 // acknowledged if the store is loaded with the latest version before the
669 // refresh can occur. 749 // refresh can occur.
750 EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
670 StorePolicy(POLICY_OBJECT_A, V(3)); 751 StorePolicy(POLICY_OBJECT_A, V(3));
671 EXPECT_TRUE(IsInvalidationAcknowledged(inv)); 752 EXPECT_TRUE(IsInvalidationAcknowledged(inv));
672 EXPECT_TRUE(CheckPolicyNotRefreshed()); 753 EXPECT_TRUE(CheckPolicyNotRefreshed());
754 EXPECT_EQ(V(3), GetHighestHandledInvalidationVersion());
673 } 755 }
674 756
675 TEST_F(CloudPolicyInvalidatorTest, NoCallbackAfterShutdown) { 757 TEST_F(CloudPolicyInvalidatorTest, NoCallbackAfterShutdown) {
676 // Generate an invalidation. 758 // Generate an invalidation.
677 StorePolicy(POLICY_OBJECT_A); 759 StorePolicy(POLICY_OBJECT_A);
678 StartInvalidator(); 760 StartInvalidator();
679 syncer::Invalidation inv = FireInvalidation(POLICY_OBJECT_A, V(3), "test"); 761 syncer::Invalidation inv = FireInvalidation(POLICY_OBJECT_A, V(3), "test");
680 762
681 // Ensure that the policy refresh is not made after the invalidator is shut 763 // Ensure that the policy refresh is not made after the invalidator is shut
682 // down. 764 // down.
683 ShutdownInvalidator(); 765 ShutdownInvalidator();
684 EXPECT_TRUE(CheckPolicyNotRefreshed()); 766 EXPECT_TRUE(CheckPolicyNotRefreshed());
767 EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
685 DestroyInvalidator(); 768 DestroyInvalidator();
686 } 769 }
687 770
688 TEST_F(CloudPolicyInvalidatorTest, StateChanged) { 771 TEST_F(CloudPolicyInvalidatorTest, StateChanged) {
689 // Test invalidation service state changes while not registered. 772 // Test invalidation service state changes while not registered.
690 StartInvalidator(); 773 StartInvalidator();
691 DisableInvalidationService(); 774 DisableInvalidationService();
692 EnableInvalidationService(); 775 EnableInvalidationService();
693 EXPECT_FALSE(InvalidationsEnabled()); 776 EXPECT_FALSE(InvalidationsEnabled());
694 777
(...skipping 18 matching lines...) Expand all
713 EXPECT_TRUE(InvalidationsEnabled()); 796 EXPECT_TRUE(InvalidationsEnabled());
714 StorePolicy(POLICY_OBJECT_A); 797 StorePolicy(POLICY_OBJECT_A);
715 EXPECT_TRUE(InvalidationsEnabled()); 798 EXPECT_TRUE(InvalidationsEnabled());
716 799
717 // Test registration changes with invalidation service disabled. 800 // Test registration changes with invalidation service disabled.
718 DisableInvalidationService(); 801 DisableInvalidationService();
719 EXPECT_FALSE(InvalidationsEnabled()); 802 EXPECT_FALSE(InvalidationsEnabled());
720 StorePolicy(POLICY_OBJECT_NONE); 803 StorePolicy(POLICY_OBJECT_NONE);
721 StorePolicy(POLICY_OBJECT_A); 804 StorePolicy(POLICY_OBJECT_A);
722 EXPECT_FALSE(InvalidationsEnabled()); 805 EXPECT_FALSE(InvalidationsEnabled());
806 EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
723 } 807 }
724 808
725 TEST_F(CloudPolicyInvalidatorTest, Disconnect) { 809 TEST_F(CloudPolicyInvalidatorTest, Disconnect) {
726 // Generate an invalidation. 810 // Generate an invalidation.
727 StorePolicy(POLICY_OBJECT_A); 811 StorePolicy(POLICY_OBJECT_A);
728 StartInvalidator(); 812 StartInvalidator();
729 syncer::Invalidation inv = FireInvalidation(POLICY_OBJECT_A, V(1), "test"); 813 syncer::Invalidation inv = FireInvalidation(POLICY_OBJECT_A, V(1), "test");
730 EXPECT_TRUE(InvalidationsEnabled()); 814 EXPECT_TRUE(InvalidationsEnabled());
731 815
732 // Ensure that the policy is not refreshed after disconnecting the core, but 816 // Ensure that the policy is not refreshed after disconnecting the core, but
(...skipping 19 matching lines...) Expand all
752 // Ensure that the invalidator returns to normal after reconnecting. 836 // Ensure that the invalidator returns to normal after reconnecting.
753 ConnectCore(); 837 ConnectCore();
754 StartRefreshScheduler(); 838 StartRefreshScheduler();
755 EXPECT_TRUE(CheckPolicyNotRefreshed()); 839 EXPECT_TRUE(CheckPolicyNotRefreshed());
756 EXPECT_TRUE(InvalidationsEnabled()); 840 EXPECT_TRUE(InvalidationsEnabled());
757 FireInvalidation(POLICY_OBJECT_A, V(5), "test"); 841 FireInvalidation(POLICY_OBJECT_A, V(5), "test");
758 EXPECT_TRUE(CheckInvalidationInfo(V(5), "test")); 842 EXPECT_TRUE(CheckInvalidationInfo(V(5), "test"));
759 EXPECT_TRUE(CheckPolicyRefreshed()); 843 EXPECT_TRUE(CheckPolicyRefreshed());
760 DisableInvalidationService(); 844 DisableInvalidationService();
761 EXPECT_FALSE(InvalidationsEnabled()); 845 EXPECT_FALSE(InvalidationsEnabled());
846 EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
762 } 847 }
763 848
764 class CloudPolicyInvalidatorUserTypedTest 849 class CloudPolicyInvalidatorUserTypedTest
765 : public CloudPolicyInvalidatorTest, 850 : public CloudPolicyInvalidatorTest,
766 public testing::WithParamInterface<em::DeviceRegisterRequest::Type> { 851 public testing::WithParamInterface<em::DeviceRegisterRequest::Type> {
767 protected: 852 protected:
768 CloudPolicyInvalidatorUserTypedTest(); 853 CloudPolicyInvalidatorUserTypedTest();
769 virtual ~CloudPolicyInvalidatorUserTypedTest(); 854 virtual ~CloudPolicyInvalidatorUserTypedTest();
770 855
771 // CloudPolicyInvalidatorTest: 856 // CloudPolicyInvalidatorTest:
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 TEST_P(CloudPolicyInvalidatorUserTypedTest, RefreshMetricsUnregistered) { 928 TEST_P(CloudPolicyInvalidatorUserTypedTest, RefreshMetricsUnregistered) {
844 // Store loads occurring before invalidation registration are not counted. 929 // Store loads occurring before invalidation registration are not counted.
845 StartInvalidator(); 930 StartInvalidator();
846 StorePolicy(POLICY_OBJECT_NONE, 0, false /* policy_changed */); 931 StorePolicy(POLICY_OBJECT_NONE, 0, false /* policy_changed */);
847 StorePolicy(POLICY_OBJECT_NONE, 0, true /* policy_changed */); 932 StorePolicy(POLICY_OBJECT_NONE, 0, true /* policy_changed */);
848 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_CHANGED)); 933 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_CHANGED));
849 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS)); 934 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS));
850 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_UNCHANGED)); 935 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_UNCHANGED));
851 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED)); 936 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED));
852 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED)); 937 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED));
938 EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
853 } 939 }
854 940
855 TEST_P(CloudPolicyInvalidatorUserTypedTest, RefreshMetricsNoInvalidations) { 941 TEST_P(CloudPolicyInvalidatorUserTypedTest, RefreshMetricsNoInvalidations) {
856 // Store loads occurring while registered should be differentiated depending 942 // Store loads occurring while registered should be differentiated depending
857 // on whether the invalidation service was enabled or not. 943 // on whether the invalidation service was enabled or not.
858 StorePolicy(POLICY_OBJECT_A); 944 StorePolicy(POLICY_OBJECT_A);
859 StartInvalidator(); 945 StartInvalidator();
860 946
861 // Initially, invalidations have not been enabled past the grace period, so 947 // Initially, invalidations have not been enabled past the grace period, so
862 // invalidations are OFF. 948 // invalidations are OFF.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 AdvanceClock(base::TimeDelta::FromSeconds( 980 AdvanceClock(base::TimeDelta::FromSeconds(
895 CloudPolicyInvalidator::kInvalidationGracePeriod)); 981 CloudPolicyInvalidator::kInvalidationGracePeriod));
896 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); 982 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */);
897 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */); 983 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */);
898 984
899 EXPECT_EQ(2, GetCount(METRIC_POLICY_REFRESH_CHANGED)); 985 EXPECT_EQ(2, GetCount(METRIC_POLICY_REFRESH_CHANGED));
900 EXPECT_EQ(4, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS)); 986 EXPECT_EQ(4, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS));
901 EXPECT_EQ(6, GetCount(METRIC_POLICY_REFRESH_UNCHANGED)); 987 EXPECT_EQ(6, GetCount(METRIC_POLICY_REFRESH_UNCHANGED));
902 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED)); 988 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED));
903 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED)); 989 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED));
990 EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
904 } 991 }
905 992
906 TEST_P(CloudPolicyInvalidatorUserTypedTest, RefreshMetricsInvalidation) { 993 TEST_P(CloudPolicyInvalidatorUserTypedTest, RefreshMetricsInvalidation) {
907 // Store loads after an invalidation are counted as invalidated, even if 994 // Store loads after an invalidation are counted as invalidated, even if
908 // the loads do not result in the invalidation being acknowledged. 995 // the loads do not result in the invalidation being acknowledged.
909 StartInvalidator(); 996 StartInvalidator();
910 StorePolicy(POLICY_OBJECT_A); 997 StorePolicy(POLICY_OBJECT_A);
911 AdvanceClock(base::TimeDelta::FromSeconds( 998 AdvanceClock(base::TimeDelta::FromSeconds(
912 CloudPolicyInvalidator::kInvalidationGracePeriod)); 999 CloudPolicyInvalidator::kInvalidationGracePeriod));
913 FireInvalidation(POLICY_OBJECT_A, V(5), "test"); 1000 FireInvalidation(POLICY_OBJECT_A, V(5), "test");
914 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); 1001 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */);
915 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */); 1002 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */);
1003 EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
916 StorePolicy(POLICY_OBJECT_A, V(5), true /* policy_changed */); 1004 StorePolicy(POLICY_OBJECT_A, V(5), true /* policy_changed */);
1005 EXPECT_EQ(V(5), GetHighestHandledInvalidationVersion());
917 1006
918 // Store loads after the invalidation is complete are not counted as 1007 // Store loads after the invalidation is complete are not counted as
919 // invalidated. 1008 // invalidated.
920 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); 1009 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */);
921 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */); 1010 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */);
922 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); 1011 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */);
923 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */); 1012 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */);
924 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); 1013 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */);
925 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */); 1014 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */);
926 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); 1015 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */);
927 1016
928 EXPECT_EQ(3, GetCount(METRIC_POLICY_REFRESH_CHANGED)); 1017 EXPECT_EQ(3, GetCount(METRIC_POLICY_REFRESH_CHANGED));
929 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS)); 1018 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS));
930 EXPECT_EQ(4, GetCount(METRIC_POLICY_REFRESH_UNCHANGED)); 1019 EXPECT_EQ(4, GetCount(METRIC_POLICY_REFRESH_UNCHANGED));
931 EXPECT_EQ(2, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED)); 1020 EXPECT_EQ(2, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED));
932 EXPECT_EQ(1, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED)); 1021 EXPECT_EQ(1, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED));
1022 EXPECT_EQ(V(5), GetHighestHandledInvalidationVersion());
933 } 1023 }
934 1024
935 TEST_P(CloudPolicyInvalidatorUserTypedTest, ExpiredInvalidations) { 1025 TEST_P(CloudPolicyInvalidatorUserTypedTest, ExpiredInvalidations) {
936 StorePolicy(POLICY_OBJECT_A, 0, false, Now()); 1026 StorePolicy(POLICY_OBJECT_A, 0, false, Now());
937 StartInvalidator(); 1027 StartInvalidator();
938 1028
939 // Invalidations fired before the last fetch time (adjusted by max time delta) 1029 // Invalidations fired before the last fetch time (adjusted by max time delta)
940 // should be ignored. 1030 // should be ignored.
941 base::Time time = Now() - base::TimeDelta::FromSeconds( 1031 base::Time time = Now() - base::TimeDelta::FromSeconds(
942 CloudPolicyInvalidator::kMaxInvalidationTimeDelta + 300); 1032 CloudPolicyInvalidator::kMaxInvalidationTimeDelta + 300);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 inv = FireUnknownVersionInvalidation(POLICY_OBJECT_A); 1074 inv = FireUnknownVersionInvalidation(POLICY_OBJECT_A);
985 ASSERT_FALSE(IsInvalidationAcknowledged(inv)); 1075 ASSERT_FALSE(IsInvalidationAcknowledged(inv));
986 ASSERT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); 1076 ASSERT_TRUE(CheckPolicyRefreshedWithUnknownVersion());
987 1077
988 // Verify that received invalidations metrics are correct. 1078 // Verify that received invalidations metrics are correct.
989 EXPECT_EQ(1, GetInvalidationCount(POLICY_INVALIDATION_TYPE_NO_PAYLOAD)); 1079 EXPECT_EQ(1, GetInvalidationCount(POLICY_INVALIDATION_TYPE_NO_PAYLOAD));
990 EXPECT_EQ(3, GetInvalidationCount(POLICY_INVALIDATION_TYPE_NORMAL)); 1080 EXPECT_EQ(3, GetInvalidationCount(POLICY_INVALIDATION_TYPE_NORMAL));
991 EXPECT_EQ(2, 1081 EXPECT_EQ(2,
992 GetInvalidationCount(POLICY_INVALIDATION_TYPE_NO_PAYLOAD_EXPIRED)); 1082 GetInvalidationCount(POLICY_INVALIDATION_TYPE_NO_PAYLOAD_EXPIRED));
993 EXPECT_EQ(2, GetInvalidationCount(POLICY_INVALIDATION_TYPE_EXPIRED)); 1083 EXPECT_EQ(2, GetInvalidationCount(POLICY_INVALIDATION_TYPE_EXPIRED));
1084 EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
994 } 1085 }
995 1086
996 #if defined(OS_CHROMEOS) 1087 #if defined(OS_CHROMEOS)
997 INSTANTIATE_TEST_CASE_P( 1088 INSTANTIATE_TEST_CASE_P(
998 CloudPolicyInvalidatorUserTypedTestInstance, 1089 CloudPolicyInvalidatorUserTypedTestInstance,
999 CloudPolicyInvalidatorUserTypedTest, 1090 CloudPolicyInvalidatorUserTypedTest,
1000 testing::Values(em::DeviceRegisterRequest::USER, 1091 testing::Values(em::DeviceRegisterRequest::USER,
1001 em::DeviceRegisterRequest::DEVICE)); 1092 em::DeviceRegisterRequest::DEVICE));
1002 #elif defined(OS_ANDROID) 1093 #elif defined(OS_ANDROID)
1003 INSTANTIATE_TEST_CASE_P( 1094 INSTANTIATE_TEST_CASE_P(
1004 CloudPolicyInvalidatorUserTypedTestInstance, 1095 CloudPolicyInvalidatorUserTypedTestInstance,
1005 CloudPolicyInvalidatorUserTypedTest, 1096 CloudPolicyInvalidatorUserTypedTest,
1006 testing::Values(em::DeviceRegisterRequest::ANDROID_BROWSER)); 1097 testing::Values(em::DeviceRegisterRequest::ANDROID_BROWSER));
1007 #elif defined(OS_IOS) 1098 #elif defined(OS_IOS)
1008 INSTANTIATE_TEST_CASE_P( 1099 INSTANTIATE_TEST_CASE_P(
1009 CloudPolicyInvalidatorUserTypedTestInstance, 1100 CloudPolicyInvalidatorUserTypedTestInstance,
1010 CloudPolicyInvalidatorUserTypedTest, 1101 CloudPolicyInvalidatorUserTypedTest,
1011 testing::Values(em::DeviceRegisterRequest::IOS_BROWSER)); 1102 testing::Values(em::DeviceRegisterRequest::IOS_BROWSER));
1012 #else 1103 #else
1013 INSTANTIATE_TEST_CASE_P( 1104 INSTANTIATE_TEST_CASE_P(
1014 CloudPolicyInvalidatorUserTypedTestInstance, 1105 CloudPolicyInvalidatorUserTypedTestInstance,
1015 CloudPolicyInvalidatorUserTypedTest, 1106 CloudPolicyInvalidatorUserTypedTest,
1016 testing::Values(em::DeviceRegisterRequest::BROWSER)); 1107 testing::Values(em::DeviceRegisterRequest::BROWSER));
1017 #endif 1108 #endif
1018 1109
1019 } // namespace policy 1110 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698