| 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->updateLongTaskInstrumentation(); |
| 45 EXPECT_FALSE(hasLongTaskInspectorAgent()); |
| 46 |
| 47 // Adding LongTask observer (with filer option) enables instrumentation. |
| 48 addLongTaskObserver(); |
| 49 m_performance->updateLongTaskInstrumentation(); |
| 50 EXPECT_TRUE(hasLongTaskInspectorAgent()); |
| 51 |
| 52 // While LongTask observer is present, updateLongTaskInstrumentation has no
effect. |
| 53 m_performance->updateLongTaskInstrumentation(); |
| 54 EXPECT_TRUE(hasLongTaskInspectorAgent()); |
| 55 |
| 56 // Removing LongTask observer disables instrumentation. |
| 57 removeLongTaskObserver(); |
| 58 m_performance->updateLongTaskInstrumentation(); |
| 59 EXPECT_FALSE(hasLongTaskInspectorAgent()); |
| 60 } |
| 61 |
| 62 } |
| OLD | NEW |