| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 void StorePolicy(PolicyObject object) { | 100 void StorePolicy(PolicyObject object) { |
| 101 StorePolicy(object, 0); | 101 StorePolicy(object, 0); |
| 102 } | 102 } |
| 103 | 103 |
| 104 // Disables the invalidation service. It is enabled by default. | 104 // Disables the invalidation service. It is enabled by default. |
| 105 void DisableInvalidationService(); | 105 void DisableInvalidationService(); |
| 106 | 106 |
| 107 // Enables the invalidation service. It is enabled by default. | 107 // Enables the invalidation service. It is enabled by default. |
| 108 void EnableInvalidationService(); | 108 void EnableInvalidationService(); |
| 109 | 109 |
| 110 // Causes the invalidation service to fire an invalidation. Returns an ack | 110 // Causes the invalidation service to fire an invalidation. |
| 111 // handle which be used to verify that the invalidation was acknowledged. | 111 syncer::Invalidation FireInvalidation( |
| 112 syncer::AckHandle FireInvalidation( | |
| 113 PolicyObject object, | 112 PolicyObject object, |
| 114 int64 version, | 113 int64 version, |
| 115 const std::string& payload); | 114 const std::string& payload); |
| 116 | 115 |
| 117 // Causes the invalidation service to fire an invalidation with unknown | 116 // Causes the invalidation service to fire an invalidation with unknown |
| 118 // version. Returns an ack handle which be used to verify that the | 117 // version. |
| 119 // invalidation was acknowledged. | 118 syncer::Invalidation FireUnknownVersionInvalidation(PolicyObject object); |
| 120 syncer::AckHandle FireUnknownVersionInvalidation(PolicyObject object); | |
| 121 | 119 |
| 122 // Checks the expected value of the currently set invalidation info. | 120 // Checks the expected value of the currently set invalidation info. |
| 123 bool CheckInvalidationInfo(int64 version, const std::string& payload); | 121 bool CheckInvalidationInfo(int64 version, const std::string& payload); |
| 124 | 122 |
| 125 // Checks that the policy was not refreshed due to an invalidation. | 123 // Checks that the policy was not refreshed due to an invalidation. |
| 126 bool CheckPolicyNotRefreshed(); | 124 bool CheckPolicyNotRefreshed(); |
| 127 | 125 |
| 128 // Checks that the policy was refreshed due to an invalidation within an | 126 // Checks that the policy was refreshed due to an invalidation within an |
| 129 // appropriate timeframe depending on whether the invalidation had unknown | 127 // appropriate timeframe depending on whether the invalidation had unknown |
| 130 // version. | 128 // version. |
| 131 bool CheckPolicyRefreshed(); | 129 bool CheckPolicyRefreshed(); |
| 132 bool CheckPolicyRefreshedWithUnknownVersion(); | 130 bool CheckPolicyRefreshedWithUnknownVersion(); |
| 133 | 131 |
| 132 bool IsUnsent(const syncer::Invalidation& invalidation); |
| 133 |
| 134 // Returns the invalidations enabled state set by the invalidator on the | 134 // Returns the invalidations enabled state set by the invalidator on the |
| 135 // refresh scheduler. | 135 // refresh scheduler. |
| 136 bool InvalidationsEnabled(); | 136 bool InvalidationsEnabled(); |
| 137 | 137 |
| 138 // Determines if the invalidation with the given ack handle has been | 138 // Determines if the invalidation with the given ack handle has been |
| 139 // acknowledged. | 139 // acknowledged. |
| 140 bool IsInvalidationAcknowledged(const syncer::AckHandle& ack_handle); | 140 bool IsInvalidationAcknowledged(const syncer::Invalidation& invalidation); |
| 141 | 141 |
| 142 // Determines if the invalidator has registered for an object with the | 142 // Determines if the invalidator has registered for an object with the |
| 143 // invalidation service. | 143 // invalidation service. |
| 144 bool IsInvalidatorRegistered(); | 144 bool IsInvalidatorRegistered(); |
| 145 | 145 |
| 146 // Get the current count for the given metric. | 146 // Get the current count for the given metric. |
| 147 base::HistogramBase::Count GetCount(MetricPolicyRefresh metric); | 147 base::HistogramBase::Count GetCount(MetricPolicyRefresh metric); |
| 148 base::HistogramBase::Count GetInvalidationCount(bool with_payload); | 148 base::HistogramBase::Count GetInvalidationCount(bool with_payload); |
| 149 | 149 |
| 150 private: | 150 private: |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 policy_value_b_("zxcv"), | 210 policy_value_b_("zxcv"), |
| 211 policy_value_cur_(policy_value_a_) {} | 211 policy_value_cur_(policy_value_a_) {} |
| 212 | 212 |
| 213 void CloudPolicyInvalidatorTest::SetUp() { | 213 void CloudPolicyInvalidatorTest::SetUp() { |
| 214 base::StatisticsRecorder::Initialize(); | 214 base::StatisticsRecorder::Initialize(); |
| 215 refresh_samples_ = GetHistogramSamples(kMetricPolicyRefresh); | 215 refresh_samples_ = GetHistogramSamples(kMetricPolicyRefresh); |
| 216 invalidations_samples_ = GetHistogramSamples(kMetricPolicyInvalidations); | 216 invalidations_samples_ = GetHistogramSamples(kMetricPolicyInvalidations); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void CloudPolicyInvalidatorTest::TearDown() { | 219 void CloudPolicyInvalidatorTest::TearDown() { |
| 220 EXPECT_FALSE(invalidation_service_.ReceivedInvalidAcknowledgement()); | |
| 221 if (invalidator_) | 220 if (invalidator_) |
| 222 invalidator_->Shutdown(); | 221 invalidator_->Shutdown(); |
| 223 core_.Disconnect(); | 222 core_.Disconnect(); |
| 224 } | 223 } |
| 225 | 224 |
| 226 void CloudPolicyInvalidatorTest::StartInvalidator( | 225 void CloudPolicyInvalidatorTest::StartInvalidator( |
| 227 bool initialize, | 226 bool initialize, |
| 228 bool start_refresh_scheduler) { | 227 bool start_refresh_scheduler) { |
| 229 invalidator_.reset(new CloudPolicyInvalidator(&core_, task_runner_)); | 228 invalidator_.reset(new CloudPolicyInvalidator(&core_, task_runner_)); |
| 230 if (start_refresh_scheduler) { | 229 if (start_refresh_scheduler) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 293 |
| 295 void CloudPolicyInvalidatorTest::DisableInvalidationService() { | 294 void CloudPolicyInvalidatorTest::DisableInvalidationService() { |
| 296 invalidation_service_.SetInvalidatorState( | 295 invalidation_service_.SetInvalidatorState( |
| 297 syncer::TRANSIENT_INVALIDATION_ERROR); | 296 syncer::TRANSIENT_INVALIDATION_ERROR); |
| 298 } | 297 } |
| 299 | 298 |
| 300 void CloudPolicyInvalidatorTest::EnableInvalidationService() { | 299 void CloudPolicyInvalidatorTest::EnableInvalidationService() { |
| 301 invalidation_service_.SetInvalidatorState(syncer::INVALIDATIONS_ENABLED); | 300 invalidation_service_.SetInvalidatorState(syncer::INVALIDATIONS_ENABLED); |
| 302 } | 301 } |
| 303 | 302 |
| 304 syncer::AckHandle CloudPolicyInvalidatorTest::FireInvalidation( | 303 syncer::Invalidation CloudPolicyInvalidatorTest::FireInvalidation( |
| 305 PolicyObject object, | 304 PolicyObject object, |
| 306 int64 version, | 305 int64 version, |
| 307 const std::string& payload) { | 306 const std::string& payload) { |
| 308 syncer::Invalidation invalidation = syncer::Invalidation::Init( | 307 syncer::Invalidation invalidation = syncer::Invalidation::Init( |
| 309 GetPolicyObjectId(object), | 308 GetPolicyObjectId(object), |
| 310 version, | 309 version, |
| 311 payload); | 310 payload); |
| 312 invalidation_service_.EmitInvalidationForTest(invalidation); | 311 invalidation_service_.EmitInvalidationForTest(invalidation); |
| 313 return invalidation.ack_handle(); | 312 return invalidation; |
| 314 } | 313 } |
| 315 | 314 |
| 316 syncer::AckHandle CloudPolicyInvalidatorTest::FireUnknownVersionInvalidation( | 315 syncer::Invalidation CloudPolicyInvalidatorTest::FireUnknownVersionInvalidation( |
| 317 PolicyObject object) { | 316 PolicyObject object) { |
| 318 syncer::Invalidation invalidation = | 317 syncer::Invalidation invalidation = syncer::Invalidation::InitUnknownVersion( |
| 319 syncer::Invalidation::InitUnknownVersion(GetPolicyObjectId(object)); | 318 GetPolicyObjectId(object)); |
| 320 invalidation_service_.EmitInvalidationForTest(invalidation); | 319 invalidation_service_.EmitInvalidationForTest(invalidation); |
| 321 return invalidation.ack_handle(); | 320 return invalidation; |
| 322 } | 321 } |
| 323 | 322 |
| 324 bool CloudPolicyInvalidatorTest::CheckInvalidationInfo( | 323 bool CloudPolicyInvalidatorTest::CheckInvalidationInfo( |
| 325 int64 version, | 324 int64 version, |
| 326 const std::string& payload) { | 325 const std::string& payload) { |
| 327 MockCloudPolicyClient* client = | 326 MockCloudPolicyClient* client = |
| 328 static_cast<MockCloudPolicyClient*>(core_.client()); | 327 static_cast<MockCloudPolicyClient*>(core_.client()); |
| 329 return version == client->invalidation_version_ && | 328 return version == client->invalidation_version_ && |
| 330 payload == client->invalidation_payload_; | 329 payload == client->invalidation_payload_; |
| 331 } | 330 } |
| 332 | 331 |
| 333 bool CloudPolicyInvalidatorTest::CheckPolicyNotRefreshed() { | 332 bool CloudPolicyInvalidatorTest::CheckPolicyNotRefreshed() { |
| 334 return CheckPolicyRefreshCount(0); | 333 return CheckPolicyRefreshCount(0); |
| 335 } | 334 } |
| 336 | 335 |
| 337 bool CloudPolicyInvalidatorTest::CheckPolicyRefreshed() { | 336 bool CloudPolicyInvalidatorTest::CheckPolicyRefreshed() { |
| 338 return CheckPolicyRefreshed(base::TimeDelta()); | 337 return CheckPolicyRefreshed(base::TimeDelta()); |
| 339 } | 338 } |
| 340 | 339 |
| 340 bool CloudPolicyInvalidatorTest::IsUnsent( |
| 341 const syncer::Invalidation& invalidation) { |
| 342 return invalidation_service_.GetMockAckHandler()->IsUnsent(invalidation); |
| 343 } |
| 344 |
| 341 bool CloudPolicyInvalidatorTest::CheckPolicyRefreshedWithUnknownVersion() { | 345 bool CloudPolicyInvalidatorTest::CheckPolicyRefreshedWithUnknownVersion() { |
| 342 return CheckPolicyRefreshed(base::TimeDelta::FromMinutes( | 346 return CheckPolicyRefreshed(base::TimeDelta::FromMinutes( |
| 343 CloudPolicyInvalidator::kMissingPayloadDelay)); | 347 CloudPolicyInvalidator::kMissingPayloadDelay)); |
| 344 } | 348 } |
| 345 | 349 |
| 346 bool CloudPolicyInvalidatorTest::InvalidationsEnabled() { | 350 bool CloudPolicyInvalidatorTest::InvalidationsEnabled() { |
| 347 return core_.refresh_scheduler()->invalidations_available(); | 351 return core_.refresh_scheduler()->invalidations_available(); |
| 348 } | 352 } |
| 349 | 353 |
| 350 bool CloudPolicyInvalidatorTest::IsInvalidationAcknowledged( | 354 bool CloudPolicyInvalidatorTest::IsInvalidationAcknowledged( |
| 351 const syncer::AckHandle& ack_handle) { | 355 const syncer::Invalidation& invalidation) { |
| 352 return invalidation_service_.IsInvalidationAcknowledged(ack_handle); | 356 // The acknowledgement task is run through a WeakHandle that posts back to our |
| 357 // own thread. We need to run any posted tasks before we can check |
| 358 // acknowledgement status. |
| 359 loop_.RunUntilIdle(); |
| 360 |
| 361 EXPECT_FALSE(IsUnsent(invalidation)); |
| 362 return !invalidation_service_.GetMockAckHandler()->IsUnacked(invalidation); |
| 353 } | 363 } |
| 354 | 364 |
| 355 bool CloudPolicyInvalidatorTest::IsInvalidatorRegistered() { | 365 bool CloudPolicyInvalidatorTest::IsInvalidatorRegistered() { |
| 356 return !invalidation_service_.invalidator_registrar() | 366 return !invalidation_service_.invalidator_registrar() |
| 357 .GetRegisteredIds(invalidator_.get()).empty(); | 367 .GetRegisteredIds(invalidator_.get()).empty(); |
| 358 } | 368 } |
| 359 | 369 |
| 360 base::HistogramBase::Count CloudPolicyInvalidatorTest::GetCount( | 370 base::HistogramBase::Count CloudPolicyInvalidatorTest::GetCount( |
| 361 MetricPolicyRefresh metric) { | 371 MetricPolicyRefresh metric) { |
| 362 return GetHistogramSamples(kMetricPolicyRefresh)->GetCount(metric) - | 372 return GetHistogramSamples(kMetricPolicyRefresh)->GetCount(metric) - |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 if (!histogram) | 425 if (!histogram) |
| 416 return scoped_ptr<base::HistogramSamples>(new base::SampleMap()); | 426 return scoped_ptr<base::HistogramSamples>(new base::SampleMap()); |
| 417 return histogram->SnapshotSamples(); | 427 return histogram->SnapshotSamples(); |
| 418 } | 428 } |
| 419 | 429 |
| 420 TEST_F(CloudPolicyInvalidatorTest, Uninitialized) { | 430 TEST_F(CloudPolicyInvalidatorTest, Uninitialized) { |
| 421 // No invalidations should be processed if the invalidator is not initialized. | 431 // No invalidations should be processed if the invalidator is not initialized. |
| 422 StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */); | 432 StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */); |
| 423 StorePolicy(POLICY_OBJECT_A); | 433 StorePolicy(POLICY_OBJECT_A); |
| 424 EXPECT_FALSE(IsInvalidatorRegistered()); | 434 EXPECT_FALSE(IsInvalidatorRegistered()); |
| 425 FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 435 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A))); |
| 426 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 436 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 427 } | 437 } |
| 428 | 438 |
| 429 TEST_F(CloudPolicyInvalidatorTest, RefreshSchedulerNotStarted) { | 439 TEST_F(CloudPolicyInvalidatorTest, RefreshSchedulerNotStarted) { |
| 430 // No invalidations should be processed if the refresh scheduler is not | 440 // No invalidations should be processed if the refresh scheduler is not |
| 431 // started. | 441 // started. |
| 432 StartInvalidator(true /* initialize */, false /* start_refresh_scheduler */); | 442 StartInvalidator(true /* initialize */, false /* start_refresh_scheduler */); |
| 433 StorePolicy(POLICY_OBJECT_A); | 443 StorePolicy(POLICY_OBJECT_A); |
| 434 EXPECT_FALSE(IsInvalidatorRegistered()); | 444 EXPECT_FALSE(IsInvalidatorRegistered()); |
| 435 FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 445 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A))); |
| 436 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 446 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 437 } | 447 } |
| 438 | 448 |
| 439 TEST_F(CloudPolicyInvalidatorTest, DisconnectCoreThenInitialize) { | 449 TEST_F(CloudPolicyInvalidatorTest, DisconnectCoreThenInitialize) { |
| 440 // No invalidations should be processed if the core is disconnected before | 450 // No invalidations should be processed if the core is disconnected before |
| 441 // initialization. | 451 // initialization. |
| 442 StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */); | 452 StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */); |
| 443 DisconnectCore(); | 453 DisconnectCore(); |
| 444 InitializeInvalidator(); | 454 InitializeInvalidator(); |
| 445 StorePolicy(POLICY_OBJECT_A); | 455 StorePolicy(POLICY_OBJECT_A); |
| 446 EXPECT_FALSE(IsInvalidatorRegistered()); | 456 EXPECT_FALSE(IsInvalidatorRegistered()); |
| 447 FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 457 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A))); |
| 448 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 458 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 449 } | 459 } |
| 450 | 460 |
| 451 TEST_F(CloudPolicyInvalidatorTest, InitializeThenStartRefreshScheduler) { | 461 TEST_F(CloudPolicyInvalidatorTest, InitializeThenStartRefreshScheduler) { |
| 452 // Make sure registration occurs and invalidations are processed when | 462 // Make sure registration occurs and invalidations are processed when |
| 453 // Initialize is called before starting the refresh scheduler. | 463 // Initialize is called before starting the refresh scheduler. |
| 454 // Note that the reverse case (start refresh scheduler then initialize) is | 464 // Note that the reverse case (start refresh scheduler then initialize) is |
| 455 // the default behavior for the test fixture, so will be tested in most other | 465 // the default behavior for the test fixture, so will be tested in most other |
| 456 // tests. | 466 // tests. |
| 457 StartInvalidator(true /* initialize */, false /* start_refresh_scheduler */); | 467 StartInvalidator(true /* initialize */, false /* start_refresh_scheduler */); |
| 458 ConnectCore(); | 468 ConnectCore(); |
| 459 StartRefreshScheduler(); | 469 StartRefreshScheduler(); |
| 460 StorePolicy(POLICY_OBJECT_A); | 470 StorePolicy(POLICY_OBJECT_A); |
| 461 EXPECT_TRUE(IsInvalidatorRegistered()); | 471 EXPECT_TRUE(IsInvalidatorRegistered()); |
| 462 FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 472 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 463 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 473 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 464 } | 474 } |
| 465 | 475 |
| 466 TEST_F(CloudPolicyInvalidatorTest, RegisterOnStoreLoaded) { | 476 TEST_F(CloudPolicyInvalidatorTest, RegisterOnStoreLoaded) { |
| 467 // No registration when store is not loaded. | 477 // No registration when store is not loaded. |
| 468 StartInvalidator(); | 478 StartInvalidator(); |
| 469 EXPECT_FALSE(IsInvalidatorRegistered()); | 479 EXPECT_FALSE(IsInvalidatorRegistered()); |
| 470 EXPECT_FALSE(InvalidationsEnabled()); | 480 EXPECT_FALSE(InvalidationsEnabled()); |
| 471 FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 481 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A))); |
| 472 FireUnknownVersionInvalidation(POLICY_OBJECT_B); | 482 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_B))); |
| 473 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 483 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 474 | 484 |
| 475 // No registration when store is loaded with no invalidation object id. | 485 // No registration when store is loaded with no invalidation object id. |
| 476 StorePolicy(POLICY_OBJECT_NONE); | 486 StorePolicy(POLICY_OBJECT_NONE); |
| 477 EXPECT_FALSE(IsInvalidatorRegistered()); | 487 EXPECT_FALSE(IsInvalidatorRegistered()); |
| 478 EXPECT_FALSE(InvalidationsEnabled()); | 488 EXPECT_FALSE(InvalidationsEnabled()); |
| 479 FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 489 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A))); |
| 480 FireUnknownVersionInvalidation(POLICY_OBJECT_B); | 490 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_B))); |
| 481 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 491 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 482 | 492 |
| 483 // Check registration when store is loaded for object A. | 493 // Check registration when store is loaded for object A. |
| 484 StorePolicy(POLICY_OBJECT_A); | 494 StorePolicy(POLICY_OBJECT_A); |
| 485 EXPECT_TRUE(IsInvalidatorRegistered()); | 495 EXPECT_TRUE(IsInvalidatorRegistered()); |
| 486 EXPECT_TRUE(InvalidationsEnabled()); | 496 EXPECT_TRUE(InvalidationsEnabled()); |
| 487 FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 497 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 488 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 498 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 489 FireUnknownVersionInvalidation(POLICY_OBJECT_B); | 499 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_B))); |
| 490 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 500 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 491 } | 501 } |
| 492 | 502 |
| 493 TEST_F(CloudPolicyInvalidatorTest, ChangeRegistration) { | 503 TEST_F(CloudPolicyInvalidatorTest, ChangeRegistration) { |
| 494 // Register for object A. | 504 // Register for object A. |
| 495 StartInvalidator(); | 505 StartInvalidator(); |
| 496 StorePolicy(POLICY_OBJECT_A); | 506 StorePolicy(POLICY_OBJECT_A); |
| 497 EXPECT_TRUE(IsInvalidatorRegistered()); | 507 EXPECT_TRUE(IsInvalidatorRegistered()); |
| 498 EXPECT_TRUE(InvalidationsEnabled()); | 508 EXPECT_TRUE(InvalidationsEnabled()); |
| 499 FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 509 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 500 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 510 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 501 FireUnknownVersionInvalidation(POLICY_OBJECT_B); | 511 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_B))); |
| 502 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 512 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 503 syncer::AckHandle ack = FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 513 syncer::Invalidation inv = FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 504 | 514 |
| 505 // Check re-registration for object B. Make sure the pending invalidation for | 515 // Check re-registration for object B. Make sure the pending invalidation for |
| 506 // object A is acknowledged without making the callback. | 516 // object A is acknowledged without making the callback. |
| 507 StorePolicy(POLICY_OBJECT_B); | 517 StorePolicy(POLICY_OBJECT_B); |
| 508 EXPECT_TRUE(IsInvalidatorRegistered()); | 518 EXPECT_TRUE(IsInvalidatorRegistered()); |
| 509 EXPECT_TRUE(InvalidationsEnabled()); | 519 EXPECT_TRUE(InvalidationsEnabled()); |
| 510 EXPECT_TRUE(IsInvalidationAcknowledged(ack)); | 520 EXPECT_TRUE(IsInvalidationAcknowledged(inv)); |
| 511 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 521 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 512 | 522 |
| 513 // Make sure future invalidations for object A are ignored and for object B | 523 // Make sure future invalidations for object A are ignored and for object B |
| 514 // are processed. | 524 // are processed. |
| 515 FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 525 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A))); |
| 516 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 526 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 517 FireUnknownVersionInvalidation(POLICY_OBJECT_B); | 527 FireUnknownVersionInvalidation(POLICY_OBJECT_B); |
| 518 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 528 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 519 } | 529 } |
| 520 | 530 |
| 521 TEST_F(CloudPolicyInvalidatorTest, UnregisterOnStoreLoaded) { | 531 TEST_F(CloudPolicyInvalidatorTest, UnregisterOnStoreLoaded) { |
| 522 // Register for object A. | 532 // Register for object A. |
| 523 StartInvalidator(); | 533 StartInvalidator(); |
| 524 StorePolicy(POLICY_OBJECT_A); | 534 StorePolicy(POLICY_OBJECT_A); |
| 525 EXPECT_TRUE(IsInvalidatorRegistered()); | 535 EXPECT_TRUE(IsInvalidatorRegistered()); |
| 526 EXPECT_TRUE(InvalidationsEnabled()); | 536 EXPECT_TRUE(InvalidationsEnabled()); |
| 527 FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 537 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 528 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 538 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 529 | 539 |
| 530 // Check unregistration when store is loaded with no invalidation object id. | 540 // Check unregistration when store is loaded with no invalidation object id. |
| 531 syncer::AckHandle ack = FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 541 syncer::Invalidation inv = FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 532 EXPECT_FALSE(IsInvalidationAcknowledged(ack)); | 542 EXPECT_FALSE(IsInvalidationAcknowledged(inv)); |
| 533 StorePolicy(POLICY_OBJECT_NONE); | 543 StorePolicy(POLICY_OBJECT_NONE); |
| 534 EXPECT_FALSE(IsInvalidatorRegistered()); | 544 EXPECT_FALSE(IsInvalidatorRegistered()); |
| 535 EXPECT_TRUE(IsInvalidationAcknowledged(ack)); | 545 EXPECT_TRUE(IsInvalidationAcknowledged(inv)); |
| 536 EXPECT_FALSE(InvalidationsEnabled()); | 546 EXPECT_FALSE(InvalidationsEnabled()); |
| 537 FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 547 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A))); |
| 538 FireUnknownVersionInvalidation(POLICY_OBJECT_B); | 548 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_B))); |
| 539 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 549 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 540 | 550 |
| 541 // Check re-registration for object B. | 551 // Check re-registration for object B. |
| 542 StorePolicy(POLICY_OBJECT_B); | 552 StorePolicy(POLICY_OBJECT_B); |
| 543 EXPECT_TRUE(IsInvalidatorRegistered()); | 553 EXPECT_TRUE(IsInvalidatorRegistered()); |
| 544 EXPECT_TRUE(InvalidationsEnabled()); | 554 EXPECT_TRUE(InvalidationsEnabled()); |
| 545 FireUnknownVersionInvalidation(POLICY_OBJECT_B); | 555 FireUnknownVersionInvalidation(POLICY_OBJECT_B); |
| 546 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 556 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 547 } | 557 } |
| 548 | 558 |
| 549 TEST_F(CloudPolicyInvalidatorTest, HandleInvalidation) { | 559 TEST_F(CloudPolicyInvalidatorTest, HandleInvalidation) { |
| 550 // Register and fire invalidation | 560 // Register and fire invalidation |
| 551 StorePolicy(POLICY_OBJECT_A); | 561 StorePolicy(POLICY_OBJECT_A); |
| 552 StartInvalidator(); | 562 StartInvalidator(); |
| 553 EXPECT_TRUE(InvalidationsEnabled()); | 563 EXPECT_TRUE(InvalidationsEnabled()); |
| 554 syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A, 12, "test_payload"); | 564 syncer::Invalidation inv = |
| 565 FireInvalidation(POLICY_OBJECT_A, 12, "test_payload"); |
| 555 | 566 |
| 556 // Make sure client info is set as soon as the invalidation is received. | 567 // Make sure client info is set as soon as the invalidation is received. |
| 557 EXPECT_TRUE(CheckInvalidationInfo(12, "test_payload")); | 568 EXPECT_TRUE(CheckInvalidationInfo(12, "test_payload")); |
| 558 EXPECT_TRUE(CheckPolicyRefreshed()); | 569 EXPECT_TRUE(CheckPolicyRefreshed()); |
| 559 | 570 |
| 560 // Make sure invalidation is not acknowledged until the store is loaded. | 571 // Make sure invalidation is not acknowledged until the store is loaded. |
| 561 EXPECT_FALSE(IsInvalidationAcknowledged(ack)); | 572 EXPECT_FALSE(IsInvalidationAcknowledged(inv)); |
| 562 EXPECT_TRUE(CheckInvalidationInfo(12, "test_payload")); | 573 EXPECT_TRUE(CheckInvalidationInfo(12, "test_payload")); |
| 563 StorePolicy(POLICY_OBJECT_A, 12); | 574 StorePolicy(POLICY_OBJECT_A, 12); |
| 564 EXPECT_TRUE(IsInvalidationAcknowledged(ack)); | 575 EXPECT_TRUE(IsInvalidationAcknowledged(inv)); |
| 565 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); | 576 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
| 566 } | 577 } |
| 567 | 578 |
| 568 TEST_F(CloudPolicyInvalidatorTest, HandleInvalidationWithUnknownVersion) { | 579 TEST_F(CloudPolicyInvalidatorTest, HandleInvalidationWithUnknownVersion) { |
| 569 // Register and fire invalidation with unknown version. | 580 // Register and fire invalidation with unknown version. |
| 570 StorePolicy(POLICY_OBJECT_A); | 581 StorePolicy(POLICY_OBJECT_A); |
| 571 StartInvalidator(); | 582 StartInvalidator(); |
| 572 syncer::AckHandle ack = FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 583 syncer::Invalidation inv = FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 573 | 584 |
| 574 // Make sure client info is not set until after the invalidation callback is | 585 // Make sure client info is not set until after the invalidation callback is |
| 575 // made. | 586 // made. |
| 576 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); | 587 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
| 577 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 588 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 578 EXPECT_TRUE(CheckInvalidationInfo(-1, std::string())); | 589 EXPECT_TRUE(CheckInvalidationInfo(-1, std::string())); |
| 579 | 590 |
| 580 // Make sure invalidation is not acknowledged until the store is loaded. | 591 // Make sure invalidation is not acknowledged until the store is loaded. |
| 581 EXPECT_FALSE(IsInvalidationAcknowledged(ack)); | 592 EXPECT_FALSE(IsInvalidationAcknowledged(inv)); |
| 582 StorePolicy(POLICY_OBJECT_A, -1); | 593 StorePolicy(POLICY_OBJECT_A, -1); |
| 583 EXPECT_TRUE(IsInvalidationAcknowledged(ack)); | 594 EXPECT_TRUE(IsInvalidationAcknowledged(inv)); |
| 584 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); | 595 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
| 585 } | 596 } |
| 586 | 597 |
| 587 TEST_F(CloudPolicyInvalidatorTest, HandleMultipleInvalidations) { | 598 TEST_F(CloudPolicyInvalidatorTest, HandleMultipleInvalidations) { |
| 588 // Generate multiple invalidations. | 599 // Generate multiple invalidations. |
| 589 StorePolicy(POLICY_OBJECT_A); | 600 StorePolicy(POLICY_OBJECT_A); |
| 590 StartInvalidator(); | 601 StartInvalidator(); |
| 591 syncer::AckHandle ack1 = FireInvalidation(POLICY_OBJECT_A, 1, "test1"); | 602 syncer::Invalidation inv1 = FireInvalidation(POLICY_OBJECT_A, 1, "test1"); |
| 592 EXPECT_TRUE(CheckInvalidationInfo(1, "test1")); | 603 EXPECT_TRUE(CheckInvalidationInfo(1, "test1")); |
| 593 syncer::AckHandle ack2 = FireInvalidation(POLICY_OBJECT_A, 2, "test2"); | 604 syncer::Invalidation inv2 = FireInvalidation(POLICY_OBJECT_A, 2, "test2"); |
| 594 EXPECT_TRUE(CheckInvalidationInfo(2, "test2")); | 605 EXPECT_TRUE(CheckInvalidationInfo(2, "test2")); |
| 595 syncer::AckHandle ack3= FireInvalidation(POLICY_OBJECT_A, 3, "test3"); | 606 syncer::Invalidation inv3 = FireInvalidation(POLICY_OBJECT_A, 3, "test3"); |
| 596 EXPECT_TRUE(CheckInvalidationInfo(3, "test3")); | 607 EXPECT_TRUE(CheckInvalidationInfo(3, "test3")); |
| 597 | 608 |
| 598 // Make sure the replaced invalidations are acknowledged. | 609 // Make sure the replaced invalidations are acknowledged. |
| 599 EXPECT_TRUE(IsInvalidationAcknowledged(ack1)); | 610 EXPECT_TRUE(IsInvalidationAcknowledged(inv1)); |
| 600 EXPECT_TRUE(IsInvalidationAcknowledged(ack2)); | 611 EXPECT_TRUE(IsInvalidationAcknowledged(inv2)); |
| 601 | 612 |
| 602 // Make sure the policy is refreshed once. | 613 // Make sure the policy is refreshed once. |
| 603 EXPECT_TRUE(CheckPolicyRefreshed()); | 614 EXPECT_TRUE(CheckPolicyRefreshed()); |
| 604 | 615 |
| 605 // Make sure that the last invalidation is only acknowledged after the store | 616 // Make sure that the last invalidation is only acknowledged after the store |
| 606 // is loaded with the latest version. | 617 // is loaded with the latest version. |
| 607 StorePolicy(POLICY_OBJECT_A, 1); | 618 StorePolicy(POLICY_OBJECT_A, 1); |
| 608 EXPECT_FALSE(IsInvalidationAcknowledged(ack3)); | 619 EXPECT_FALSE(IsInvalidationAcknowledged(inv3)); |
| 609 StorePolicy(POLICY_OBJECT_A, 2); | 620 StorePolicy(POLICY_OBJECT_A, 2); |
| 610 EXPECT_FALSE(IsInvalidationAcknowledged(ack3)); | 621 EXPECT_FALSE(IsInvalidationAcknowledged(inv3)); |
| 611 StorePolicy(POLICY_OBJECT_A, 3); | 622 StorePolicy(POLICY_OBJECT_A, 3); |
| 612 EXPECT_TRUE(IsInvalidationAcknowledged(ack3)); | 623 EXPECT_TRUE(IsInvalidationAcknowledged(inv3)); |
| 613 } | 624 } |
| 614 | 625 |
| 615 TEST_F(CloudPolicyInvalidatorTest, | 626 TEST_F(CloudPolicyInvalidatorTest, |
| 616 HandleMultipleInvalidationsWithUnknownVersion) { | 627 HandleMultipleInvalidationsWithUnknownVersion) { |
| 617 // Validate that multiple invalidations with unknown version each generate | 628 // Validate that multiple invalidations with unknown version each generate |
| 618 // unique invalidation version numbers. | 629 // unique invalidation version numbers. |
| 619 StorePolicy(POLICY_OBJECT_A); | 630 StorePolicy(POLICY_OBJECT_A); |
| 620 StartInvalidator(); | 631 StartInvalidator(); |
| 621 syncer::AckHandle ack1 = FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 632 syncer::Invalidation inv1 = FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 622 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); | 633 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
| 623 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 634 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 624 EXPECT_TRUE(CheckInvalidationInfo(-1, std::string())); | 635 EXPECT_TRUE(CheckInvalidationInfo(-1, std::string())); |
| 625 syncer::AckHandle ack2 = FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 636 syncer::Invalidation inv2 = FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 626 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); | 637 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
| 627 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 638 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 628 EXPECT_TRUE(CheckInvalidationInfo(-2, std::string())); | 639 EXPECT_TRUE(CheckInvalidationInfo(-2, std::string())); |
| 629 syncer::AckHandle ack3 = FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 640 syncer::Invalidation inv3 = FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 630 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); | 641 EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
| 631 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 642 EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 632 EXPECT_TRUE(CheckInvalidationInfo(-3, std::string())); | 643 EXPECT_TRUE(CheckInvalidationInfo(-3, std::string())); |
| 633 | 644 |
| 634 // Make sure the replaced invalidations are acknowledged. | 645 // Make sure the replaced invalidations are acknowledged. |
| 635 EXPECT_TRUE(IsInvalidationAcknowledged(ack1)); | 646 EXPECT_TRUE(IsInvalidationAcknowledged(inv1)); |
| 636 EXPECT_TRUE(IsInvalidationAcknowledged(ack2)); | 647 EXPECT_TRUE(IsInvalidationAcknowledged(inv2)); |
| 637 | 648 |
| 638 // Make sure that the last invalidation is only acknowledged after the store | 649 // Make sure that the last invalidation is only acknowledged after the store |
| 639 // is loaded with the last unknown version. | 650 // is loaded with the last unknown version. |
| 640 StorePolicy(POLICY_OBJECT_A, -1); | 651 StorePolicy(POLICY_OBJECT_A, -1); |
| 641 EXPECT_FALSE(IsInvalidationAcknowledged(ack3)); | 652 EXPECT_FALSE(IsInvalidationAcknowledged(inv3)); |
| 642 StorePolicy(POLICY_OBJECT_A, -2); | 653 StorePolicy(POLICY_OBJECT_A, -2); |
| 643 EXPECT_FALSE(IsInvalidationAcknowledged(ack3)); | 654 EXPECT_FALSE(IsInvalidationAcknowledged(inv3)); |
| 644 StorePolicy(POLICY_OBJECT_A, -3); | 655 StorePolicy(POLICY_OBJECT_A, -3); |
| 645 EXPECT_TRUE(IsInvalidationAcknowledged(ack3)); | 656 EXPECT_TRUE(IsInvalidationAcknowledged(inv3)); |
| 646 } | 657 } |
| 647 | 658 |
| 648 TEST_F(CloudPolicyInvalidatorTest, AcknowledgeBeforeRefresh) { | 659 TEST_F(CloudPolicyInvalidatorTest, AcknowledgeBeforeRefresh) { |
| 649 // Generate an invalidation. | 660 // Generate an invalidation. |
| 650 StorePolicy(POLICY_OBJECT_A); | 661 StorePolicy(POLICY_OBJECT_A); |
| 651 StartInvalidator(); | 662 StartInvalidator(); |
| 652 syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A, 3, "test"); | 663 syncer::Invalidation inv = FireInvalidation(POLICY_OBJECT_A, 3, "test"); |
| 653 | 664 |
| 654 // Ensure that the policy is not refreshed and the invalidation is | 665 // Ensure that the policy is not refreshed and the invalidation is |
| 655 // acknowledged if the store is loaded with the latest version before the | 666 // acknowledged if the store is loaded with the latest version before the |
| 656 // refresh can occur. | 667 // refresh can occur. |
| 657 StorePolicy(POLICY_OBJECT_A, 3); | 668 StorePolicy(POLICY_OBJECT_A, 3); |
| 658 EXPECT_TRUE(IsInvalidationAcknowledged(ack)); | 669 EXPECT_TRUE(IsInvalidationAcknowledged(inv)); |
| 659 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 670 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 660 } | 671 } |
| 661 | 672 |
| 662 TEST_F(CloudPolicyInvalidatorTest, NoCallbackAfterShutdown) { | 673 TEST_F(CloudPolicyInvalidatorTest, NoCallbackAfterShutdown) { |
| 663 // Generate an invalidation. | 674 // Generate an invalidation. |
| 664 StorePolicy(POLICY_OBJECT_A); | 675 StorePolicy(POLICY_OBJECT_A); |
| 665 StartInvalidator(); | 676 StartInvalidator(); |
| 666 syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A, 3, "test"); | 677 syncer::Invalidation inv = FireInvalidation(POLICY_OBJECT_A, 3, "test"); |
| 667 | 678 |
| 668 // Ensure that the policy refresh is not made after the invalidator is shut | 679 // Ensure that the policy refresh is not made after the invalidator is shut |
| 669 // down. | 680 // down. |
| 670 ShutdownInvalidator(); | 681 ShutdownInvalidator(); |
| 671 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 682 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 672 DestroyInvalidator(); | 683 DestroyInvalidator(); |
| 673 } | 684 } |
| 674 | 685 |
| 675 TEST_F(CloudPolicyInvalidatorTest, StateChanged) { | 686 TEST_F(CloudPolicyInvalidatorTest, StateChanged) { |
| 676 // Test invalidation service state changes while not registered. | 687 // Test invalidation service state changes while not registered. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 706 EXPECT_FALSE(InvalidationsEnabled()); | 717 EXPECT_FALSE(InvalidationsEnabled()); |
| 707 StorePolicy(POLICY_OBJECT_NONE); | 718 StorePolicy(POLICY_OBJECT_NONE); |
| 708 StorePolicy(POLICY_OBJECT_A); | 719 StorePolicy(POLICY_OBJECT_A); |
| 709 EXPECT_FALSE(InvalidationsEnabled()); | 720 EXPECT_FALSE(InvalidationsEnabled()); |
| 710 } | 721 } |
| 711 | 722 |
| 712 TEST_F(CloudPolicyInvalidatorTest, Disconnect) { | 723 TEST_F(CloudPolicyInvalidatorTest, Disconnect) { |
| 713 // Generate an invalidation. | 724 // Generate an invalidation. |
| 714 StorePolicy(POLICY_OBJECT_A); | 725 StorePolicy(POLICY_OBJECT_A); |
| 715 StartInvalidator(); | 726 StartInvalidator(); |
| 716 syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A, 1, "test"); | 727 syncer::Invalidation inv = FireInvalidation(POLICY_OBJECT_A, 1, "test"); |
| 717 EXPECT_TRUE(InvalidationsEnabled()); | 728 EXPECT_TRUE(InvalidationsEnabled()); |
| 718 | 729 |
| 719 // Ensure that the policy is not refreshed after disconnecting the core, but | 730 // Ensure that the policy is not refreshed after disconnecting the core, but |
| 720 // a call to indicate that invalidations are disabled is made. | 731 // a call to indicate that invalidations are disabled is made. |
| 721 DisconnectCore(); | 732 DisconnectCore(); |
| 722 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 733 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 723 | 734 |
| 724 // Ensure that invalidation service events do not cause refreshes while the | 735 // Ensure that invalidation service events do not cause refreshes while the |
| 725 // invalidator is stopped. | 736 // invalidator is stopped. |
| 726 FireInvalidation(POLICY_OBJECT_A, 2, "test"); | 737 EXPECT_TRUE(IsUnsent(FireInvalidation(POLICY_OBJECT_A, 2, "test"))); |
| 727 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 738 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 728 DisableInvalidationService(); | 739 DisableInvalidationService(); |
| 729 EnableInvalidationService(); | 740 EnableInvalidationService(); |
| 730 | 741 |
| 731 // Connect and disconnect without starting the refresh scheduler. | 742 // Connect and disconnect without starting the refresh scheduler. |
| 732 ConnectCore(); | 743 ConnectCore(); |
| 733 FireInvalidation(POLICY_OBJECT_A, 3, "test"); | 744 EXPECT_TRUE(IsUnsent(FireInvalidation(POLICY_OBJECT_A, 3, "test"))); |
| 734 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 745 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 735 DisconnectCore(); | 746 DisconnectCore(); |
| 736 FireInvalidation(POLICY_OBJECT_A, 4, "test"); | 747 EXPECT_TRUE(IsUnsent(FireInvalidation(POLICY_OBJECT_A, 4, "test"))); |
| 737 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 748 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 738 | 749 |
| 739 // Ensure that the invalidator returns to normal after reconnecting. | 750 // Ensure that the invalidator returns to normal after reconnecting. |
| 740 ConnectCore(); | 751 ConnectCore(); |
| 741 StartRefreshScheduler(); | 752 StartRefreshScheduler(); |
| 742 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 753 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 743 EXPECT_TRUE(InvalidationsEnabled()); | 754 EXPECT_TRUE(InvalidationsEnabled()); |
| 744 FireInvalidation(POLICY_OBJECT_A, 5, "test"); | 755 FireInvalidation(POLICY_OBJECT_A, 5, "test"); |
| 745 EXPECT_TRUE(CheckInvalidationInfo(5, "test")); | 756 EXPECT_TRUE(CheckInvalidationInfo(5, "test")); |
| 746 EXPECT_TRUE(CheckPolicyRefreshed()); | 757 EXPECT_TRUE(CheckPolicyRefreshed()); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS)); | 836 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS)); |
| 826 EXPECT_EQ(4, GetCount(METRIC_POLICY_REFRESH_UNCHANGED)); | 837 EXPECT_EQ(4, GetCount(METRIC_POLICY_REFRESH_UNCHANGED)); |
| 827 EXPECT_EQ(2, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED)); | 838 EXPECT_EQ(2, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED)); |
| 828 EXPECT_EQ(1, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED)); | 839 EXPECT_EQ(1, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED)); |
| 829 } | 840 } |
| 830 | 841 |
| 831 TEST_F(CloudPolicyInvalidatorTest, InvalidationMetrics) { | 842 TEST_F(CloudPolicyInvalidatorTest, InvalidationMetrics) { |
| 832 // Generate a mix of versioned and unknown-version invalidations. | 843 // Generate a mix of versioned and unknown-version invalidations. |
| 833 StorePolicy(POLICY_OBJECT_A); | 844 StorePolicy(POLICY_OBJECT_A); |
| 834 StartInvalidator(); | 845 StartInvalidator(); |
| 835 FireUnknownVersionInvalidation(POLICY_OBJECT_B); | 846 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_B))); |
| 836 FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 847 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 837 FireInvalidation(POLICY_OBJECT_B, 1, "test"); | 848 EXPECT_TRUE(IsUnsent(FireInvalidation(POLICY_OBJECT_B, 1, "test"))); |
| 838 FireInvalidation(POLICY_OBJECT_A, 1, "test"); | 849 FireInvalidation(POLICY_OBJECT_A, 1, "test"); |
| 839 FireInvalidation(POLICY_OBJECT_A, 2, "test"); | 850 FireInvalidation(POLICY_OBJECT_A, 2, "test"); |
| 840 FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 851 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 841 FireUnknownVersionInvalidation(POLICY_OBJECT_A); | 852 FireUnknownVersionInvalidation(POLICY_OBJECT_A); |
| 842 FireInvalidation(POLICY_OBJECT_A, 3, "test"); | 853 FireInvalidation(POLICY_OBJECT_A, 3, "test"); |
| 843 FireInvalidation(POLICY_OBJECT_A, 4, "test"); | 854 FireInvalidation(POLICY_OBJECT_A, 4, "test"); |
| 844 | 855 |
| 845 // Verify that received invalidations metrics are correct. | 856 // Verify that received invalidations metrics are correct. |
| 846 EXPECT_EQ(3, GetInvalidationCount(false /* with_payload */)); | 857 EXPECT_EQ(3, GetInvalidationCount(false /* with_payload */)); |
| 847 EXPECT_EQ(4, GetInvalidationCount(true /* with_payload */)); | 858 EXPECT_EQ(4, GetInvalidationCount(true /* with_payload */)); |
| 848 } | 859 } |
| 849 | 860 |
| 850 } // namespace policy | 861 } // namespace policy |
| OLD | NEW |