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 15 matching lines...) Expand all Loading... | |
26 | 26 |
27 // The tests that are run by this extension are expected to record the following | 27 // The tests that are run by this extension are expected to record the following |
28 // histograms. If the tests in test.js are modified, this array may need to be | 28 // histograms. If the tests in test.js are modified, this array may need to be |
29 // updated. | 29 // updated. |
30 struct RecordedHistogram { | 30 struct RecordedHistogram { |
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 } g_histograms[] = { | 37 } g_histograms[] = { |
37 {"test.h.1", base::HISTOGRAM, 1, 100, 50}, // custom | 38 {"test.h.1", base::HISTOGRAM, 1, 100, 50, 1}, // custom |
38 {"test.h.2", base::LINEAR_HISTOGRAM, 1, 200, 50}, // custom | 39 {"test.h.2", base::LINEAR_HISTOGRAM, 1, 200, 50, 1}, // custom |
39 {"test.h.3", base::LINEAR_HISTOGRAM, 1, 101, 102}, // percentage | 40 {"test.h.3", base::LINEAR_HISTOGRAM, 1, 101, 102, 2}, // percentage |
40 {"test.time", base::HISTOGRAM, 1, 10000, 50}, | 41 {"test.time", base::HISTOGRAM, 1, 10000, 50, 1}, |
41 {"test.medium.time", base::HISTOGRAM, 1, 180000, 50}, | 42 {"test.medium.time", base::HISTOGRAM, 1, 180000, 50, 1}, |
42 {"test.long.time", base::HISTOGRAM, 1, 3600000, 50}, | 43 {"test.long.time", base::HISTOGRAM, 1, 3600000, 50, 1}, |
43 {"test.count", base::HISTOGRAM, 1, 1000000, 50}, | 44 {"test.count", base::HISTOGRAM, 1, 1000000, 50, 1}, |
44 {"test.medium.count", base::HISTOGRAM, 1, 10000, 50}, | 45 {"test.medium.count", base::HISTOGRAM, 1, 10000, 50, 1}, |
45 {"test.small.count", base::HISTOGRAM, 1, 100, 50}, | 46 {"test.small.count", base::HISTOGRAM, 1, 100, 50, 1}, |
47 {"test.bucketchange.linear", base::LINEAR_HISTOGRAM, 1, 100, 10, 2}, | |
Alexei Svitkine (slow)
2014/01/17 15:40:13
Can you also add tests for this to histogram_unitt
elijahtaylor1
2014/01/17 20:04:16
Done.
| |
48 {"test.bucketchange.log", base::HISTOGRAM, 1, 100, 10, 2}, | |
46 }; | 49 }; |
47 | 50 |
48 // This class observes and collects user action notifications that are sent | 51 // This class observes and collects user action notifications that are sent |
49 // by the tests, so that they can be examined afterwards for correctness. | 52 // by the tests, so that they can be examined afterwards for correctness. |
50 class UserActionObserver { | 53 class UserActionObserver { |
51 public: | 54 public: |
52 UserActionObserver(); | 55 UserActionObserver(); |
53 ~UserActionObserver(); | 56 ~UserActionObserver(); |
54 | 57 |
55 void ValidateUserActions(const RecordedUserAction* recorded, int count); | 58 void ValidateUserActions(const RecordedUserAction* recorded, int count); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 for (int i = 0; i < count; ++i) { | 112 for (int i = 0; i < count; ++i) { |
110 const RecordedHistogram& r = recorded[i]; | 113 const RecordedHistogram& r = recorded[i]; |
111 size_t j = 0; | 114 size_t j = 0; |
112 for (j = 0; j < histograms.size(); ++j) { | 115 for (j = 0; j < histograms.size(); ++j) { |
113 base::HistogramBase* histogram(histograms[j]); | 116 base::HistogramBase* histogram(histograms[j]); |
114 | 117 |
115 if (r.name == histogram->histogram_name()) { | 118 if (r.name == histogram->histogram_name()) { |
116 EXPECT_EQ(r.type, histogram->GetHistogramType()); | 119 EXPECT_EQ(r.type, histogram->GetHistogramType()); |
117 EXPECT_TRUE( | 120 EXPECT_TRUE( |
118 histogram->HasConstructionArguments(r.min, r.max, r.buckets)); | 121 histogram->HasConstructionArguments(r.min, r.max, r.buckets)); |
122 scoped_ptr<base::HistogramSamples> snapshot = | |
123 histogram->SnapshotSamples(); | |
124 base::HistogramBase::Count sample_count = snapshot->TotalCount(); | |
125 EXPECT_EQ(sample_count, r.count); | |
119 break; | 126 break; |
120 } | 127 } |
121 } | 128 } |
122 EXPECT_LT(j, histograms.size()); | 129 EXPECT_LT(j, histograms.size()); |
123 } | 130 } |
124 } | 131 } |
125 | 132 |
126 } // anonymous namespace | 133 } // anonymous namespace |
127 | 134 |
128 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Metrics) { | 135 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Metrics) { |
129 UserActionObserver observer; | 136 UserActionObserver observer; |
130 | 137 |
131 base::FieldTrialList::CreateFieldTrial("apitestfieldtrial2", "group1"); | 138 base::FieldTrialList::CreateFieldTrial("apitestfieldtrial2", "group1"); |
132 | 139 |
133 std::map<std::string, std::string> params; | 140 std::map<std::string, std::string> params; |
134 params["a"] = "aa"; | 141 params["a"] = "aa"; |
135 params["b"] = "bb"; | 142 params["b"] = "bb"; |
136 ASSERT_TRUE(chrome_variations::AssociateVariationParams( | 143 ASSERT_TRUE(chrome_variations::AssociateVariationParams( |
137 "apitestfieldtrial2", "group1", params)); | 144 "apitestfieldtrial2", "group1", params)); |
138 | 145 |
139 ASSERT_TRUE(RunComponentExtensionTest("metrics")) << message_; | 146 ASSERT_TRUE(RunComponentExtensionTest("metrics")) << message_; |
140 | 147 |
141 observer.ValidateUserActions(g_user_actions, arraysize(g_user_actions)); | 148 observer.ValidateUserActions(g_user_actions, arraysize(g_user_actions)); |
142 ValidateHistograms(g_histograms, arraysize(g_histograms)); | 149 ValidateHistograms(g_histograms, arraysize(g_histograms)); |
143 } | 150 } |
OLD | NEW |