Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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. | |
| 4 | |
| 5 #include "core/timing/Performance.h" | |
| 6 | |
| 7 #include "core/testing/DummyPageHolder.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 namespace blink { | |
| 11 | |
| 12 class PerformanceTest : public ::testing::Test { | |
| 13 protected: | |
| 14 void SetUp() override | |
| 15 { | |
| 16 m_pageHolder = DummyPageHolder::create(IntSize(800, 600)); | |
| 17 m_pageHolder->document().setURL(KURL(KURL(), "https://example.com")); | |
| 18 m_performance = Performance::create(&m_pageHolder->frame()); | |
| 19 } | |
| 20 | |
| 21 bool hasLongTaskInspectorAgent() | |
| 22 { | |
| 23 return m_performance->m_longTaskInspectorAgent; | |
| 24 } | |
| 25 | |
| 26 void addLongTaskObserver() | |
| 27 { | |
| 28 // simulate with filter options. | |
| 29 m_performance->m_observerFilterOptions |= PerformanceEntry::LongTask; | |
| 30 } | |
| 31 | |
| 32 void removeLongTaskObserver() | |
| 33 { | |
| 34 // simulate with filter options. | |
| 35 m_performance->m_observerFilterOptions = PerformanceEntry::Invalid; | |
| 36 } | |
| 37 | |
| 38 Persistent<Performance> m_performance; | |
| 39 std::unique_ptr<DummyPageHolder> m_pageHolder; | |
| 40 }; | |
| 41 | |
| 42 TEST_F(PerformanceTest, LongTaskObserverInstrumentation) | |
| 43 { | |
| 44 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,
| |
| 45 EXPECT_FALSE(hasLongTaskInspectorAgent()); | |
| 46 | |
| 47 // Adding LongTask observer (with filer option) enables instrumentation. | |
| 48 addLongTaskObserver(); | |
| 49 m_performance->enableLongTaskInstrumentation(); | |
| 50 EXPECT_TRUE(hasLongTaskInspectorAgent()); | |
| 51 | |
| 52 // While LongTask observer is present, disableLongTaskInstrumentation has no effect. | |
| 53 m_performance->disableLongTaskInstrumentation(); | |
| 54 EXPECT_TRUE(hasLongTaskInspectorAgent()); | |
| 55 | |
| 56 // Removing LongTask observer disables instrumentation. | |
| 57 removeLongTaskObserver(); | |
| 58 m_performance->disableLongTaskInstrumentation(); | |
| 59 EXPECT_FALSE(hasLongTaskInspectorAgent()); | |
| 60 } | |
| 61 | |
| 62 } | |
| OLD | NEW |