OLD | NEW |
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 "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 // Note that the new histogram names will change once the semantics stabilize; | 13 // Note that the new histogram names will change once the semantics stabilize; |
14 const char* const kFeaturesHistogramName = "WebCore.UseCounter_TEST.Features"; | 14 const char* const kFeaturesHistogramName = "WebCore.UseCounter_TEST.Features"; |
15 const char* const kCSSHistogramName = "WebCore.UseCounter_TEST.CSSProperties"; | 15 const char* const kCSSHistogramName = "WebCore.UseCounter_TEST.CSSProperties"; |
| 16 const char* const kSVGFeaturesHistogramName = "WebCore.UseCounter_TEST.SVGImage.
Features"; |
| 17 const char* const kSVGCSSHistogramName = "WebCore.UseCounter_TEST.SVGImage.CSSPr
operties"; |
16 const char* const kLegacyFeaturesHistogramName = "WebCore.FeatureObserver"; | 18 const char* const kLegacyFeaturesHistogramName = "WebCore.FeatureObserver"; |
17 const char* const kLegacyCSSHistogramName = "WebCore.FeatureObserver.CSSProperti
es"; | 19 const char* const kLegacyCSSHistogramName = "WebCore.FeatureObserver.CSSProperti
es"; |
18 } | 20 } |
19 | 21 |
20 namespace blink { | 22 namespace blink { |
21 | 23 |
22 TEST(UseCounterTest, RecordingFeatures) | 24 TEST(UseCounterTest, RecordingFeatures) |
23 { | 25 { |
24 UseCounter useCounter; | 26 UseCounter useCounter; |
25 HistogramTester histogramTester; | 27 HistogramTester histogramTester; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::Fetch)); | 67 EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::Fetch)); |
66 histogramTester.expectBucketCount(kFeaturesHistogramName, UseCounter::Fetch,
2); | 68 histogramTester.expectBucketCount(kFeaturesHistogramName, UseCounter::Fetch,
2); |
67 histogramTester.expectTotalCount(kFeaturesHistogramName, 4); | 69 histogramTester.expectTotalCount(kFeaturesHistogramName, 4); |
68 | 70 |
69 // And on the next page load, the legacy histogram will again be updated | 71 // And on the next page load, the legacy histogram will again be updated |
70 useCounter.didCommitLoad(); | 72 useCounter.didCommitLoad(); |
71 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, UseCounter::
Fetch, 2); | 73 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, UseCounter::
Fetch, 2); |
72 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, UseCounter::
FetchBodyStream, 1); | 74 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, UseCounter::
FetchBodyStream, 1); |
73 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, UseCounter::
PageVisits, 2); | 75 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, UseCounter::
PageVisits, 2); |
74 histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 5); | 76 histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 5); |
| 77 |
| 78 // None of this should update any of the SVG histograms |
| 79 histogramTester.expectTotalCount(kSVGFeaturesHistogramName, 0); |
| 80 histogramTester.expectTotalCount(kSVGCSSHistogramName, 0); |
75 } | 81 } |
76 | 82 |
77 TEST(UseCounterTest, RecordingCSSProperties) | 83 TEST(UseCounterTest, RecordingCSSProperties) |
78 { | 84 { |
79 UseCounter useCounter; | 85 UseCounter useCounter; |
80 HistogramTester histogramTester; | 86 HistogramTester histogramTester; |
81 | 87 |
82 // Test recording a single (arbitrary) property | 88 // Test recording a single (arbitrary) property |
83 EXPECT_FALSE(useCounter.isCounted(CSSPropertyFont)); | 89 EXPECT_FALSE(useCounter.isCounted(CSSPropertyFont)); |
84 useCounter.count(HTMLStandardMode, CSSPropertyFont); | 90 useCounter.count(HTMLStandardMode, CSSPropertyFont); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 EXPECT_TRUE(useCounter.isCounted(CSSPropertyFont)); | 126 EXPECT_TRUE(useCounter.isCounted(CSSPropertyFont)); |
121 histogramTester.expectBucketCount(kCSSHistogramName, UseCounter::mapCSSPrope
rtyIdToCSSSampleIdForHistogram(CSSPropertyFont), 2); | 127 histogramTester.expectBucketCount(kCSSHistogramName, UseCounter::mapCSSPrope
rtyIdToCSSSampleIdForHistogram(CSSPropertyFont), 2); |
122 histogramTester.expectTotalCount(kCSSHistogramName, 4); | 128 histogramTester.expectTotalCount(kCSSHistogramName, 4); |
123 | 129 |
124 // And on the next page load, the legacy histogram will again be updated | 130 // And on the next page load, the legacy histogram will again be updated |
125 useCounter.didCommitLoad(); | 131 useCounter.didCommitLoad(); |
126 histogramTester.expectBucketCount(kLegacyCSSHistogramName, UseCounter::mapCS
SPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 2); | 132 histogramTester.expectBucketCount(kLegacyCSSHistogramName, UseCounter::mapCS
SPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 2); |
127 histogramTester.expectBucketCount(kLegacyCSSHistogramName, UseCounter::mapCS
SPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom), 1); | 133 histogramTester.expectBucketCount(kLegacyCSSHistogramName, UseCounter::mapCS
SPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom), 1); |
128 histogramTester.expectBucketCount(kLegacyCSSHistogramName, 1, 2); | 134 histogramTester.expectBucketCount(kLegacyCSSHistogramName, 1, 2); |
129 histogramTester.expectTotalCount(kLegacyCSSHistogramName, 5); | 135 histogramTester.expectTotalCount(kLegacyCSSHistogramName, 5); |
| 136 |
| 137 // None of this should update any of the SVG histograms |
| 138 histogramTester.expectTotalCount(kSVGFeaturesHistogramName, 0); |
| 139 histogramTester.expectTotalCount(kSVGCSSHistogramName, 0); |
| 140 } |
| 141 |
| 142 TEST(UseCounterTest, SVGImageContext) |
| 143 { |
| 144 UseCounter useCounter(UseCounter::SVGImageContext); |
| 145 HistogramTester histogramTester; |
| 146 |
| 147 // Verify that SVGImage related feature counters get recorded in a separate
histogram. |
| 148 EXPECT_FALSE(useCounter.hasRecordedMeasurement(UseCounter::SVGSMILAdditiveAn
imation)); |
| 149 useCounter.recordMeasurement(UseCounter::SVGSMILAdditiveAnimation); |
| 150 EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::SVGSMILAdditiveAni
mation)); |
| 151 histogramTester.expectUniqueSample(kSVGFeaturesHistogramName, UseCounter::SV
GSMILAdditiveAnimation, 1); |
| 152 |
| 153 // And for the CSS counters |
| 154 EXPECT_FALSE(useCounter.isCounted(CSSPropertyFont)); |
| 155 useCounter.count(HTMLStandardMode, CSSPropertyFont); |
| 156 EXPECT_TRUE(useCounter.isCounted(CSSPropertyFont)); |
| 157 histogramTester.expectUniqueSample(kSVGCSSHistogramName, UseCounter::mapCSSP
ropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 1); |
| 158 |
| 159 // After a page load, the histograms will be updated |
| 160 useCounter.didCommitLoad(); |
| 161 histogramTester.expectBucketCount(kSVGFeaturesHistogramName, UseCounter::Pag
eVisits, 1); |
| 162 histogramTester.expectTotalCount(kSVGFeaturesHistogramName, 2); |
| 163 histogramTester.expectBucketCount(kSVGCSSHistogramName, 1, 1); |
| 164 histogramTester.expectTotalCount(kSVGCSSHistogramName, 2); |
| 165 |
| 166 // And the legacy histogram will be updated to include these |
| 167 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, UseCounter::
SVGSMILAdditiveAnimation, 1); |
| 168 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, UseCounter::
PageVisits, 1); |
| 169 histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 2); |
| 170 histogramTester.expectBucketCount(kLegacyCSSHistogramName, UseCounter::mapCS
SPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 1); |
| 171 histogramTester.expectBucketCount(kLegacyCSSHistogramName, 1, 1); |
| 172 histogramTester.expectTotalCount(kLegacyCSSHistogramName, 2); |
| 173 |
| 174 // None of this should update the non-legacy non-SVG histograms |
| 175 histogramTester.expectTotalCount(kCSSHistogramName, 0); |
| 176 histogramTester.expectTotalCount(kFeaturesHistogramName, 0); |
130 } | 177 } |
131 | 178 |
132 TEST(UseCounterTest, InspectorDisablesMeasurement) | 179 TEST(UseCounterTest, InspectorDisablesMeasurement) |
133 { | 180 { |
134 UseCounter useCounter; | 181 UseCounter useCounter; |
135 HistogramTester histogramTester; | 182 HistogramTester histogramTester; |
136 | 183 |
137 // The specific feature we use here isn't important. | 184 // The specific feature we use here isn't important. |
138 UseCounter::Feature feature = UseCounter::Feature::SVGSMILElementInDocument; | 185 UseCounter::Feature feature = UseCounter::Feature::SVGSMILElementInDocument; |
139 CSSPropertyID property = CSSPropertyFontWeight; | 186 CSSPropertyID property = CSSPropertyFontWeight; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 269 |
223 m_deprecation.unmuteForInspector(); | 270 m_deprecation.unmuteForInspector(); |
224 Deprecation::warnOnDeprecatedProperties(frame(), property); | 271 Deprecation::warnOnDeprecatedProperties(frame(), property); |
225 // TODO: use the actually deprecated property to get a deprecation message. | 272 // TODO: use the actually deprecated property to get a deprecation message. |
226 EXPECT_FALSE(m_deprecation.isSuppressed(property)); | 273 EXPECT_FALSE(m_deprecation.isSuppressed(property)); |
227 Deprecation::countDeprecation(frame(), feature); | 274 Deprecation::countDeprecation(frame(), feature); |
228 EXPECT_TRUE(m_useCounter.hasRecordedMeasurement(feature)); | 275 EXPECT_TRUE(m_useCounter.hasRecordedMeasurement(feature)); |
229 } | 276 } |
230 | 277 |
231 } // namespace blink | 278 } // namespace blink |
OLD | NEW |