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

Unified 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: Addressed nits. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/policy/cloud/cloud_policy_invalidator_unittest.cc
diff --git a/chrome/browser/policy/cloud/cloud_policy_invalidator_unittest.cc b/chrome/browser/policy/cloud/cloud_policy_invalidator_unittest.cc
index 3e37658b2c8eaf8b732973767569fe559e43d66f..5a55fd092dee7e843f674e4647a1800e79cecf0a 100644
--- a/chrome/browser/policy/cloud/cloud_policy_invalidator_unittest.cc
+++ b/chrome/browser/policy/cloud/cloud_policy_invalidator_unittest.cc
@@ -53,9 +53,15 @@ class CloudPolicyInvalidatorTest : public testing::Test {
// Starts the invalidator which will be tested.
// |initialize| determines if the invalidator should be initialized.
// |start_refresh_scheduler| determines if the refresh scheduler should start.
- void StartInvalidator(bool initialize, bool start_refresh_scheduler);
+ // |highest_handled_invalidation_version| is the highest invalidation version
+ // that was handled already before this invalidator was created.
+ void StartInvalidator(bool initialize,
+ bool start_refresh_scheduler,
+ int64 highest_handled_invalidation_version);
void StartInvalidator() {
- StartInvalidator(true /* initialize */, true /* start_refresh_scheduler */);
+ StartInvalidator(true, /* initialize */
+ true, /* start_refresh_scheduler */
+ 0 /* highest_handled_invalidation_version */);
}
// Calls Initialize on the invalidator.
@@ -147,6 +153,10 @@ class CloudPolicyInvalidatorTest : public testing::Test {
// invalidation service.
bool IsInvalidatorRegistered();
+ // Returns the highest invalidation version that was handled already according
+ // to the |invalidator_|.
+ int64 GetHighestHandledInvalidationVersion() const;
+
// Advance the test clock.
void AdvanceClock(base::TimeDelta delta);
@@ -225,12 +235,14 @@ void CloudPolicyInvalidatorTest::TearDown() {
void CloudPolicyInvalidatorTest::StartInvalidator(
bool initialize,
- bool start_refresh_scheduler) {
+ bool start_refresh_scheduler,
+ int64 highest_handled_invalidation_version) {
invalidator_.reset(new CloudPolicyInvalidator(
GetPolicyType(),
&core_,
task_runner_,
- scoped_ptr<base::Clock>(clock_)));
+ scoped_ptr<base::Clock>(clock_),
+ highest_handled_invalidation_version));
if (start_refresh_scheduler) {
ConnectCore();
StartRefreshScheduler();
@@ -371,6 +383,10 @@ bool CloudPolicyInvalidatorTest::IsInvalidatorRegistered() {
.GetRegisteredIds(invalidator_.get()).empty();
}
+int64 CloudPolicyInvalidatorTest::GetHighestHandledInvalidationVersion() const {
+ return invalidator_->highest_handled_invalidation_version();
+}
+
void CloudPolicyInvalidatorTest::AdvanceClock(base::TimeDelta delta) {
clock_->Advance(delta);
}
@@ -431,33 +447,42 @@ const invalidation::ObjectId& CloudPolicyInvalidatorTest::GetPolicyObjectId(
TEST_F(CloudPolicyInvalidatorTest, Uninitialized) {
// No invalidations should be processed if the invalidator is not initialized.
- StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */);
+ StartInvalidator(false, /* initialize */
+ true, /* start_refresh_scheduler */
+ 0 /* highest_handled_invalidation_version*/);
StorePolicy(POLICY_OBJECT_A);
EXPECT_FALSE(IsInvalidatorRegistered());
EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A)));
EXPECT_TRUE(CheckPolicyNotRefreshed());
+ EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
}
TEST_F(CloudPolicyInvalidatorTest, RefreshSchedulerNotStarted) {
// No invalidations should be processed if the refresh scheduler is not
// started.
- StartInvalidator(true /* initialize */, false /* start_refresh_scheduler */);
+ StartInvalidator(true, /* initialize */
+ false, /* start_refresh_scheduler */
+ 0 /* highest_handled_invalidation_version*/);
StorePolicy(POLICY_OBJECT_A);
EXPECT_FALSE(IsInvalidatorRegistered());
EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A)));
EXPECT_TRUE(CheckPolicyNotRefreshed());
+ EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
}
TEST_F(CloudPolicyInvalidatorTest, DisconnectCoreThenInitialize) {
// No invalidations should be processed if the core is disconnected before
// initialization.
- StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */);
+ StartInvalidator(false, /* initialize */
+ true, /* start_refresh_scheduler */
+ 0 /* highest_handled_invalidation_version*/);
DisconnectCore();
InitializeInvalidator();
StorePolicy(POLICY_OBJECT_A);
EXPECT_FALSE(IsInvalidatorRegistered());
EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A)));
EXPECT_TRUE(CheckPolicyNotRefreshed());
+ EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
}
TEST_F(CloudPolicyInvalidatorTest, InitializeThenStartRefreshScheduler) {
@@ -466,13 +491,16 @@ TEST_F(CloudPolicyInvalidatorTest, InitializeThenStartRefreshScheduler) {
// Note that the reverse case (start refresh scheduler then initialize) is
// the default behavior for the test fixture, so will be tested in most other
// tests.
- StartInvalidator(true /* initialize */, false /* start_refresh_scheduler */);
+ StartInvalidator(true, /* initialize */
+ false, /* start_refresh_scheduler */
+ 0 /* highest_handled_invalidation_version*/);
ConnectCore();
StartRefreshScheduler();
StorePolicy(POLICY_OBJECT_A);
EXPECT_TRUE(IsInvalidatorRegistered());
FireUnknownVersionInvalidation(POLICY_OBJECT_A);
EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion());
+ EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
}
TEST_F(CloudPolicyInvalidatorTest, RegisterOnStoreLoaded) {
@@ -500,6 +528,7 @@ TEST_F(CloudPolicyInvalidatorTest, RegisterOnStoreLoaded) {
EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion());
EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_B)));
EXPECT_TRUE(CheckPolicyNotRefreshed());
+ EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
}
TEST_F(CloudPolicyInvalidatorTest, ChangeRegistration) {
@@ -528,6 +557,7 @@ TEST_F(CloudPolicyInvalidatorTest, ChangeRegistration) {
EXPECT_TRUE(CheckPolicyNotRefreshed());
FireUnknownVersionInvalidation(POLICY_OBJECT_B);
EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion());
+ EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
}
TEST_F(CloudPolicyInvalidatorTest, UnregisterOnStoreLoaded) {
@@ -556,6 +586,7 @@ TEST_F(CloudPolicyInvalidatorTest, UnregisterOnStoreLoaded) {
EXPECT_TRUE(InvalidationsEnabled());
FireUnknownVersionInvalidation(POLICY_OBJECT_B);
EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion());
+ EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
}
TEST_F(CloudPolicyInvalidatorTest, HandleInvalidation) {
@@ -572,10 +603,12 @@ TEST_F(CloudPolicyInvalidatorTest, HandleInvalidation) {
// Make sure invalidation is not acknowledged until the store is loaded.
EXPECT_FALSE(IsInvalidationAcknowledged(inv));
+ EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
EXPECT_TRUE(CheckInvalidationInfo(V(12), "test_payload"));
StorePolicy(POLICY_OBJECT_A, V(12));
EXPECT_TRUE(IsInvalidationAcknowledged(inv));
EXPECT_TRUE(CheckInvalidationInfo(0, std::string()));
+ EXPECT_EQ(V(12), GetHighestHandledInvalidationVersion());
}
TEST_F(CloudPolicyInvalidatorTest, HandleInvalidationWithUnknownVersion) {
@@ -595,6 +628,7 @@ TEST_F(CloudPolicyInvalidatorTest, HandleInvalidationWithUnknownVersion) {
StorePolicy(POLICY_OBJECT_A, -1);
EXPECT_TRUE(IsInvalidationAcknowledged(inv));
EXPECT_TRUE(CheckInvalidationInfo(0, std::string()));
+ EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
}
TEST_F(CloudPolicyInvalidatorTest, HandleMultipleInvalidations) {
@@ -617,12 +651,16 @@ TEST_F(CloudPolicyInvalidatorTest, HandleMultipleInvalidations) {
// Make sure that the last invalidation is only acknowledged after the store
// is loaded with the latest version.
+ EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
StorePolicy(POLICY_OBJECT_A, V(1));
EXPECT_FALSE(IsInvalidationAcknowledged(inv3));
+ EXPECT_EQ(V(1), GetHighestHandledInvalidationVersion());
StorePolicy(POLICY_OBJECT_A, V(2));
EXPECT_FALSE(IsInvalidationAcknowledged(inv3));
+ EXPECT_EQ(V(2), GetHighestHandledInvalidationVersion());
StorePolicy(POLICY_OBJECT_A, V(3));
EXPECT_TRUE(IsInvalidationAcknowledged(inv3));
+ EXPECT_EQ(V(3), GetHighestHandledInvalidationVersion());
}
TEST_F(CloudPolicyInvalidatorTest,
@@ -656,6 +694,48 @@ TEST_F(CloudPolicyInvalidatorTest,
EXPECT_FALSE(IsInvalidationAcknowledged(inv3));
StorePolicy(POLICY_OBJECT_A, -3);
EXPECT_TRUE(IsInvalidationAcknowledged(inv3));
+ EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
+}
+
+TEST_F(CloudPolicyInvalidatorTest,
+ InitialHighestHandledInvalidationVersionNonZero) {
+ StorePolicy(POLICY_OBJECT_A);
+ StartInvalidator(true, /* initialize */
+ true, /* start_refresh_scheduler */
+ V(2) /* highest_handled_invalidation_version*/);
+
+ // Check that an invalidation whose version is lower than the highest handled
+ // so far is acknowledged but ignored otherwise.
+ syncer::Invalidation inv1 = FireInvalidation(POLICY_OBJECT_A, V(1), "test1");
+ EXPECT_TRUE(CheckPolicyNotRefreshed());
+ EXPECT_TRUE(CheckInvalidationInfo(0, std::string()));
+ EXPECT_TRUE(IsInvalidationAcknowledged(inv1));
+ EXPECT_EQ(V(2), GetHighestHandledInvalidationVersion());
+
+ // Check that an invalidation with an unknown version is handled.
+ syncer::Invalidation inv = FireUnknownVersionInvalidation(POLICY_OBJECT_A);
+ EXPECT_TRUE(CheckPolicyRefreshedWithUnknownVersion());
+ EXPECT_TRUE(CheckInvalidationInfo(-1, std::string()));
+ StorePolicy(POLICY_OBJECT_A, -1);
+ EXPECT_TRUE(IsInvalidationAcknowledged(inv));
+ EXPECT_EQ(V(2), GetHighestHandledInvalidationVersion());
+
+ // Check that an invalidation whose version matches the highest handled so far
+ // is acknowledged but ignored otherwise.
+ syncer::Invalidation inv2 = FireInvalidation(POLICY_OBJECT_A, V(2), "test2");
+ EXPECT_TRUE(CheckPolicyNotRefreshed());
+ EXPECT_TRUE(CheckInvalidationInfo(0, std::string()));
+ EXPECT_TRUE(IsInvalidationAcknowledged(inv2));
+ EXPECT_EQ(V(2), GetHighestHandledInvalidationVersion());
+
+ // Check that an invalidation whose version is higher than the highest handled
+ // so far is handled, causing a policy refresh.
+ syncer::Invalidation inv3 = FireInvalidation(POLICY_OBJECT_A, V(3), "test3");
+ EXPECT_TRUE(CheckPolicyRefreshed());
+ EXPECT_TRUE(CheckInvalidationInfo(V(3), "test3"));
+ StorePolicy(POLICY_OBJECT_A, V(3));
+ EXPECT_TRUE(IsInvalidationAcknowledged(inv3));
+ EXPECT_EQ(V(3), GetHighestHandledInvalidationVersion());
}
TEST_F(CloudPolicyInvalidatorTest, AcknowledgeBeforeRefresh) {
@@ -667,9 +747,11 @@ TEST_F(CloudPolicyInvalidatorTest, AcknowledgeBeforeRefresh) {
// Ensure that the policy is not refreshed and the invalidation is
// acknowledged if the store is loaded with the latest version before the
// refresh can occur.
+ EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
StorePolicy(POLICY_OBJECT_A, V(3));
EXPECT_TRUE(IsInvalidationAcknowledged(inv));
EXPECT_TRUE(CheckPolicyNotRefreshed());
+ EXPECT_EQ(V(3), GetHighestHandledInvalidationVersion());
}
TEST_F(CloudPolicyInvalidatorTest, NoCallbackAfterShutdown) {
@@ -682,6 +764,7 @@ TEST_F(CloudPolicyInvalidatorTest, NoCallbackAfterShutdown) {
// down.
ShutdownInvalidator();
EXPECT_TRUE(CheckPolicyNotRefreshed());
+ EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
DestroyInvalidator();
}
@@ -720,6 +803,7 @@ TEST_F(CloudPolicyInvalidatorTest, StateChanged) {
StorePolicy(POLICY_OBJECT_NONE);
StorePolicy(POLICY_OBJECT_A);
EXPECT_FALSE(InvalidationsEnabled());
+ EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
}
TEST_F(CloudPolicyInvalidatorTest, Disconnect) {
@@ -759,6 +843,7 @@ TEST_F(CloudPolicyInvalidatorTest, Disconnect) {
EXPECT_TRUE(CheckPolicyRefreshed());
DisableInvalidationService();
EXPECT_FALSE(InvalidationsEnabled());
+ EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
}
class CloudPolicyInvalidatorUserTypedTest
@@ -850,6 +935,7 @@ TEST_P(CloudPolicyInvalidatorUserTypedTest, RefreshMetricsUnregistered) {
EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_UNCHANGED));
EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED));
EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED));
+ EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
}
TEST_P(CloudPolicyInvalidatorUserTypedTest, RefreshMetricsNoInvalidations) {
@@ -901,6 +987,7 @@ TEST_P(CloudPolicyInvalidatorUserTypedTest, RefreshMetricsNoInvalidations) {
EXPECT_EQ(6, GetCount(METRIC_POLICY_REFRESH_UNCHANGED));
EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED));
EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED));
+ EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
}
TEST_P(CloudPolicyInvalidatorUserTypedTest, RefreshMetricsInvalidation) {
@@ -913,7 +1000,9 @@ TEST_P(CloudPolicyInvalidatorUserTypedTest, RefreshMetricsInvalidation) {
FireInvalidation(POLICY_OBJECT_A, V(5), "test");
StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */);
StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */);
+ EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
StorePolicy(POLICY_OBJECT_A, V(5), true /* policy_changed */);
+ EXPECT_EQ(V(5), GetHighestHandledInvalidationVersion());
// Store loads after the invalidation is complete are not counted as
// invalidated.
@@ -930,6 +1019,7 @@ TEST_P(CloudPolicyInvalidatorUserTypedTest, RefreshMetricsInvalidation) {
EXPECT_EQ(4, GetCount(METRIC_POLICY_REFRESH_UNCHANGED));
EXPECT_EQ(2, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED));
EXPECT_EQ(1, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED));
+ EXPECT_EQ(V(5), GetHighestHandledInvalidationVersion());
}
TEST_P(CloudPolicyInvalidatorUserTypedTest, ExpiredInvalidations) {
@@ -991,6 +1081,7 @@ TEST_P(CloudPolicyInvalidatorUserTypedTest, ExpiredInvalidations) {
EXPECT_EQ(2,
GetInvalidationCount(POLICY_INVALIDATION_TYPE_NO_PAYLOAD_EXPIRED));
EXPECT_EQ(2, GetInvalidationCount(POLICY_INVALIDATION_TYPE_EXPIRED));
+ EXPECT_EQ(0, GetHighestHandledInvalidationVersion());
}
#if defined(OS_CHROMEOS)
« no previous file with comments | « chrome/browser/policy/cloud/cloud_policy_invalidator.cc ('k') | chrome/browser/policy/cloud/user_cloud_policy_invalidator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698