| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/metrics/statistics_recorder.h" | 9 #include "base/metrics/statistics_recorder.h" |
| 10 #include "base/metrics/user_metrics.h" | 10 #include "base/metrics/user_metrics.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 const char* name; | 31 const char* name; |
| 32 base::HistogramType type; | 32 base::HistogramType type; |
| 33 int min; | 33 int min; |
| 34 int max; | 34 int max; |
| 35 size_t buckets; | 35 size_t buckets; |
| 36 int count; | 36 int count; |
| 37 } g_histograms[] = { | 37 } g_histograms[] = { |
| 38 {"test.h.1", base::HISTOGRAM, 1, 100, 50, 1}, // custom | 38 {"test.h.1", base::HISTOGRAM, 1, 100, 50, 1}, // custom |
| 39 {"test.h.2", base::LINEAR_HISTOGRAM, 1, 200, 50, 1}, // custom | 39 {"test.h.2", base::LINEAR_HISTOGRAM, 1, 200, 50, 1}, // custom |
| 40 {"test.h.3", base::LINEAR_HISTOGRAM, 1, 101, 102, 2}, // percentage | 40 {"test.h.3", base::LINEAR_HISTOGRAM, 1, 101, 102, 2}, // percentage |
| 41 {"test.sparse.1", base::SPARSE_HISTOGRAM, 0, 0, 0, 1}, |
| 42 {"test.sparse.2", base::SPARSE_HISTOGRAM, 0, 0, 0, 2}, |
| 41 {"test.time", base::HISTOGRAM, 1, 10000, 50, 1}, | 43 {"test.time", base::HISTOGRAM, 1, 10000, 50, 1}, |
| 42 {"test.medium.time", base::HISTOGRAM, 1, 180000, 50, 1}, | 44 {"test.medium.time", base::HISTOGRAM, 1, 180000, 50, 1}, |
| 43 {"test.long.time", base::HISTOGRAM, 1, 3600000, 50, 1}, | 45 {"test.long.time", base::HISTOGRAM, 1, 3600000, 50, 1}, |
| 44 {"test.count", base::HISTOGRAM, 1, 1000000, 50, 1}, | 46 {"test.count", base::HISTOGRAM, 1, 1000000, 50, 1}, |
| 45 {"test.medium.count", base::HISTOGRAM, 1, 10000, 50, 1}, | 47 {"test.medium.count", base::HISTOGRAM, 1, 10000, 50, 1}, |
| 46 {"test.small.count", base::HISTOGRAM, 1, 100, 50, 1}, | 48 {"test.small.count", base::HISTOGRAM, 1, 100, 50, 1}, |
| 47 {"test.bucketchange.linear", base::LINEAR_HISTOGRAM, 1, 100, 10, 2}, | 49 {"test.bucketchange.linear", base::LINEAR_HISTOGRAM, 1, 100, 10, 2}, |
| 48 {"test.bucketchange.log", base::HISTOGRAM, 1, 100, 10, 2}, }; | 50 {"test.bucketchange.log", base::HISTOGRAM, 1, 100, 10, 2}, }; |
| 49 | 51 |
| 50 // This class observes and collects user action notifications that are sent | 52 // This class observes and collects user action notifications that are sent |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // expect to see are present in the list, and that their basic info is | 111 // expect to see are present in the list, and that their basic info is |
| 110 // correct. | 112 // correct. |
| 111 for (int i = 0; i < count; ++i) { | 113 for (int i = 0; i < count; ++i) { |
| 112 const RecordedHistogram& r = recorded[i]; | 114 const RecordedHistogram& r = recorded[i]; |
| 113 size_t j = 0; | 115 size_t j = 0; |
| 114 for (j = 0; j < histograms.size(); ++j) { | 116 for (j = 0; j < histograms.size(); ++j) { |
| 115 base::HistogramBase* histogram(histograms[j]); | 117 base::HistogramBase* histogram(histograms[j]); |
| 116 | 118 |
| 117 if (r.name == histogram->histogram_name()) { | 119 if (r.name == histogram->histogram_name()) { |
| 118 EXPECT_EQ(r.type, histogram->GetHistogramType()); | 120 EXPECT_EQ(r.type, histogram->GetHistogramType()); |
| 119 EXPECT_TRUE( | 121 if (r.type == base::SPARSE_HISTOGRAM) { |
| 120 histogram->HasConstructionArguments(r.min, r.max, r.buckets)); | 122 EXPECT_FALSE( |
| 123 histogram->HasConstructionArguments(r.min, r.max, r.buckets)); |
| 124 } else { |
| 125 EXPECT_TRUE( |
| 126 histogram->HasConstructionArguments(r.min, r.max, r.buckets)); |
| 127 } |
| 121 scoped_ptr<base::HistogramSamples> snapshot = | 128 scoped_ptr<base::HistogramSamples> snapshot = |
| 122 histogram->SnapshotSamples(); | 129 histogram->SnapshotSamples(); |
| 123 base::HistogramBase::Count sample_count = snapshot->TotalCount(); | 130 base::HistogramBase::Count sample_count = snapshot->TotalCount(); |
| 124 EXPECT_EQ(sample_count, r.count); | 131 EXPECT_EQ(sample_count, r.count); |
| 125 break; | 132 break; |
| 126 } | 133 } |
| 127 } | 134 } |
| 128 EXPECT_LT(j, histograms.size()); | 135 EXPECT_LT(j, histograms.size()); |
| 129 } | 136 } |
| 130 } | 137 } |
| 131 | 138 |
| 132 } // anonymous namespace | 139 } // anonymous namespace |
| 133 | 140 |
| 134 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Metrics) { | 141 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Metrics) { |
| 135 UserActionObserver observer; | 142 UserActionObserver observer; |
| 136 | 143 |
| 137 base::FieldTrialList::CreateFieldTrial("apitestfieldtrial2", "group1"); | 144 base::FieldTrialList::CreateFieldTrial("apitestfieldtrial2", "group1"); |
| 138 | 145 |
| 139 std::map<std::string, std::string> params; | 146 std::map<std::string, std::string> params; |
| 140 params["a"] = "aa"; | 147 params["a"] = "aa"; |
| 141 params["b"] = "bb"; | 148 params["b"] = "bb"; |
| 142 ASSERT_TRUE(chrome_variations::AssociateVariationParams( | 149 ASSERT_TRUE(chrome_variations::AssociateVariationParams( |
| 143 "apitestfieldtrial2", "group1", params)); | 150 "apitestfieldtrial2", "group1", params)); |
| 144 | 151 |
| 145 ASSERT_TRUE(RunComponentExtensionTest("metrics")) << message_; | 152 ASSERT_TRUE(RunComponentExtensionTest("metrics")) << message_; |
| 146 | 153 |
| 147 observer.ValidateUserActions(g_user_actions, arraysize(g_user_actions)); | 154 observer.ValidateUserActions(g_user_actions, arraysize(g_user_actions)); |
| 148 ValidateHistograms(g_histograms, arraysize(g_histograms)); | 155 ValidateHistograms(g_histograms, arraysize(g_histograms)); |
| 149 } | 156 } |
| OLD | NEW |