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

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

Issue 2604633002: Mute use counters for internal pages (Closed)
Patch Set: Update a related comment 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";
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 useCounter.recordMeasurement(UseCounter::FetchBodyStream); 55 useCounter.recordMeasurement(UseCounter::FetchBodyStream);
54 EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::FetchBodyStream)); 56 EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::FetchBodyStream));
55 histogramTester.expectBucketCount(kFeaturesHistogramName, UseCounter::Fetch, 57 histogramTester.expectBucketCount(kFeaturesHistogramName, UseCounter::Fetch,
56 1); 58 1);
57 histogramTester.expectBucketCount(kFeaturesHistogramName, 59 histogramTester.expectBucketCount(kFeaturesHistogramName,
58 UseCounter::FetchBodyStream, 1); 60 UseCounter::FetchBodyStream, 1);
59 histogramTester.expectTotalCount(kFeaturesHistogramName, 2); 61 histogramTester.expectTotalCount(kFeaturesHistogramName, 2);
60 histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 0); 62 histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 0);
61 63
62 // Test the impact of page load on the new histogram 64 // Test the impact of page load on the new histogram
63 useCounter.didCommitLoad(); 65 useCounter.didCommitLoad(URLTestHelpers::toKURL("https://dummysite.com/"));
64 histogramTester.expectBucketCount(kFeaturesHistogramName, UseCounter::Fetch, 66 histogramTester.expectBucketCount(kFeaturesHistogramName, UseCounter::Fetch,
65 1); 67 1);
66 histogramTester.expectBucketCount(kFeaturesHistogramName, 68 histogramTester.expectBucketCount(kFeaturesHistogramName,
67 UseCounter::FetchBodyStream, 1); 69 UseCounter::FetchBodyStream, 1);
68 histogramTester.expectBucketCount(kFeaturesHistogramName, 70 histogramTester.expectBucketCount(kFeaturesHistogramName,
69 UseCounter::PageVisits, 1); 71 UseCounter::PageVisits, 1);
70 histogramTester.expectTotalCount(kFeaturesHistogramName, 3); 72 histogramTester.expectTotalCount(kFeaturesHistogramName, 3);
71 73
72 // And verify the legacy histogram now looks the same 74 // And verify the legacy histogram now looks the same
73 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, 75 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName,
74 UseCounter::Fetch, 1); 76 UseCounter::Fetch, 1);
75 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, 77 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName,
76 UseCounter::FetchBodyStream, 1); 78 UseCounter::FetchBodyStream, 1);
77 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, 79 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName,
78 UseCounter::PageVisits, 1); 80 UseCounter::PageVisits, 1);
79 histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 3); 81 histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 3);
80 82
81 // Now a repeat measurement should get recorded again, exactly once 83 // Now a repeat measurement should get recorded again, exactly once
82 EXPECT_FALSE(useCounter.hasRecordedMeasurement(UseCounter::Fetch)); 84 EXPECT_FALSE(useCounter.hasRecordedMeasurement(UseCounter::Fetch));
83 useCounter.recordMeasurement(UseCounter::Fetch); 85 useCounter.recordMeasurement(UseCounter::Fetch);
84 useCounter.recordMeasurement(UseCounter::Fetch); 86 useCounter.recordMeasurement(UseCounter::Fetch);
85 EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::Fetch)); 87 EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::Fetch));
86 histogramTester.expectBucketCount(kFeaturesHistogramName, UseCounter::Fetch, 88 histogramTester.expectBucketCount(kFeaturesHistogramName, UseCounter::Fetch,
87 2); 89 2);
88 histogramTester.expectTotalCount(kFeaturesHistogramName, 4); 90 histogramTester.expectTotalCount(kFeaturesHistogramName, 4);
89 91
90 // And on the next page load, the legacy histogram will again be updated 92 // And on the next page load, the legacy histogram will again be updated
91 useCounter.didCommitLoad(); 93 useCounter.didCommitLoad(URLTestHelpers::toKURL("https://dummysite.com/"));
92 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, 94 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName,
93 UseCounter::Fetch, 2); 95 UseCounter::Fetch, 2);
94 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, 96 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName,
95 UseCounter::FetchBodyStream, 1); 97 UseCounter::FetchBodyStream, 1);
96 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, 98 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName,
97 UseCounter::PageVisits, 2); 99 UseCounter::PageVisits, 2);
98 histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 5); 100 histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 5);
99 101
100 // None of this should update any of the SVG histograms 102 // None of this should update any of the SVG histograms
101 histogramTester.expectTotalCount(kSVGFeaturesHistogramName, 0); 103 histogramTester.expectTotalCount(kSVGFeaturesHistogramName, 0);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 135 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont),
134 1); 136 1);
135 histogramTester.expectBucketCount( 137 histogramTester.expectBucketCount(
136 kCSSHistogramName, 138 kCSSHistogramName,
137 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom), 139 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom),
138 1); 140 1);
139 histogramTester.expectTotalCount(kCSSHistogramName, 2); 141 histogramTester.expectTotalCount(kCSSHistogramName, 2);
140 histogramTester.expectTotalCount(kLegacyCSSHistogramName, 0); 142 histogramTester.expectTotalCount(kLegacyCSSHistogramName, 0);
141 143
142 // Test the impact of page load on the new histogram 144 // Test the impact of page load on the new histogram
143 useCounter.didCommitLoad(); 145 useCounter.didCommitLoad(URLTestHelpers::toKURL("https://dummysite.com/"));
144 histogramTester.expectBucketCount( 146 histogramTester.expectBucketCount(
145 kCSSHistogramName, 147 kCSSHistogramName,
146 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 148 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont),
147 1); 149 1);
148 histogramTester.expectBucketCount( 150 histogramTester.expectBucketCount(
149 kCSSHistogramName, 151 kCSSHistogramName,
150 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom), 152 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom),
151 1); 153 1);
152 histogramTester.expectBucketCount(kCSSHistogramName, 1, 1); 154 histogramTester.expectBucketCount(kCSSHistogramName, 1, 1);
153 histogramTester.expectTotalCount(kCSSHistogramName, 3); 155 histogramTester.expectTotalCount(kCSSHistogramName, 3);
(...skipping 15 matching lines...) Expand all
169 useCounter.count(HTMLStandardMode, CSSPropertyFont); 171 useCounter.count(HTMLStandardMode, CSSPropertyFont);
170 useCounter.count(HTMLStandardMode, CSSPropertyFont); 172 useCounter.count(HTMLStandardMode, CSSPropertyFont);
171 EXPECT_TRUE(useCounter.isCounted(CSSPropertyFont)); 173 EXPECT_TRUE(useCounter.isCounted(CSSPropertyFont));
172 histogramTester.expectBucketCount( 174 histogramTester.expectBucketCount(
173 kCSSHistogramName, 175 kCSSHistogramName,
174 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 176 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont),
175 2); 177 2);
176 histogramTester.expectTotalCount(kCSSHistogramName, 4); 178 histogramTester.expectTotalCount(kCSSHistogramName, 4);
177 179
178 // And on the next page load, the legacy histogram will again be updated 180 // And on the next page load, the legacy histogram will again be updated
179 useCounter.didCommitLoad(); 181 useCounter.didCommitLoad(URLTestHelpers::toKURL("https://dummysite.com/"));
180 histogramTester.expectBucketCount( 182 histogramTester.expectBucketCount(
181 kLegacyCSSHistogramName, 183 kLegacyCSSHistogramName,
182 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 184 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont),
183 2); 185 2);
184 histogramTester.expectBucketCount( 186 histogramTester.expectBucketCount(
185 kLegacyCSSHistogramName, 187 kLegacyCSSHistogramName,
186 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom), 188 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom),
187 1); 189 1);
188 histogramTester.expectBucketCount(kLegacyCSSHistogramName, 1, 2); 190 histogramTester.expectBucketCount(kLegacyCSSHistogramName, 1, 2);
189 histogramTester.expectTotalCount(kLegacyCSSHistogramName, 5); 191 histogramTester.expectTotalCount(kLegacyCSSHistogramName, 5);
(...skipping 26 matching lines...) Expand all
216 218
217 // And for the CSS counters 219 // And for the CSS counters
218 EXPECT_FALSE(useCounter.isCounted(CSSPropertyFont)); 220 EXPECT_FALSE(useCounter.isCounted(CSSPropertyFont));
219 useCounter.count(HTMLStandardMode, CSSPropertyFont); 221 useCounter.count(HTMLStandardMode, CSSPropertyFont);
220 EXPECT_TRUE(useCounter.isCounted(CSSPropertyFont)); 222 EXPECT_TRUE(useCounter.isCounted(CSSPropertyFont));
221 histogramTester.expectUniqueSample( 223 histogramTester.expectUniqueSample(
222 kSVGCSSHistogramName, 224 kSVGCSSHistogramName,
223 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 225 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont),
224 1); 226 1);
225 227
226 // After a page load, the histograms will be updated 228 // After a page load, the histograms will be updated, even when the URL
227 useCounter.didCommitLoad(); 229 // scheme is internal (in practice SVGs always appear to get loaded with
230 // an about:blank URL).
231 useCounter.didCommitLoad(URLTestHelpers::toKURL("about:blank"));
228 histogramTester.expectBucketCount(kSVGFeaturesHistogramName, 232 histogramTester.expectBucketCount(kSVGFeaturesHistogramName,
229 UseCounter::PageVisits, 1); 233 UseCounter::PageVisits, 1);
230 histogramTester.expectTotalCount(kSVGFeaturesHistogramName, 2); 234 histogramTester.expectTotalCount(kSVGFeaturesHistogramName, 2);
231 histogramTester.expectBucketCount(kSVGCSSHistogramName, 1, 1); 235 histogramTester.expectBucketCount(kSVGCSSHistogramName, 1, 1);
232 histogramTester.expectTotalCount(kSVGCSSHistogramName, 2); 236 histogramTester.expectTotalCount(kSVGCSSHistogramName, 2);
233 237
234 // And the legacy histogram will be updated to include these 238 // And the legacy histogram will be updated to include these
235 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, 239 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName,
236 UseCounter::SVGSMILAdditiveAnimation, 1); 240 UseCounter::SVGSMILAdditiveAnimation, 1);
237 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, 241 histogramTester.expectBucketCount(kLegacyFeaturesHistogramName,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 useCounter.recordMeasurement(feature); 299 useCounter.recordMeasurement(feature);
296 EXPECT_TRUE(useCounter.hasRecordedMeasurement(feature)); 300 EXPECT_TRUE(useCounter.hasRecordedMeasurement(feature));
297 useCounter.count(parserMode, property); 301 useCounter.count(parserMode, property);
298 EXPECT_TRUE(useCounter.isCounted(property)); 302 EXPECT_TRUE(useCounter.isCounted(property));
299 histogramTester.expectUniqueSample(kFeaturesHistogramName, feature, 1); 303 histogramTester.expectUniqueSample(kFeaturesHistogramName, feature, 1);
300 histogramTester.expectUniqueSample( 304 histogramTester.expectUniqueSample(
301 kCSSHistogramName, 305 kCSSHistogramName,
302 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property), 1); 306 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property), 1);
303 } 307 }
304 308
309 void expectHistograms(const HistogramTester& histogramTester,
310 int visitsCount,
311 UseCounter::Feature feature,
312 int featureCount,
313 CSSPropertyID property,
314 int propertyCount) {
315 histogramTester.expectBucketCount(kFeaturesHistogramName,
316 UseCounter::PageVisits, visitsCount);
317 histogramTester.expectBucketCount(kFeaturesHistogramName, feature,
318 featureCount);
319 histogramTester.expectTotalCount(kFeaturesHistogramName,
320 visitsCount + featureCount);
321 histogramTester.expectBucketCount(kCSSHistogramName, 1, visitsCount);
322 histogramTester.expectBucketCount(
323 kCSSHistogramName,
324 UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property),
325 propertyCount);
326 histogramTester.expectTotalCount(kCSSHistogramName,
327 visitsCount + propertyCount);
328 }
329
330 // Failing on Android: crbug.com/667913
331 #if OS(ANDROID)
332 #define MAYBE_MutedDocuments DISABLED_MutedDocuments
333 #else
334 #define MAYBE_MutedDocuments MutedDocuments
335 #endif
336 TEST(UseCounterTest, MAYBE_MutedDocuments) {
337 UseCounter useCounter;
338 HistogramTester histogramTester;
339
340 // Counters triggered before any load are always reported.
341 useCounter.recordMeasurement(UseCounter::Fetch);
342 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
343 expectHistograms(histogramTester, 0, UseCounter::Fetch, 1,
344 CSSPropertyFontWeight, 1);
345
346 // Loading an internal page doesn't bump PageVisits and metrics not reported.
347 useCounter.didCommitLoad(URLTestHelpers::toKURL("about:blank"));
348 EXPECT_FALSE(useCounter.hasRecordedMeasurement(UseCounter::Fetch));
349 EXPECT_FALSE(useCounter.isCounted(CSSPropertyFontWeight));
350 useCounter.recordMeasurement(UseCounter::Fetch);
351 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
352 expectHistograms(histogramTester, 0, UseCounter::Fetch, 1,
353 CSSPropertyFontWeight, 1);
354
355 // But the fact that the features were seen is still known.
356 EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::Fetch));
357 EXPECT_TRUE(useCounter.isCounted(CSSPropertyFontWeight));
358
359 // Inspector muting then unmuting doesn't change the behavior.
360 useCounter.muteForInspector();
361 useCounter.unmuteForInspector();
362 useCounter.recordMeasurement(UseCounter::Fetch);
363 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
364 expectHistograms(histogramTester, 0, UseCounter::Fetch, 1,
365 CSSPropertyFontWeight, 1);
366
367 // If we now load a real web page, metrics are reported again.
368 useCounter.didCommitLoad(URLTestHelpers::toKURL("http://foo.com/"));
369 useCounter.recordMeasurement(UseCounter::Fetch);
370 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
371 expectHistograms(histogramTester, 1, UseCounter::Fetch, 2,
372 CSSPropertyFontWeight, 2);
373
374 // HTTPs URLs are the same.
375 useCounter.didCommitLoad(
376 URLTestHelpers::toKURL("https://baz.com:1234/blob.html"));
377 useCounter.recordMeasurement(UseCounter::Fetch);
378 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
379 expectHistograms(histogramTester, 2, UseCounter::Fetch, 3,
380 CSSPropertyFontWeight, 3);
381
382 // Extensions aren't counted.
383 useCounter.didCommitLoad(
384 URLTestHelpers::toKURL("chrome-extension://1238ba908adf/"));
385 useCounter.recordMeasurement(UseCounter::Fetch);
386 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
387 expectHistograms(histogramTester, 2, UseCounter::Fetch, 3,
388 CSSPropertyFontWeight, 3);
389
390 // Nor is devtools
391 useCounter.didCommitLoad(
392 URLTestHelpers::toKURL("chrome-devtools://1238ba908adf/"));
393 useCounter.recordMeasurement(UseCounter::Fetch);
394 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
395 expectHistograms(histogramTester, 2, UseCounter::Fetch, 3,
396 CSSPropertyFontWeight, 3);
397
398 // Nor are data URLs
399 useCounter.didCommitLoad(
400 URLTestHelpers::toKURL("data:text/plain,thisisaurl"));
401 useCounter.recordMeasurement(UseCounter::Fetch);
402 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
403 expectHistograms(histogramTester, 2, UseCounter::Fetch, 3,
404 CSSPropertyFontWeight, 3);
405
406 // Or empty URLs (a main frame with no Document)
407 useCounter.didCommitLoad(KURL());
408 useCounter.recordMeasurement(UseCounter::Fetch);
409 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
410 expectHistograms(histogramTester, 2, UseCounter::Fetch, 3,
411 CSSPropertyFontWeight, 3);
412
413 // But file URLs are
414 useCounter.didCommitLoad(URLTestHelpers::toKURL("file:///c/autoexec.bat"));
415 useCounter.recordMeasurement(UseCounter::Fetch);
416 useCounter.count(HTMLStandardMode, CSSPropertyFontWeight);
417 expectHistograms(histogramTester, 3, UseCounter::Fetch, 4,
418 CSSPropertyFontWeight, 4);
419 }
420
305 class DeprecationTest : public ::testing::Test { 421 class DeprecationTest : public ::testing::Test {
306 public: 422 public:
307 DeprecationTest() 423 DeprecationTest()
308 : m_dummy(DummyPageHolder::create()), 424 : m_dummy(DummyPageHolder::create()),
309 m_deprecation(m_dummy->page().frameHost().deprecation()), 425 m_deprecation(m_dummy->page().frameHost().deprecation()),
310 m_useCounter(m_dummy->page().frameHost().useCounter()) {} 426 m_useCounter(m_dummy->page().frameHost().useCounter()) {}
311 427
312 protected: 428 protected:
313 LocalFrame* frame() { return &m_dummy->frame(); } 429 LocalFrame* frame() { return &m_dummy->frame(); }
314 430
(...skipping 29 matching lines...) Expand all
344 460
345 m_deprecation.unmuteForInspector(); 461 m_deprecation.unmuteForInspector();
346 Deprecation::warnOnDeprecatedProperties(frame(), property); 462 Deprecation::warnOnDeprecatedProperties(frame(), property);
347 // TODO: use the actually deprecated property to get a deprecation message. 463 // TODO: use the actually deprecated property to get a deprecation message.
348 EXPECT_FALSE(m_deprecation.isSuppressed(property)); 464 EXPECT_FALSE(m_deprecation.isSuppressed(property));
349 Deprecation::countDeprecation(frame(), feature); 465 Deprecation::countDeprecation(frame(), feature);
350 EXPECT_TRUE(m_useCounter.hasRecordedMeasurement(feature)); 466 EXPECT_TRUE(m_useCounter.hasRecordedMeasurement(feature));
351 } 467 }
352 468
353 } // namespace blink 469 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698