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

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

Issue 11342060: Histogram type support in HistogramBase and remove SetRangeDescription function (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove "using" from metrics.cc Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/api/metrics/metrics.cc ('k') | net/disk_cache/stats_histogram.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/metrics/statistics_recorder.h" 8 #include "base/metrics/statistics_recorder.h"
9 #include "chrome/browser/extensions/extension_apitest.h" 9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "content/public/browser/notification_registrar.h" 10 #include "content/public/browser/notification_registrar.h"
(...skipping 10 matching lines...) Expand all
21 } g_user_actions[] = { 21 } g_user_actions[] = {
22 {"test.ua.1", 1}, 22 {"test.ua.1", 1},
23 {"test.ua.2", 2}, 23 {"test.ua.2", 2},
24 }; 24 };
25 25
26 // The tests that are run by this extension are expected to record the following 26 // The tests that are run by this extension are expected to record the following
27 // histograms. If the tests in test.js are modified, this array may need to be 27 // histograms. If the tests in test.js are modified, this array may need to be
28 // updated. 28 // updated.
29 struct RecordedHistogram { 29 struct RecordedHistogram {
30 const char* name; 30 const char* name;
31 base::Histogram::ClassType type; 31 base::HistogramType type;
32 int min; 32 int min;
33 int max; 33 int max;
34 size_t buckets; 34 size_t buckets;
35 } g_histograms[] = { 35 } g_histograms[] = {
36 {"test.h.1", base::Histogram::HISTOGRAM, 1, 100, 50}, // custom 36 {"test.h.1", base::HISTOGRAM, 1, 100, 50}, // custom
37 {"test.h.2", base::Histogram::LINEAR_HISTOGRAM, 1, 200, 50}, // custom 37 {"test.h.2", base::LINEAR_HISTOGRAM, 1, 200, 50}, // custom
38 {"test.h.3", base::Histogram::LINEAR_HISTOGRAM, 1, 101, 102}, // percentage 38 {"test.h.3", base::LINEAR_HISTOGRAM, 1, 101, 102}, // percentage
39 {"test.time", base::Histogram::HISTOGRAM, 1, 10000, 50}, 39 {"test.time", base::HISTOGRAM, 1, 10000, 50},
40 {"test.medium.time", base::Histogram::HISTOGRAM, 1, 180000, 50}, 40 {"test.medium.time", base::HISTOGRAM, 1, 180000, 50},
41 {"test.long.time", base::Histogram::HISTOGRAM, 1, 3600000, 50}, 41 {"test.long.time", base::HISTOGRAM, 1, 3600000, 50},
42 {"test.count", base::Histogram::HISTOGRAM, 1, 1000000, 50}, 42 {"test.count", base::HISTOGRAM, 1, 1000000, 50},
43 {"test.medium.count", base::Histogram::HISTOGRAM, 1, 10000, 50}, 43 {"test.medium.count", base::HISTOGRAM, 1, 10000, 50},
44 {"test.small.count", base::Histogram::HISTOGRAM, 1, 100, 50}, 44 {"test.small.count", base::HISTOGRAM, 1, 100, 50},
45 }; 45 };
46 46
47 // This class observes and collects user action notifications that are sent 47 // This class observes and collects user action notifications that are sent
48 // by the tests, so that they can be examined afterwards for correctness. 48 // by the tests, so that they can be examined afterwards for correctness.
49 class UserActionObserver : public content::NotificationObserver { 49 class UserActionObserver : public content::NotificationObserver {
50 public: 50 public:
51 UserActionObserver(); 51 UserActionObserver();
52 52
53 void ValidateUserActions(const RecordedUserAction* recorded, int count); 53 void ValidateUserActions(const RecordedUserAction* recorded, int count);
54 54
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // we will ignore those. This function validates that all the histogram we 103 // we will ignore those. This function validates that all the histogram we
104 // expect to see are present in the list, and that their basic info is 104 // expect to see are present in the list, and that their basic info is
105 // correct. 105 // correct.
106 for (int i = 0; i < count; ++i) { 106 for (int i = 0; i < count; ++i) {
107 const RecordedHistogram& r = recorded[i]; 107 const RecordedHistogram& r = recorded[i];
108 size_t j = 0; 108 size_t j = 0;
109 for (j = 0; j < histograms.size(); ++j) { 109 for (j = 0; j < histograms.size(); ++j) {
110 base::Histogram* histogram(histograms[j]); 110 base::Histogram* histogram(histograms[j]);
111 111
112 if (r.name == histogram->histogram_name()) { 112 if (r.name == histogram->histogram_name()) {
113 EXPECT_EQ(r.type, histogram->histogram_type()); 113 EXPECT_EQ(r.type, histogram->GetHistogramType());
114 EXPECT_EQ(r.min, histogram->declared_min()); 114 EXPECT_EQ(r.min, histogram->declared_min());
115 EXPECT_EQ(r.max, histogram->declared_max()); 115 EXPECT_EQ(r.max, histogram->declared_max());
116 EXPECT_EQ(r.buckets, histogram->bucket_count()); 116 EXPECT_EQ(r.buckets, histogram->bucket_count());
117 break; 117 break;
118 } 118 }
119 } 119 }
120 EXPECT_LT(j, histograms.size()); 120 EXPECT_LT(j, histograms.size());
121 } 121 }
122 } 122 }
123 123
124 } // anonymous namespace 124 } // anonymous namespace
125 125
126 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Metrics) { 126 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Metrics) {
127 UserActionObserver observer; 127 UserActionObserver observer;
128 128
129 ASSERT_TRUE(RunComponentExtensionTest("metrics")) << message_; 129 ASSERT_TRUE(RunComponentExtensionTest("metrics")) << message_;
130 130
131 observer.ValidateUserActions(g_user_actions, arraysize(g_user_actions)); 131 observer.ValidateUserActions(g_user_actions, arraysize(g_user_actions));
132 ValidateHistograms(g_histograms, arraysize(g_histograms)); 132 ValidateHistograms(g_histograms, arraysize(g_histograms));
133 } 133 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/metrics/metrics.cc ('k') | net/disk_cache/stats_histogram.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698