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

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

Issue 2290733002: Add new UseCounter metric (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Overhaul tests Created 4 years, 3 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 "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 namespace blink { 12 namespace blink {
12 13
13 class UseCounterTest : public ::testing::Test { 14 TEST(UseCounterTest, RecordingFeatures)
14 protected:
15 bool hasRecordedMeasurement(const UseCounter& useCounter, UseCounter::Featur e feature)
16 {
17 return useCounter.hasRecordedMeasurement(feature);
18 }
19
20 void recordMeasurement(UseCounter& useCounter, UseCounter::Feature feature)
21 {
22 useCounter.recordMeasurement(feature);
23 }
24 };
25
26 TEST_F(UseCounterTest, RecordingMeasurements)
27 { 15 {
28 UseCounter useCounter; 16 UseCounter useCounter;
29 for (unsigned feature = 0; feature < UseCounter::NumberOfFeatures; feature++ ) { 17 HistogramTester histogramTester;
30 if (feature != UseCounter::Feature::PageDestruction) { 18
31 EXPECT_FALSE(hasRecordedMeasurement(useCounter, static_cast<UseCount er::Feature>(feature))); 19 // Test recording a single (arbitrary) counter
32 recordMeasurement(useCounter, static_cast<UseCounter::Feature>(featu re)); 20 EXPECT_FALSE(useCounter.hasRecordedMeasurement(UseCounter::Fetch));
33 EXPECT_TRUE(hasRecordedMeasurement(useCounter, static_cast<UseCounte r::Feature>(feature))); 21 useCounter.recordMeasurement(UseCounter::Fetch);
34 } 22 EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::Fetch));
35 } 23 histogramTester.expectUniqueSample("WebCore.UseCounter.Features", UseCounter ::Fetch, 1);
24 histogramTester.expectTotalCount("WebCore.FeatureObserver", 0);
25
26 // Test that repeated measurements have no effect
27 useCounter.recordMeasurement(UseCounter::Fetch);
28 histogramTester.expectUniqueSample("WebCore.UseCounter.Features", UseCounter ::Fetch, 1);
29 histogramTester.expectTotalCount("WebCore.FeatureObserver", 0);
30
31 // Test recording a different sample
32 EXPECT_FALSE(useCounter.hasRecordedMeasurement(UseCounter::FetchBodyStream)) ;
33 useCounter.recordMeasurement(UseCounter::FetchBodyStream);
34 EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::FetchBodyStream));
35 histogramTester.expectBucketCount("WebCore.UseCounter.Features", UseCounter: :Fetch, 1);
36 histogramTester.expectBucketCount("WebCore.UseCounter.Features", UseCounter: :FetchBodyStream, 1);
37 histogramTester.expectTotalCount("WebCore.UseCounter.Features", 2);
38 histogramTester.expectTotalCount("WebCore.FeatureObserver", 0);
39
40 // Test the impact of page load on the new histogram
41 useCounter.didCommitLoad();
42 histogramTester.expectBucketCount("WebCore.UseCounter.Features", UseCounter: :Fetch, 1);
43 histogramTester.expectBucketCount("WebCore.UseCounter.Features", UseCounter: :FetchBodyStream, 1);
44 histogramTester.expectBucketCount("WebCore.UseCounter.Features", UseCounter: :PageVisits, 1);
45 histogramTester.expectTotalCount("WebCore.UseCounter.Features", 3);
46
47 // And verify the legacy histogram now looks the same
48 histogramTester.expectBucketCount("WebCore.FeatureObserver", UseCounter::Fet ch, 1);
49 histogramTester.expectBucketCount("WebCore.FeatureObserver", UseCounter::Fet chBodyStream, 1);
50 histogramTester.expectBucketCount("WebCore.FeatureObserver", UseCounter::Pag eVisits, 1);
51 histogramTester.expectTotalCount("WebCore.FeatureObserver", 3);
52
53 // Now a repeat measurement should get recorded again, exactly once
54 EXPECT_FALSE(useCounter.hasRecordedMeasurement(UseCounter::Fetch));
55 useCounter.recordMeasurement(UseCounter::Fetch);
56 useCounter.recordMeasurement(UseCounter::Fetch);
57 EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::Fetch));
58 histogramTester.expectBucketCount("WebCore.UseCounter.Features", UseCounter: :Fetch, 2);
59 histogramTester.expectTotalCount("WebCore.UseCounter.Features", 4);
60
61 // And on the next page load, the legacy histogram will again be updated
62 useCounter.didCommitLoad();
63 histogramTester.expectBucketCount("WebCore.FeatureObserver", UseCounter::Fet ch, 2);
64 histogramTester.expectBucketCount("WebCore.FeatureObserver", UseCounter::Fet chBodyStream, 1);
65 histogramTester.expectBucketCount("WebCore.FeatureObserver", UseCounter::Pag eVisits, 2);
66 histogramTester.expectTotalCount("WebCore.FeatureObserver", 5);
36 } 67 }
37 68
38 TEST_F(UseCounterTest, MultipleMeasurements) 69 TEST(UseCounterTest, RecordingCSSProperties)
39 { 70 {
40 UseCounter useCounter; 71 UseCounter useCounter;
41 for (unsigned feature = 0; feature < UseCounter::NumberOfFeatures; feature++ ) { 72 HistogramTester histogramTester;
42 if (feature != UseCounter::Feature::PageDestruction) { 73
43 recordMeasurement(useCounter, static_cast<UseCounter::Feature>(featu re)); 74 // Test recording a single (arbitrary) property
44 recordMeasurement(useCounter, static_cast<UseCounter::Feature>(featu re)); 75 EXPECT_FALSE(useCounter.isCounted(CSSPropertyFont));
45 EXPECT_TRUE(hasRecordedMeasurement(useCounter, static_cast<UseCounte r::Feature>(feature))); 76 useCounter.count(HTMLStandardMode, CSSPropertyFont);
46 } 77 EXPECT_TRUE(useCounter.isCounted(CSSPropertyFont));
47 } 78 histogramTester.expectUniqueSample("WebCore.UseCounter.CSSProperties", UseCo unter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 1);
79 histogramTester.expectTotalCount("WebCore.FeatureObserver.CSSProperties", 0) ;
80
81 // Test that repeated measurements have no effect
82 useCounter.count(HTMLStandardMode, CSSPropertyFont);
83 histogramTester.expectUniqueSample("WebCore.UseCounter.CSSProperties", UseCo unter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 1);
84 histogramTester.expectTotalCount("WebCore.FeatureObserver.CSSProperties", 0) ;
85
86 // Test recording a different sample
87 EXPECT_FALSE(useCounter.isCounted(CSSPropertyZoom));
88 useCounter.count(HTMLStandardMode, CSSPropertyZoom);
89 EXPECT_TRUE(useCounter.isCounted(CSSPropertyZoom));
90 histogramTester.expectBucketCount("WebCore.UseCounter.CSSProperties", UseCou nter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 1);
91 histogramTester.expectBucketCount("WebCore.UseCounter.CSSProperties", UseCou nter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom), 1);
92 histogramTester.expectTotalCount("WebCore.UseCounter.CSSProperties", 2);
93 histogramTester.expectTotalCount("WebCore.FeatureObserver.CSSProperties", 0) ;
94
95 // Test the impact of page load on the new histogram
96 useCounter.didCommitLoad();
97 histogramTester.expectBucketCount("WebCore.UseCounter.CSSProperties", UseCou nter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 1);
98 histogramTester.expectBucketCount("WebCore.UseCounter.CSSProperties", UseCou nter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom), 1);
99 histogramTester.expectBucketCount("WebCore.UseCounter.CSSProperties", 1, 1);
100 histogramTester.expectTotalCount("WebCore.UseCounter.CSSProperties", 3);
101
102 // And verify the legacy histogram now looks the same
103 histogramTester.expectBucketCount("WebCore.FeatureObserver.CSSProperties", U seCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 1);
104 histogramTester.expectBucketCount("WebCore.FeatureObserver.CSSProperties", U seCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom), 1);
105 histogramTester.expectBucketCount("WebCore.FeatureObserver.CSSProperties", 1 , 1);
106 histogramTester.expectTotalCount("WebCore.FeatureObserver.CSSProperties", 3) ;
107
108 // Now a repeat measurement should get recorded again, exactly once
109 EXPECT_FALSE(useCounter.isCounted(CSSPropertyFont));
110 useCounter.count(HTMLStandardMode, CSSPropertyFont);
111 useCounter.count(HTMLStandardMode, CSSPropertyFont);
112 EXPECT_TRUE(useCounter.isCounted(CSSPropertyFont));
113 histogramTester.expectBucketCount("WebCore.UseCounter.CSSProperties", UseCou nter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 2);
114 histogramTester.expectTotalCount("WebCore.UseCounter.CSSProperties", 4);
115
116 // And on the next page load, the legacy histogram will again be updated
117 useCounter.didCommitLoad();
118 histogramTester.expectBucketCount("WebCore.FeatureObserver.CSSProperties", U seCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 2);
119 histogramTester.expectBucketCount("WebCore.FeatureObserver.CSSProperties", U seCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom), 1);
120 histogramTester.expectBucketCount("WebCore.FeatureObserver.CSSProperties", 1 , 2);
121 histogramTester.expectTotalCount("WebCore.FeatureObserver.CSSProperties", 5) ;
48 } 122 }
49 123
50 TEST_F(UseCounterTest, InspectorDisablesMeasurement) 124 TEST(UseCounterTest, InspectorDisablesMeasurement)
51 { 125 {
52 UseCounter useCounter; 126 UseCounter useCounter;
127 HistogramTester histogramTester;
53 128
54 // The specific feature we use here isn't important. 129 // The specific feature we use here isn't important.
55 UseCounter::Feature feature = UseCounter::Feature::SVGSMILElementInDocument; 130 UseCounter::Feature feature = UseCounter::Feature::SVGSMILElementInDocument;
56 CSSPropertyID property = CSSPropertyFontWeight; 131 CSSPropertyID property = CSSPropertyFontWeight;
57 CSSParserMode parserMode = HTMLStandardMode; 132 CSSParserMode parserMode = HTMLStandardMode;
58 133
59 EXPECT_FALSE(hasRecordedMeasurement(useCounter, feature)); 134 EXPECT_FALSE(useCounter.hasRecordedMeasurement(feature));
60 135
61 useCounter.muteForInspector(); 136 useCounter.muteForInspector();
62 recordMeasurement(useCounter, feature); 137 useCounter.recordMeasurement(feature);
63 EXPECT_FALSE(hasRecordedMeasurement(useCounter, feature)); 138 EXPECT_FALSE(useCounter.hasRecordedMeasurement(feature));
64 useCounter.count(parserMode, property); 139 useCounter.count(parserMode, property);
65 EXPECT_FALSE(useCounter.isCounted(property)); 140 EXPECT_FALSE(useCounter.isCounted(property));
141 histogramTester.expectTotalCount("WebCore.UseCounter.Features", 0);
dtapuska 2016/09/09 18:30:19 Can we not repeat the names all over this file? Ca
Rick Byers 2016/09/09 19:31:37 Done.
142 histogramTester.expectTotalCount("WebCore.UseCounter.CSSProperties", 0);
66 143
67 useCounter.muteForInspector(); 144 useCounter.muteForInspector();
68 recordMeasurement(useCounter, feature); 145 useCounter.recordMeasurement(feature);
69 EXPECT_FALSE(hasRecordedMeasurement(useCounter, feature)); 146 EXPECT_FALSE(useCounter.hasRecordedMeasurement(feature));
70 useCounter.count(parserMode, property); 147 useCounter.count(parserMode, property);
71 EXPECT_FALSE(useCounter.isCounted(property)); 148 EXPECT_FALSE(useCounter.isCounted(property));
149 histogramTester.expectTotalCount("WebCore.UseCounter.Features", 0);
150 histogramTester.expectTotalCount("WebCore.UseCounter.CSSProperties", 0);
72 151
73 useCounter.unmuteForInspector(); 152 useCounter.unmuteForInspector();
74 recordMeasurement(useCounter, feature); 153 useCounter.recordMeasurement(feature);
75 EXPECT_FALSE(hasRecordedMeasurement(useCounter, feature)); 154 EXPECT_FALSE(useCounter.hasRecordedMeasurement(feature));
76 useCounter.count(parserMode, property); 155 useCounter.count(parserMode, property);
77 EXPECT_FALSE(useCounter.isCounted(property)); 156 EXPECT_FALSE(useCounter.isCounted(property));
157 histogramTester.expectTotalCount("WebCore.UseCounter.Features", 0);
158 histogramTester.expectTotalCount("WebCore.UseCounter.CSSProperties", 0);
78 159
79 useCounter.unmuteForInspector(); 160 useCounter.unmuteForInspector();
80 recordMeasurement(useCounter, feature); 161 useCounter.recordMeasurement(feature);
81 EXPECT_TRUE(hasRecordedMeasurement(useCounter, feature)); 162 EXPECT_TRUE(useCounter.hasRecordedMeasurement(feature));
82 useCounter.count(parserMode, property); 163 useCounter.count(parserMode, property);
83 EXPECT_TRUE(useCounter.isCounted(property)); 164 EXPECT_TRUE(useCounter.isCounted(property));
165 histogramTester.expectUniqueSample("WebCore.UseCounter.Features", feature, 1 );
166 histogramTester.expectUniqueSample("WebCore.UseCounter.CSSProperties", UseCo unter::mapCSSPropertyIdToCSSSampleIdForHistogram(property), 1);
84 } 167 }
85 168
86 class DeprecationTest : public ::testing::Test { 169 class DeprecationTest : public ::testing::Test {
87 public: 170 public:
88 DeprecationTest() 171 DeprecationTest()
89 : m_dummy(DummyPageHolder::create()) 172 : m_dummy(DummyPageHolder::create())
90 , m_deprecation(m_dummy->page().frameHost().deprecation()) 173 , m_deprecation(m_dummy->page().frameHost().deprecation())
91 , m_useCounter(m_dummy->page().frameHost().useCounter()) 174 , m_useCounter(m_dummy->page().frameHost().useCounter())
92 { 175 {
93 } 176 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 214
132 m_deprecation.unmuteForInspector(); 215 m_deprecation.unmuteForInspector();
133 Deprecation::warnOnDeprecatedProperties(frame(), property); 216 Deprecation::warnOnDeprecatedProperties(frame(), property);
134 // TODO: use the actually deprecated property to get a deprecation message. 217 // TODO: use the actually deprecated property to get a deprecation message.
135 EXPECT_FALSE(m_deprecation.isSuppressed(property)); 218 EXPECT_FALSE(m_deprecation.isSuppressed(property));
136 Deprecation::countDeprecation(frame(), feature); 219 Deprecation::countDeprecation(frame(), feature);
137 EXPECT_TRUE(m_useCounter.hasRecordedMeasurement(feature)); 220 EXPECT_TRUE(m_useCounter.hasRecordedMeasurement(feature));
138 } 221 }
139 222
140 } // namespace blink 223 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698