Chromium Code Reviews| Index: third_party/WebKit/Source/core/frame/UseCounterTest.cpp |
| diff --git a/third_party/WebKit/Source/core/frame/UseCounterTest.cpp b/third_party/WebKit/Source/core/frame/UseCounterTest.cpp |
| index 9d47640b1aa7319f598c24dfa52700d902df00f0..74eb15762431f5e68bdebbcb8991da164b8ab903 100644 |
| --- a/third_party/WebKit/Source/core/frame/UseCounterTest.cpp |
| +++ b/third_party/WebKit/Source/core/frame/UseCounterTest.cpp |
| @@ -7,6 +7,8 @@ |
| #include "core/frame/UseCounter.h" |
| #include "core/testing/DummyPageHolder.h" |
| #include "platform/testing/HistogramTester.h" |
| +#include "platform/testing/URLTestHelpers.h" |
| +#include "platform/weborigin/KURL.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace { |
| @@ -33,6 +35,7 @@ namespace blink { |
| TEST(UseCounterTest, MAYBE_RecordingFeatures) { |
| UseCounter useCounter; |
| HistogramTester histogramTester; |
| + 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
|
| // Test recording a single (arbitrary) counter |
| EXPECT_FALSE(useCounter.hasRecordedMeasurement(UseCounter::Fetch)); |
| @@ -60,7 +63,7 @@ TEST(UseCounterTest, MAYBE_RecordingFeatures) { |
| histogramTester.expectTotalCount(kLegacyFeaturesHistogramName, 0); |
| // Test the impact of page load on the new histogram |
| - useCounter.didCommitLoad(); |
| + useCounter.didCommitLoad(dummyUrl); |
| histogramTester.expectBucketCount(kFeaturesHistogramName, UseCounter::Fetch, |
| 1); |
| histogramTester.expectBucketCount(kFeaturesHistogramName, |
| @@ -88,7 +91,7 @@ TEST(UseCounterTest, MAYBE_RecordingFeatures) { |
| histogramTester.expectTotalCount(kFeaturesHistogramName, 4); |
| // And on the next page load, the legacy histogram will again be updated |
| - useCounter.didCommitLoad(); |
| + useCounter.didCommitLoad(dummyUrl); |
| histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, |
| UseCounter::Fetch, 2); |
| histogramTester.expectBucketCount(kLegacyFeaturesHistogramName, |
| @@ -105,6 +108,7 @@ TEST(UseCounterTest, MAYBE_RecordingFeatures) { |
| TEST(UseCounterTest, RecordingCSSProperties) { |
| UseCounter useCounter; |
| HistogramTester histogramTester; |
| + KURL dummyUrl = URLTestHelpers::toKURL("https://dummysite.com/"); |
| // Test recording a single (arbitrary) property |
| EXPECT_FALSE(useCounter.isCounted(CSSPropertyFont)); |
| @@ -140,7 +144,7 @@ TEST(UseCounterTest, RecordingCSSProperties) { |
| histogramTester.expectTotalCount(kLegacyCSSHistogramName, 0); |
| // Test the impact of page load on the new histogram |
| - useCounter.didCommitLoad(); |
| + useCounter.didCommitLoad(dummyUrl); |
| histogramTester.expectBucketCount( |
| kCSSHistogramName, |
| UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), |
| @@ -176,7 +180,7 @@ TEST(UseCounterTest, RecordingCSSProperties) { |
| histogramTester.expectTotalCount(kCSSHistogramName, 4); |
| // And on the next page load, the legacy histogram will again be updated |
| - useCounter.didCommitLoad(); |
| + useCounter.didCommitLoad(dummyUrl); |
| histogramTester.expectBucketCount( |
| kLegacyCSSHistogramName, |
| UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), |
| @@ -203,6 +207,7 @@ TEST(UseCounterTest, RecordingCSSProperties) { |
| TEST(UseCounterTest, MAYBE_SVGImageContext) { |
| UseCounter useCounter(UseCounter::SVGImageContext); |
| HistogramTester histogramTester; |
| + KURL dummyUrl = URLTestHelpers::toKURL("https://dummysite.com/"); |
| // Verify that SVGImage related feature counters get recorded in a separate |
| // histogram. |
| @@ -224,7 +229,7 @@ TEST(UseCounterTest, MAYBE_SVGImageContext) { |
| 1); |
| // After a page load, the histograms will be updated |
| - useCounter.didCommitLoad(); |
| + useCounter.didCommitLoad(dummyUrl); |
| histogramTester.expectBucketCount(kSVGFeaturesHistogramName, |
| UseCounter::PageVisits, 1); |
| histogramTester.expectTotalCount(kSVGFeaturesHistogramName, 2); |
| @@ -302,6 +307,106 @@ TEST(UseCounterTest, MAYBE_InspectorDisablesMeasurement) { |
| UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property), 1); |
| } |
| +void expectHistograms(const HistogramTester& histogramTester, |
| + int visitsCount, |
| + UseCounter::Feature feature, |
| + int featureCount, |
| + CSSPropertyID property, |
| + int propertyCount) { |
| + histogramTester.expectBucketCount(kFeaturesHistogramName, |
| + UseCounter::PageVisits, visitsCount); |
| + histogramTester.expectBucketCount(kFeaturesHistogramName, feature, |
| + featureCount); |
| + histogramTester.expectTotalCount(kFeaturesHistogramName, |
| + visitsCount + featureCount); |
| + histogramTester.expectBucketCount(kCSSHistogramName, 1, visitsCount); |
| + histogramTester.expectBucketCount( |
| + kCSSHistogramName, |
| + UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property), |
| + propertyCount); |
| + histogramTester.expectTotalCount(kCSSHistogramName, |
| + visitsCount + propertyCount); |
| +} |
| + |
| +// Failing on Android: crbug.com/667913 |
| +#if OS(ANDROID) |
| +#define MAYBE_MutedDocuments DISABLED_MutedDocuments |
| +#else |
| +#define MAYBE_MutedDocuments MutedDocuments |
| +#endif |
| +TEST(UseCounterTest, MAYBE_MutedDocuments) { |
| + UseCounter useCounter; |
| + HistogramTester histogramTester; |
| + |
| + // Counters triggered before any load are always reported. |
| + useCounter.recordMeasurement(UseCounter::Fetch); |
| + useCounter.count(HTMLStandardMode, CSSPropertyFontWeight); |
| + expectHistograms(histogramTester, 0, UseCounter::Fetch, 1, |
| + CSSPropertyFontWeight, 1); |
| + |
| + // Loading an internal page doesn't bump PageVisits and future metrics are |
| + // muted. |
| + useCounter.didCommitLoad(URLTestHelpers::toKURL("about:blank")); |
| + useCounter.recordMeasurement(UseCounter::Fetch); |
| + useCounter.count(HTMLStandardMode, CSSPropertyFontWeight); |
| + expectHistograms(histogramTester, 0, UseCounter::Fetch, 1, |
| + CSSPropertyFontWeight, 1); |
| + |
| + // Even if the inspector mutes and unmutes. |
| + useCounter.muteForInspector(); |
| + useCounter.unmuteForInspector(); |
| + useCounter.recordMeasurement(UseCounter::Fetch); |
| + useCounter.count(HTMLStandardMode, CSSPropertyFontWeight); |
| + expectHistograms(histogramTester, 0, UseCounter::Fetch, 1, |
| + CSSPropertyFontWeight, 1); |
| + |
| + // If we now load a real web page, metrics are reported again. |
| + useCounter.didCommitLoad(URLTestHelpers::toKURL("http://foo.com/")); |
| + useCounter.recordMeasurement(UseCounter::Fetch); |
| + useCounter.count(HTMLStandardMode, CSSPropertyFontWeight); |
| + expectHistograms(histogramTester, 1, UseCounter::Fetch, 2, |
| + CSSPropertyFontWeight, 2); |
| + |
| + // HTTPs URLs are the same. |
| + useCounter.didCommitLoad( |
| + URLTestHelpers::toKURL("https://baz.com:1234/blob.html")); |
| + useCounter.recordMeasurement(UseCounter::Fetch); |
| + useCounter.count(HTMLStandardMode, CSSPropertyFontWeight); |
| + expectHistograms(histogramTester, 2, UseCounter::Fetch, 3, |
| + CSSPropertyFontWeight, 3); |
| + |
| + // Extensions aren't counted. |
| + useCounter.didCommitLoad( |
| + URLTestHelpers::toKURL("chrome-extension://1238ba908adf/")); |
| + useCounter.recordMeasurement(UseCounter::Fetch); |
| + useCounter.count(HTMLStandardMode, CSSPropertyFontWeight); |
| + expectHistograms(histogramTester, 2, UseCounter::Fetch, 3, |
| + CSSPropertyFontWeight, 3); |
| + |
| + // Nor is devtools |
| + useCounter.didCommitLoad( |
| + URLTestHelpers::toKURL("chrome-devtools://1238ba908adf/")); |
| + useCounter.recordMeasurement(UseCounter::Fetch); |
| + useCounter.count(HTMLStandardMode, CSSPropertyFontWeight); |
| + expectHistograms(histogramTester, 2, UseCounter::Fetch, 3, |
| + CSSPropertyFontWeight, 3); |
| + |
| + // Nor are data URLs |
| + useCounter.didCommitLoad( |
| + URLTestHelpers::toKURL("data:text/plain,thisisaurl")); |
| + useCounter.recordMeasurement(UseCounter::Fetch); |
| + useCounter.count(HTMLStandardMode, CSSPropertyFontWeight); |
| + expectHistograms(histogramTester, 2, UseCounter::Fetch, 3, |
| + CSSPropertyFontWeight, 3); |
| + |
| + // But file URLs are |
| + useCounter.didCommitLoad(URLTestHelpers::toKURL("file:///c/autoexec.bat")); |
| + useCounter.recordMeasurement(UseCounter::Fetch); |
| + useCounter.count(HTMLStandardMode, CSSPropertyFontWeight); |
| + expectHistograms(histogramTester, 3, UseCounter::Fetch, 4, |
| + CSSPropertyFontWeight, 4); |
| +} |
| + |
| class DeprecationTest : public ::testing::Test { |
| public: |
| DeprecationTest() |