| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // Causes the invalidation service to fire an invalidation. Returns an ack | 109 // Causes the invalidation service to fire an invalidation. Returns an ack |
| 110 // handle which be used to verify that the invalidation was acknowledged. | 110 // handle which be used to verify that the invalidation was acknowledged. |
| 111 syncer::AckHandle FireInvalidation( | 111 syncer::AckHandle FireInvalidation( |
| 112 PolicyObject object, | 112 PolicyObject object, |
| 113 int64 version, | 113 int64 version, |
| 114 const std::string& payload); | 114 const std::string& payload); |
| 115 | 115 |
| 116 // Causes the invalidation service to fire an invalidation with unknown | 116 // Causes the invalidation service to fire an invalidation with unknown |
| 117 // version. Returns an ack handle which be used to verify that the | 117 // version. Returns an ack handle which be used to verify that the |
| 118 // invalidation was acknowledged. | 118 // invalidation was acknowledged. |
| 119 syncer::AckHandle FireInvalidation(PolicyObject object); | 119 syncer::AckHandle FireUnknownVersionInvalidation(PolicyObject object); |
| 120 | 120 |
| 121 // Checks the expected value of the currently set invalidation info. | 121 // Checks the expected value of the currently set invalidation info. |
| 122 bool CheckInvalidationInfo(int64 version, const std::string& payload); | 122 bool CheckInvalidationInfo(int64 version, const std::string& payload); |
| 123 | 123 |
| 124 // Checks that the policy was not refreshed due to an invalidation. | 124 // Checks that the policy was not refreshed due to an invalidation. |
| 125 bool CheckPolicyNotRefreshed(); | 125 bool CheckPolicyNotRefreshed(); |
| 126 | 126 |
| 127 // Checks that the policy was refreshed due to an invalidation within an | 127 // Checks that the policy was refreshed due to an invalidation within an |
| 128 // appropriate timeframe depending on whether the invalidation had unknown | 128 // appropriate timeframe depending on whether the invalidation had unknown |
| 129 // version. | 129 // version. |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 } | 289 } |
| 290 | 290 |
| 291 void CloudPolicyInvalidatorTest::EnableInvalidationService() { | 291 void CloudPolicyInvalidatorTest::EnableInvalidationService() { |
| 292 invalidation_service_.SetInvalidatorState(syncer::INVALIDATIONS_ENABLED); | 292 invalidation_service_.SetInvalidatorState(syncer::INVALIDATIONS_ENABLED); |
| 293 } | 293 } |
| 294 | 294 |
| 295 syncer::AckHandle CloudPolicyInvalidatorTest::FireInvalidation( | 295 syncer::AckHandle CloudPolicyInvalidatorTest::FireInvalidation( |
| 296 PolicyObject object, | 296 PolicyObject object, |
| 297 int64 version, | 297 int64 version, |
| 298 const std::string& payload) { | 298 const std::string& payload) { |
| 299 return invalidation_service_.EmitInvalidationForTest( | 299 syncer::Invalidation invalidation = syncer::Invalidation::Init( |
| 300 GetPolicyObjectId(object), | 300 GetPolicyObjectId(object), |
| 301 version, | 301 version, |
| 302 payload); | 302 payload); |
| 303 invalidation_service_.EmitInvalidationForTest(invalidation); |
| 304 return invalidation.GetAckHandle(); |
| 303 } | 305 } |
| 304 | 306 |
| 305 syncer::AckHandle CloudPolicyInvalidatorTest::FireInvalidation( | 307 syncer::AckHandle CloudPolicyInvalidatorTest::FireUnknownVersionInvalidation( |
| 306 PolicyObject object) { | 308 PolicyObject object) { |
| 307 return invalidation_service_.EmitInvalidationForTest( | 309 syncer::Invalidation invalidation = |
| 308 GetPolicyObjectId(object), | 310 syncer::Invalidation::InitUnknownVersion(GetPolicyObjectId(object)); |
| 309 syncer::Invalidation::kUnknownVersion, | 311 invalidation_service_.EmitInvalidationForTest(invalidation); |
| 310 std::string()); | 312 return invalidation.GetAckHandle(); |
| 311 } | 313 } |
| 312 | 314 |
| 313 bool CloudPolicyInvalidatorTest::CheckInvalidationInfo( | 315 bool CloudPolicyInvalidatorTest::CheckInvalidationInfo( |
| 314 int64 version, | 316 int64 version, |
| 315 const std::string& payload) { | 317 const std::string& payload) { |
| 316 MockCloudPolicyClient* client = | 318 MockCloudPolicyClient* client = |
| 317 static_cast<MockCloudPolicyClient*>(core_.client()); | 319 static_cast<MockCloudPolicyClient*>(core_.client()); |
| 318 return version == client->invalidation_version_ && | 320 return version == client->invalidation_version_ && |
| 319 payload == client->invalidation_payload_; | 321 payload == client->invalidation_payload_; |
| 320 } | 322 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 if (!histogram) | 392 if (!histogram) |
| 391 return scoped_ptr<base::HistogramSamples>(new base::SampleMap()); | 393 return scoped_ptr<base::HistogramSamples>(new base::SampleMap()); |
| 392 return histogram->SnapshotSamples(); | 394 return histogram->SnapshotSamples(); |
| 393 } | 395 } |
| 394 | 396 |
| 395 TEST_F(CloudPolicyInvalidatorTest, Uninitialized) { | 397 TEST_F(CloudPolicyInvalidatorTest, Uninitialized) { |
| 396 // No invalidations should be processed if the invalidator is not initialized. | 398 // No invalidations should be processed if the invalidator is not initialized. |
| 397 StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */); | 399 StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */); |
| 398 StorePolicy(POLICY_OBJECT_A); | 400 StorePolicy(POLICY_OBJECT_A); |
| 399 EXPECT_FALSE(IsInvalidatorRegistered()); | 401 EXPECT_FALSE(IsInvalidatorRegistered()); |
| 400 FireInvalidation(POLICY_OBJECT_A); | 402 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 401 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 403 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 402 } | 404 } |
| 403 | 405 |
| 404 TEST_F(CloudPolicyInvalidatorTest, RefreshSchedulerNotStarted) { | 406 TEST_F(CloudPolicyInvalidatorTest, RefreshSchedulerNotStarted) { |
| 405 // No invalidations should be processed if the refresh scheduler is not | 407 // No invalidations should be processed if the refresh scheduler is not |
| 406 // started. | 408 // started. |
| 407 StartInvalidator(true /* initialize */, false /* start_refresh_scheduler */); | 409 StartInvalidator(true /* initialize */, false /* start_refresh_scheduler */); |
| 408 StorePolicy(POLICY_OBJECT_A); | 410 StorePolicy(POLICY_OBJECT_A); |
| 409 EXPECT_FALSE(IsInvalidatorRegistered()); | 411 EXPECT_FALSE(IsInvalidatorRegistered()); |
| 410 FireInvalidation(POLICY_OBJECT_A); | 412 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 411 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 413 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 412 } | 414 } |
| 413 | 415 |
| 414 TEST_F(CloudPolicyInvalidatorTest, DisconnectCoreThenInitialize) { | 416 TEST_F(CloudPolicyInvalidatorTest, DisconnectCoreThenInitialize) { |
| 415 // No invalidations should be processed if the core is disconnected before | 417 // No invalidations should be processed if the core is disconnected before |
| 416 // initialization. | 418 // initialization. |
| 417 StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */); | 419 StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */); |
| 418 DisconnectCore(); | 420 DisconnectCore(); |
| 419 InitializeInvalidator(); | 421 InitializeInvalidator(); |
| 420 StorePolicy(POLICY_OBJECT_A); | 422 StorePolicy(POLICY_OBJECT_A); |
| 421 EXPECT_FALSE(IsInvalidatorRegistered()); | 423 EXPECT_FALSE(IsInvalidatorRegistered()); |
| 422 FireInvalidation(POLICY_OBJECT_A); | 424 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 423 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 425 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 424 } | 426 } |
| 425 | 427 |
| 426 TEST_F(CloudPolicyInvalidatorTest, InitializeThenStartRefreshScheduler) { | 428 TEST_F(CloudPolicyInvalidatorTest, InitializeThenStartRefreshScheduler) { |
| 427 // Make sure registration occurs and invalidations are processed when | 429 // Make sure registration occurs and invalidations are processed when |
| 428 // Initialize is called before starting the refresh scheduler. | 430 // Initialize is called before starting the refresh scheduler. |
| 429 // Note that the reverse case (start refresh scheduler then initialize) is | 431 // Note that the reverse case (start refresh scheduler then initialize) is |
| 430 // the default behavior for the test fixture, so will be tested in most other | 432 // the default behavior for the test fixture, so will be tested in most other |
| 431 // tests. | 433 // tests. |
| 432 StartInvalidator(true /* initialize */, false /* start_refresh_scheduler */); | 434 StartInvalidator(true /* initialize */, false /* start_refresh_scheduler */); |
| 433 ConnectCore(); | 435 ConnectCore(); |
| 434 StartRefreshScheduler(); | 436 StartRefreshScheduler(); |
| 435 StorePolicy(POLICY_OBJECT_A); | 437 StorePolicy(POLICY_OBJECT_A); |
| 436 EXPECT_TRUE(IsInvalidatorRegistered()); | 438 EXPECT_TRUE(IsInvalidatorRegistered()); |
| 437 FireInvalidation(POLICY_OBJECT_A); | 439 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 438 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 440 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 439 } | 441 } |
| 440 | 442 |
| 441 TEST_F(CloudPolicyInvalidatorTest, RegisterOnStoreLoaded) { | 443 TEST_F(CloudPolicyInvalidatorTest, RegisterOnStoreLoaded) { |
| 442 // No registration when store is not loaded. | 444 // No registration when store is not loaded. |
| 443 StartInvalidator(); | 445 StartInvalidator(); |
| 444 EXPECT_FALSE(IsInvalidatorRegistered()); | 446 EXPECT_FALSE(IsInvalidatorRegistered()); |
| 445 EXPECT_FALSE(InvalidationsEnabled()); | 447 EXPECT_FALSE(InvalidationsEnabled()); |
| 446 FireInvalidation(POLICY_OBJECT_A); | 448 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 447 FireInvalidation(POLICY_OBJECT_B); | 449 FireUnknownVersionInvalidation(POLICY_OBJECT_B); |
| 448 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 450 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 449 | 451 |
| 450 // No registration when store is loaded with no invalidation object id. | 452 // No registration when store is loaded with no invalidation object id. |
| 451 StorePolicy(POLICY_OBJECT_NONE); | 453 StorePolicy(POLICY_OBJECT_NONE); |
| 452 EXPECT_FALSE(IsInvalidatorRegistered()); | 454 EXPECT_FALSE(IsInvalidatorRegistered()); |
| 453 EXPECT_FALSE(InvalidationsEnabled()); | 455 EXPECT_FALSE(InvalidationsEnabled()); |
| 454 FireInvalidation(POLICY_OBJECT_A); | 456 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 455 FireInvalidation(POLICY_OBJECT_B); | 457 FireUnknownVersionInvalidation(POLICY_OBJECT_B); |
| 456 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 458 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 457 | 459 |
| 458 // Check registration when store is loaded for object A. | 460 // Check registration when store is loaded for object A. |
| 459 StorePolicy(POLICY_OBJECT_A); | 461 StorePolicy(POLICY_OBJECT_A); |
| 460 EXPECT_TRUE(IsInvalidatorRegistered()); | 462 EXPECT_TRUE(IsInvalidatorRegistered()); |
| 461 EXPECT_TRUE(InvalidationsEnabled()); | 463 EXPECT_TRUE(InvalidationsEnabled()); |
| 462 FireInvalidation(POLICY_OBJECT_A); | 464 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 463 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 465 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 464 FireInvalidation(POLICY_OBJECT_B); | 466 FireUnknownVersionInvalidation(POLICY_OBJECT_B); |
| 465 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 467 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 466 } | 468 } |
| 467 | 469 |
| 468 TEST_F(CloudPolicyInvalidatorTest, ChangeRegistration) { | 470 TEST_F(CloudPolicyInvalidatorTest, ChangeRegistration) { |
| 469 // Register for object A. | 471 // Register for object A. |
| 470 StartInvalidator(); | 472 StartInvalidator(); |
| 471 StorePolicy(POLICY_OBJECT_A); | 473 StorePolicy(POLICY_OBJECT_A); |
| 472 EXPECT_TRUE(IsInvalidatorRegistered()); | 474 EXPECT_TRUE(IsInvalidatorRegistered()); |
| 473 EXPECT_TRUE(InvalidationsEnabled()); | 475 EXPECT_TRUE(InvalidationsEnabled()); |
| 474 FireInvalidation(POLICY_OBJECT_A); | 476 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 475 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 477 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 476 FireInvalidation(POLICY_OBJECT_B); | 478 FireUnknownVersionInvalidation(POLICY_OBJECT_B); |
| 477 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 479 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 478 syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A); | 480 syncer::AckHandle ack = FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 479 | 481 |
| 480 // Check re-registration for object B. Make sure the pending invalidation for | 482 // Check re-registration for object B. Make sure the pending invalidation for |
| 481 // object A is acknowledged without making the callback. | 483 // object A is acknowledged without making the callback. |
| 482 StorePolicy(POLICY_OBJECT_B); | 484 StorePolicy(POLICY_OBJECT_B); |
| 483 EXPECT_TRUE(IsInvalidatorRegistered()); | 485 EXPECT_TRUE(IsInvalidatorRegistered()); |
| 484 EXPECT_TRUE(InvalidationsEnabled()); | 486 EXPECT_TRUE(InvalidationsEnabled()); |
| 485 EXPECT_TRUE(IsInvalidationAcknowledged(ack)); | 487 EXPECT_TRUE(IsInvalidationAcknowledged(ack)); |
| 486 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 488 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 487 | 489 |
| 488 // Make sure future invalidations for object A are ignored and for object B | 490 // Make sure future invalidations for object A are ignored and for object B |
| 489 // are processed. | 491 // are processed. |
| 490 FireInvalidation(POLICY_OBJECT_A); | 492 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 491 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 493 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 492 FireInvalidation(POLICY_OBJECT_B); | 494 FireUnknownVersionInvalidation(POLICY_OBJECT_B); |
| 493 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 495 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 494 } | 496 } |
| 495 | 497 |
| 496 TEST_F(CloudPolicyInvalidatorTest, UnregisterOnStoreLoaded) { | 498 TEST_F(CloudPolicyInvalidatorTest, UnregisterOnStoreLoaded) { |
| 497 // Register for object A. | 499 // Register for object A. |
| 498 StartInvalidator(); | 500 StartInvalidator(); |
| 499 StorePolicy(POLICY_OBJECT_A); | 501 StorePolicy(POLICY_OBJECT_A); |
| 500 EXPECT_TRUE(IsInvalidatorRegistered()); | 502 EXPECT_TRUE(IsInvalidatorRegistered()); |
| 501 EXPECT_TRUE(InvalidationsEnabled()); | 503 EXPECT_TRUE(InvalidationsEnabled()); |
| 502 FireInvalidation(POLICY_OBJECT_A); | 504 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 503 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 505 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 504 | 506 |
| 505 // Check unregistration when store is loaded with no invalidation object id. | 507 // Check unregistration when store is loaded with no invalidation object id. |
| 506 syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A); | 508 syncer::AckHandle ack = FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 507 EXPECT_FALSE(IsInvalidationAcknowledged(ack)); | 509 EXPECT_FALSE(IsInvalidationAcknowledged(ack)); |
| 508 StorePolicy(POLICY_OBJECT_NONE); | 510 StorePolicy(POLICY_OBJECT_NONE); |
| 509 EXPECT_FALSE(IsInvalidatorRegistered()); | 511 EXPECT_FALSE(IsInvalidatorRegistered()); |
| 510 EXPECT_TRUE(IsInvalidationAcknowledged(ack)); | 512 EXPECT_TRUE(IsInvalidationAcknowledged(ack)); |
| 511 EXPECT_FALSE(InvalidationsEnabled()); | 513 EXPECT_FALSE(InvalidationsEnabled()); |
| 512 FireInvalidation(POLICY_OBJECT_A); | 514 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 513 FireInvalidation(POLICY_OBJECT_B); | 515 FireUnknownVersionInvalidation(POLICY_OBJECT_B); |
| 514 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 516 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 515 | 517 |
| 516 // Check re-registration for object B. | 518 // Check re-registration for object B. |
| 517 StorePolicy(POLICY_OBJECT_B); | 519 StorePolicy(POLICY_OBJECT_B); |
| 518 EXPECT_TRUE(IsInvalidatorRegistered()); | 520 EXPECT_TRUE(IsInvalidatorRegistered()); |
| 519 EXPECT_TRUE(InvalidationsEnabled()); | 521 EXPECT_TRUE(InvalidationsEnabled()); |
| 520 FireInvalidation(POLICY_OBJECT_B); | 522 FireUnknownVersionInvalidation(POLICY_OBJECT_B); |
| 521 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 523 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 522 } | 524 } |
| 523 | 525 |
| 524 TEST_F(CloudPolicyInvalidatorTest, HandleInvalidation) { | 526 TEST_F(CloudPolicyInvalidatorTest, HandleInvalidation) { |
| 525 // Register and fire invalidation | 527 // Register and fire invalidation |
| 526 StorePolicy(POLICY_OBJECT_A); | 528 StorePolicy(POLICY_OBJECT_A); |
| 527 StartInvalidator(); | 529 StartInvalidator(); |
| 528 EXPECT_TRUE(InvalidationsEnabled()); | 530 EXPECT_TRUE(InvalidationsEnabled()); |
| 529 syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A, 12, "test_payload"); | 531 syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A, 12, "test_payload"); |
| 530 | 532 |
| 531 // Make sure client info is set as soon as the invalidation is received. | 533 // Make sure client info is set as soon as the invalidation is received. |
| 532 EXPECT_TRUE(CheckInvalidationInfo(12, "test_payload")); | 534 EXPECT_TRUE(CheckInvalidationInfo(12, "test_payload")); |
| 533 EXPECT_TRUE(CheckPolicyRefreshed()); | 535 EXPECT_TRUE(CheckPolicyRefreshed()); |
| 534 | 536 |
| 535 // Make sure invalidation is not acknowledged until the store is loaded. | 537 // Make sure invalidation is not acknowledged until the store is loaded. |
| 536 EXPECT_FALSE(IsInvalidationAcknowledged(ack)); | 538 EXPECT_FALSE(IsInvalidationAcknowledged(ack)); |
| 537 EXPECT_TRUE(CheckInvalidationInfo(12, "test_payload")); | 539 EXPECT_TRUE(CheckInvalidationInfo(12, "test_payload")); |
| 538 StorePolicy(POLICY_OBJECT_A, 12); | 540 StorePolicy(POLICY_OBJECT_A, 12); |
| 539 EXPECT_TRUE(IsInvalidationAcknowledged(ack)); | 541 EXPECT_TRUE(IsInvalidationAcknowledged(ack)); |
| 540 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); | 542 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
| 541 } | 543 } |
| 542 | 544 |
| 543 TEST_F(CloudPolicyInvalidatorTest, HandleInvalidationWithUnknownVersion) { | 545 TEST_F(CloudPolicyInvalidatorTest, HandleInvalidationWithUnknownVersion) { |
| 544 // Register and fire invalidation with unknown version. | 546 // Register and fire invalidation with unknown version. |
| 545 StorePolicy(POLICY_OBJECT_A); | 547 StorePolicy(POLICY_OBJECT_A); |
| 546 StartInvalidator(); | 548 StartInvalidator(); |
| 547 syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A); | 549 syncer::AckHandle ack = FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 548 | 550 |
| 549 // Make sure client info is not set until after the invalidation callback is | 551 // Make sure client info is not set until after the invalidation callback is |
| 550 // made. | 552 // made. |
| 551 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); | 553 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
| 552 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 554 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 553 EXPECT_TRUE(CheckInvalidationInfo(-1, std::string())); | 555 EXPECT_TRUE(CheckInvalidationInfo(-1, std::string())); |
| 554 | 556 |
| 555 // Make sure invalidation is not acknowledged until the store is loaded. | 557 // Make sure invalidation is not acknowledged until the store is loaded. |
| 556 EXPECT_FALSE(IsInvalidationAcknowledged(ack)); | 558 EXPECT_FALSE(IsInvalidationAcknowledged(ack)); |
| 557 StorePolicy(POLICY_OBJECT_A, -1); | 559 StorePolicy(POLICY_OBJECT_A, -1); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 586 StorePolicy(POLICY_OBJECT_A, 3); | 588 StorePolicy(POLICY_OBJECT_A, 3); |
| 587 EXPECT_TRUE(IsInvalidationAcknowledged(ack3)); | 589 EXPECT_TRUE(IsInvalidationAcknowledged(ack3)); |
| 588 } | 590 } |
| 589 | 591 |
| 590 TEST_F(CloudPolicyInvalidatorTest, | 592 TEST_F(CloudPolicyInvalidatorTest, |
| 591 HandleMultipleInvalidationsWithUnknownVersion) { | 593 HandleMultipleInvalidationsWithUnknownVersion) { |
| 592 // Validate that multiple invalidations with unknown version each generate | 594 // Validate that multiple invalidations with unknown version each generate |
| 593 // unique invalidation version numbers. | 595 // unique invalidation version numbers. |
| 594 StorePolicy(POLICY_OBJECT_A); | 596 StorePolicy(POLICY_OBJECT_A); |
| 595 StartInvalidator(); | 597 StartInvalidator(); |
| 596 syncer::AckHandle ack1 = FireInvalidation(POLICY_OBJECT_A); | 598 syncer::AckHandle ack1 = FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 597 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); | 599 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
| 598 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 600 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 599 EXPECT_TRUE(CheckInvalidationInfo(-1, std::string())); | 601 EXPECT_TRUE(CheckInvalidationInfo(-1, std::string())); |
| 600 syncer::AckHandle ack2 = FireInvalidation(POLICY_OBJECT_A); | 602 syncer::AckHandle ack2 = FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 601 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); | 603 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
| 602 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 604 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 603 EXPECT_TRUE(CheckInvalidationInfo(-2, std::string())); | 605 EXPECT_TRUE(CheckInvalidationInfo(-2, std::string())); |
| 604 syncer::AckHandle ack3 = FireInvalidation(POLICY_OBJECT_A); | 606 syncer::AckHandle ack3 = FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 605 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); | 607 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
| 606 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 608 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 607 EXPECT_TRUE(CheckInvalidationInfo(-3, std::string())); | 609 EXPECT_TRUE(CheckInvalidationInfo(-3, std::string())); |
| 608 | 610 |
| 609 // Make sure the replaced invalidations are acknowledged. | 611 // Make sure the replaced invalidations are acknowledged. |
| 610 EXPECT_TRUE(IsInvalidationAcknowledged(ack1)); | 612 EXPECT_TRUE(IsInvalidationAcknowledged(ack1)); |
| 611 EXPECT_TRUE(IsInvalidationAcknowledged(ack2)); | 613 EXPECT_TRUE(IsInvalidationAcknowledged(ack2)); |
| 612 | 614 |
| 613 // Make sure that the last invalidation is only acknowledged after the store | 615 // Make sure that the last invalidation is only acknowledged after the store |
| 614 // is loaded with the last unknown version. | 616 // is loaded with the last unknown version. |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS)); | 802 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS)); |
| 801 EXPECT_EQ(4, GetCount(METRIC_POLICY_REFRESH_UNCHANGED)); | 803 EXPECT_EQ(4, GetCount(METRIC_POLICY_REFRESH_UNCHANGED)); |
| 802 EXPECT_EQ(2, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED)); | 804 EXPECT_EQ(2, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED)); |
| 803 EXPECT_EQ(1, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED)); | 805 EXPECT_EQ(1, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED)); |
| 804 } | 806 } |
| 805 | 807 |
| 806 TEST_F(CloudPolicyInvalidatorTest, InvalidationMetrics) { | 808 TEST_F(CloudPolicyInvalidatorTest, InvalidationMetrics) { |
| 807 // Generate a mix of versioned and unknown-version invalidations. | 809 // Generate a mix of versioned and unknown-version invalidations. |
| 808 StorePolicy(POLICY_OBJECT_A); | 810 StorePolicy(POLICY_OBJECT_A); |
| 809 StartInvalidator(); | 811 StartInvalidator(); |
| 810 FireInvalidation(POLICY_OBJECT_B); | 812 FireUnknownVersionInvalidation(POLICY_OBJECT_B); |
| 811 FireInvalidation(POLICY_OBJECT_A); | 813 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 812 FireInvalidation(POLICY_OBJECT_B, 1, "test"); | 814 FireInvalidation(POLICY_OBJECT_B, 1, "test"); |
| 813 FireInvalidation(POLICY_OBJECT_A, 1, "test"); | 815 FireInvalidation(POLICY_OBJECT_A, 1, "test"); |
| 814 FireInvalidation(POLICY_OBJECT_A, 2, "test"); | 816 FireInvalidation(POLICY_OBJECT_A, 2, "test"); |
| 815 FireInvalidation(POLICY_OBJECT_A); | 817 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 816 FireInvalidation(POLICY_OBJECT_A); | 818 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 817 FireInvalidation(POLICY_OBJECT_A, 3, "test"); | 819 FireInvalidation(POLICY_OBJECT_A, 3, "test"); |
| 818 FireInvalidation(POLICY_OBJECT_A, 4, "test"); | 820 FireInvalidation(POLICY_OBJECT_A, 4, "test"); |
| 819 | 821 |
| 820 // Verify that received invalidations metrics are correct. | 822 // Verify that received invalidations metrics are correct. |
| 821 EXPECT_EQ(3, GetInvalidationCount(false /* with_payload */)); | 823 EXPECT_EQ(3, GetInvalidationCount(false /* with_payload */)); |
| 822 EXPECT_EQ(4, GetInvalidationCount(true /* with_payload */)); | 824 EXPECT_EQ(4, GetInvalidationCount(true /* with_payload */)); |
| 823 } | 825 } |
| 824 | 826 |
| 825 } // namespace policy | 827 } // namespace policy |
| OLD | NEW |