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

Side by Side Diff: chrome/browser/extensions/api/metrics_private/metrics_apitest.cc

Issue 141393002: Return a NULL histogram pointer on construction error (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, git cl format Created 6 years, 9 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 unified diff | Download patch
OLDNEW
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
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},
46 }; 47 {"test.bucketchange.linear", base::LINEAR_HISTOGRAM, 1, 100, 10, 2},
48 {"test.bucketchange.log", base::HISTOGRAM, 1, 100, 10, 2}, };
47 49
48 // This class observes and collects user action notifications that are sent 50 // This class observes and collects user action notifications that are sent
49 // by the tests, so that they can be examined afterwards for correctness. 51 // by the tests, so that they can be examined afterwards for correctness.
50 class UserActionObserver { 52 class UserActionObserver {
51 public: 53 public:
52 UserActionObserver(); 54 UserActionObserver();
53 ~UserActionObserver(); 55 ~UserActionObserver();
54 56
55 void ValidateUserActions(const RecordedUserAction* recorded, int count); 57 void ValidateUserActions(const RecordedUserAction* recorded, int count);
56 58
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 for (int i = 0; i < count; ++i) { 111 for (int i = 0; i < count; ++i) {
110 const RecordedHistogram& r = recorded[i]; 112 const RecordedHistogram& r = recorded[i];
111 size_t j = 0; 113 size_t j = 0;
112 for (j = 0; j < histograms.size(); ++j) { 114 for (j = 0; j < histograms.size(); ++j) {
113 base::HistogramBase* histogram(histograms[j]); 115 base::HistogramBase* histogram(histograms[j]);
114 116
115 if (r.name == histogram->histogram_name()) { 117 if (r.name == histogram->histogram_name()) {
116 EXPECT_EQ(r.type, histogram->GetHistogramType()); 118 EXPECT_EQ(r.type, histogram->GetHistogramType());
117 EXPECT_TRUE( 119 EXPECT_TRUE(
118 histogram->HasConstructionArguments(r.min, r.max, r.buckets)); 120 histogram->HasConstructionArguments(r.min, r.max, r.buckets));
121 scoped_ptr<base::HistogramSamples> snapshot =
122 histogram->SnapshotSamples();
123 base::HistogramBase::Count sample_count = snapshot->TotalCount();
124 EXPECT_EQ(sample_count, r.count);
119 break; 125 break;
120 } 126 }
121 } 127 }
122 EXPECT_LT(j, histograms.size()); 128 EXPECT_LT(j, histograms.size());
123 } 129 }
124 } 130 }
125 131
126 } // anonymous namespace 132 } // anonymous namespace
127 133
128 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Metrics) { 134 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Metrics) {
129 UserActionObserver observer; 135 UserActionObserver observer;
130 136
131 base::FieldTrialList::CreateFieldTrial("apitestfieldtrial2", "group1"); 137 base::FieldTrialList::CreateFieldTrial("apitestfieldtrial2", "group1");
132 138
133 std::map<std::string, std::string> params; 139 std::map<std::string, std::string> params;
134 params["a"] = "aa"; 140 params["a"] = "aa";
135 params["b"] = "bb"; 141 params["b"] = "bb";
136 ASSERT_TRUE(chrome_variations::AssociateVariationParams( 142 ASSERT_TRUE(chrome_variations::AssociateVariationParams(
137 "apitestfieldtrial2", "group1", params)); 143 "apitestfieldtrial2", "group1", params));
138 144
139 ASSERT_TRUE(RunComponentExtensionTest("metrics")) << message_; 145 ASSERT_TRUE(RunComponentExtensionTest("metrics")) << message_;
140 146
141 observer.ValidateUserActions(g_user_actions, arraysize(g_user_actions)); 147 observer.ValidateUserActions(g_user_actions, arraysize(g_user_actions));
142 ValidateHistograms(g_histograms, arraysize(g_histograms)); 148 ValidateHistograms(g_histograms, arraysize(g_histograms));
143 } 149 }
OLDNEW
« no previous file with comments | « base/metrics/histogram_unittest.cc ('k') | chrome/browser/extensions/api/metrics_private/metrics_private_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698