| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/timing/Performance.h" | 5 #include "core/timing/Performance.h" |
| 6 | 6 |
| 7 #include "core/timing/PerformanceBase.h" | 7 #include "core/timing/PerformanceBase.h" |
| 8 #include "core/timing/PerformanceLongTaskTiming.h" |
| 8 #include "core/timing/PerformanceObserver.h" | 9 #include "core/timing/PerformanceObserver.h" |
| 9 #include "core/timing/PerformanceObserverCallback.h" | 10 #include "core/timing/PerformanceObserverCallback.h" |
| 11 #include "core/timing/PerformanceObserverInit.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 13 |
| 12 namespace blink { | 14 namespace blink { |
| 13 | 15 |
| 14 class TestPerformanceBase : public PerformanceBase { | 16 class TestPerformanceBase : public PerformanceBase { |
| 15 public: | 17 public: |
| 16 TestPerformanceBase() : PerformanceBase(0) {} | 18 TestPerformanceBase() : PerformanceBase(0) {} |
| 17 ~TestPerformanceBase() {} | 19 ~TestPerformanceBase() {} |
| 18 | 20 |
| 19 ExecutionContext* getExecutionContext() const override { return nullptr; } | 21 ExecutionContext* getExecutionContext() const override { return nullptr; } |
| 20 | 22 |
| 21 int numActiveObservers() { return m_activeObservers.size(); } | 23 int numActiveObservers() { return m_activeObservers.size(); } |
| 22 | 24 |
| 23 int numObservers() { return m_observers.size(); } | 25 int numObservers() { return m_observers.size(); } |
| 24 | 26 |
| 27 int numLongTaskTimingEntries() |
| 28 { |
| 29 return m_longTaskTimingBuffer.size(); |
| 30 } |
| 31 |
| 25 DEFINE_INLINE_TRACE() | 32 DEFINE_INLINE_TRACE() |
| 26 { | 33 { |
| 27 PerformanceBase::trace(visitor); | 34 PerformanceBase::trace(visitor); |
| 28 } | 35 } |
| 29 }; | 36 }; |
| 30 | 37 |
| 31 class MockPerformanceObserverCallback : public PerformanceObserverCallback { | 38 class MockPerformanceObserverCallback : public PerformanceObserverCallback { |
| 32 public: | 39 public: |
| 33 MockPerformanceObserverCallback() {} | 40 MockPerformanceObserverCallback() {} |
| 34 ~MockPerformanceObserverCallback() {} | 41 ~MockPerformanceObserverCallback() {} |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 88 |
| 82 m_base->activateObserver(*m_observer.get()); | 89 m_base->activateObserver(*m_observer.get()); |
| 83 EXPECT_EQ(1, m_base->numObservers()); | 90 EXPECT_EQ(1, m_base->numObservers()); |
| 84 EXPECT_EQ(1, m_base->numActiveObservers()); | 91 EXPECT_EQ(1, m_base->numActiveObservers()); |
| 85 | 92 |
| 86 m_base->unregisterPerformanceObserver(*m_observer.get()); | 93 m_base->unregisterPerformanceObserver(*m_observer.get()); |
| 87 EXPECT_EQ(0, m_base->numObservers()); | 94 EXPECT_EQ(0, m_base->numObservers()); |
| 88 EXPECT_EQ(0, m_base->numActiveObservers()); | 95 EXPECT_EQ(0, m_base->numActiveObservers()); |
| 89 } | 96 } |
| 90 | 97 |
| 98 TEST_F(PerformanceBaseTest, AddLongTaskTiming) |
| 99 { |
| 100 // Add a long task entry, but no observer registered. |
| 101 m_base->addLongTaskTiming(1234, 5678, "www.foo.com/bar"); |
| 102 EXPECT_EQ(0, m_base->numLongTaskTimingEntries()); // has no effect |
| 103 |
| 104 // Make an observer for longtask |
| 105 NonThrowableExceptionState exceptionState; |
| 106 PerformanceObserverInit options; |
| 107 Vector<String> entryTypeVec; |
| 108 entryTypeVec.append("longtask"); |
| 109 options.setEntryTypes(entryTypeVec); |
| 110 m_observer->observe(options, exceptionState); |
| 111 |
| 112 // Add a long task entry |
| 113 m_base->addLongTaskTiming(1234, 5678, "www.foo.com/bar"); |
| 114 EXPECT_EQ(1, m_base->numLongTaskTimingEntries()); // added an entry |
| 115 } |
| 116 |
| 91 } // namespace blink | 117 } // namespace blink |
| OLD | NEW |