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

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

Issue 2604633002: Mute use counters for internal pages (Closed)
Patch Set: lunalu CR feedback: improve comments/tests 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/");
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 svgUrl = URLTestHelpers::toKURL("about:blank");
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, even when the URL
227 useCounter.didCommitLoad(); 232 // scheme is internal (in practice SVGs always appear to get loaded with
233 // an about:blank URL).
234 useCounter.didCommitLoad(svgUrl);
lunalu1 2016/12/23 19:26:25 Can we just do useCounter.didCommitLoad(URLTestHel
Rick Byers 2016/12/23 19:34:59 Done.
228 histogramTester.expectBucketCount(kSVGFeaturesHistogramName, 235 histogramTester.expectBucketCount(kSVGFeaturesHistogramName,
229 UseCounter::PageVisits, 1); 236 UseCounter::PageVisits, 1);
230 histogramTester.expectTotalCount(kSVGFeaturesHistogramName, 2); 237 histogramTester.expectTotalCount(kSVGFeaturesHistogramName, 2);
231 histogramTester.expectBucketCount(kSVGCSSHistogramName, 1, 1); 238 histogramTester.expectBucketCount(kSVGCSSHistogramName, 1, 1);
232 histogramTester.expectTotalCount(kSVGCSSHistogramName, 2); 239 histogramTester.expectTotalCount(kSVGCSSHistogramName, 2);
233 240
234 // And the legacy histogram will be updated to include these 241 // And the legacy histogram will be updated to include these
235 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, 242 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName,
236 UseCounter::SVGSMILAdditiveAnimation, 1); 243 UseCounter::SVGSMILAdditiveAnimation, 1);
237 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, 244 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 useCounter.recordMeasurement(feature); 302 useCounter.recordMeasurement(feature);
296 EXPECT_TRUE(useCounter.hasRecordedMeasurement(feature)); 303 EXPECT_TRUE(useCounter.hasRecordedMeasurement(feature));
297 useCounter.count(parserMode, property); 304 useCounter.count(parserMode, property);
298 EXPECT_TRUE(useCounter.isCounted(property)); 305 EXPECT_TRUE(useCounter.isCounted(property));
299 histogramTester.expectUniqueSample(kFeaturesHistogramName, feature, 1); 306 histogramTester.expectUniqueSample(kFeaturesHistogramName, feature, 1);
300 histogramTester.expectUniqueSample( 307 histogramTester.expectUniqueSample(
301 kCSSHistogramName, 308 kCSSHistogramName,
302 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property), 1); 309 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property), 1);
303 } 310 }
304 311
312 void expectHistograms(const HistogramTester& histogramTester,
313 int visitsCount,
314 UseCounter::Feature feature,
315 int featureCount,
316 CSSPropertyID property,
317 int propertyCount) {
318 histogramTester.expectBucketCount(kFeaturesHistogramName,
319 UseCounter::PageVisits, visitsCount);
320 histogramTester.expectBucketCount(kFeaturesHistogramName, feature,
321 featureCount);
322 histogramTester.expectTotalCount(kFeaturesHistogramName,
323 visitsCount + featureCount);
324 histogramTester.expectBucketCount(kCSSHistogramName, 1, visitsCount);
325 histogramTester.expectBucketCount(
326 kCSSHistogramName,
327 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property),
328 propertyCount);
329 histogramTester.expectTotalCount(kCSSHistogramName,
330 visitsCount + propertyCount);
331 }
332
333 // Failing on Android: crbug.com/667913
334 #if OS(ANDROID)
335 #define MAYBE_MutedDocuments DISABLED_MutedDocuments
336 #else
337 #define MAYBE_MutedDocuments MutedDocuments
338 #endif
339 TEST(UseCounterTest, MAYBE_MutedDocuments) {
340 UseCounter useCounter;
341 HistogramTester histogramTester;
342
343 // Counters triggered before any load are always reported.
344 useCounter.recordMeasurement(UseCounter::Fetch);
345 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
346 expectHistograms(histogramTester, 0, UseCounter::Fetch, 1,
347 CSSPropertyFontWeight, 1);
348
349 // Loading an internal page doesn't bump PageVisits and future metrics are
350 // muted.
351 useCounter.didCommitLoad(URLTestHelpers::toKURL("about:blank"));
352 useCounter.recordMeasurement(UseCounter::Fetch);
353 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
354 expectHistograms(histogramTester, 0, UseCounter::Fetch, 1,
355 CSSPropertyFontWeight, 1);
356
357 // Even if the inspector mutes and unmutes.
358 useCounter.muteForInspector();
359 useCounter.unmuteForInspector();
360 useCounter.recordMeasurement(UseCounter::Fetch);
361 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
362 expectHistograms(histogramTester, 0, UseCounter::Fetch, 1,
363 CSSPropertyFontWeight, 1);
364
365 // If we now load a real web page, metrics are reported again.
366 useCounter.didCommitLoad(URLTestHelpers::toKURL("http://foo.com/"));
367 useCounter.recordMeasurement(UseCounter::Fetch);
368 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
369 expectHistograms(histogramTester, 1, UseCounter::Fetch, 2,
370 CSSPropertyFontWeight, 2);
371
372 // HTTPs URLs are the same.
373 useCounter.didCommitLoad(
374 URLTestHelpers::toKURL("https://baz.com:1234/blob.html"));
375 useCounter.recordMeasurement(UseCounter::Fetch);
376 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
377 expectHistograms(histogramTester, 2, UseCounter::Fetch, 3,
378 CSSPropertyFontWeight, 3);
379
380 // Extensions aren't counted.
381 useCounter.didCommitLoad(
382 URLTestHelpers::toKURL("chrome-extension://1238ba908adf/"));
383 useCounter.recordMeasurement(UseCounter::Fetch);
384 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
385 expectHistograms(histogramTester, 2, UseCounter::Fetch, 3,
386 CSSPropertyFontWeight, 3);
387
388 // Nor is devtools
389 useCounter.didCommitLoad(
390 URLTestHelpers::toKURL("chrome-devtools://1238ba908adf/"));
391 useCounter.recordMeasurement(UseCounter::Fetch);
392 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
393 expectHistograms(histogramTester, 2, UseCounter::Fetch, 3,
394 CSSPropertyFontWeight, 3);
395
396 // Nor are data URLs
397 useCounter.didCommitLoad(
398 URLTestHelpers::toKURL("data:text/plain,thisisaurl"));
399 useCounter.recordMeasurement(UseCounter::Fetch);
400 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
401 expectHistograms(histogramTester, 2, UseCounter::Fetch, 3,
402 CSSPropertyFontWeight, 3);
403
404 // Or empty URLs (a main frame with no Document)
405 useCounter.didCommitLoad(KURL());
406 useCounter.recordMeasurement(UseCounter::Fetch);
407 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
408 expectHistograms(histogramTester, 2, UseCounter::Fetch, 3,
409 CSSPropertyFontWeight, 3);
410
411 // But file URLs are
412 useCounter.didCommitLoad(URLTestHelpers::toKURL("file:///c/autoexec.bat"));
413 useCounter.recordMeasurement(UseCounter::Fetch);
414 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
415 expectHistograms(histogramTester, 3, UseCounter::Fetch, 4,
416 CSSPropertyFontWeight, 4);
417 }
418
305 class DeprecationTest : public ::testing::Test { 419 class DeprecationTest : public ::testing::Test {
306 public: 420 public:
307 DeprecationTest() 421 DeprecationTest()
308 : m_dummy(DummyPageHolder::create()), 422 : m_dummy(DummyPageHolder::create()),
309 m_deprecation(m_dummy->page().frameHost().deprecation()), 423 m_deprecation(m_dummy->page().frameHost().deprecation()),
310 m_useCounter(m_dummy->page().frameHost().useCounter()) {} 424 m_useCounter(m_dummy->page().frameHost().useCounter()) {}
311 425
312 protected: 426 protected:
313 LocalFrame* frame() { return &m_dummy->frame(); } 427 LocalFrame* frame() { return &m_dummy->frame(); }
314 428
(...skipping 29 matching lines...) Expand all
344 458
345 m_deprecation.unmuteForInspector(); 459 m_deprecation.unmuteForInspector();
346 Deprecation::warnOnDeprecatedProperties(frame(), property); 460 Deprecation::warnOnDeprecatedProperties(frame(), property);
347 // TODO: use the actually deprecated property to get a deprecation message. 461 // TODO: use the actually deprecated property to get a deprecation message.
348 EXPECT_FALSE(m_deprecation.isSuppressed(property)); 462 EXPECT_FALSE(m_deprecation.isSuppressed(property));
349 Deprecation::countDeprecation(frame(), feature); 463 Deprecation::countDeprecation(frame(), feature);
350 EXPECT_TRUE(m_useCounter.hasRecordedMeasurement(feature)); 464 EXPECT_TRUE(m_useCounter.hasRecordedMeasurement(feature));
351 } 465 }
352 466
353 } // namespace blink 467 } // 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