Chromium Code Reviews| Index: third_party/WebKit/Source/core/timing/PerformanceTest.cpp |
| diff --git a/third_party/WebKit/Source/core/timing/PerformanceTest.cpp b/third_party/WebKit/Source/core/timing/PerformanceTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..983360ef1ed2c22faf0a99e238f9fca801460b8e |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/timing/PerformanceTest.cpp |
| @@ -0,0 +1,62 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/timing/Performance.h" |
| + |
| +#include "core/testing/DummyPageHolder.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace blink { |
| + |
| +class PerformanceTest : public ::testing::Test { |
| +protected: |
| + void SetUp() override |
| + { |
| + m_pageHolder = DummyPageHolder::create(IntSize(800, 600)); |
| + m_pageHolder->document().setURL(KURL(KURL(), "https://example.com")); |
| + m_performance = Performance::create(&m_pageHolder->frame()); |
| + } |
| + |
| + bool hasLongTaskInspectorAgent() |
| + { |
| + return m_performance->m_longTaskInspectorAgent; |
| + } |
| + |
| + void addLongTaskObserver() |
| + { |
| + // simulate with filter options. |
| + m_performance->m_observerFilterOptions |= PerformanceEntry::LongTask; |
| + } |
| + |
| + void removeLongTaskObserver() |
| + { |
| + // simulate with filter options. |
| + m_performance->m_observerFilterOptions = PerformanceEntry::Invalid; |
| + } |
| + |
| + Persistent<Performance> m_performance; |
| + std::unique_ptr<DummyPageHolder> m_pageHolder; |
| +}; |
| + |
| +TEST_F(PerformanceTest, LongTaskObserverInstrumentation) |
| +{ |
| + m_performance->enableLongTaskInstrumentation(); |
|
caseq
2016/09/19 22:18:06
Can we rather express the test in a higher-level t
panicker
2016/09/20 12:00:39
Since I've moved this out of PerformanceObserver,
|
| + EXPECT_FALSE(hasLongTaskInspectorAgent()); |
| + |
| + // Adding LongTask observer (with filer option) enables instrumentation. |
| + addLongTaskObserver(); |
| + m_performance->enableLongTaskInstrumentation(); |
| + EXPECT_TRUE(hasLongTaskInspectorAgent()); |
| + |
| + // While LongTask observer is present, disableLongTaskInstrumentation has no effect. |
| + m_performance->disableLongTaskInstrumentation(); |
| + EXPECT_TRUE(hasLongTaskInspectorAgent()); |
| + |
| + // Removing LongTask observer disables instrumentation. |
| + removeLongTaskObserver(); |
| + m_performance->disableLongTaskInstrumentation(); |
| + EXPECT_FALSE(hasLongTaskInspectorAgent()); |
| +} |
| + |
| +} |