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

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

Issue 2678143003: Move CSS animations use counters to UseCounter (Closed)
Patch Set: Rebase on top of crrev.com/2701353002 Created 3 years, 10 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/FrameHost.h" 6 #include "core/frame/FrameHost.h"
7 #include "core/frame/UseCounter.h" 7 #include "core/frame/UseCounter.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 // Note that the new histogram names will change once the semantics stabilize;
alancutter (OOO until 2018) 2017/02/20 23:49:38 I don't know the context around this comment, why
16 const char* const kFeaturesHistogramName = "Blink.UseCounter.Features"; 15 const char* const kFeaturesHistogramName = "Blink.UseCounter.Features";
17 const char* const kCSSHistogramName = "Blink.UseCounter.CSSProperties"; 16 const char* const kCSSHistogramName = "Blink.UseCounter.CSSProperties";
17 const char* const kAnimatedCSSHistogramName =
18 "Blink.UseCounter.AnimatedCSSProperties";
19
18 const char* const kSVGFeaturesHistogramName = 20 const char* const kSVGFeaturesHistogramName =
19 "Blink.UseCounter.SVGImage.Features"; 21 "Blink.UseCounter.SVGImage.Features";
20 const char* const kSVGCSSHistogramName = 22 const char* const kSVGCSSHistogramName =
21 "Blink.UseCounter.SVGImage.CSSProperties"; 23 "Blink.UseCounter.SVGImage.CSSProperties";
24 const char* const kSVGAnimatedCSSHistogramName =
25 "Blink.UseCounter.SVGImage.AnimatedCSSProperties";
26
22 const char* const kLegacyFeaturesHistogramName = "WebCore.FeatureObserver"; 27 const char* const kLegacyFeaturesHistogramName = "WebCore.FeatureObserver";
23 const char* const kLegacyCSSHistogramName = 28 const char* const kLegacyCSSHistogramName =
24 "WebCore.FeatureObserver.CSSProperties"; 29 "WebCore.FeatureObserver.CSSProperties";
25 } 30 }
26 31
27 namespace blink { 32 namespace blink {
28 33
29 template <typename T> 34 template <typename T>
30 void histogramBasicTest(const std::string& histogram, 35 void histogramBasicTest(const std::string& histogram,
31 const std::string& legacyHistogram, 36 const std::string& legacyHistogram,
32 const std::vector<std::string>& unaffectedHistograms, 37 const std::vector<std::string>& unaffectedHistograms,
33 T item, 38 T item,
34 T secondItem, 39 T secondItem,
35 std::function<bool(T)> counted, 40 std::function<bool(T)> counted,
36 std::function<void(T)> count, 41 std::function<void(T)> count,
37 std::function<int(T)> histogramMap, 42 std::function<int(T)> histogramMap,
38 std::function<void(KURL)> didCommitLoad, 43 std::function<void(KURL)> didCommitLoad,
39 const std::string& url, 44 const std::string& url,
40 int pageVisitBucket) { 45 int pageVisitBucket) {
41 HistogramTester histogramTester; 46 HistogramTester histogramTester;
42 47
43 // Test recording a single (arbitrary) counter 48 // Test recording a single (arbitrary) counter
44 EXPECT_FALSE(counted(item)); 49 EXPECT_FALSE(counted(item));
45 count(item); 50 count(item);
46 EXPECT_TRUE(counted(item)); 51 EXPECT_TRUE(counted(item));
47 histogramTester.expectUniqueSample(histogram, histogramMap(item), 1); 52 histogramTester.expectUniqueSample(histogram, histogramMap(item), 1);
48 histogramTester.expectTotalCount(legacyHistogram, 0); 53 if (!legacyHistogram.empty()) {
54 histogramTester.expectTotalCount(legacyHistogram, 0);
55 }
49 56
50 // Test that repeated measurements have no effect 57 // Test that repeated measurements have no effect
51 count(item); 58 count(item);
52 histogramTester.expectUniqueSample(histogram, histogramMap(item), 1); 59 histogramTester.expectUniqueSample(histogram, histogramMap(item), 1);
53 histogramTester.expectTotalCount(legacyHistogram, 0); 60 if (!legacyHistogram.empty()) {
61 histogramTester.expectTotalCount(legacyHistogram, 0);
62 }
54 63
55 // Test recording a different sample 64 // Test recording a different sample
56 EXPECT_FALSE(counted(secondItem)); 65 EXPECT_FALSE(counted(secondItem));
57 count(secondItem); 66 count(secondItem);
58 EXPECT_TRUE(counted(secondItem)); 67 EXPECT_TRUE(counted(secondItem));
59 histogramTester.expectBucketCount(histogram, histogramMap(item), 1); 68 histogramTester.expectBucketCount(histogram, histogramMap(item), 1);
60 histogramTester.expectBucketCount(histogram, histogramMap(secondItem), 1); 69 histogramTester.expectBucketCount(histogram, histogramMap(secondItem), 1);
61 histogramTester.expectTotalCount(histogram, 2); 70 histogramTester.expectTotalCount(histogram, 2);
62 histogramTester.expectTotalCount(legacyHistogram, 0); 71 if (!legacyHistogram.empty()) {
72 histogramTester.expectTotalCount(legacyHistogram, 0);
73 }
63 74
64 // After a page load, the histograms will be updated, even when the URL 75 // After a page load, the histograms will be updated, even when the URL
65 // scheme is internal 76 // scheme is internal
66 didCommitLoad(URLTestHelpers::toKURL(url)); 77 didCommitLoad(URLTestHelpers::toKURL(url));
67 histogramTester.expectBucketCount(histogram, histogramMap(item), 1); 78 histogramTester.expectBucketCount(histogram, histogramMap(item), 1);
68 histogramTester.expectBucketCount(histogram, histogramMap(secondItem), 1); 79 histogramTester.expectBucketCount(histogram, histogramMap(secondItem), 1);
69 histogramTester.expectBucketCount(histogram, pageVisitBucket, 1); 80 histogramTester.expectBucketCount(histogram, pageVisitBucket, 1);
70 histogramTester.expectTotalCount(histogram, 3); 81 histogramTester.expectTotalCount(histogram, 3);
71 82
72 // And verify the legacy histogram now looks the same 83 // And verify the legacy histogram now looks the same
73 histogramTester.expectBucketCount(legacyHistogram, histogramMap(item), 1); 84 if (!legacyHistogram.empty()) {
74 histogramTester.expectBucketCount(legacyHistogram, histogramMap(secondItem), 85 histogramTester.expectBucketCount(legacyHistogram, histogramMap(item), 1);
75 1); 86 histogramTester.expectBucketCount(legacyHistogram, histogramMap(secondItem),
76 histogramTester.expectBucketCount(legacyHistogram, pageVisitBucket, 1); 87 1);
77 histogramTester.expectTotalCount(legacyHistogram, 3); 88 histogramTester.expectBucketCount(legacyHistogram, pageVisitBucket, 1);
89 histogramTester.expectTotalCount(legacyHistogram, 3);
90 }
78 91
79 // Now a repeat measurement should get recorded again, exactly once 92 // Now a repeat measurement should get recorded again, exactly once
80 EXPECT_FALSE(counted(item)); 93 EXPECT_FALSE(counted(item));
81 count(item); 94 count(item);
82 count(item); 95 count(item);
83 EXPECT_TRUE(counted(item)); 96 EXPECT_TRUE(counted(item));
84 histogramTester.expectBucketCount(histogram, histogramMap(item), 2); 97 histogramTester.expectBucketCount(histogram, histogramMap(item), 2);
85 histogramTester.expectTotalCount(histogram, 4); 98 histogramTester.expectTotalCount(histogram, 4);
86 99
87 // And on the next page load, the legacy histogram will again be updated 100 // And on the next page load, the legacy histogram will again be updated
88 didCommitLoad(URLTestHelpers::toKURL(url)); 101 didCommitLoad(URLTestHelpers::toKURL(url));
89 histogramTester.expectBucketCount(legacyHistogram, histogramMap(item), 2); 102 if (!legacyHistogram.empty()) {
90 histogramTester.expectBucketCount(legacyHistogram, histogramMap(secondItem), 103 histogramTester.expectBucketCount(legacyHistogram, histogramMap(item), 2);
91 1); 104 histogramTester.expectBucketCount(legacyHistogram, histogramMap(secondItem),
92 histogramTester.expectBucketCount(legacyHistogram, pageVisitBucket, 2); 105 1);
93 histogramTester.expectTotalCount(legacyHistogram, 5); 106 histogramTester.expectBucketCount(legacyHistogram, pageVisitBucket, 2);
107 histogramTester.expectTotalCount(legacyHistogram, 5);
108 }
94 109
95 for (size_t i = 0; i < unaffectedHistograms.size(); ++i) { 110 for (size_t i = 0; i < unaffectedHistograms.size(); ++i) {
96 histogramTester.expectTotalCount(unaffectedHistograms[i], 0); 111 histogramTester.expectTotalCount(unaffectedHistograms[i], 0);
97 } 112 }
98 } 113 }
99 114
100 // Failing on Android: crbug.com/667913 115 // Failing on Android: crbug.com/667913
101 #if OS(ANDROID) 116 #if OS(ANDROID)
102 #define MAYBE_RecordingFeatures DISABLED_RecordingFeatures 117 #define MAYBE_RecordingFeatures DISABLED_RecordingFeatures
103 #else 118 #else
(...skipping 28 matching lines...) Expand all
132 [&](CSSPropertyID property) { 147 [&](CSSPropertyID property) {
133 useCounter.count(HTMLStandardMode, property); 148 useCounter.count(HTMLStandardMode, property);
134 }, 149 },
135 [](CSSPropertyID property) -> int { 150 [](CSSPropertyID property) -> int {
136 return UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property); 151 return UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property);
137 }, 152 },
138 [&](KURL kurl) { useCounter.didCommitLoad(kurl); }, 153 [&](KURL kurl) { useCounter.didCommitLoad(kurl); },
139 "https://dummysite.com/", 1 /* page visit bucket */); 154 "https://dummysite.com/", 1 /* page visit bucket */);
140 } 155 }
141 156
157 TEST(UseCounterTest, RecordingAnimatedCSSProperties) {
158 UseCounter useCounter;
159 histogramBasicTest<CSSPropertyID>(
160 kAnimatedCSSHistogramName, "",
161 {kSVGCSSHistogramName, kSVGAnimatedCSSHistogramName}, CSSPropertyOpacity,
162 CSSPropertyVariable,
163 [&](CSSPropertyID property) -> bool {
164 return useCounter.isCountedAnimatedCSS(property);
165 },
166 [&](CSSPropertyID property) { useCounter.countAnimatedCSS(property); },
167 [](CSSPropertyID property) -> int {
168 return UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property);
169 },
170 [&](KURL kurl) { useCounter.didCommitLoad(kurl); },
171 "https://dummysite.com/", 1 /* page visit bucket */);
172 }
173
142 // Failing on Android: crbug.com/667913 174 // Failing on Android: crbug.com/667913
143 #if OS(ANDROID) 175 #if OS(ANDROID)
144 #define MAYBE_SVGImageContextFeatures DISABLED_SVGImageContextFeatures 176 #define MAYBE_SVGImageContextFeatures DISABLED_SVGImageContextFeatures
145 #else 177 #else
146 #define MAYBE_SVGImageContextFeatures SVGImageContextFeatures 178 #define MAYBE_SVGImageContextFeatures SVGImageContextFeatures
147 #endif 179 #endif
148 TEST(UseCounterTest, MAYBE_SVGImageContextFeatures) { 180 TEST(UseCounterTest, MAYBE_SVGImageContextFeatures) {
149 UseCounter useCounter(UseCounter::SVGImageContext); 181 UseCounter useCounter(UseCounter::SVGImageContext);
150 histogramBasicTest<UseCounter::Feature>( 182 histogramBasicTest<UseCounter::Feature>(
151 kSVGFeaturesHistogramName, kLegacyFeaturesHistogramName, 183 kSVGFeaturesHistogramName, kLegacyFeaturesHistogramName,
(...skipping 25 matching lines...) Expand all
177 useCounter.count(HTMLStandardMode, property); 209 useCounter.count(HTMLStandardMode, property);
178 }, 210 },
179 [](CSSPropertyID property) -> int { 211 [](CSSPropertyID property) -> int {
180 return UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property); 212 return UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property);
181 }, 213 },
182 [&](KURL kurl) { useCounter.didCommitLoad(kurl); }, "about:blank", 214 [&](KURL kurl) { useCounter.didCommitLoad(kurl); }, "about:blank",
183 // In practice SVGs always appear to be loaded with an about:blank URL 215 // In practice SVGs always appear to be loaded with an about:blank URL
184 1 /* page visit bucket */); 216 1 /* page visit bucket */);
185 } 217 }
186 218
219 TEST(UseCounterTest, SVGImageContextAnimatedCSSProperties) {
220 UseCounter useCounter(UseCounter::SVGImageContext);
221 histogramBasicTest<CSSPropertyID>(
222 kSVGAnimatedCSSHistogramName, "",
223 {kCSSHistogramName, kAnimatedCSSHistogramName}, CSSPropertyOpacity,
224 CSSPropertyVariable,
225 [&](CSSPropertyID property) -> bool {
226 return useCounter.isCountedAnimatedCSS(property);
227 },
228 [&](CSSPropertyID property) { useCounter.countAnimatedCSS(property); },
229 [](CSSPropertyID property) -> int {
230 return UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property);
231 },
232 [&](KURL kurl) { useCounter.didCommitLoad(kurl); }, "about:blank",
233 // In practice SVGs always appear to be loaded with an about:blank URL
234 1 /* page visit bucket */);
235 }
236
187 // Failing on Android: crbug.com/667913 237 // Failing on Android: crbug.com/667913
188 #if OS(ANDROID) 238 #if OS(ANDROID)
189 #define MAYBE_InspectorDisablesMeasurement DISABLED_InspectorDisablesMeasurement 239 #define MAYBE_InspectorDisablesMeasurement DISABLED_InspectorDisablesMeasurement
190 #else 240 #else
191 #define MAYBE_InspectorDisablesMeasurement InspectorDisablesMeasurement 241 #define MAYBE_InspectorDisablesMeasurement InspectorDisablesMeasurement
192 #endif 242 #endif
193 TEST(UseCounterTest, MAYBE_InspectorDisablesMeasurement) { 243 TEST(UseCounterTest, MAYBE_InspectorDisablesMeasurement) {
194 UseCounter useCounter; 244 UseCounter useCounter;
195 HistogramTester histogramTester; 245 HistogramTester histogramTester;
196 246
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 440
391 m_deprecation.unmuteForInspector(); 441 m_deprecation.unmuteForInspector();
392 Deprecation::warnOnDeprecatedProperties(frame(), property); 442 Deprecation::warnOnDeprecatedProperties(frame(), property);
393 // TODO: use the actually deprecated property to get a deprecation message. 443 // TODO: use the actually deprecated property to get a deprecation message.
394 EXPECT_FALSE(m_deprecation.isSuppressed(property)); 444 EXPECT_FALSE(m_deprecation.isSuppressed(property));
395 Deprecation::countDeprecation(frame(), feature); 445 Deprecation::countDeprecation(frame(), feature);
396 EXPECT_TRUE(m_useCounter.hasRecordedMeasurement(feature)); 446 EXPECT_TRUE(m_useCounter.hasRecordedMeasurement(feature));
397 } 447 }
398 448
399 } // namespace blink 449 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698