Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / core / frame / UseCounterTest.cpp
blob8db0aa8f2cb8b8111d641ed2747581dfbc1f6b14
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
3 // found in the LICENSE file.
5 #include "config.h"
6 #include "core/frame/UseCounter.h"
8 #include <gtest/gtest.h>
10 namespace blink {
12 class UseCounterTest : public ::testing::Test {
13 protected:
14 bool hasRecordedMeasurement(const UseCounter& useCounter, UseCounter::Feature feature)
16 return useCounter.hasRecordedMeasurement(feature);
19 void recordMeasurement(UseCounter& useCounter, UseCounter::Feature feature)
21 useCounter.recordMeasurement(feature);
24 void setUseCounterMuted(UseCounter& useCounter, bool muteCount)
26 UseCounter::m_muteCount = muteCount;
30 TEST_F(UseCounterTest, RecordingMeasurements)
32 UseCounter useCounter;
33 for (unsigned feature = 0; feature < UseCounter::NumberOfFeatures; feature++) {
34 if (feature != UseCounter::Feature::PageDestruction) {
35 EXPECT_FALSE(hasRecordedMeasurement(useCounter, static_cast<UseCounter::Feature>(feature)));
36 recordMeasurement(useCounter, static_cast<UseCounter::Feature>(feature));
37 EXPECT_TRUE(hasRecordedMeasurement(useCounter, static_cast<UseCounter::Feature>(feature)));
42 TEST_F(UseCounterTest, MultipleMeasurements)
44 UseCounter useCounter;
45 for (unsigned feature = 0; feature < UseCounter::NumberOfFeatures; feature++) {
46 if (feature != UseCounter::Feature::PageDestruction) {
47 recordMeasurement(useCounter, static_cast<UseCounter::Feature>(feature));
48 recordMeasurement(useCounter, static_cast<UseCounter::Feature>(feature));
49 EXPECT_TRUE(hasRecordedMeasurement(useCounter, static_cast<UseCounter::Feature>(feature)));
54 TEST_F(UseCounterTest, InspectorDisablesMeasurement)
56 UseCounter useCounter;
58 // The specific feature we use here isn't important.
59 UseCounter::Feature feature = UseCounter::Feature::SVGSMILElementInDocument;
61 EXPECT_FALSE(hasRecordedMeasurement(useCounter, feature));
63 UseCounter::muteForInspector();
64 recordMeasurement(useCounter, feature);
65 EXPECT_FALSE(hasRecordedMeasurement(useCounter, feature));
67 UseCounter::muteForInspector();
68 recordMeasurement(useCounter, feature);
69 EXPECT_FALSE(hasRecordedMeasurement(useCounter, feature));
71 UseCounter::unmuteForInspector();
72 recordMeasurement(useCounter, feature);
73 EXPECT_FALSE(hasRecordedMeasurement(useCounter, feature));
75 UseCounter::unmuteForInspector();
76 recordMeasurement(useCounter, feature);
77 EXPECT_TRUE(hasRecordedMeasurement(useCounter, feature));
80 } // namespace blink