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 a982bf4eec6f286f965f353aef137dca11511f4e..e3423ce6349b0696fd4c5a4850d5c38c1e25a3df 100644 |
| --- a/third_party/WebKit/Source/core/frame/UseCounterTest.cpp |
| +++ b/third_party/WebKit/Source/core/frame/UseCounterTest.cpp |
| @@ -6,81 +6,164 @@ |
| #include "core/frame/FrameHost.h" |
| #include "core/frame/UseCounter.h" |
| #include "core/testing/DummyPageHolder.h" |
| +#include "platform/testing/HistogramTester.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace blink { |
| -class UseCounterTest : public ::testing::Test { |
| -protected: |
| - bool hasRecordedMeasurement(const UseCounter& useCounter, UseCounter::Feature feature) |
| - { |
| - return useCounter.hasRecordedMeasurement(feature); |
| - } |
| - |
| - void recordMeasurement(UseCounter& useCounter, UseCounter::Feature feature) |
| - { |
| - useCounter.recordMeasurement(feature); |
| - } |
| -}; |
| - |
| -TEST_F(UseCounterTest, RecordingMeasurements) |
| +TEST(UseCounterTest, RecordingFeatures) |
| { |
| UseCounter useCounter; |
| - for (unsigned feature = 0; feature < UseCounter::NumberOfFeatures; feature++) { |
| - if (feature != UseCounter::Feature::PageDestruction) { |
| - EXPECT_FALSE(hasRecordedMeasurement(useCounter, static_cast<UseCounter::Feature>(feature))); |
| - recordMeasurement(useCounter, static_cast<UseCounter::Feature>(feature)); |
| - EXPECT_TRUE(hasRecordedMeasurement(useCounter, static_cast<UseCounter::Feature>(feature))); |
| - } |
| - } |
| + HistogramTester histogramTester; |
| + |
| + // Test recording a single (arbitrary) counter |
| + EXPECT_FALSE(useCounter.hasRecordedMeasurement(UseCounter::Fetch)); |
| + useCounter.recordMeasurement(UseCounter::Fetch); |
| + EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::Fetch)); |
| + histogramTester.expectUniqueSample("WebCore.UseCounter.Features", UseCounter::Fetch, 1); |
| + histogramTester.expectTotalCount("WebCore.FeatureObserver", 0); |
| + |
| + // Test that repeated measurements have no effect |
| + useCounter.recordMeasurement(UseCounter::Fetch); |
| + histogramTester.expectUniqueSample("WebCore.UseCounter.Features", UseCounter::Fetch, 1); |
| + histogramTester.expectTotalCount("WebCore.FeatureObserver", 0); |
| + |
| + // Test recording a different sample |
| + EXPECT_FALSE(useCounter.hasRecordedMeasurement(UseCounter::FetchBodyStream)); |
| + useCounter.recordMeasurement(UseCounter::FetchBodyStream); |
| + EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::FetchBodyStream)); |
| + histogramTester.expectBucketCount("WebCore.UseCounter.Features", UseCounter::Fetch, 1); |
| + histogramTester.expectBucketCount("WebCore.UseCounter.Features", UseCounter::FetchBodyStream, 1); |
| + histogramTester.expectTotalCount("WebCore.UseCounter.Features", 2); |
| + histogramTester.expectTotalCount("WebCore.FeatureObserver", 0); |
| + |
| + // Test the impact of page load on the new histogram |
| + useCounter.didCommitLoad(); |
| + histogramTester.expectBucketCount("WebCore.UseCounter.Features", UseCounter::Fetch, 1); |
| + histogramTester.expectBucketCount("WebCore.UseCounter.Features", UseCounter::FetchBodyStream, 1); |
| + histogramTester.expectBucketCount("WebCore.UseCounter.Features", UseCounter::PageVisits, 1); |
| + histogramTester.expectTotalCount("WebCore.UseCounter.Features", 3); |
| + |
| + // And verify the legacy histogram now looks the same |
| + histogramTester.expectBucketCount("WebCore.FeatureObserver", UseCounter::Fetch, 1); |
| + histogramTester.expectBucketCount("WebCore.FeatureObserver", UseCounter::FetchBodyStream, 1); |
| + histogramTester.expectBucketCount("WebCore.FeatureObserver", UseCounter::PageVisits, 1); |
| + histogramTester.expectTotalCount("WebCore.FeatureObserver", 3); |
| + |
| + // Now a repeat measurement should get recorded again, exactly once |
| + EXPECT_FALSE(useCounter.hasRecordedMeasurement(UseCounter::Fetch)); |
| + useCounter.recordMeasurement(UseCounter::Fetch); |
| + useCounter.recordMeasurement(UseCounter::Fetch); |
| + EXPECT_TRUE(useCounter.hasRecordedMeasurement(UseCounter::Fetch)); |
| + histogramTester.expectBucketCount("WebCore.UseCounter.Features", UseCounter::Fetch, 2); |
| + histogramTester.expectTotalCount("WebCore.UseCounter.Features", 4); |
| + |
| + // And on the next page load, the legacy histogram will again be updated |
| + useCounter.didCommitLoad(); |
| + histogramTester.expectBucketCount("WebCore.FeatureObserver", UseCounter::Fetch, 2); |
| + histogramTester.expectBucketCount("WebCore.FeatureObserver", UseCounter::FetchBodyStream, 1); |
| + histogramTester.expectBucketCount("WebCore.FeatureObserver", UseCounter::PageVisits, 2); |
| + histogramTester.expectTotalCount("WebCore.FeatureObserver", 5); |
| } |
| -TEST_F(UseCounterTest, MultipleMeasurements) |
| +TEST(UseCounterTest, RecordingCSSProperties) |
| { |
| UseCounter useCounter; |
| - for (unsigned feature = 0; feature < UseCounter::NumberOfFeatures; feature++) { |
| - if (feature != UseCounter::Feature::PageDestruction) { |
| - recordMeasurement(useCounter, static_cast<UseCounter::Feature>(feature)); |
| - recordMeasurement(useCounter, static_cast<UseCounter::Feature>(feature)); |
| - EXPECT_TRUE(hasRecordedMeasurement(useCounter, static_cast<UseCounter::Feature>(feature))); |
| - } |
| - } |
| + HistogramTester histogramTester; |
| + |
| + // Test recording a single (arbitrary) property |
| + EXPECT_FALSE(useCounter.isCounted(CSSPropertyFont)); |
| + useCounter.count(HTMLStandardMode, CSSPropertyFont); |
| + EXPECT_TRUE(useCounter.isCounted(CSSPropertyFont)); |
| + histogramTester.expectUniqueSample("WebCore.UseCounter.CSSProperties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 1); |
| + histogramTester.expectTotalCount("WebCore.FeatureObserver.CSSProperties", 0); |
| + |
| + // Test that repeated measurements have no effect |
| + useCounter.count(HTMLStandardMode, CSSPropertyFont); |
| + histogramTester.expectUniqueSample("WebCore.UseCounter.CSSProperties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 1); |
| + histogramTester.expectTotalCount("WebCore.FeatureObserver.CSSProperties", 0); |
| + |
| + // Test recording a different sample |
| + EXPECT_FALSE(useCounter.isCounted(CSSPropertyZoom)); |
| + useCounter.count(HTMLStandardMode, CSSPropertyZoom); |
| + EXPECT_TRUE(useCounter.isCounted(CSSPropertyZoom)); |
| + histogramTester.expectBucketCount("WebCore.UseCounter.CSSProperties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 1); |
| + histogramTester.expectBucketCount("WebCore.UseCounter.CSSProperties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom), 1); |
| + histogramTester.expectTotalCount("WebCore.UseCounter.CSSProperties", 2); |
| + histogramTester.expectTotalCount("WebCore.FeatureObserver.CSSProperties", 0); |
| + |
| + // Test the impact of page load on the new histogram |
| + useCounter.didCommitLoad(); |
| + histogramTester.expectBucketCount("WebCore.UseCounter.CSSProperties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 1); |
| + histogramTester.expectBucketCount("WebCore.UseCounter.CSSProperties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom), 1); |
| + histogramTester.expectBucketCount("WebCore.UseCounter.CSSProperties", 1, 1); |
| + histogramTester.expectTotalCount("WebCore.UseCounter.CSSProperties", 3); |
| + |
| + // And verify the legacy histogram now looks the same |
| + histogramTester.expectBucketCount("WebCore.FeatureObserver.CSSProperties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 1); |
| + histogramTester.expectBucketCount("WebCore.FeatureObserver.CSSProperties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom), 1); |
| + histogramTester.expectBucketCount("WebCore.FeatureObserver.CSSProperties", 1, 1); |
| + histogramTester.expectTotalCount("WebCore.FeatureObserver.CSSProperties", 3); |
| + |
| + // Now a repeat measurement should get recorded again, exactly once |
| + EXPECT_FALSE(useCounter.isCounted(CSSPropertyFont)); |
| + useCounter.count(HTMLStandardMode, CSSPropertyFont); |
| + useCounter.count(HTMLStandardMode, CSSPropertyFont); |
| + EXPECT_TRUE(useCounter.isCounted(CSSPropertyFont)); |
| + histogramTester.expectBucketCount("WebCore.UseCounter.CSSProperties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 2); |
| + histogramTester.expectTotalCount("WebCore.UseCounter.CSSProperties", 4); |
| + |
| + // And on the next page load, the legacy histogram will again be updated |
| + useCounter.didCommitLoad(); |
| + histogramTester.expectBucketCount("WebCore.FeatureObserver.CSSProperties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyFont), 2); |
| + histogramTester.expectBucketCount("WebCore.FeatureObserver.CSSProperties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyZoom), 1); |
| + histogramTester.expectBucketCount("WebCore.FeatureObserver.CSSProperties", 1, 2); |
| + histogramTester.expectTotalCount("WebCore.FeatureObserver.CSSProperties", 5); |
| } |
| -TEST_F(UseCounterTest, InspectorDisablesMeasurement) |
| +TEST(UseCounterTest, InspectorDisablesMeasurement) |
| { |
| UseCounter useCounter; |
| + HistogramTester histogramTester; |
| // The specific feature we use here isn't important. |
| UseCounter::Feature feature = UseCounter::Feature::SVGSMILElementInDocument; |
| CSSPropertyID property = CSSPropertyFontWeight; |
| CSSParserMode parserMode = HTMLStandardMode; |
| - EXPECT_FALSE(hasRecordedMeasurement(useCounter, feature)); |
| + EXPECT_FALSE(useCounter.hasRecordedMeasurement(feature)); |
| useCounter.muteForInspector(); |
| - recordMeasurement(useCounter, feature); |
| - EXPECT_FALSE(hasRecordedMeasurement(useCounter, feature)); |
| + useCounter.recordMeasurement(feature); |
| + EXPECT_FALSE(useCounter.hasRecordedMeasurement(feature)); |
| useCounter.count(parserMode, property); |
| EXPECT_FALSE(useCounter.isCounted(property)); |
| + 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.
|
| + histogramTester.expectTotalCount("WebCore.UseCounter.CSSProperties", 0); |
| useCounter.muteForInspector(); |
| - recordMeasurement(useCounter, feature); |
| - EXPECT_FALSE(hasRecordedMeasurement(useCounter, feature)); |
| + useCounter.recordMeasurement(feature); |
| + EXPECT_FALSE(useCounter.hasRecordedMeasurement(feature)); |
| useCounter.count(parserMode, property); |
| EXPECT_FALSE(useCounter.isCounted(property)); |
| + histogramTester.expectTotalCount("WebCore.UseCounter.Features", 0); |
| + histogramTester.expectTotalCount("WebCore.UseCounter.CSSProperties", 0); |
| useCounter.unmuteForInspector(); |
| - recordMeasurement(useCounter, feature); |
| - EXPECT_FALSE(hasRecordedMeasurement(useCounter, feature)); |
| + useCounter.recordMeasurement(feature); |
| + EXPECT_FALSE(useCounter.hasRecordedMeasurement(feature)); |
| useCounter.count(parserMode, property); |
| EXPECT_FALSE(useCounter.isCounted(property)); |
| + histogramTester.expectTotalCount("WebCore.UseCounter.Features", 0); |
| + histogramTester.expectTotalCount("WebCore.UseCounter.CSSProperties", 0); |
| useCounter.unmuteForInspector(); |
| - recordMeasurement(useCounter, feature); |
| - EXPECT_TRUE(hasRecordedMeasurement(useCounter, feature)); |
| + useCounter.recordMeasurement(feature); |
| + EXPECT_TRUE(useCounter.hasRecordedMeasurement(feature)); |
| useCounter.count(parserMode, property); |
| EXPECT_TRUE(useCounter.isCounted(property)); |
| + histogramTester.expectUniqueSample("WebCore.UseCounter.Features", feature, 1); |
| + histogramTester.expectUniqueSample("WebCore.UseCounter.CSSProperties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property), 1); |
| } |
| class DeprecationTest : public ::testing::Test { |