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

Side by Side Diff: third_party/WebKit/Source/core/frame/UseCounterTest.cpp

Issue 2796283005: Adding UseCounter specific for extensions (Closed)
Patch Set: Codereview: nit + refactored UseCounterTests unaffected_histograms => all_histograms / affected_his… Created 3 years, 7 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "core/frame/Deprecation.h" 5 #include "core/frame/Deprecation.h"
6 #include "core/frame/UseCounter.h" 6 #include "core/frame/UseCounter.h"
7 #include "core/page/Page.h" 7 #include "core/page/Page.h"
8 #include "core/testing/DummyPageHolder.h" 8 #include "core/testing/DummyPageHolder.h"
9 #include "platform/testing/HistogramTester.h" 9 #include "platform/testing/HistogramTester.h"
10 #include "platform/testing/URLTestHelpers.h" 10 #include "platform/testing/URLTestHelpers.h"
11 #include "platform/weborigin/KURL.h" 11 #include "platform/weborigin/KURL.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace { 14 namespace {
15 const char* const kFeaturesHistogramName = "Blink.UseCounter.Features"; 15 const char* const kFeaturesHistogramName = "Blink.UseCounter.Features";
16 const char* const kCSSHistogramName = "Blink.UseCounter.CSSProperties"; 16 const char* const kCSSHistogramName = "Blink.UseCounter.CSSProperties";
17 const char* const kAnimatedCSSHistogramName = 17 const char* const kAnimatedCSSHistogramName =
18 "Blink.UseCounter.AnimatedCSSProperties"; 18 "Blink.UseCounter.AnimatedCSSProperties";
19 const char* const kExtensionFeaturesHistogramName =
20 "Blink.UseCounter.Extensions.Features";
19 21
20 const char* const kSVGFeaturesHistogramName = 22 const char* const kSVGFeaturesHistogramName =
21 "Blink.UseCounter.SVGImage.Features"; 23 "Blink.UseCounter.SVGImage.Features";
22 const char* const kSVGCSSHistogramName = 24 const char* const kSVGCSSHistogramName =
23 "Blink.UseCounter.SVGImage.CSSProperties"; 25 "Blink.UseCounter.SVGImage.CSSProperties";
24 const char* const kSVGAnimatedCSSHistogramName = 26 const char* const kSVGAnimatedCSSHistogramName =
25 "Blink.UseCounter.SVGImage.AnimatedCSSProperties"; 27 "Blink.UseCounter.SVGImage.AnimatedCSSProperties";
26 28
27 const char* const kLegacyFeaturesHistogramName = "WebCore.FeatureObserver"; 29 const char* const kLegacyFeaturesHistogramName = "WebCore.FeatureObserver";
28 const char* const kLegacyCSSHistogramName = 30 const char* const kLegacyCSSHistogramName =
29 "WebCore.FeatureObserver.CSSProperties"; 31 "WebCore.FeatureObserver.CSSProperties";
32
33 // Sorted list of all histograms to be tested.
34 const std::vector<std::string>& all_histograms = {
35 kAnimatedCSSHistogramName, kCSSHistogramName,
36 kExtensionFeaturesHistogramName, kFeaturesHistogramName,
37 kSVGAnimatedCSSHistogramName, kSVGCSSHistogramName,
38 kSVGFeaturesHistogramName};
30 } 39 }
31 40
32 namespace blink { 41 namespace blink {
33 42
34 template <typename T> 43 template <typename T>
35 void HistogramBasicTest(const std::string& histogram, 44 void HistogramBasicTest(const std::string& histogram,
36 const std::string& legacy_histogram, 45 const std::string& legacy_histogram,
37 const std::vector<std::string>& unaffected_histograms, 46 const std::vector<std::string>& affected_histograms,
Rick Byers 2017/05/01 21:19:20 I was thinking that the only affected histograms w
lunalu1 2017/05/04 15:33:56 That was my initial thought. Although everything f
38 T item, 47 T item,
39 T second_item, 48 T second_item,
40 std::function<bool(T)> counted, 49 std::function<bool(T)> counted,
41 std::function<void(T)> count, 50 std::function<void(T)> count,
42 std::function<int(T)> histogram_map, 51 std::function<int(T)> histogram_map,
43 std::function<void(KURL)> did_commit_load, 52 std::function<void(KURL)> did_commit_load,
44 const std::string& url, 53 const std::string& url,
45 int page_visit_bucket) { 54 int page_visit_bucket) {
46 HistogramTester histogram_tester; 55 HistogramTester histogram_tester;
47 56
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 did_commit_load(URLTestHelpers::ToKURL(url)); 111 did_commit_load(URLTestHelpers::ToKURL(url));
103 if (!legacy_histogram.empty()) { 112 if (!legacy_histogram.empty()) {
104 histogram_tester.ExpectBucketCount(legacy_histogram, histogram_map(item), 113 histogram_tester.ExpectBucketCount(legacy_histogram, histogram_map(item),
105 2); 114 2);
106 histogram_tester.ExpectBucketCount(legacy_histogram, 115 histogram_tester.ExpectBucketCount(legacy_histogram,
107 histogram_map(second_item), 1); 116 histogram_map(second_item), 1);
108 histogram_tester.ExpectBucketCount(legacy_histogram, page_visit_bucket, 2); 117 histogram_tester.ExpectBucketCount(legacy_histogram, page_visit_bucket, 2);
109 histogram_tester.ExpectTotalCount(legacy_histogram, 5); 118 histogram_tester.ExpectTotalCount(legacy_histogram, 5);
110 } 119 }
111 120
112 for (size_t i = 0; i < unaffected_histograms.size(); ++i) { 121 std::vector<std::string> unaffected_histograms(all_histograms.size() -
113 histogram_tester.ExpectTotalCount(unaffected_histograms[i], 0); 122 affected_histograms.size());
114 } 123 std::set_difference(all_histograms.begin(), all_histograms.end(),
Rick Byers 2017/05/01 21:19:20 can you also remove "histogram" and "legacy_histog
lunalu1 2017/05/04 15:33:56 Yes. I thought about that. But I decided explicitl
124 affected_histograms.begin(), affected_histograms.end(),
125 unaffected_histograms.begin());
126 for (const auto unaffected_histogram : unaffected_histograms)
127 histogram_tester.ExpectTotalCount(unaffected_histogram, 0);
115 } 128 }
116 129
117 TEST(UseCounterTest, RecordingFeatures) { 130 TEST(UseCounterTest, RecordingFeatures) {
118 UseCounter use_counter; 131 UseCounter use_counter;
119 HistogramBasicTest<UseCounter::Feature>( 132 HistogramBasicTest<UseCounter::Feature>(
120 kFeaturesHistogramName, kLegacyFeaturesHistogramName, 133 kFeaturesHistogramName, kLegacyFeaturesHistogramName,
121 {kSVGFeaturesHistogramName, kSVGCSSHistogramName, 134 {kAnimatedCSSHistogramName, kCSSHistogramName, kFeaturesHistogramName},
Rick Byers 2017/05/01 21:19:20 I assume you need to specify the CSS histograms he
Rick Byers 2017/05/01 21:19:20 Why does this pass without kLegacyFeaturesHistogra
lunalu1 2017/05/04 15:33:56 That makes sense. I assume "getPageVisitsBucketfor
lunalu1 2017/05/04 15:33:56 I didn't include the legacy histograms in all_hist
122 kSVGAnimatedCSSHistogramName},
123 UseCounter::kFetch, UseCounter::kFetchBodyStream, 135 UseCounter::kFetch, UseCounter::kFetchBodyStream,
124 [&](UseCounter::Feature feature) -> bool { 136 [&](UseCounter::Feature feature) -> bool {
125 return use_counter.HasRecordedMeasurement(feature); 137 return use_counter.HasRecordedMeasurement(feature);
126 }, 138 },
127 [&](UseCounter::Feature feature) { 139 [&](UseCounter::Feature feature) {
128 use_counter.RecordMeasurement(feature); 140 use_counter.RecordMeasurement(feature);
129 }, 141 },
130 [](UseCounter::Feature feature) -> int { return feature; }, 142 [](UseCounter::Feature feature) -> int { return feature; },
131 [&](KURL kurl) { use_counter.DidCommitLoad(kurl); }, 143 [&](KURL kurl) { use_counter.DidCommitLoad(kurl); },
132 "https://dummysite.com/", UseCounter::kPageVisits); 144 "https://dummysite.com/", UseCounter::kPageVisits);
133 } 145 }
134 146
135 TEST(UseCounterTest, RecordingCSSProperties) { 147 TEST(UseCounterTest, RecordingCSSProperties) {
136 UseCounter use_counter; 148 UseCounter use_counter;
137 HistogramBasicTest<CSSPropertyID>( 149 HistogramBasicTest<CSSPropertyID>(
138 kCSSHistogramName, kLegacyCSSHistogramName, 150 kCSSHistogramName, kLegacyCSSHistogramName,
139 {kSVGFeaturesHistogramName, kSVGCSSHistogramName, 151 {kAnimatedCSSHistogramName, kCSSHistogramName, kFeaturesHistogramName},
140 kSVGAnimatedCSSHistogramName},
141 CSSPropertyFont, CSSPropertyZoom, 152 CSSPropertyFont, CSSPropertyZoom,
142 [&](CSSPropertyID property) -> bool { 153 [&](CSSPropertyID property) -> bool {
143 return use_counter.IsCounted(property); 154 return use_counter.IsCounted(property);
144 }, 155 },
145 [&](CSSPropertyID property) { 156 [&](CSSPropertyID property) {
146 use_counter.Count(kHTMLStandardMode, property); 157 use_counter.Count(kHTMLStandardMode, property);
147 }, 158 },
148 [](CSSPropertyID property) -> int { 159 [](CSSPropertyID property) -> int {
149 return UseCounter::MapCSSPropertyIdToCSSSampleIdForHistogram(property); 160 return UseCounter::MapCSSPropertyIdToCSSSampleIdForHistogram(property);
150 }, 161 },
151 [&](KURL kurl) { use_counter.DidCommitLoad(kurl); }, 162 [&](KURL kurl) { use_counter.DidCommitLoad(kurl); },
152 "https://dummysite.com/", 1 /* page visit bucket */); 163 "https://dummysite.com/", 1 /* page visit bucket */);
153 } 164 }
154 165
155 TEST(UseCounterTest, RecordingAnimatedCSSProperties) { 166 TEST(UseCounterTest, RecordingAnimatedCSSProperties) {
156 UseCounter use_counter; 167 UseCounter use_counter;
157 HistogramBasicTest<CSSPropertyID>( 168 HistogramBasicTest<CSSPropertyID>(
158 kAnimatedCSSHistogramName, "", 169 kAnimatedCSSHistogramName, "",
159 {kSVGCSSHistogramName, kSVGAnimatedCSSHistogramName}, CSSPropertyOpacity, 170 {kAnimatedCSSHistogramName, kCSSHistogramName, kFeaturesHistogramName,
160 CSSPropertyVariable, 171 kSVGFeaturesHistogramName},
Rick Byers 2017/05/01 21:19:20 Is kSVGFeaturesHistogramName really affected? I d
lunalu1 2017/05/04 15:33:56 You are so right. My bad! I just did an exclusive
172 CSSPropertyOpacity, CSSPropertyVariable,
161 [&](CSSPropertyID property) -> bool { 173 [&](CSSPropertyID property) -> bool {
162 return use_counter.IsCountedAnimatedCSS(property); 174 return use_counter.IsCountedAnimatedCSS(property);
163 }, 175 },
164 [&](CSSPropertyID property) { use_counter.CountAnimatedCSS(property); }, 176 [&](CSSPropertyID property) { use_counter.CountAnimatedCSS(property); },
165 [](CSSPropertyID property) -> int { 177 [](CSSPropertyID property) -> int {
166 return UseCounter::MapCSSPropertyIdToCSSSampleIdForHistogram(property); 178 return UseCounter::MapCSSPropertyIdToCSSSampleIdForHistogram(property);
167 }, 179 },
168 [&](KURL kurl) { use_counter.DidCommitLoad(kurl); }, 180 [&](KURL kurl) { use_counter.DidCommitLoad(kurl); },
169 "https://dummysite.com/", 1 /* page visit bucket */); 181 "https://dummysite.com/", 1 /* page visit bucket */);
170 } 182 }
171 183
184 TEST(UseCounterTest, RecordingExtensions) {
185 UseCounter use_counter(UseCounter::kExtensionContext);
186 HistogramBasicTest<UseCounter::Feature>(
187 kExtensionFeaturesHistogramName, kLegacyFeaturesHistogramName,
188 {kExtensionFeaturesHistogramName}, UseCounter::kFetch,
189 UseCounter::kFetchBodyStream,
190 [&](UseCounter::Feature feature) -> bool {
191 return use_counter.HasRecordedMeasurement(feature);
192 },
193 [&](UseCounter::Feature feature) {
194 use_counter.RecordMeasurement(feature);
195 },
196 [](UseCounter::Feature feature) -> int { return feature; },
197 [&](KURL kurl) { use_counter.DidCommitLoad(kurl); },
198 "chrome-extension://dummysite", UseCounter::kPageVisits);
199 }
200
172 TEST(UseCounterTest, SVGImageContextFeatures) { 201 TEST(UseCounterTest, SVGImageContextFeatures) {
173 UseCounter use_counter(UseCounter::kSVGImageContext); 202 UseCounter use_counter(UseCounter::kSVGImageContext);
174 HistogramBasicTest<UseCounter::Feature>( 203 HistogramBasicTest<UseCounter::Feature>(
175 kSVGFeaturesHistogramName, kLegacyFeaturesHistogramName, 204 kSVGFeaturesHistogramName, kLegacyFeaturesHistogramName,
176 {kFeaturesHistogramName, kCSSHistogramName, kAnimatedCSSHistogramName}, 205 {kSVGAnimatedCSSHistogramName, kSVGCSSHistogramName,
206 kSVGFeaturesHistogramName},
177 UseCounter::kSVGSMILAdditiveAnimation, 207 UseCounter::kSVGSMILAdditiveAnimation,
178 UseCounter::kSVGSMILAnimationElementTiming, 208 UseCounter::kSVGSMILAnimationElementTiming,
179 [&](UseCounter::Feature feature) -> bool { 209 [&](UseCounter::Feature feature) -> bool {
180 return use_counter.HasRecordedMeasurement(feature); 210 return use_counter.HasRecordedMeasurement(feature);
181 }, 211 },
182 [&](UseCounter::Feature feature) { 212 [&](UseCounter::Feature feature) {
183 use_counter.RecordMeasurement(feature); 213 use_counter.RecordMeasurement(feature);
184 }, 214 },
185 [](UseCounter::Feature feature) -> int { return feature; }, 215 [](UseCounter::Feature feature) -> int { return feature; },
186 [&](KURL kurl) { use_counter.DidCommitLoad(kurl); }, "about:blank", 216 [&](KURL kurl) { use_counter.DidCommitLoad(kurl); }, "about:blank",
187 // In practice SVGs always appear to be loaded with an about:blank URL 217 // In practice SVGs always appear to be loaded with an about:blank URL
188 UseCounter::kPageVisits); 218 UseCounter::kPageVisits);
189 } 219 }
190 220
191 TEST(UseCounterTest, SVGImageContextCSSProperties) { 221 TEST(UseCounterTest, SVGImageContextCSSProperties) {
192 UseCounter use_counter(UseCounter::kSVGImageContext); 222 UseCounter use_counter(UseCounter::kSVGImageContext);
193 HistogramBasicTest<CSSPropertyID>( 223 HistogramBasicTest<CSSPropertyID>(
194 kSVGCSSHistogramName, kLegacyCSSHistogramName, 224 kSVGCSSHistogramName, kLegacyCSSHistogramName,
195 {kFeaturesHistogramName, kCSSHistogramName, kAnimatedCSSHistogramName}, 225 {kSVGAnimatedCSSHistogramName, kSVGCSSHistogramName,
226 kSVGFeaturesHistogramName},
196 CSSPropertyFont, CSSPropertyZoom, 227 CSSPropertyFont, CSSPropertyZoom,
197 [&](CSSPropertyID property) -> bool { 228 [&](CSSPropertyID property) -> bool {
198 return use_counter.IsCounted(property); 229 return use_counter.IsCounted(property);
199 }, 230 },
200 [&](CSSPropertyID property) { 231 [&](CSSPropertyID property) {
201 use_counter.Count(kHTMLStandardMode, property); 232 use_counter.Count(kHTMLStandardMode, property);
202 }, 233 },
203 [](CSSPropertyID property) -> int { 234 [](CSSPropertyID property) -> int {
204 return UseCounter::MapCSSPropertyIdToCSSSampleIdForHistogram(property); 235 return UseCounter::MapCSSPropertyIdToCSSSampleIdForHistogram(property);
205 }, 236 },
206 [&](KURL kurl) { use_counter.DidCommitLoad(kurl); }, "about:blank", 237 [&](KURL kurl) { use_counter.DidCommitLoad(kurl); }, "about:blank",
207 // In practice SVGs always appear to be loaded with an about:blank URL 238 // In practice SVGs always appear to be loaded with an about:blank URL
208 1 /* page visit bucket */); 239 1 /* page visit bucket */);
209 } 240 }
210 241
211 TEST(UseCounterTest, SVGImageContextAnimatedCSSProperties) { 242 TEST(UseCounterTest, SVGImageContextAnimatedCSSProperties) {
212 UseCounter use_counter(UseCounter::kSVGImageContext); 243 UseCounter use_counter(UseCounter::kSVGImageContext);
213 HistogramBasicTest<CSSPropertyID>( 244 HistogramBasicTest<CSSPropertyID>(
214 kSVGAnimatedCSSHistogramName, "", 245 kSVGAnimatedCSSHistogramName, "",
215 {kCSSHistogramName, kAnimatedCSSHistogramName}, CSSPropertyOpacity, 246 {kFeaturesHistogramName, kSVGAnimatedCSSHistogramName,
216 CSSPropertyVariable, 247 kSVGCSSHistogramName, kSVGFeaturesHistogramName},
248 CSSPropertyOpacity, CSSPropertyVariable,
217 [&](CSSPropertyID property) -> bool { 249 [&](CSSPropertyID property) -> bool {
218 return use_counter.IsCountedAnimatedCSS(property); 250 return use_counter.IsCountedAnimatedCSS(property);
219 }, 251 },
220 [&](CSSPropertyID property) { use_counter.CountAnimatedCSS(property); }, 252 [&](CSSPropertyID property) { use_counter.CountAnimatedCSS(property); },
221 [](CSSPropertyID property) -> int { 253 [](CSSPropertyID property) -> int {
222 return UseCounter::MapCSSPropertyIdToCSSSampleIdForHistogram(property); 254 return UseCounter::MapCSSPropertyIdToCSSSampleIdForHistogram(property);
223 }, 255 },
224 [&](KURL kurl) { use_counter.DidCommitLoad(kurl); }, "about:blank", 256 [&](KURL kurl) { use_counter.DidCommitLoad(kurl); }, "about:blank",
225 // In practice SVGs always appear to be loaded with an about:blank URL 257 // In practice SVGs always appear to be loaded with an about:blank URL
226 1 /* page visit bucket */); 258 1 /* page visit bucket */);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 452
421 deprecation_.UnmuteForInspector(); 453 deprecation_.UnmuteForInspector();
422 Deprecation::WarnOnDeprecatedProperties(GetFrame(), property); 454 Deprecation::WarnOnDeprecatedProperties(GetFrame(), property);
423 // TODO: use the actually deprecated property to get a deprecation message. 455 // TODO: use the actually deprecated property to get a deprecation message.
424 EXPECT_FALSE(deprecation_.IsSuppressed(property)); 456 EXPECT_FALSE(deprecation_.IsSuppressed(property));
425 Deprecation::CountDeprecation(GetFrame(), feature); 457 Deprecation::CountDeprecation(GetFrame(), feature);
426 EXPECT_TRUE(use_counter_.HasRecordedMeasurement(feature)); 458 EXPECT_TRUE(use_counter_.HasRecordedMeasurement(feature));
427 } 459 }
428 460
429 } // namespace blink 461 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/UseCounter.cpp ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698