| 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 28 matching lines...) Expand all Loading... |
| 39 protected: | 39 protected: |
| 40 // Policy objects which can be used in tests. | 40 // Policy objects which can be used in tests. |
| 41 enum PolicyObject { | 41 enum PolicyObject { |
| 42 POLICY_OBJECT_NONE, | 42 POLICY_OBJECT_NONE, |
| 43 POLICY_OBJECT_A, | 43 POLICY_OBJECT_A, |
| 44 POLICY_OBJECT_B | 44 POLICY_OBJECT_B |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 CloudPolicyInvalidatorTest(); | 47 CloudPolicyInvalidatorTest(); |
| 48 | 48 |
| 49 virtual void SetUp() OVERRIDE; | |
| 50 | |
| 51 virtual void TearDown() OVERRIDE; | 49 virtual void TearDown() OVERRIDE; |
| 52 | 50 |
| 53 // Starts the invalidator which will be tested. | 51 // Starts the invalidator which will be tested. |
| 54 // |initialize| determines if the invalidator should be initialized. | 52 // |initialize| determines if the invalidator should be initialized. |
| 55 // |start_refresh_scheduler| determines if the refresh scheduler should start. | 53 // |start_refresh_scheduler| determines if the refresh scheduler should start. |
| 56 void StartInvalidator(bool initialize, bool start_refresh_scheduler); | 54 void StartInvalidator(bool initialize, bool start_refresh_scheduler); |
| 57 void StartInvalidator() { | 55 void StartInvalidator() { |
| 58 StartInvalidator(true /* initialize */, true /* start_refresh_scheduler */); | 56 StartInvalidator(true /* initialize */, true /* start_refresh_scheduler */); |
| 59 } | 57 } |
| 60 | 58 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 bool InvalidationsEnabled(); | 138 bool InvalidationsEnabled(); |
| 141 | 139 |
| 142 // Determines if the invalidation with the given ack handle has been | 140 // Determines if the invalidation with the given ack handle has been |
| 143 // acknowledged. | 141 // acknowledged. |
| 144 bool IsInvalidationAcknowledged(const syncer::Invalidation& invalidation); | 142 bool IsInvalidationAcknowledged(const syncer::Invalidation& invalidation); |
| 145 | 143 |
| 146 // Determines if the invalidator has registered for an object with the | 144 // Determines if the invalidator has registered for an object with the |
| 147 // invalidation service. | 145 // invalidation service. |
| 148 bool IsInvalidatorRegistered(); | 146 bool IsInvalidatorRegistered(); |
| 149 | 147 |
| 150 // Get the current count for the given metric. | |
| 151 base::HistogramBase::Count GetCount(MetricPolicyRefresh metric); | |
| 152 base::HistogramBase::Count GetInvalidationCount(PolicyInvalidationType type); | |
| 153 | |
| 154 // Advance the test clock. | 148 // Advance the test clock. |
| 155 void AdvanceClock(base::TimeDelta delta); | 149 void AdvanceClock(base::TimeDelta delta); |
| 156 | 150 |
| 157 // Get the current time on the test clock. | 151 // Get the current time on the test clock. |
| 158 base::Time Now(); | 152 base::Time Now(); |
| 159 | 153 |
| 160 // Translate a version number into an appropriate invalidation version (which | 154 // Translate a version number into an appropriate invalidation version (which |
| 161 // is based on the current time). | 155 // is based on the current time). |
| 162 int64 V(int version); | 156 int64 V(int version); |
| 163 | 157 |
| 164 // Get an invalidation version for the given time. | 158 // Get an invalidation version for the given time. |
| 165 int64 GetVersion(base::Time time); | 159 int64 GetVersion(base::Time time); |
| 166 | 160 |
| 161 // Whether the |invalidator_| is responsible for user policy (as opposed to |
| 162 // device policy). |
| 163 virtual bool IsHandlingUserPolicy() const; |
| 164 |
| 167 private: | 165 private: |
| 168 // Checks that the policy was refreshed due to an invalidation with the given | 166 // Checks that the policy was refreshed due to an invalidation with the given |
| 169 // base delay. | 167 // base delay. |
| 170 bool CheckPolicyRefreshed(base::TimeDelta delay); | 168 bool CheckPolicyRefreshed(base::TimeDelta delay); |
| 171 | 169 |
| 172 // Checks that the policy was refreshed the given number of times. | 170 // Checks that the policy was refreshed the given number of times. |
| 173 bool CheckPolicyRefreshCount(int count); | 171 bool CheckPolicyRefreshCount(int count); |
| 174 | 172 |
| 175 // Returns the object id of the given policy object. | 173 // Returns the object id of the given policy object. |
| 176 const invalidation::ObjectId& GetPolicyObjectId(PolicyObject object) const; | 174 const invalidation::ObjectId& GetPolicyObjectId(PolicyObject object) const; |
| 177 | 175 |
| 178 // Get histogram samples for the given histogram. | |
| 179 scoped_ptr<base::HistogramSamples> GetHistogramSamples( | |
| 180 const std::string& name) const; | |
| 181 | |
| 182 base::MessageLoop loop_; | 176 base::MessageLoop loop_; |
| 183 | 177 |
| 184 // Objects the invalidator depends on. | 178 // Objects the invalidator depends on. |
| 185 invalidation::FakeInvalidationService invalidation_service_; | 179 invalidation::FakeInvalidationService invalidation_service_; |
| 186 MockCloudPolicyStore store_; | 180 MockCloudPolicyStore store_; |
| 187 CloudPolicyCore core_; | 181 CloudPolicyCore core_; |
| 188 MockCloudPolicyClient* client_; | 182 MockCloudPolicyClient* client_; |
| 189 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 183 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
| 190 base::SimpleTestClock* clock_; | 184 base::SimpleTestClock* clock_; |
| 191 | 185 |
| 192 // The invalidator which will be tested. | 186 // The invalidator which will be tested. |
| 193 scoped_ptr<CloudPolicyInvalidator> invalidator_; | 187 scoped_ptr<CloudPolicyInvalidator> invalidator_; |
| 194 | 188 |
| 195 // Object ids for the test policy objects. | 189 // Object ids for the test policy objects. |
| 196 invalidation::ObjectId object_id_a_; | 190 invalidation::ObjectId object_id_a_; |
| 197 invalidation::ObjectId object_id_b_; | 191 invalidation::ObjectId object_id_b_; |
| 198 | 192 |
| 199 // Fake policy values which are alternated to cause the store to report a | 193 // Fake policy values which are alternated to cause the store to report a |
| 200 // changed policy. | 194 // changed policy. |
| 201 const char* policy_value_a_; | 195 const char* policy_value_a_; |
| 202 const char* policy_value_b_; | 196 const char* policy_value_b_; |
| 203 | 197 |
| 204 // The currently used policy value. | 198 // The currently used policy value. |
| 205 const char* policy_value_cur_; | 199 const char* policy_value_cur_; |
| 206 | |
| 207 // Stores starting histogram counts for kMetricPolicyRefresh. | |
| 208 scoped_ptr<base::HistogramSamples> refresh_samples_; | |
| 209 | |
| 210 // Stores starting histogram counts for kMetricPolicyInvalidations. | |
| 211 scoped_ptr<base::HistogramSamples> invalidations_samples_; | |
| 212 }; | 200 }; |
| 213 | 201 |
| 214 CloudPolicyInvalidatorTest::CloudPolicyInvalidatorTest() | 202 CloudPolicyInvalidatorTest::CloudPolicyInvalidatorTest() |
| 215 : core_(PolicyNamespaceKey(dm_protocol::kChromeUserPolicyType, | 203 : core_(PolicyNamespaceKey(dm_protocol::kChromeUserPolicyType, |
| 216 std::string()), | 204 std::string()), |
| 217 &store_, | 205 &store_, |
| 218 loop_.message_loop_proxy()), | 206 loop_.message_loop_proxy()), |
| 219 client_(NULL), | 207 client_(NULL), |
| 220 task_runner_(new base::TestSimpleTaskRunner()), | 208 task_runner_(new base::TestSimpleTaskRunner()), |
| 221 clock_(new base::SimpleTestClock()), | 209 clock_(new base::SimpleTestClock()), |
| 222 object_id_a_(135, "asdf"), | 210 object_id_a_(135, "asdf"), |
| 223 object_id_b_(246, "zxcv"), | 211 object_id_b_(246, "zxcv"), |
| 224 policy_value_a_("asdf"), | 212 policy_value_a_("asdf"), |
| 225 policy_value_b_("zxcv"), | 213 policy_value_b_("zxcv"), |
| 226 policy_value_cur_(policy_value_a_) { | 214 policy_value_cur_(policy_value_a_) { |
| 227 clock_->SetNow( | 215 clock_->SetNow( |
| 228 base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(987654321)); | 216 base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(987654321)); |
| 229 } | 217 } |
| 230 | 218 |
| 231 void CloudPolicyInvalidatorTest::SetUp() { | |
| 232 base::StatisticsRecorder::Initialize(); | |
| 233 refresh_samples_ = GetHistogramSamples(kMetricPolicyRefresh); | |
| 234 invalidations_samples_ = GetHistogramSamples(kMetricPolicyInvalidations); | |
| 235 } | |
| 236 | |
| 237 void CloudPolicyInvalidatorTest::TearDown() { | 219 void CloudPolicyInvalidatorTest::TearDown() { |
| 238 if (invalidator_) | 220 if (invalidator_) |
| 239 invalidator_->Shutdown(); | 221 invalidator_->Shutdown(); |
| 240 core_.Disconnect(); | 222 core_.Disconnect(); |
| 241 } | 223 } |
| 242 | 224 |
| 243 void CloudPolicyInvalidatorTest::StartInvalidator( | 225 void CloudPolicyInvalidatorTest::StartInvalidator( |
| 244 bool initialize, | 226 bool initialize, |
| 245 bool start_refresh_scheduler) { | 227 bool start_refresh_scheduler) { |
| 246 invalidator_.reset(new CloudPolicyInvalidator( | 228 invalidator_.reset(new CloudPolicyInvalidator( |
| 229 IsHandlingUserPolicy(), |
| 247 &core_, | 230 &core_, |
| 248 task_runner_, | 231 task_runner_, |
| 249 scoped_ptr<base::Clock>(clock_))); | 232 scoped_ptr<base::Clock>(clock_))); |
| 250 if (start_refresh_scheduler) { | 233 if (start_refresh_scheduler) { |
| 251 ConnectCore(); | 234 ConnectCore(); |
| 252 StartRefreshScheduler(); | 235 StartRefreshScheduler(); |
| 253 } | 236 } |
| 254 if (initialize) | 237 if (initialize) |
| 255 InitializeInvalidator(); | 238 InitializeInvalidator(); |
| 256 } | 239 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 | 364 |
| 382 EXPECT_FALSE(IsUnsent(invalidation)); | 365 EXPECT_FALSE(IsUnsent(invalidation)); |
| 383 return !invalidation_service_.GetMockAckHandler()->IsUnacked(invalidation); | 366 return !invalidation_service_.GetMockAckHandler()->IsUnacked(invalidation); |
| 384 } | 367 } |
| 385 | 368 |
| 386 bool CloudPolicyInvalidatorTest::IsInvalidatorRegistered() { | 369 bool CloudPolicyInvalidatorTest::IsInvalidatorRegistered() { |
| 387 return !invalidation_service_.invalidator_registrar() | 370 return !invalidation_service_.invalidator_registrar() |
| 388 .GetRegisteredIds(invalidator_.get()).empty(); | 371 .GetRegisteredIds(invalidator_.get()).empty(); |
| 389 } | 372 } |
| 390 | 373 |
| 391 base::HistogramBase::Count CloudPolicyInvalidatorTest::GetCount( | |
| 392 MetricPolicyRefresh metric) { | |
| 393 return GetHistogramSamples(kMetricPolicyRefresh)->GetCount(metric) - | |
| 394 refresh_samples_->GetCount(metric); | |
| 395 } | |
| 396 | |
| 397 base::HistogramBase::Count CloudPolicyInvalidatorTest::GetInvalidationCount( | |
| 398 PolicyInvalidationType type) { | |
| 399 return GetHistogramSamples(kMetricPolicyInvalidations)->GetCount(type) - | |
| 400 invalidations_samples_->GetCount(type); | |
| 401 } | |
| 402 | |
| 403 void CloudPolicyInvalidatorTest::AdvanceClock(base::TimeDelta delta) { | 374 void CloudPolicyInvalidatorTest::AdvanceClock(base::TimeDelta delta) { |
| 404 clock_->Advance(delta); | 375 clock_->Advance(delta); |
| 405 } | 376 } |
| 406 | 377 |
| 407 base::Time CloudPolicyInvalidatorTest::Now() { | 378 base::Time CloudPolicyInvalidatorTest::Now() { |
| 408 return clock_->Now(); | 379 return clock_->Now(); |
| 409 } | 380 } |
| 410 | 381 |
| 411 int64 CloudPolicyInvalidatorTest::V(int version) { | 382 int64 CloudPolicyInvalidatorTest::V(int version) { |
| 412 return GetVersion(Now()) + version; | 383 return GetVersion(Now()) + version; |
| 413 } | 384 } |
| 414 | 385 |
| 415 int64 CloudPolicyInvalidatorTest::GetVersion(base::Time time) { | 386 int64 CloudPolicyInvalidatorTest::GetVersion(base::Time time) { |
| 416 return (time - base::Time::UnixEpoch()).InMicroseconds(); | 387 return (time - base::Time::UnixEpoch()).InMicroseconds(); |
| 417 } | 388 } |
| 418 | 389 |
| 390 bool CloudPolicyInvalidatorTest::IsHandlingUserPolicy() const { |
| 391 return true; |
| 392 } |
| 393 |
| 419 bool CloudPolicyInvalidatorTest::CheckPolicyRefreshed(base::TimeDelta delay) { | 394 bool CloudPolicyInvalidatorTest::CheckPolicyRefreshed(base::TimeDelta delay) { |
| 420 base::TimeDelta max_delay = delay + base::TimeDelta::FromMilliseconds( | 395 base::TimeDelta max_delay = delay + base::TimeDelta::FromMilliseconds( |
| 421 CloudPolicyInvalidator::kMaxFetchDelayMin); | 396 CloudPolicyInvalidator::kMaxFetchDelayMin); |
| 422 | 397 |
| 423 if (task_runner_->GetPendingTasks().empty()) | 398 if (task_runner_->GetPendingTasks().empty()) |
| 424 return false; | 399 return false; |
| 425 base::TimeDelta actual_delay = task_runner_->GetPendingTasks().back().delay; | 400 base::TimeDelta actual_delay = task_runner_->GetPendingTasks().back().delay; |
| 426 EXPECT_GE(actual_delay, delay); | 401 EXPECT_GE(actual_delay, delay); |
| 427 EXPECT_LE(actual_delay, max_delay); | 402 EXPECT_LE(actual_delay, max_delay); |
| 428 | 403 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 446 base::RunLoop().RunUntilIdle(); | 421 base::RunLoop().RunUntilIdle(); |
| 447 return testing::Mock::VerifyAndClearExpectations(client_); | 422 return testing::Mock::VerifyAndClearExpectations(client_); |
| 448 } | 423 } |
| 449 | 424 |
| 450 const invalidation::ObjectId& CloudPolicyInvalidatorTest::GetPolicyObjectId( | 425 const invalidation::ObjectId& CloudPolicyInvalidatorTest::GetPolicyObjectId( |
| 451 PolicyObject object) const { | 426 PolicyObject object) const { |
| 452 EXPECT_TRUE(object == POLICY_OBJECT_A || object == POLICY_OBJECT_B); | 427 EXPECT_TRUE(object == POLICY_OBJECT_A || object == POLICY_OBJECT_B); |
| 453 return object == POLICY_OBJECT_A ? object_id_a_ : object_id_b_; | 428 return object == POLICY_OBJECT_A ? object_id_a_ : object_id_b_; |
| 454 } | 429 } |
| 455 | 430 |
| 456 scoped_ptr<base::HistogramSamples> | |
| 457 CloudPolicyInvalidatorTest::GetHistogramSamples( | |
| 458 const std::string& name) const { | |
| 459 base::HistogramBase* histogram = | |
| 460 base::StatisticsRecorder::FindHistogram(name); | |
| 461 if (!histogram) | |
| 462 return scoped_ptr<base::HistogramSamples>(new base::SampleMap()); | |
| 463 return histogram->SnapshotSamples(); | |
| 464 } | |
| 465 | |
| 466 TEST_F(CloudPolicyInvalidatorTest, Uninitialized) { | 431 TEST_F(CloudPolicyInvalidatorTest, Uninitialized) { |
| 467 // No invalidations should be processed if the invalidator is not initialized. | 432 // No invalidations should be processed if the invalidator is not initialized. |
| 468 StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */); | 433 StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */); |
| 469 StorePolicy(POLICY_OBJECT_A); | 434 StorePolicy(POLICY_OBJECT_A); |
| 470 EXPECT_FALSE(IsInvalidatorRegistered()); | 435 EXPECT_FALSE(IsInvalidatorRegistered()); |
| 471 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A))); | 436 EXPECT_TRUE(IsUnsent(FireUnknownVersionInvalidation(POLICY_OBJECT_A))); |
| 472 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 437 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 473 } | 438 } |
| 474 | 439 |
| 475 TEST_F(CloudPolicyInvalidatorTest, RefreshSchedulerNotStarted) { | 440 TEST_F(CloudPolicyInvalidatorTest, RefreshSchedulerNotStarted) { |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 StartRefreshScheduler(); | 753 StartRefreshScheduler(); |
| 789 EXPECT_TRUE(CheckPolicyNotRefreshed()); | 754 EXPECT_TRUE(CheckPolicyNotRefreshed()); |
| 790 EXPECT_TRUE(InvalidationsEnabled()); | 755 EXPECT_TRUE(InvalidationsEnabled()); |
| 791 FireInvalidation(POLICY_OBJECT_A, V(5), "test"); | 756 FireInvalidation(POLICY_OBJECT_A, V(5), "test"); |
| 792 EXPECT_TRUE(CheckInvalidationInfo(V(5), "test")); | 757 EXPECT_TRUE(CheckInvalidationInfo(V(5), "test")); |
| 793 EXPECT_TRUE(CheckPolicyRefreshed()); | 758 EXPECT_TRUE(CheckPolicyRefreshed()); |
| 794 DisableInvalidationService(); | 759 DisableInvalidationService(); |
| 795 EXPECT_FALSE(InvalidationsEnabled()); | 760 EXPECT_FALSE(InvalidationsEnabled()); |
| 796 } | 761 } |
| 797 | 762 |
| 798 TEST_F(CloudPolicyInvalidatorTest, RefreshMetricsUnregistered) { | 763 class CloudPolicyInvalidatorUserAndDevicePolicyTest |
| 764 : public CloudPolicyInvalidatorTest, |
| 765 public ::testing::WithParamInterface<bool> { |
| 766 protected: |
| 767 // CloudPolicyInvalidatorTest: |
| 768 virtual void SetUp() OVERRIDE; |
| 769 |
| 770 // Get the current count for the given metric. |
| 771 base::HistogramBase::Count GetCount(MetricPolicyRefresh metric); |
| 772 base::HistogramBase::Count GetInvalidationCount(PolicyInvalidationType type); |
| 773 |
| 774 private: |
| 775 // CloudPolicyInvalidatorTest: |
| 776 virtual bool IsHandlingUserPolicy() const OVERRIDE; |
| 777 |
| 778 // Get histogram samples for the given histogram. |
| 779 scoped_ptr<base::HistogramSamples> GetHistogramSamples( |
| 780 const std::string& name) const; |
| 781 |
| 782 // Stores starting histogram counts for kMetricPolicyRefresh. |
| 783 scoped_ptr<base::HistogramSamples> refresh_samples_; |
| 784 |
| 785 // Stores starting histogram counts for kMetricPolicyInvalidations. |
| 786 scoped_ptr<base::HistogramSamples> invalidations_samples_; |
| 787 }; |
| 788 |
| 789 void CloudPolicyInvalidatorUserAndDevicePolicyTest::SetUp() { |
| 790 base::StatisticsRecorder::Initialize(); |
| 791 refresh_samples_ = GetHistogramSamples( |
| 792 IsHandlingUserPolicy() ? kMetricUserPolicyRefresh |
| 793 : kMetricDevicePolicyRefresh); |
| 794 invalidations_samples_ = GetHistogramSamples( |
| 795 IsHandlingUserPolicy() ? kMetricUserPolicyInvalidations |
| 796 : kMetricDevicePolicyInvalidations); |
| 797 } |
| 798 |
| 799 base::HistogramBase::Count |
| 800 CloudPolicyInvalidatorUserAndDevicePolicyTest::GetCount( |
| 801 MetricPolicyRefresh metric) { |
| 802 return GetHistogramSamples( |
| 803 IsHandlingUserPolicy() ? kMetricUserPolicyRefresh : |
| 804 kMetricDevicePolicyRefresh)->GetCount(metric) - |
| 805 refresh_samples_->GetCount(metric); |
| 806 } |
| 807 |
| 808 base::HistogramBase::Count |
| 809 CloudPolicyInvalidatorUserAndDevicePolicyTest::GetInvalidationCount( |
| 810 PolicyInvalidationType type) { |
| 811 return GetHistogramSamples( |
| 812 IsHandlingUserPolicy() ? kMetricUserPolicyInvalidations |
| 813 : kMetricDevicePolicyInvalidations)-> |
| 814 GetCount(type) - invalidations_samples_->GetCount(type); |
| 815 } |
| 816 |
| 817 bool |
| 818 CloudPolicyInvalidatorUserAndDevicePolicyTest::IsHandlingUserPolicy() const { |
| 819 return GetParam(); |
| 820 } |
| 821 |
| 822 scoped_ptr<base::HistogramSamples> |
| 823 CloudPolicyInvalidatorUserAndDevicePolicyTest::GetHistogramSamples( |
| 824 const std::string& name) const { |
| 825 base::HistogramBase* histogram = |
| 826 base::StatisticsRecorder::FindHistogram(name); |
| 827 if (!histogram) |
| 828 return scoped_ptr<base::HistogramSamples>(new base::SampleMap()); |
| 829 return histogram->SnapshotSamples(); |
| 830 } |
| 831 |
| 832 TEST_P(CloudPolicyInvalidatorUserAndDevicePolicyTest, |
| 833 RefreshMetricsUnregistered) { |
| 799 // Store loads occurring before invalidation registration are not counted. | 834 // Store loads occurring before invalidation registration are not counted. |
| 800 StartInvalidator(); | 835 StartInvalidator(); |
| 801 StorePolicy(POLICY_OBJECT_NONE, 0, false /* policy_changed */); | 836 StorePolicy(POLICY_OBJECT_NONE, 0, false /* policy_changed */); |
| 802 StorePolicy(POLICY_OBJECT_NONE, 0, true /* policy_changed */); | 837 StorePolicy(POLICY_OBJECT_NONE, 0, true /* policy_changed */); |
| 803 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_CHANGED)); | 838 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_CHANGED)); |
| 804 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS)); | 839 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS)); |
| 805 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_UNCHANGED)); | 840 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_UNCHANGED)); |
| 806 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED)); | 841 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED)); |
| 807 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED)); | 842 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED)); |
| 808 } | 843 } |
| 809 | 844 |
| 810 TEST_F(CloudPolicyInvalidatorTest, RefreshMetricsNoInvalidations) { | 845 TEST_P(CloudPolicyInvalidatorUserAndDevicePolicyTest, |
| 846 RefreshMetricsNoInvalidations) { |
| 811 // Store loads occurring while registered should be differentiated depending | 847 // Store loads occurring while registered should be differentiated depending |
| 812 // on whether the invalidation service was enabled or not. | 848 // on whether the invalidation service was enabled or not. |
| 813 StorePolicy(POLICY_OBJECT_A); | 849 StorePolicy(POLICY_OBJECT_A); |
| 814 StartInvalidator(); | 850 StartInvalidator(); |
| 815 | 851 |
| 816 // Initially, invalidations have not been enabled past the grace period, so | 852 // Initially, invalidations have not been enabled past the grace period, so |
| 817 // invalidations are OFF. | 853 // invalidations are OFF. |
| 818 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); | 854 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); |
| 819 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */); | 855 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */); |
| 820 EXPECT_EQ(1, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS)); | 856 EXPECT_EQ(1, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 851 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); | 887 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); |
| 852 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */); | 888 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */); |
| 853 | 889 |
| 854 EXPECT_EQ(2, GetCount(METRIC_POLICY_REFRESH_CHANGED)); | 890 EXPECT_EQ(2, GetCount(METRIC_POLICY_REFRESH_CHANGED)); |
| 855 EXPECT_EQ(4, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS)); | 891 EXPECT_EQ(4, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS)); |
| 856 EXPECT_EQ(6, GetCount(METRIC_POLICY_REFRESH_UNCHANGED)); | 892 EXPECT_EQ(6, GetCount(METRIC_POLICY_REFRESH_UNCHANGED)); |
| 857 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED)); | 893 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED)); |
| 858 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED)); | 894 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED)); |
| 859 } | 895 } |
| 860 | 896 |
| 861 TEST_F(CloudPolicyInvalidatorTest, RefreshMetricsInvalidation) { | 897 TEST_P(CloudPolicyInvalidatorUserAndDevicePolicyTest, |
| 898 RefreshMetricsInvalidation) { |
| 862 // Store loads after an invalidation are counted as invalidated, even if | 899 // Store loads after an invalidation are counted as invalidated, even if |
| 863 // the loads do not result in the invalidation being acknowledged. | 900 // the loads do not result in the invalidation being acknowledged. |
| 864 StartInvalidator(); | 901 StartInvalidator(); |
| 865 StorePolicy(POLICY_OBJECT_A); | 902 StorePolicy(POLICY_OBJECT_A); |
| 866 AdvanceClock(base::TimeDelta::FromSeconds( | 903 AdvanceClock(base::TimeDelta::FromSeconds( |
| 867 CloudPolicyInvalidator::kInvalidationGracePeriod)); | 904 CloudPolicyInvalidator::kInvalidationGracePeriod)); |
| 868 FireInvalidation(POLICY_OBJECT_A, V(5), "test"); | 905 FireInvalidation(POLICY_OBJECT_A, V(5), "test"); |
| 869 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); | 906 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); |
| 870 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */); | 907 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */); |
| 871 StorePolicy(POLICY_OBJECT_A, V(5), true /* policy_changed */); | 908 StorePolicy(POLICY_OBJECT_A, V(5), true /* policy_changed */); |
| 872 | 909 |
| 873 // Store loads after the invalidation is complete are not counted as | 910 // Store loads after the invalidation is complete are not counted as |
| 874 // invalidated. | 911 // invalidated. |
| 875 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); | 912 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); |
| 876 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */); | 913 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */); |
| 877 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); | 914 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); |
| 878 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */); | 915 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */); |
| 879 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); | 916 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); |
| 880 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */); | 917 StorePolicy(POLICY_OBJECT_A, 0, true /* policy_changed */); |
| 881 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); | 918 StorePolicy(POLICY_OBJECT_A, 0, false /* policy_changed */); |
| 882 | 919 |
| 883 EXPECT_EQ(3, GetCount(METRIC_POLICY_REFRESH_CHANGED)); | 920 EXPECT_EQ(3, GetCount(METRIC_POLICY_REFRESH_CHANGED)); |
| 884 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS)); | 921 EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS)); |
| 885 EXPECT_EQ(4, GetCount(METRIC_POLICY_REFRESH_UNCHANGED)); | 922 EXPECT_EQ(4, GetCount(METRIC_POLICY_REFRESH_UNCHANGED)); |
| 886 EXPECT_EQ(2, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED)); | 923 EXPECT_EQ(2, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_CHANGED)); |
| 887 EXPECT_EQ(1, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED)); | 924 EXPECT_EQ(1, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED)); |
| 888 } | 925 } |
| 889 | 926 |
| 890 TEST_F(CloudPolicyInvalidatorTest, ExpiredInvalidations) { | 927 TEST_P(CloudPolicyInvalidatorUserAndDevicePolicyTest, ExpiredInvalidations) { |
| 891 StorePolicy(POLICY_OBJECT_A, 0, false, Now()); | 928 StorePolicy(POLICY_OBJECT_A, 0, false, Now()); |
| 892 StartInvalidator(); | 929 StartInvalidator(); |
| 893 | 930 |
| 894 // Invalidations fired before the last fetch time (adjusted by max time delta) | 931 // Invalidations fired before the last fetch time (adjusted by max time delta) |
| 895 // should be ignored. | 932 // should be ignored. |
| 896 base::Time time = Now() - base::TimeDelta::FromSeconds( | 933 base::Time time = Now() - base::TimeDelta::FromSeconds( |
| 897 CloudPolicyInvalidator::kMaxInvalidationTimeDelta + 300); | 934 CloudPolicyInvalidator::kMaxInvalidationTimeDelta + 300); |
| 898 syncer::Invalidation inv = | 935 syncer::Invalidation inv = |
| 899 FireInvalidation(POLICY_OBJECT_A, GetVersion(time), "test"); | 936 FireInvalidation(POLICY_OBJECT_A, GetVersion(time), "test"); |
| 900 ASSERT_TRUE(IsInvalidationAcknowledged(inv)); | 937 ASSERT_TRUE(IsInvalidationAcknowledged(inv)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 ASSERT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); | 978 ASSERT_TRUE(CheckPolicyRefreshedWithUnknownVersion()); |
| 942 | 979 |
| 943 // Verify that received invalidations metrics are correct. | 980 // Verify that received invalidations metrics are correct. |
| 944 EXPECT_EQ(1, GetInvalidationCount(POLICY_INVALIDATION_TYPE_NO_PAYLOAD)); | 981 EXPECT_EQ(1, GetInvalidationCount(POLICY_INVALIDATION_TYPE_NO_PAYLOAD)); |
| 945 EXPECT_EQ(3, GetInvalidationCount(POLICY_INVALIDATION_TYPE_NORMAL)); | 982 EXPECT_EQ(3, GetInvalidationCount(POLICY_INVALIDATION_TYPE_NORMAL)); |
| 946 EXPECT_EQ(2, | 983 EXPECT_EQ(2, |
| 947 GetInvalidationCount(POLICY_INVALIDATION_TYPE_NO_PAYLOAD_EXPIRED)); | 984 GetInvalidationCount(POLICY_INVALIDATION_TYPE_NO_PAYLOAD_EXPIRED)); |
| 948 EXPECT_EQ(2, GetInvalidationCount(POLICY_INVALIDATION_TYPE_EXPIRED)); | 985 EXPECT_EQ(2, GetInvalidationCount(POLICY_INVALIDATION_TYPE_EXPIRED)); |
| 949 } | 986 } |
| 950 | 987 |
| 988 INSTANTIATE_TEST_CASE_P(CloudPolicyInvalidatorUserAndDevicePolicyTestInstance, |
| 989 CloudPolicyInvalidatorUserAndDevicePolicyTest, |
| 990 testing::Bool()); |
| 991 |
| 951 } // namespace policy | 992 } // namespace policy |
| OLD | NEW |