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

Unified Diff: chrome/browser/policy/cloud/cloud_policy_invalidator_unittest.cc

Issue 465433002: Separate UMA histograms for user and device policy invalidation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 75f7ec41acda48d0483228d4143d754b47b62e86..50039f0c29fcde8314ec14d8995642a31dd69559 100644
--- a/chrome/browser/policy/cloud/cloud_policy_invalidator_unittest.cc
+++ b/chrome/browser/policy/cloud/cloud_policy_invalidator_unittest.cc
@@ -46,8 +46,6 @@ class CloudPolicyInvalidatorTest : public testing::Test {
CloudPolicyInvalidatorTest();
- virtual void SetUp() OVERRIDE;
-
virtual void TearDown() OVERRIDE;
// Starts the invalidator which will be tested.
@@ -147,10 +145,6 @@ class CloudPolicyInvalidatorTest : public testing::Test {
// invalidation service.
bool IsInvalidatorRegistered();
- // Get the current count for the given metric.
- base::HistogramBase::Count GetCount(MetricPolicyRefresh metric);
- base::HistogramBase::Count GetInvalidationCount(PolicyInvalidationType type);
-
// Advance the test clock.
void AdvanceClock(base::TimeDelta delta);
@@ -164,6 +158,10 @@ class CloudPolicyInvalidatorTest : public testing::Test {
// Get an invalidation version for the given time.
int64 GetVersion(base::Time time);
+ // Whether the |invalidator_| is responsible for user policy (as opposed to
+ // device policy).
+ virtual bool IsHandlingUserPolicy() const;
+
private:
// Checks that the policy was refreshed due to an invalidation with the given
// base delay.
@@ -175,10 +173,6 @@ class CloudPolicyInvalidatorTest : public testing::Test {
// Returns the object id of the given policy object.
const invalidation::ObjectId& GetPolicyObjectId(PolicyObject object) const;
- // Get histogram samples for the given histogram.
- scoped_ptr<base::HistogramSamples> GetHistogramSamples(
- const std::string& name) const;
-
base::MessageLoop loop_;
// Objects the invalidator depends on.
@@ -203,12 +197,6 @@ class CloudPolicyInvalidatorTest : public testing::Test {
// The currently used policy value.
const char* policy_value_cur_;
-
- // Stores starting histogram counts for kMetricPolicyRefresh.
- scoped_ptr<base::HistogramSamples> refresh_samples_;
-
- // Stores starting histogram counts for kMetricPolicyInvalidations.
- scoped_ptr<base::HistogramSamples> invalidations_samples_;
};
CloudPolicyInvalidatorTest::CloudPolicyInvalidatorTest()
@@ -228,12 +216,6 @@ CloudPolicyInvalidatorTest::CloudPolicyInvalidatorTest()
base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(987654321));
}
-void CloudPolicyInvalidatorTest::SetUp() {
- base::StatisticsRecorder::Initialize();
- refresh_samples_ = GetHistogramSamples(kMetricPolicyRefresh);
- invalidations_samples_ = GetHistogramSamples(kMetricPolicyInvalidations);
-}
-
void CloudPolicyInvalidatorTest::TearDown() {
if (invalidator_)
invalidator_->Shutdown();
@@ -244,6 +226,7 @@ void CloudPolicyInvalidatorTest::StartInvalidator(
bool initialize,
bool start_refresh_scheduler) {
invalidator_.reset(new CloudPolicyInvalidator(
+ IsHandlingUserPolicy(),
&core_,
task_runner_,
scoped_ptr<base::Clock>(clock_)));
@@ -388,18 +371,6 @@ bool CloudPolicyInvalidatorTest::IsInvalidatorRegistered() {
.GetRegisteredIds(invalidator_.get()).empty();
}
-base::HistogramBase::Count CloudPolicyInvalidatorTest::GetCount(
- MetricPolicyRefresh metric) {
- return GetHistogramSamples(kMetricPolicyRefresh)->GetCount(metric) -
- refresh_samples_->GetCount(metric);
-}
-
-base::HistogramBase::Count CloudPolicyInvalidatorTest::GetInvalidationCount(
- PolicyInvalidationType type) {
- return GetHistogramSamples(kMetricPolicyInvalidations)->GetCount(type) -
- invalidations_samples_->GetCount(type);
-}
-
void CloudPolicyInvalidatorTest::AdvanceClock(base::TimeDelta delta) {
clock_->Advance(delta);
}
@@ -416,6 +387,10 @@ int64 CloudPolicyInvalidatorTest::GetVersion(base::Time time) {
return (time - base::Time::UnixEpoch()).InMicroseconds();
}
+bool CloudPolicyInvalidatorTest::IsHandlingUserPolicy() const {
+ return true;
+}
+
bool CloudPolicyInvalidatorTest::CheckPolicyRefreshed(base::TimeDelta delay) {
base::TimeDelta max_delay = delay + base::TimeDelta::FromMilliseconds(
CloudPolicyInvalidator::kMaxFetchDelayMin);
@@ -453,16 +428,6 @@ const invalidation::ObjectId& CloudPolicyInvalidatorTest::GetPolicyObjectId(
return object == POLICY_OBJECT_A ? object_id_a_ : object_id_b_;
}
-scoped_ptr<base::HistogramSamples>
- CloudPolicyInvalidatorTest::GetHistogramSamples(
- const std::string& name) const {
- base::HistogramBase* histogram =
- base::StatisticsRecorder::FindHistogram(name);
- if (!histogram)
- return scoped_ptr<base::HistogramSamples>(new base::SampleMap());
- return histogram->SnapshotSamples();
-}
-
TEST_F(CloudPolicyInvalidatorTest, Uninitialized) {
// No invalidations should be processed if the invalidator is not initialized.
StartInvalidator(false /* initialize */, true /* start_refresh_scheduler */);
@@ -795,7 +760,77 @@ TEST_F(CloudPolicyInvalidatorTest, Disconnect) {
EXPECT_FALSE(InvalidationsEnabled());
}
-TEST_F(CloudPolicyInvalidatorTest, RefreshMetricsUnregistered) {
+class CloudPolicyInvalidatorUserAndDevicePolicyTest
+ : public CloudPolicyInvalidatorTest,
+ public ::testing::WithParamInterface<bool> {
+ protected:
+ // CloudPolicyInvalidatorTest:
+ virtual void SetUp() OVERRIDE;
+
+ // Get the current count for the given metric.
+ base::HistogramBase::Count GetCount(MetricPolicyRefresh metric);
+ base::HistogramBase::Count GetInvalidationCount(PolicyInvalidationType type);
+
+ private:
+ // CloudPolicyInvalidatorTest:
+ virtual bool IsHandlingUserPolicy() const OVERRIDE;
+
+ // Get histogram samples for the given histogram.
+ scoped_ptr<base::HistogramSamples> GetHistogramSamples(
+ const std::string& name) const;
+
+ // Stores starting histogram counts for kMetricPolicyRefresh.
+ scoped_ptr<base::HistogramSamples> refresh_samples_;
+
+ // Stores starting histogram counts for kMetricPolicyInvalidations.
+ scoped_ptr<base::HistogramSamples> invalidations_samples_;
+};
+
+void CloudPolicyInvalidatorUserAndDevicePolicyTest::SetUp() {
+ base::StatisticsRecorder::Initialize();
+ refresh_samples_ = GetHistogramSamples(
+ IsHandlingUserPolicy() ? kMetricUserPolicyRefresh
+ : kMetricDevicePolicyRefresh);
+ invalidations_samples_ = GetHistogramSamples(
+ IsHandlingUserPolicy() ? kMetricUserPolicyInvalidations
+ : kMetricDevicePolicyInvalidations);
+}
+
+base::HistogramBase::Count
+CloudPolicyInvalidatorUserAndDevicePolicyTest::GetCount(
+ MetricPolicyRefresh metric) {
+ return GetHistogramSamples(
+ IsHandlingUserPolicy() ? kMetricUserPolicyRefresh :
+ kMetricDevicePolicyRefresh)->GetCount(metric) -
+ refresh_samples_->GetCount(metric);
+}
+
+base::HistogramBase::Count
+CloudPolicyInvalidatorUserAndDevicePolicyTest::GetInvalidationCount(
+ PolicyInvalidationType type) {
+ return GetHistogramSamples(
+ IsHandlingUserPolicy() ? kMetricUserPolicyInvalidations
+ : kMetricDevicePolicyInvalidations)->
+ GetCount(type) - invalidations_samples_->GetCount(type);
+}
+
+bool
+CloudPolicyInvalidatorUserAndDevicePolicyTest::IsHandlingUserPolicy() const {
+ return GetParam();
+}
+
+scoped_ptr<base::HistogramSamples>
+CloudPolicyInvalidatorUserAndDevicePolicyTest::GetHistogramSamples(
+ const std::string& name) const {
+ base::HistogramBase* histogram =
+ base::StatisticsRecorder::FindHistogram(name);
+ if (!histogram)
+ return scoped_ptr<base::HistogramSamples>(new base::SampleMap());
+ return histogram->SnapshotSamples();
+}
+
+TEST_P(CloudPolicyInvalidatorUserAndDevicePolicyTest,
+ RefreshMetricsUnregistered) {
// Store loads occurring before invalidation registration are not counted.
StartInvalidator();
StorePolicy(POLICY_OBJECT_NONE, 0, false /* policy_changed */);
@@ -807,7 +842,8 @@ TEST_F(CloudPolicyInvalidatorTest, RefreshMetricsUnregistered) {
EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED));
}
-TEST_F(CloudPolicyInvalidatorTest, RefreshMetricsNoInvalidations) {
+TEST_P(CloudPolicyInvalidatorUserAndDevicePolicyTest,
+ RefreshMetricsNoInvalidations) {
// Store loads occurring while registered should be differentiated depending
// on whether the invalidation service was enabled or not.
StorePolicy(POLICY_OBJECT_A);
@@ -858,7 +894,8 @@ TEST_F(CloudPolicyInvalidatorTest, RefreshMetricsNoInvalidations) {
EXPECT_EQ(0, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED));
}
-TEST_F(CloudPolicyInvalidatorTest, RefreshMetricsInvalidation) {
+TEST_P(CloudPolicyInvalidatorUserAndDevicePolicyTest,
+ RefreshMetricsInvalidation) {
// Store loads after an invalidation are counted as invalidated, even if
// the loads do not result in the invalidation being acknowledged.
StartInvalidator();
@@ -887,7 +924,7 @@ TEST_F(CloudPolicyInvalidatorTest, RefreshMetricsInvalidation) {
EXPECT_EQ(1, GetCount(METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED));
}
-TEST_F(CloudPolicyInvalidatorTest, ExpiredInvalidations) {
+TEST_P(CloudPolicyInvalidatorUserAndDevicePolicyTest, ExpiredInvalidations) {
StorePolicy(POLICY_OBJECT_A, 0, false, Now());
StartInvalidator();
@@ -948,4 +985,8 @@ TEST_F(CloudPolicyInvalidatorTest, ExpiredInvalidations) {
EXPECT_EQ(2, GetInvalidationCount(POLICY_INVALIDATION_TYPE_EXPIRED));
}
+INSTANTIATE_TEST_CASE_P(CloudPolicyInvalidatorUserAndDevicePolicyTestInstance,
+ CloudPolicyInvalidatorUserAndDevicePolicyTest,
+ testing::Bool());
+
} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698