| 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 "bindings/core/v8/PerformanceObserverCallback.h" |
| 7 #include "bindings/core/v8/V8BindingForTesting.h" | 8 #include "bindings/core/v8/V8BindingForTesting.h" |
| 8 #include "bindings/core/v8/V8PerformanceObserverCallback.h" | |
| 9 #include "core/timing/PerformanceBase.h" | 9 #include "core/timing/PerformanceBase.h" |
| 10 #include "core/timing/PerformanceLongTaskTiming.h" | 10 #include "core/timing/PerformanceLongTaskTiming.h" |
| 11 #include "core/timing/PerformanceObserver.h" | 11 #include "core/timing/PerformanceObserver.h" |
| 12 #include "core/timing/PerformanceObserverInit.h" | 12 #include "core/timing/PerformanceObserverInit.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 class TestPerformanceBase : public PerformanceBase { | 17 class TestPerformanceBase : public PerformanceBase { |
| 18 public: | 18 public: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 30 DEFINE_INLINE_TRACE() { PerformanceBase::trace(visitor); } | 30 DEFINE_INLINE_TRACE() { PerformanceBase::trace(visitor); } |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 class PerformanceBaseTest : public ::testing::Test { | 33 class PerformanceBaseTest : public ::testing::Test { |
| 34 protected: | 34 protected: |
| 35 void initialize(ScriptState* scriptState) { | 35 void initialize(ScriptState* scriptState) { |
| 36 v8::Local<v8::Function> callback = | 36 v8::Local<v8::Function> callback = |
| 37 v8::Function::New(scriptState->context(), nullptr).ToLocalChecked(); | 37 v8::Function::New(scriptState->context(), nullptr).ToLocalChecked(); |
| 38 m_base = new TestPerformanceBase(); | 38 m_base = new TestPerformanceBase(); |
| 39 m_cb = | 39 m_cb = |
| 40 V8PerformanceObserverCallback::create(scriptState->isolate(), callback); | 40 PerformanceObserverCallback::create(scriptState->isolate(), callback); |
| 41 m_observer = PerformanceObserver::create(scriptState, m_base, m_cb); | 41 m_observer = PerformanceObserver::create(scriptState, m_base, m_cb); |
| 42 } | 42 } |
| 43 | 43 |
| 44 Persistent<TestPerformanceBase> m_base; | 44 Persistent<TestPerformanceBase> m_base; |
| 45 Persistent<PerformanceObserver> m_observer; | 45 Persistent<PerformanceObserver> m_observer; |
| 46 Persistent<V8PerformanceObserverCallback> m_cb; | 46 Persistent<PerformanceObserverCallback> m_cb; |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 TEST_F(PerformanceBaseTest, Register) { | 49 TEST_F(PerformanceBaseTest, Register) { |
| 50 V8TestingScope scope; | 50 V8TestingScope scope; |
| 51 initialize(scope.getScriptState()); | 51 initialize(scope.getScriptState()); |
| 52 | 52 |
| 53 EXPECT_EQ(0, m_base->numObservers()); | 53 EXPECT_EQ(0, m_base->numObservers()); |
| 54 EXPECT_EQ(0, m_base->numActiveObservers()); | 54 EXPECT_EQ(0, m_base->numActiveObservers()); |
| 55 | 55 |
| 56 m_base->registerPerformanceObserver(*m_observer.get()); | 56 m_base->registerPerformanceObserver(*m_observer.get()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 entryTypeVec.append("longtask"); | 97 entryTypeVec.append("longtask"); |
| 98 options.setEntryTypes(entryTypeVec); | 98 options.setEntryTypes(entryTypeVec); |
| 99 m_observer->observe(options, exceptionState); | 99 m_observer->observe(options, exceptionState); |
| 100 | 100 |
| 101 // Add a long task entry | 101 // Add a long task entry |
| 102 m_base->addLongTaskTiming(1234, 5678, "www.foo.com/bar"); | 102 m_base->addLongTaskTiming(1234, 5678, "www.foo.com/bar"); |
| 103 EXPECT_EQ(1, m_base->numLongTaskTimingEntries()); // added an entry | 103 EXPECT_EQ(1, m_base->numLongTaskTimingEntries()); // added an entry |
| 104 } | 104 } |
| 105 | 105 |
| 106 } // namespace blink | 106 } // namespace blink |
| OLD | NEW |