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

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

Issue 2604633002: Mute use counters for internal pages (Closed)
Patch Set: Created 3 years, 12 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"
11 #include "platform/weborigin/KURL.h"
10 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
11 13
12 namespace { 14 namespace {
13 // Note that the new histogram names will change once the semantics stabilize; 15 // Note that the new histogram names will change once the semantics stabilize;
14 const char* const kFeaturesHistogramName = "WebCore.UseCounter_TEST.Features"; 16 const char* const kFeaturesHistogramName = "WebCore.UseCounter_TEST.Features";
15 const char* const kCSSHistogramName = "WebCore.UseCounter_TEST.CSSProperties"; 17 const char* const kCSSHistogramName = "WebCore.UseCounter_TEST.CSSProperties";
16 const char* const kSVGFeaturesHistogramName = 18 const char* const kSVGFeaturesHistogramName =
17 "WebCore.UseCounter_TEST.SVGImage.Features"; 19 "WebCore.UseCounter_TEST.SVGImage.Features";
18 const char* const kSVGCSSHistogramName = 20 const char* const kSVGCSSHistogramName =
19 "WebCore.UseCounter_TEST.SVGImage.CSSProperties"; 21 "WebCore.UseCounter_TEST.SVGImage.CSSProperties";
20 const char* const kLegacyFeaturesHistogramName = "WebCore.FeatureObserver"; 22 const char* const kLegacyFeaturesHistogramName = "WebCore.FeatureObserver";
21 const char* const kLegacyCSSHistogramName = 23 const char* const kLegacyCSSHistogramName =
22 "WebCore.FeatureObserver.CSSProperties"; 24 "WebCore.FeatureObserver.CSSProperties";
23 } 25 }
24 26
25 namespace blink { 27 namespace blink {
26 28
27 // Failing on Android: crbug.com/667913 29 // Failing on Android: crbug.com/667913
28 #if OS(ANDROID) 30 #if OS(ANDROID)
29 #define MAYBE_RecordingFeatures DISABLED_RecordingFeatures 31 #define MAYBE_RecordingFeatures DISABLED_RecordingFeatures
30 #else 32 #else
31 #define MAYBE_RecordingFeatures RecordingFeatures 33 #define MAYBE_RecordingFeatures RecordingFeatures
32 #endif 34 #endif
33 TEST(UseCounterTest, MAYBE_RecordingFeatures) { 35 TEST(UseCounterTest, MAYBE_RecordingFeatures) {
34 UseCounter useCounter; 36 UseCounter useCounter;
35 HistogramTester histogramTester; 37 HistogramTester histogramTester;
38 KURL dummyUrl = URLTestHelpers::toKURL("https://dummysite.com/");
lunalu1 2016/12/23 19:26:25 Please correct me if I am wrong. I see "dummyUrl"
Rick Byers 2016/12/23 19:34:59 Since we have to run the KURL constructor at some
36 39
37 // Test recording a single (arbitrary) counter 40 // Test recording a single (arbitrary) counter
38 EXPECT_FALSE(useCounter.hasRecordedMeasurement(UseCounter::Fetch)); 41 EXPECT_FALSE(useCounter.hasRecordedMeasurement(UseCounter::Fetch));
39 useCounter.recordMeasurement(UseCounter::Fetch); 42 useCounter.recordMeasurement(UseCounter::Fetch);
40 EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::Fetch)); 43 EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::Fetch));
41 histogramTester.expectUniqueSample(kFeaturesHistogramName, UseCounter::Fetch, 44 histogramTester.expectUniqueSample(kFeaturesHistogramName, UseCounter::Fetch,
42 1); 45 1);
43 histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 0); 46 histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 0);
44 47
45 // Test that repeated measurements have no effect 48 // Test that repeated measurements have no effect
46 useCounter.recordMeasurement(UseCounter::Fetch); 49 useCounter.recordMeasurement(UseCounter::Fetch);
47 histogramTester.expectUniqueSample(kFeaturesHistogramName, UseCounter::Fetch, 50 histogramTester.expectUniqueSample(kFeaturesHistogramName, UseCounter::Fetch,
48 1); 51 1);
49 histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 0); 52 histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 0);
50 53
51 // Test recording a different sample 54 // Test recording a different sample
52 EXPECT_FALSE(useCounter.hasRecordedMeasurement(UseCounter::FetchBodyStream)); 55 EXPECT_FALSE(useCounter.hasRecordedMeasurement(UseCounter::FetchBodyStream));
53 useCounter.recordMeasurement(UseCounter::FetchBodyStream); 56 useCounter.recordMeasurement(UseCounter::FetchBodyStream);
54 EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::FetchBodyStream)); 57 EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::FetchBodyStream));
55 histogramTester.expectBucketCount(kFeaturesHistogramName, UseCounter::Fetch, 58 histogramTester.expectBucketCount(kFeaturesHistogramName, UseCounter::Fetch,
56 1); 59 1);
57 histogramTester.expectBucketCount(kFeaturesHistogramName, 60 histogramTester.expectBucketCount(kFeaturesHistogramName,
58 UseCounter::FetchBodyStream, 1); 61 UseCounter::FetchBodyStream, 1);
59 histogramTester.expectTotalCount(kFeaturesHistogramName, 2); 62 histogramTester.expectTotalCount(kFeaturesHistogramName, 2);
60 histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 0); 63 histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 0);
61 64
62 // Test the impact of page load on the new histogram 65 // Test the impact of page load on the new histogram
63 useCounter.didCommitLoad(); 66 useCounter.didCommitLoad(dummyUrl);
64 histogramTester.expectBucketCount(kFeaturesHistogramName, UseCounter::Fetch, 67 histogramTester.expectBucketCount(kFeaturesHistogramName, UseCounter::Fetch,
65 1); 68 1);
66 histogramTester.expectBucketCount(kFeaturesHistogramName, 69 histogramTester.expectBucketCount(kFeaturesHistogramName,
67 UseCounter::FetchBodyStream, 1); 70 UseCounter::FetchBodyStream, 1);
68 histogramTester.expectBucketCount(kFeaturesHistogramName, 71 histogramTester.expectBucketCount(kFeaturesHistogramName,
69 UseCounter::PageVisits, 1); 72 UseCounter::PageVisits, 1);
70 histogramTester.expectTotalCount(kFeaturesHistogramName, 3); 73 histogramTester.expectTotalCount(kFeaturesHistogramName, 3);
71 74
72 // And verify the legacy histogram now looks the same 75 // And verify the legacy histogram now looks the same
73 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, 76 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName,
74 UseCounter::Fetch, 1); 77 UseCounter::Fetch, 1);
75 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, 78 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName,
76 UseCounter::FetchBodyStream, 1); 79 UseCounter::FetchBodyStream, 1);
77 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, 80 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName,
78 UseCounter::PageVisits, 1); 81 UseCounter::PageVisits, 1);
79 histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 3); 82 histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 3);
80 83
81 // Now a repeat measurement should get recorded again, exactly once 84 // Now a repeat measurement should get recorded again, exactly once
82 EXPECT_FALSE(useCounter.hasRecordedMeasurement(UseCounter::Fetch)); 85 EXPECT_FALSE(useCounter.hasRecordedMeasurement(UseCounter::Fetch));
83 useCounter.recordMeasurement(UseCounter::Fetch); 86 useCounter.recordMeasurement(UseCounter::Fetch);
84 useCounter.recordMeasurement(UseCounter::Fetch); 87 useCounter.recordMeasurement(UseCounter::Fetch);
85 EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::Fetch)); 88 EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::Fetch));
86 histogramTester.expectBucketCount(kFeaturesHistogramName, UseCounter::Fetch, 89 histogramTester.expectBucketCount(kFeaturesHistogramName, UseCounter::Fetch,
87 2); 90 2);
88 histogramTester.expectTotalCount(kFeaturesHistogramName, 4); 91 histogramTester.expectTotalCount(kFeaturesHistogramName, 4);
89 92
90 // And on the next page load, the legacy histogram will again be updated 93 // And on the next page load, the legacy histogram will again be updated
91 useCounter.didCommitLoad(); 94 useCounter.didCommitLoad(dummyUrl);
92 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, 95 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName,
93 UseCounter::Fetch, 2); 96 UseCounter::Fetch, 2);
94 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, 97 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName,
95 UseCounter::FetchBodyStream, 1); 98 UseCounter::FetchBodyStream, 1);
96 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, 99 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName,
97 UseCounter::PageVisits, 2); 100 UseCounter::PageVisits, 2);
98 histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 5); 101 histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 5);
99 102
100 // None of this should update any of the SVG histograms 103 // None of this should update any of the SVG histograms
101 histogramTester.expectTotalCount(kSVGFeaturesHistogramName, 0); 104 histogramTester.expectTotalCount(kSVGFeaturesHistogramName, 0);
102 histogramTester.expectTotalCount(kSVGCSSHistogramName, 0); 105 histogramTester.expectTotalCount(kSVGCSSHistogramName, 0);
103 } 106 }
104 107
105 TEST(UseCounterTest, RecordingCSSProperties) { 108 TEST(UseCounterTest, RecordingCSSProperties) {
106 UseCounter useCounter; 109 UseCounter useCounter;
107 HistogramTester histogramTester; 110 HistogramTester histogramTester;
111 KURL dummyUrl = URLTestHelpers::toKURL("https://dummysite.com/");
108 112
109 // Test recording a single (arbitrary) property 113 // Test recording a single (arbitrary) property
110 EXPECT_FALSE(useCounter.isCounted(CSSPropertyFont)); 114 EXPECT_FALSE(useCounter.isCounted(CSSPropertyFont));
111 useCounter.count(HTMLStandardMode, CSSPropertyFont); 115 useCounter.count(HTMLStandardMode, CSSPropertyFont);
112 EXPECT_TRUE(useCounter.isCounted(CSSPropertyFont)); 116 EXPECT_TRUE(useCounter.isCounted(CSSPropertyFont));
113 histogramTester.expectUniqueSample( 117 histogramTester.expectUniqueSample(
114 kCSSHistogramName, 118 kCSSHistogramName,
115 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 119 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont),
116 1); 120 1);
117 histogramTester.expectTotalCount(kLegacyCSSHistogramName, 0); 121 histogramTester.expectTotalCount(kLegacyCSSHistogramName, 0);
(...skipping 15 matching lines...) Expand all
133 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 137 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont),
134 1); 138 1);
135 histogramTester.expectBucketCount( 139 histogramTester.expectBucketCount(
136 kCSSHistogramName, 140 kCSSHistogramName,
137 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom), 141 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom),
138 1); 142 1);
139 histogramTester.expectTotalCount(kCSSHistogramName, 2); 143 histogramTester.expectTotalCount(kCSSHistogramName, 2);
140 histogramTester.expectTotalCount(kLegacyCSSHistogramName, 0); 144 histogramTester.expectTotalCount(kLegacyCSSHistogramName, 0);
141 145
142 // Test the impact of page load on the new histogram 146 // Test the impact of page load on the new histogram
143 useCounter.didCommitLoad(); 147 useCounter.didCommitLoad(dummyUrl);
144 histogramTester.expectBucketCount( 148 histogramTester.expectBucketCount(
145 kCSSHistogramName, 149 kCSSHistogramName,
146 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 150 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont),
147 1); 151 1);
148 histogramTester.expectBucketCount( 152 histogramTester.expectBucketCount(
149 kCSSHistogramName, 153 kCSSHistogramName,
150 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom), 154 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom),
151 1); 155 1);
152 histogramTester.expectBucketCount(kCSSHistogramName, 1, 1); 156 histogramTester.expectBucketCount(kCSSHistogramName, 1, 1);
153 histogramTester.expectTotalCount(kCSSHistogramName, 3); 157 histogramTester.expectTotalCount(kCSSHistogramName, 3);
(...skipping 15 matching lines...) Expand all
169 useCounter.count(HTMLStandardMode, CSSPropertyFont); 173 useCounter.count(HTMLStandardMode, CSSPropertyFont);
170 useCounter.count(HTMLStandardMode, CSSPropertyFont); 174 useCounter.count(HTMLStandardMode, CSSPropertyFont);
171 EXPECT_TRUE(useCounter.isCounted(CSSPropertyFont)); 175 EXPECT_TRUE(useCounter.isCounted(CSSPropertyFont));
172 histogramTester.expectBucketCount( 176 histogramTester.expectBucketCount(
173 kCSSHistogramName, 177 kCSSHistogramName,
174 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 178 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont),
175 2); 179 2);
176 histogramTester.expectTotalCount(kCSSHistogramName, 4); 180 histogramTester.expectTotalCount(kCSSHistogramName, 4);
177 181
178 // And on the next page load, the legacy histogram will again be updated 182 // And on the next page load, the legacy histogram will again be updated
179 useCounter.didCommitLoad(); 183 useCounter.didCommitLoad(dummyUrl);
180 histogramTester.expectBucketCount( 184 histogramTester.expectBucketCount(
181 kLegacyCSSHistogramName, 185 kLegacyCSSHistogramName,
182 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 186 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont),
183 2); 187 2);
184 histogramTester.expectBucketCount( 188 histogramTester.expectBucketCount(
185 kLegacyCSSHistogramName, 189 kLegacyCSSHistogramName,
186 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom), 190 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom),
187 1); 191 1);
188 histogramTester.expectBucketCount(kLegacyCSSHistogramName, 1, 2); 192 histogramTester.expectBucketCount(kLegacyCSSHistogramName, 1, 2);
189 histogramTester.expectTotalCount(kLegacyCSSHistogramName, 5); 193 histogramTester.expectTotalCount(kLegacyCSSHistogramName, 5);
190 194
191 // None of this should update any of the SVG histograms 195 // None of this should update any of the SVG histograms
192 histogramTester.expectTotalCount(kSVGFeaturesHistogramName, 0); 196 histogramTester.expectTotalCount(kSVGFeaturesHistogramName, 0);
193 histogramTester.expectTotalCount(kSVGCSSHistogramName, 0); 197 histogramTester.expectTotalCount(kSVGCSSHistogramName, 0);
194 } 198 }
195 199
196 // Failing on Android: crbug.com/667913 200 // Failing on Android: crbug.com/667913
197 #if OS(ANDROID) 201 #if OS(ANDROID)
198 #define MAYBE_SVGImageContext DISABLED_SVGImageContext 202 #define MAYBE_SVGImageContext DISABLED_SVGImageContext
199 #else 203 #else
200 #define MAYBE_SVGImageContext SVGImageContext 204 #define MAYBE_SVGImageContext SVGImageContext
201 #endif 205 #endif
202 206
203 TEST(UseCounterTest, MAYBE_SVGImageContext) { 207 TEST(UseCounterTest, MAYBE_SVGImageContext) {
204 UseCounter useCounter(UseCounter::SVGImageContext); 208 UseCounter useCounter(UseCounter::SVGImageContext);
205 HistogramTester histogramTester; 209 HistogramTester histogramTester;
210 KURL dummyUrl = URLTestHelpers::toKURL("https://dummysite.com/");
206 211
207 // Verify that SVGImage related feature counters get recorded in a separate 212 // Verify that SVGImage related feature counters get recorded in a separate
208 // histogram. 213 // histogram.
209 EXPECT_FALSE( 214 EXPECT_FALSE(
210 useCounter.hasRecordedMeasurement(UseCounter::SVGSMILAdditiveAnimation)); 215 useCounter.hasRecordedMeasurement(UseCounter::SVGSMILAdditiveAnimation));
211 useCounter.recordMeasurement(UseCounter::SVGSMILAdditiveAnimation); 216 useCounter.recordMeasurement(UseCounter::SVGSMILAdditiveAnimation);
212 EXPECT_TRUE( 217 EXPECT_TRUE(
213 useCounter.hasRecordedMeasurement(UseCounter::SVGSMILAdditiveAnimation)); 218 useCounter.hasRecordedMeasurement(UseCounter::SVGSMILAdditiveAnimation));
214 histogramTester.expectUniqueSample(kSVGFeaturesHistogramName, 219 histogramTester.expectUniqueSample(kSVGFeaturesHistogramName,
215 UseCounter::SVGSMILAdditiveAnimation, 1); 220 UseCounter::SVGSMILAdditiveAnimation, 1);
216 221
217 // And for the CSS counters 222 // And for the CSS counters
218 EXPECT_FALSE(useCounter.isCounted(CSSPropertyFont)); 223 EXPECT_FALSE(useCounter.isCounted(CSSPropertyFont));
219 useCounter.count(HTMLStandardMode, CSSPropertyFont); 224 useCounter.count(HTMLStandardMode, CSSPropertyFont);
220 EXPECT_TRUE(useCounter.isCounted(CSSPropertyFont)); 225 EXPECT_TRUE(useCounter.isCounted(CSSPropertyFont));
221 histogramTester.expectUniqueSample( 226 histogramTester.expectUniqueSample(
222 kSVGCSSHistogramName, 227 kSVGCSSHistogramName,
223 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 228 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont),
224 1); 229 1);
225 230
226 // After a page load, the histograms will be updated 231 // After a page load, the histograms will be updated
227 useCounter.didCommitLoad(); 232 useCounter.didCommitLoad(dummyUrl);
228 histogramTester.expectBucketCount(kSVGFeaturesHistogramName, 233 histogramTester.expectBucketCount(kSVGFeaturesHistogramName,
229 UseCounter::PageVisits, 1); 234 UseCounter::PageVisits, 1);
230 histogramTester.expectTotalCount(kSVGFeaturesHistogramName, 2); 235 histogramTester.expectTotalCount(kSVGFeaturesHistogramName, 2);
231 histogramTester.expectBucketCount(kSVGCSSHistogramName, 1, 1); 236 histogramTester.expectBucketCount(kSVGCSSHistogramName, 1, 1);
232 histogramTester.expectTotalCount(kSVGCSSHistogramName, 2); 237 histogramTester.expectTotalCount(kSVGCSSHistogramName, 2);
233 238
234 // And the legacy histogram will be updated to include these 239 // And the legacy histogram will be updated to include these
235 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, 240 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName,
236 UseCounter::SVGSMILAdditiveAnimation, 1); 241 UseCounter::SVGSMILAdditiveAnimation, 1);
237 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, 242 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 useCounter.recordMeasurement(feature); 300 useCounter.recordMeasurement(feature);
296 EXPECT_TRUE(useCounter.hasRecordedMeasurement(feature)); 301 EXPECT_TRUE(useCounter.hasRecordedMeasurement(feature));
297 useCounter.count(parserMode, property); 302 useCounter.count(parserMode, property);
298 EXPECT_TRUE(useCounter.isCounted(property)); 303 EXPECT_TRUE(useCounter.isCounted(property));
299 histogramTester.expectUniqueSample(kFeaturesHistogramName, feature, 1); 304 histogramTester.expectUniqueSample(kFeaturesHistogramName, feature, 1);
300 histogramTester.expectUniqueSample( 305 histogramTester.expectUniqueSample(
301 kCSSHistogramName, 306 kCSSHistogramName,
302 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property), 1); 307 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property), 1);
303 } 308 }
304 309
310 void expectHistograms(const HistogramTester& histogramTester,
311 int visitsCount,
312 UseCounter::Feature feature,
313 int featureCount,
314 CSSPropertyID property,
315 int propertyCount) {
316 histogramTester.expectBucketCount(kFeaturesHistogramName,
317 UseCounter::PageVisits, visitsCount);
318 histogramTester.expectBucketCount(kFeaturesHistogramName, feature,
319 featureCount);
320 histogramTester.expectTotalCount(kFeaturesHistogramName,
321 visitsCount + featureCount);
322 histogramTester.expectBucketCount(kCSSHistogramName, 1, visitsCount);
323 histogramTester.expectBucketCount(
324 kCSSHistogramName,
325 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property),
326 propertyCount);
327 histogramTester.expectTotalCount(kCSSHistogramName,
328 visitsCount + propertyCount);
329 }
330
331 // Failing on Android: crbug.com/667913
332 #if OS(ANDROID)
333 #define MAYBE_MutedDocuments DISABLED_MutedDocuments
334 #else
335 #define MAYBE_MutedDocuments MutedDocuments
336 #endif
337 TEST(UseCounterTest, MAYBE_MutedDocuments) {
338 UseCounter useCounter;
339 HistogramTester histogramTester;
340
341 // Counters triggered before any load are always reported.
342 useCounter.recordMeasurement(UseCounter::Fetch);
343 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
344 expectHistograms(histogramTester, 0, UseCounter::Fetch, 1,
345 CSSPropertyFontWeight, 1);
346
347 // Loading an internal page doesn't bump PageVisits and future metrics are
348 // muted.
349 useCounter.didCommitLoad(URLTestHelpers::toKURL("about:blank"));
350 useCounter.recordMeasurement(UseCounter::Fetch);
351 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
352 expectHistograms(histogramTester, 0, UseCounter::Fetch, 1,
353 CSSPropertyFontWeight, 1);
354
355 // Even if the inspector mutes and unmutes.
356 useCounter.muteForInspector();
357 useCounter.unmuteForInspector();
358 useCounter.recordMeasurement(UseCounter::Fetch);
359 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
360 expectHistograms(histogramTester, 0, UseCounter::Fetch, 1,
361 CSSPropertyFontWeight, 1);
362
363 // If we now load a real web page, metrics are reported again.
364 useCounter.didCommitLoad(URLTestHelpers::toKURL("http://foo.com/"));
365 useCounter.recordMeasurement(UseCounter::Fetch);
366 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
367 expectHistograms(histogramTester, 1, UseCounter::Fetch, 2,
368 CSSPropertyFontWeight, 2);
369
370 // HTTPs URLs are the same.
371 useCounter.didCommitLoad(
372 URLTestHelpers::toKURL("https://baz.com:1234/blob.html"));
373 useCounter.recordMeasurement(UseCounter::Fetch);
374 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
375 expectHistograms(histogramTester, 2, UseCounter::Fetch, 3,
376 CSSPropertyFontWeight, 3);
377
378 // Extensions aren't counted.
379 useCounter.didCommitLoad(
380 URLTestHelpers::toKURL("chrome-extension://1238ba908adf/"));
381 useCounter.recordMeasurement(UseCounter::Fetch);
382 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
383 expectHistograms(histogramTester, 2, UseCounter::Fetch, 3,
384 CSSPropertyFontWeight, 3);
385
386 // Nor is devtools
387 useCounter.didCommitLoad(
388 URLTestHelpers::toKURL("chrome-devtools://1238ba908adf/"));
389 useCounter.recordMeasurement(UseCounter::Fetch);
390 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
391 expectHistograms(histogramTester, 2, UseCounter::Fetch, 3,
392 CSSPropertyFontWeight, 3);
393
394 // Nor are data URLs
395 useCounter.didCommitLoad(
396 URLTestHelpers::toKURL("data:text/plain,thisisaurl"));
397 useCounter.recordMeasurement(UseCounter::Fetch);
398 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
399 expectHistograms(histogramTester, 2, UseCounter::Fetch, 3,
400 CSSPropertyFontWeight, 3);
401
402 // But file URLs are
403 useCounter.didCommitLoad(URLTestHelpers::toKURL("file:///c/autoexec.bat"));
404 useCounter.recordMeasurement(UseCounter::Fetch);
405 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
406 expectHistograms(histogramTester, 3, UseCounter::Fetch, 4,
407 CSSPropertyFontWeight, 4);
408 }
409
305 class DeprecationTest : public ::testing::Test { 410 class DeprecationTest : public ::testing::Test {
306 public: 411 public:
307 DeprecationTest() 412 DeprecationTest()
308 : m_dummy(DummyPageHolder::create()), 413 : m_dummy(DummyPageHolder::create()),
309 m_deprecation(m_dummy->page().frameHost().deprecation()), 414 m_deprecation(m_dummy->page().frameHost().deprecation()),
310 m_useCounter(m_dummy->page().frameHost().useCounter()) {} 415 m_useCounter(m_dummy->page().frameHost().useCounter()) {}
311 416
312 protected: 417 protected:
313 LocalFrame* frame() { return &m_dummy->frame(); } 418 LocalFrame* frame() { return &m_dummy->frame(); }
314 419
(...skipping 29 matching lines...) Expand all
344 449
345 m_deprecation.unmuteForInspector(); 450 m_deprecation.unmuteForInspector();
346 Deprecation::warnOnDeprecatedProperties(frame(), property); 451 Deprecation::warnOnDeprecatedProperties(frame(), property);
347 // TODO: use the actually deprecated property to get a deprecation message. 452 // TODO: use the actually deprecated property to get a deprecation message.
348 EXPECT_FALSE(m_deprecation.isSuppressed(property)); 453 EXPECT_FALSE(m_deprecation.isSuppressed(property));
349 Deprecation::countDeprecation(frame(), feature); 454 Deprecation::countDeprecation(frame(), feature);
350 EXPECT_TRUE(m_useCounter.hasRecordedMeasurement(feature)); 455 EXPECT_TRUE(m_useCounter.hasRecordedMeasurement(feature));
351 } 456 }
352 457
353 } // namespace blink 458 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/UseCounter.cpp ('k') | third_party/WebKit/Source/core/page/Page.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698