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 eed8bfc9f1f6012c0baa09e7fbfe0696a9bf87f9..2162d87273e84da3137796f3c4216d1e913bdd9a 100644 |
--- a/chrome/browser/policy/cloud/cloud_policy_invalidator_unittest.cc |
+++ b/chrome/browser/policy/cloud/cloud_policy_invalidator_unittest.cc |
@@ -5,8 +5,10 @@ |
#include <string> |
#include "base/basictypes.h" |
+#include "base/bind.h" |
#include "base/memory/ref_counted.h" |
#include "base/memory/scoped_ptr.h" |
+#include "base/message_loop/message_loop.h" |
#include "base/metrics/histogram.h" |
#include "base/metrics/histogram_samples.h" |
#include "base/metrics/sample_map.h" |
@@ -15,9 +17,9 @@ |
#include "base/time/time.h" |
#include "base/values.h" |
#include "chrome/browser/invalidation/fake_invalidation_service.h" |
+#include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
#include "chrome/browser/policy/cloud/cloud_policy_core.h" |
#include "chrome/browser/policy/cloud/cloud_policy_invalidator.h" |
-#include "chrome/browser/policy/cloud/cloud_policy_service.h" |
#include "chrome/browser/policy/cloud/enterprise_metrics.h" |
#include "chrome/browser/policy/cloud/mock_cloud_policy_client.h" |
#include "chrome/browser/policy/cloud/mock_cloud_policy_store.h" |
@@ -30,8 +32,7 @@ |
namespace policy { |
-class CloudPolicyInvalidatorTest : public testing::Test, |
- public CloudPolicyInvalidationHandler { |
+class CloudPolicyInvalidatorTest : public testing::Test { |
protected: |
// Policy objects which can be used in tests. |
enum PolicyObject { |
@@ -47,11 +48,32 @@ class CloudPolicyInvalidatorTest : public testing::Test, |
virtual void TearDown() OVERRIDE; |
// Starts the invalidator which will be tested. |
- void StartInvalidator(bool initialize); |
+ // |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); |
void StartInvalidator() { |
- StartInvalidator(true /* initialize */); |
+ StartInvalidator(true /* initialize */, true /* start_refresh_scheduler */); |
} |
+ // Calls Initialize on the invalidator. |
+ void InitializeInvalidator(); |
+ |
+ // Calls Shutdown on the invalidator. Test must call DestroyInvalidator |
+ // afterwards to prevent Shutdown from being called twice. |
+ void ShutdownInvalidator(); |
+ |
+ // Destroys the invalidator. |
+ void DestroyInvalidator(); |
+ |
+ // Connects the cloud policy core. |
+ void ConnectCore(); |
+ |
+ // Starts the refresh scheduler. |
+ void StartRefreshScheduler(); |
+ |
+ // Disconnects the cloud policy core. |
+ void DisconnectCore(); |
+ |
// Simulates storing a new policy to the policy store. |
// |object| determines which policy object the store will report the |
// invalidator should register for. May be POLICY_OBJECT_NONE for no object. |
@@ -98,40 +120,41 @@ class CloudPolicyInvalidatorTest : public testing::Test, |
// Checks the expected value of the currently set invalidation info. |
bool CheckInvalidationInfo(int64 version, const std::string& payload); |
- // Checks that the invalidate callback was not called. |
- bool CheckInvalidateNotCalled(); |
+ // Checks that the policy was not refreshed due to an invalidation. |
+ bool CheckPolicyNotRefreshed(); |
- // Checks that the invalidate callback was called within an appropriate |
- // timeframe depending on whether the invalidation had unknown version. |
- bool CheckInvalidateCalled(bool unknown_version); |
- bool CheckInvalidateCalled() { |
- return CheckInvalidateCalled(true); |
+ // Checks that the policy was refreshed due to an invalidation within an |
+ // appropriate timeframe depending on whether the invalidation had unknown |
+ // version. |
+ bool CheckPolicyRefreshed(bool unknown_version); |
+ bool CheckPolicyRefreshed() { |
+ return CheckPolicyRefreshed(true); |
} |
- // Checks that the state changed callback of the invalidation handler was not |
- // called. |
+ // Checks that the call to change the invalidations enabled state was not |
+ // performed. |
bool CheckStateChangedNotCalled(); |
- // Checks that the state changed callback of the invalidation handler was |
- // called with the given state. |
+ // Checks that the call to change the invalidations enabled state was |
+ // performed with the given state. |
bool CheckStateChangedCalled(bool invalidations_enabled); |
// Determines if the invalidation with the given ack handle has been |
// acknowledged. |
bool IsInvalidationAcknowledged(const syncer::AckHandle& ack_handle); |
+ // Determines if the invalidator has registered for an object with the |
+ // invalidation service. |
+ bool IsInvalidatorRegistered(); |
+ |
// Get the current count for the given metric. |
base::HistogramBase::Count GetCount(MetricPolicyRefresh metric); |
base::HistogramBase::Count GetInvalidationCount(bool with_payload); |
- // CloudPolicyInvalidationHandler: |
- virtual void SetInvalidationInfo( |
- int64 version, |
- const std::string& payload) OVERRIDE; |
- virtual void InvalidatePolicy() OVERRIDE; |
- virtual void OnInvalidatorStateChanged(bool invalidations_enabled) OVERRIDE; |
- |
private: |
+ // Get a pointer to the invalidation service. |
+ invalidation::InvalidationService* GetInvalidationService(); |
+ |
// Returns the object id of the given policy object. |
const invalidation::ObjectId& GetPolicyObjectId(PolicyObject object) const; |
@@ -142,15 +165,12 @@ class CloudPolicyInvalidatorTest : public testing::Test, |
// Objects the invalidator depends on. |
invalidation::FakeInvalidationService invalidation_service_; |
MockCloudPolicyStore store_; |
+ CloudPolicyCore core_; |
scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
// The invalidator which will be tested. |
scoped_ptr<CloudPolicyInvalidator> invalidator_; |
- // The latest invalidation info set by the invalidator. |
- int64 invalidation_version_; |
- std::string invalidation_payload_; |
- |
// Object ids for the test policy objects. |
invalidation::ObjectId object_id_a_; |
invalidation::ObjectId object_id_b_; |
@@ -166,32 +186,33 @@ class CloudPolicyInvalidatorTest : public testing::Test, |
// The currently used policy value. |
const char* policy_value_cur_; |
- // Stores how many times the invalidate callback was called. |
- int invalidate_callback_count_; |
- |
- // Stores how many times the state change callback was called for each state. |
- int state_change_enabled_callback_count_; |
- int state_change_disabled_callback_count_; |
+ // The latest invalidation status counters read from the invalidator. |
+ int last_enabled_count_; |
+ int last_disabled_count_; |
// Stores starting histogram counts for kMetricPolicyRefresh. |
scoped_ptr<base::HistogramSamples> refresh_samples_; |
// Stores starting histogram counts for kMetricPolicyInvalidations. |
scoped_ptr<base::HistogramSamples> invalidations_samples_; |
+ |
+ // Initialize message loop. |
+ base::MessageLoop loop_; |
}; |
CloudPolicyInvalidatorTest::CloudPolicyInvalidatorTest() |
- : task_runner_(new base::TestSimpleTaskRunner()), |
- invalidation_version_(0), |
+ : core_(PolicyNamespaceKey(dm_protocol::kChromeUserPolicyType, |
+ std::string()), |
+ &store_), |
+ task_runner_(new base::TestSimpleTaskRunner()), |
object_id_a_(135, "asdf"), |
object_id_b_(246, "zxcv"), |
timestamp_(123456), |
policy_value_a_("asdf"), |
policy_value_b_("zxcv"), |
policy_value_cur_(policy_value_a_), |
- invalidate_callback_count_(0), |
- state_change_enabled_callback_count_(0), |
- state_change_disabled_callback_count_(0) {} |
+ last_enabled_count_(0), |
+ last_disabled_count_(0) {} |
void CloudPolicyInvalidatorTest::SetUp() { |
base::StatisticsRecorder::Initialize(); |
@@ -203,15 +224,45 @@ void CloudPolicyInvalidatorTest::TearDown() { |
EXPECT_FALSE(invalidation_service_.ReceivedInvalidAcknowledgement()); |
if (invalidator_) |
invalidator_->Shutdown(); |
+ core_.Disconnect(); |
} |
-void CloudPolicyInvalidatorTest::StartInvalidator(bool initialize) { |
- invalidator_.reset(new CloudPolicyInvalidator( |
- this /* invalidation_handler */, |
- &store_, |
- task_runner_)); |
+void CloudPolicyInvalidatorTest::StartInvalidator( |
+ bool initialize, |
+ bool start_refresh_scheduler) { |
+ invalidator_.reset(new CloudPolicyInvalidator(&core_, task_runner_)); |
+ if (start_refresh_scheduler) { |
+ ConnectCore(); |
+ StartRefreshScheduler(); |
+ } |
if (initialize) |
- invalidator_->InitializeWithService(&invalidation_service_); |
+ InitializeInvalidator(); |
+} |
+ |
+void CloudPolicyInvalidatorTest::InitializeInvalidator() { |
+ invalidator_->Initialize(base::Bind( |
+ &CloudPolicyInvalidatorTest::GetInvalidationService, |
+ base::Unretained(this))); |
+} |
+ |
+void CloudPolicyInvalidatorTest::ShutdownInvalidator() { |
+ invalidator_->Shutdown(); |
+} |
+ |
+void CloudPolicyInvalidatorTest::DestroyInvalidator() { |
+ invalidator_.reset(); |
+} |
+ |
+void CloudPolicyInvalidatorTest::ConnectCore() { |
+ core_.Connect(scoped_ptr<CloudPolicyClient>(new MockCloudPolicyClient())); |
+} |
+ |
+void CloudPolicyInvalidatorTest::StartRefreshScheduler() { |
+ core_.StartRefreshScheduler(); |
+} |
+ |
+void CloudPolicyInvalidatorTest::DisconnectCore() { |
+ core_.Disconnect(); |
} |
void CloudPolicyInvalidatorTest::StorePolicy( |
@@ -274,20 +325,19 @@ syncer::AckHandle CloudPolicyInvalidatorTest::FireInvalidation( |
bool CloudPolicyInvalidatorTest::CheckInvalidationInfo( |
int64 version, |
const std::string& payload) { |
- return version == invalidation_version_ && payload == invalidation_payload_; |
+ MockCloudPolicyClient* client = |
+ static_cast<MockCloudPolicyClient*>(core_.client()); |
+ return version == client->invalidation_version_ && |
+ payload == client->invalidation_payload_; |
} |
-bool CloudPolicyInvalidatorTest::CheckInvalidateNotCalled() { |
- bool result = true; |
- if (invalidate_callback_count_ != 0) |
- result = false; |
+bool CloudPolicyInvalidatorTest::CheckPolicyNotRefreshed() { |
+ int start_count = invalidator_->policy_refresh_count(); |
task_runner_->RunUntilIdle(); |
- if (invalidate_callback_count_ != 0) |
- result = false; |
- return result; |
+ return invalidator_->policy_refresh_count() == start_count; |
} |
-bool CloudPolicyInvalidatorTest::CheckInvalidateCalled(bool unknown_version) { |
+bool CloudPolicyInvalidatorTest::CheckPolicyRefreshed(bool unknown_version) { |
base::TimeDelta min_delay; |
base::TimeDelta max_delay = base::TimeDelta::FromMilliseconds( |
CloudPolicyInvalidator::kMaxFetchDelayMin); |
@@ -304,29 +354,34 @@ bool CloudPolicyInvalidatorTest::CheckInvalidateCalled(bool unknown_version) { |
EXPECT_GE(actual_delay, min_delay); |
EXPECT_LE(actual_delay, max_delay); |
- bool result = true; |
- if (invalidate_callback_count_ != 0) |
- result = false; |
+ int start_count = invalidator_->policy_refresh_count(); |
Mattias Nissler (ping if slow)
2013/09/02 11:54:52
nit: const
Steve Condie
2013/09/03 04:41:56
Done.
|
task_runner_->RunUntilIdle(); |
- if (invalidate_callback_count_ != 1) |
- result = false; |
- invalidate_callback_count_ = 0; |
- return result; |
+ return invalidator_->policy_refresh_count() == start_count + 1; |
} |
bool CloudPolicyInvalidatorTest::CheckStateChangedNotCalled() { |
- return state_change_enabled_callback_count_ == 0 && |
- state_change_disabled_callback_count_ == 0; |
+ bool result = |
+ last_enabled_count_ == invalidator_->invalidations_enabled_count() && |
+ last_disabled_count_ == invalidator_->invalidations_disabled_count(); |
+ last_enabled_count_ = invalidator_->invalidations_enabled_count(); |
+ last_disabled_count_ = invalidator_->invalidations_disabled_count(); |
+ return result; |
} |
bool CloudPolicyInvalidatorTest::CheckStateChangedCalled( |
bool invalidations_enabled) { |
- int expected_enabled_count_ = invalidations_enabled ? 1 : 0; |
- int expected_disabled_count_ = invalidations_enabled ? 0 : 1; |
- bool result = state_change_enabled_callback_count_ == expected_enabled_count_ |
- && state_change_disabled_callback_count_ == expected_disabled_count_; |
- state_change_enabled_callback_count_ = 0; |
- state_change_disabled_callback_count_ = 0; |
+ int expected_enabled_count_ = last_enabled_count_; |
+ int expected_disabled_count_ = last_disabled_count_; |
+ if (invalidations_enabled) |
+ expected_enabled_count_++; |
+ else |
+ expected_disabled_count_++; |
+ |
+ bool result = |
+ invalidator_->invalidations_enabled_count() == expected_enabled_count_ && |
+ invalidator_->invalidations_disabled_count() == expected_disabled_count_; |
+ last_enabled_count_ = invalidator_->invalidations_enabled_count(); |
+ last_disabled_count_ = invalidator_->invalidations_disabled_count(); |
return result; |
} |
@@ -335,6 +390,11 @@ bool CloudPolicyInvalidatorTest::IsInvalidationAcknowledged( |
return invalidation_service_.IsInvalidationAcknowledged(ack_handle); |
} |
+bool CloudPolicyInvalidatorTest::IsInvalidatorRegistered() { |
+ return !invalidation_service_.invalidator_registrar() |
+ .GetRegisteredIds(invalidator_.get()).empty(); |
+} |
+ |
base::HistogramBase::Count CloudPolicyInvalidatorTest::GetCount( |
MetricPolicyRefresh metric) { |
return GetHistogramSamples(kMetricPolicyRefresh)->GetCount(metric) - |
@@ -348,25 +408,9 @@ base::HistogramBase::Count CloudPolicyInvalidatorTest::GetInvalidationCount( |
invalidations_samples_->GetCount(metric); |
} |
-void CloudPolicyInvalidatorTest::SetInvalidationInfo( |
- int64 version, |
- const std::string& payload) { |
- invalidation_version_ = version; |
- invalidation_payload_ = payload; |
-} |
- |
-void CloudPolicyInvalidatorTest::InvalidatePolicy() { |
- ++invalidate_callback_count_; |
-} |
- |
-void CloudPolicyInvalidatorTest::OnInvalidatorStateChanged( |
- bool invalidations_enabled) { |
- if (invalidator_.get()) |
- EXPECT_EQ(invalidations_enabled, invalidator_->invalidations_enabled()); |
- if (invalidations_enabled) |
- ++state_change_enabled_callback_count_; |
- else |
- ++state_change_disabled_callback_count_; |
+invalidation::InvalidationService* |
+CloudPolicyInvalidatorTest::GetInvalidationService() { |
+ return &invalidation_service_; |
} |
const invalidation::ObjectId& CloudPolicyInvalidatorTest::GetPolicyObjectId( |
@@ -386,86 +430,132 @@ scoped_ptr<base::HistogramSamples> |
} |
TEST_F(CloudPolicyInvalidatorTest, Uninitialized) { |
- // No invalidations should be processed if the invalidator is not intialized. |
- StartInvalidator(false /* initialize */); |
+ // No invalidations should be processed if the invalidator is not initialized. |
+ StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */); |
+ StorePolicy(POLICY_OBJECT_A); |
+ EXPECT_FALSE(IsInvalidatorRegistered()); |
+ FireInvalidation(POLICY_OBJECT_A); |
+ EXPECT_TRUE(CheckPolicyNotRefreshed()); |
+} |
+ |
+TEST_F(CloudPolicyInvalidatorTest, RefreshSchedulerNotStarted) { |
+ // No invalidations should be processed if the refresh scheduler is not |
+ // started. |
+ StartInvalidator(true /* initialize */, false /* start_refresh_scheduler */); |
StorePolicy(POLICY_OBJECT_A); |
+ EXPECT_FALSE(IsInvalidatorRegistered()); |
FireInvalidation(POLICY_OBJECT_A); |
- EXPECT_TRUE(CheckInvalidateNotCalled()); |
+ EXPECT_TRUE(CheckPolicyNotRefreshed()); |
+} |
+ |
+TEST_F(CloudPolicyInvalidatorTest, DisconnectCoreThenInitialize) { |
+ // No invalidations should be processed if the core is disconnected before |
+ // initialization. |
+ StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */); |
+ DisconnectCore(); |
+ InitializeInvalidator(); |
+ StorePolicy(POLICY_OBJECT_A); |
+ EXPECT_FALSE(IsInvalidatorRegistered()); |
+ FireInvalidation(POLICY_OBJECT_A); |
+ EXPECT_TRUE(CheckPolicyNotRefreshed()); |
+} |
+ |
+TEST_F(CloudPolicyInvalidatorTest, InitializeThenStartRefreshScheduler) { |
+ // Make sure registration occurs and invalidations are processed when |
+ // Initialize is called before starting the refresh scheduler. |
+ // 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 */); |
+ ConnectCore(); |
+ StartRefreshScheduler(); |
+ StorePolicy(POLICY_OBJECT_A); |
+ EXPECT_TRUE(IsInvalidatorRegistered()); |
+ FireInvalidation(POLICY_OBJECT_A); |
+ EXPECT_TRUE(CheckPolicyRefreshed()); |
} |
TEST_F(CloudPolicyInvalidatorTest, RegisterOnStoreLoaded) { |
// No registration when store is not loaded. |
StartInvalidator(); |
+ EXPECT_FALSE(IsInvalidatorRegistered()); |
EXPECT_TRUE(CheckStateChangedNotCalled()); |
FireInvalidation(POLICY_OBJECT_A); |
FireInvalidation(POLICY_OBJECT_B); |
- EXPECT_TRUE(CheckInvalidateNotCalled()); |
+ EXPECT_TRUE(CheckPolicyNotRefreshed()); |
// No registration when store is loaded with no invalidation object id. |
StorePolicy(POLICY_OBJECT_NONE); |
+ EXPECT_FALSE(IsInvalidatorRegistered()); |
EXPECT_TRUE(CheckStateChangedNotCalled()); |
FireInvalidation(POLICY_OBJECT_A); |
FireInvalidation(POLICY_OBJECT_B); |
- EXPECT_TRUE(CheckInvalidateNotCalled()); |
+ EXPECT_TRUE(CheckPolicyNotRefreshed()); |
// Check registration when store is loaded for object A. |
StorePolicy(POLICY_OBJECT_A); |
+ EXPECT_TRUE(IsInvalidatorRegistered()); |
EXPECT_TRUE(CheckStateChangedCalled(true)); |
FireInvalidation(POLICY_OBJECT_A); |
- EXPECT_TRUE(CheckInvalidateCalled()); |
+ EXPECT_TRUE(CheckPolicyRefreshed()); |
FireInvalidation(POLICY_OBJECT_B); |
- EXPECT_TRUE(CheckInvalidateNotCalled()); |
+ EXPECT_TRUE(CheckPolicyNotRefreshed()); |
} |
TEST_F(CloudPolicyInvalidatorTest, ChangeRegistration) { |
// Register for object A. |
StartInvalidator(); |
StorePolicy(POLICY_OBJECT_A); |
+ EXPECT_TRUE(IsInvalidatorRegistered()); |
EXPECT_TRUE(CheckStateChangedCalled(true)); |
FireInvalidation(POLICY_OBJECT_A); |
- EXPECT_TRUE(CheckInvalidateCalled()); |
+ EXPECT_TRUE(CheckPolicyRefreshed()); |
FireInvalidation(POLICY_OBJECT_B); |
- EXPECT_TRUE(CheckInvalidateNotCalled()); |
+ EXPECT_TRUE(CheckPolicyNotRefreshed()); |
syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A); |
// Check re-registration for object B. Make sure the pending invalidation for |
// object A is acknowledged without making the callback. |
StorePolicy(POLICY_OBJECT_B); |
+ EXPECT_TRUE(IsInvalidatorRegistered()); |
EXPECT_TRUE(CheckStateChangedNotCalled()); |
EXPECT_TRUE(IsInvalidationAcknowledged(ack)); |
- EXPECT_TRUE(CheckInvalidateNotCalled()); |
+ EXPECT_TRUE(CheckPolicyNotRefreshed()); |
// Make sure future invalidations for object A are ignored and for object B |
// are processed. |
FireInvalidation(POLICY_OBJECT_A); |
- EXPECT_TRUE(CheckInvalidateNotCalled()); |
+ EXPECT_TRUE(CheckPolicyNotRefreshed()); |
FireInvalidation(POLICY_OBJECT_B); |
- EXPECT_TRUE(CheckInvalidateCalled()); |
+ EXPECT_TRUE(CheckPolicyRefreshed()); |
} |
TEST_F(CloudPolicyInvalidatorTest, UnregisterOnStoreLoaded) { |
// Register for object A. |
StartInvalidator(); |
StorePolicy(POLICY_OBJECT_A); |
+ EXPECT_TRUE(IsInvalidatorRegistered()); |
EXPECT_TRUE(CheckStateChangedCalled(true)); |
FireInvalidation(POLICY_OBJECT_A); |
- EXPECT_TRUE(CheckInvalidateCalled()); |
+ EXPECT_TRUE(CheckPolicyRefreshed()); |
// Check unregistration when store is loaded with no invalidation object id. |
syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A); |
EXPECT_FALSE(IsInvalidationAcknowledged(ack)); |
StorePolicy(POLICY_OBJECT_NONE); |
+ EXPECT_FALSE(IsInvalidatorRegistered()); |
EXPECT_TRUE(IsInvalidationAcknowledged(ack)); |
EXPECT_TRUE(CheckStateChangedCalled(false)); |
FireInvalidation(POLICY_OBJECT_A); |
FireInvalidation(POLICY_OBJECT_B); |
- EXPECT_TRUE(CheckInvalidateNotCalled()); |
+ EXPECT_TRUE(CheckPolicyNotRefreshed()); |
// Check re-registration for object B. |
StorePolicy(POLICY_OBJECT_B); |
+ EXPECT_TRUE(IsInvalidatorRegistered()); |
EXPECT_TRUE(CheckStateChangedCalled(true)); |
FireInvalidation(POLICY_OBJECT_B); |
- EXPECT_TRUE(CheckInvalidateCalled()); |
+ EXPECT_TRUE(CheckPolicyRefreshed()); |
} |
TEST_F(CloudPolicyInvalidatorTest, HandleInvalidation) { |
@@ -477,7 +567,7 @@ TEST_F(CloudPolicyInvalidatorTest, HandleInvalidation) { |
// Make sure client info is set as soon as the invalidation is received. |
EXPECT_TRUE(CheckInvalidationInfo(12, "test_payload")); |
- EXPECT_TRUE(CheckInvalidateCalled(false /* unknown_version */)); |
+ EXPECT_TRUE(CheckPolicyRefreshed(false /* unknown_version */)); |
// Make sure invalidation is not acknowledged until the store is loaded. |
EXPECT_FALSE(IsInvalidationAcknowledged(ack)); |
@@ -496,7 +586,7 @@ TEST_F(CloudPolicyInvalidatorTest, HandleInvalidationWithUnknownVersion) { |
// Make sure client info is not set until after the invalidation callback is |
// made. |
EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
- EXPECT_TRUE(CheckInvalidateCalled()); |
+ EXPECT_TRUE(CheckPolicyRefreshed()); |
EXPECT_TRUE(CheckInvalidationInfo(-1, std::string())); |
// Make sure invalidation is not acknowledged until the store is loaded. |
@@ -521,8 +611,8 @@ TEST_F(CloudPolicyInvalidatorTest, HandleMultipleInvalidations) { |
EXPECT_TRUE(IsInvalidationAcknowledged(ack1)); |
EXPECT_TRUE(IsInvalidationAcknowledged(ack2)); |
- // Make sure the invalidate callback is called once. |
- EXPECT_TRUE(CheckInvalidateCalled(false /* unknown_version */)); |
+ // Make sure the policy is refreshed once. |
+ EXPECT_TRUE(CheckPolicyRefreshed(false /* unknown_version */)); |
// Make sure that the last invalidation is only acknowledged after the store |
// is loaded with the latest version. |
@@ -542,15 +632,15 @@ TEST_F(CloudPolicyInvalidatorTest, |
StartInvalidator(); |
syncer::AckHandle ack1 = FireInvalidation(POLICY_OBJECT_A); |
EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
- EXPECT_TRUE(CheckInvalidateCalled()); |
+ EXPECT_TRUE(CheckPolicyRefreshed()); |
EXPECT_TRUE(CheckInvalidationInfo(-1, std::string())); |
syncer::AckHandle ack2 = FireInvalidation(POLICY_OBJECT_A); |
EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
- EXPECT_TRUE(CheckInvalidateCalled()); |
+ EXPECT_TRUE(CheckPolicyRefreshed()); |
EXPECT_TRUE(CheckInvalidationInfo(-2, std::string())); |
syncer::AckHandle ack3 = FireInvalidation(POLICY_OBJECT_A); |
EXPECT_TRUE(CheckInvalidationInfo(0, std::string())); |
- EXPECT_TRUE(CheckInvalidateCalled()); |
+ EXPECT_TRUE(CheckPolicyRefreshed()); |
EXPECT_TRUE(CheckInvalidationInfo(-3, std::string())); |
// Make sure the replaced invalidations are acknowledged. |
@@ -567,18 +657,31 @@ TEST_F(CloudPolicyInvalidatorTest, |
EXPECT_TRUE(IsInvalidationAcknowledged(ack3)); |
} |
-TEST_F(CloudPolicyInvalidatorTest, AcknowledgeBeforeInvalidateCallback) { |
+TEST_F(CloudPolicyInvalidatorTest, AcknowledgeBeforeRefresh) { |
// Generate an invalidation. |
StorePolicy(POLICY_OBJECT_A); |
StartInvalidator(); |
syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A, 3, "test"); |
- // Ensure that the invalidate callback is not made and the invalidation is |
+ // Ensure that the policy is not refreshed and the invalidation is |
// acknowledged if the store is loaded with the latest version before the |
- // callback is invoked. |
+ // refresh can occur. |
StorePolicy(POLICY_OBJECT_A, 3); |
EXPECT_TRUE(IsInvalidationAcknowledged(ack)); |
- EXPECT_TRUE(CheckInvalidateNotCalled()); |
+ EXPECT_TRUE(CheckPolicyNotRefreshed()); |
+} |
+ |
+TEST_F(CloudPolicyInvalidatorTest, NoCallbackAfterShutdown) { |
+ // Generate an invalidation. |
+ StorePolicy(POLICY_OBJECT_A); |
+ StartInvalidator(); |
+ syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A, 3, "test"); |
+ |
+ // Ensure that the policy refresh is not made after the invalidator is shut |
+ // down. |
+ ShutdownInvalidator(); |
+ EXPECT_TRUE(CheckPolicyNotRefreshed()); |
+ DestroyInvalidator(); |
} |
TEST_F(CloudPolicyInvalidatorTest, StateChanged) { |
@@ -622,6 +725,48 @@ TEST_F(CloudPolicyInvalidatorTest, StateChanged) { |
EXPECT_TRUE(CheckStateChangedNotCalled()); |
} |
+TEST_F(CloudPolicyInvalidatorTest, Disconnect) { |
+ // Generate an invalidation. |
+ StorePolicy(POLICY_OBJECT_A); |
+ StartInvalidator(); |
+ syncer::AckHandle ack = FireInvalidation(POLICY_OBJECT_A, 1, "test"); |
+ EXPECT_TRUE(CheckStateChangedCalled(true)); |
+ |
+ // Ensure that the policy is not refreshed after disconnecting the core, but |
+ // a call to indicate that invalidations are disabled is made. |
+ DisconnectCore(); |
+ EXPECT_TRUE(CheckPolicyNotRefreshed()); |
+ EXPECT_TRUE(CheckStateChangedCalled(false)); |
+ |
+ // Ensure that invalidation service events do not cause refreshes while the |
+ // invalidator is stopped. |
+ FireInvalidation(POLICY_OBJECT_A, 2, "test"); |
+ EXPECT_TRUE(CheckPolicyNotRefreshed()); |
+ DisableInvalidationService(); |
+ EXPECT_TRUE(CheckStateChangedNotCalled()); |
+ EnableInvalidationService(); |
+ EXPECT_TRUE(CheckStateChangedNotCalled()); |
+ |
+ // Connect and disconnect without starting the refresh scheduler. |
+ ConnectCore(); |
+ FireInvalidation(POLICY_OBJECT_A, 3, "test"); |
+ EXPECT_TRUE(CheckPolicyNotRefreshed()); |
+ DisconnectCore(); |
+ FireInvalidation(POLICY_OBJECT_A, 4, "test"); |
+ EXPECT_TRUE(CheckPolicyNotRefreshed()); |
+ |
+ // Ensure that the invalidator returns to normal after reconnecting. |
+ ConnectCore(); |
+ StartRefreshScheduler(); |
+ EXPECT_TRUE(CheckPolicyNotRefreshed()); |
+ EXPECT_TRUE(CheckStateChangedCalled(true)); |
+ FireInvalidation(POLICY_OBJECT_A, 5, "test"); |
+ EXPECT_TRUE(CheckInvalidationInfo(5, "test")); |
+ EXPECT_TRUE(CheckPolicyRefreshed(false /* unknown_version */)); |
+ DisableInvalidationService(); |
+ EXPECT_TRUE(CheckStateChangedCalled(false)); |
+} |
+ |
TEST_F(CloudPolicyInvalidatorTest, RefreshMetricsUnregistered) { |
// Store loads occurring before invalidation registration are not counted. |
StartInvalidator(); |