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/PerformanceObserverCallback.h" |
8 #include "bindings/core/v8/V8BindingForTesting.h" | 8 #include "bindings/core/v8/V8BindingForTesting.h" |
| 9 #include "core/testing/DummyPageHolder.h" |
9 #include "core/timing/PerformanceBase.h" | 10 #include "core/timing/PerformanceBase.h" |
10 #include "core/timing/PerformanceLongTaskTiming.h" | 11 #include "core/timing/PerformanceLongTaskTiming.h" |
11 #include "core/timing/PerformanceObserver.h" | 12 #include "core/timing/PerformanceObserver.h" |
12 #include "core/timing/PerformanceObserverInit.h" | 13 #include "core/timing/PerformanceObserverInit.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 namespace blink { | 16 namespace blink { |
16 | 17 |
17 class TestPerformanceBase : public PerformanceBase { | 18 class TestPerformanceBase : public PerformanceBase { |
18 public: | 19 public: |
(...skipping 16 matching lines...) Expand all Loading... |
35 class PerformanceBaseTest : public ::testing::Test { | 36 class PerformanceBaseTest : public ::testing::Test { |
36 protected: | 37 protected: |
37 void initialize(ScriptState* scriptState) { | 38 void initialize(ScriptState* scriptState) { |
38 v8::Local<v8::Function> callback = | 39 v8::Local<v8::Function> callback = |
39 v8::Function::New(scriptState->context(), nullptr).ToLocalChecked(); | 40 v8::Function::New(scriptState->context(), nullptr).ToLocalChecked(); |
40 m_base = new TestPerformanceBase(); | 41 m_base = new TestPerformanceBase(); |
41 m_cb = PerformanceObserverCallback::create(scriptState, callback); | 42 m_cb = PerformanceObserverCallback::create(scriptState, callback); |
42 m_observer = PerformanceObserver::create(scriptState, m_base, m_cb); | 43 m_observer = PerformanceObserver::create(scriptState, m_base, m_cb); |
43 } | 44 } |
44 | 45 |
| 46 void SetUp() override { |
| 47 m_pageHolder = DummyPageHolder::create(IntSize(800, 600)); |
| 48 } |
| 49 |
45 int numPerformanceEntriesInObserver() { | 50 int numPerformanceEntriesInObserver() { |
46 return m_observer->m_performanceEntries.size(); | 51 return m_observer->m_performanceEntries.size(); |
47 } | 52 } |
48 | 53 |
| 54 PerformanceNavigationTiming::NavigationType getNavigationType( |
| 55 NavigationType type, |
| 56 Document* document) { |
| 57 return PerformanceBase::getNavigationType(type, document); |
| 58 } |
| 59 |
49 Persistent<TestPerformanceBase> m_base; | 60 Persistent<TestPerformanceBase> m_base; |
50 Persistent<PerformanceObserver> m_observer; | 61 Persistent<PerformanceObserver> m_observer; |
| 62 std::unique_ptr<DummyPageHolder> m_pageHolder; |
51 Persistent<PerformanceObserverCallback> m_cb; | 63 Persistent<PerformanceObserverCallback> m_cb; |
52 }; | 64 }; |
53 | 65 |
54 TEST_F(PerformanceBaseTest, Register) { | 66 TEST_F(PerformanceBaseTest, Register) { |
55 V8TestingScope scope; | 67 V8TestingScope scope; |
56 initialize(scope.getScriptState()); | 68 initialize(scope.getScriptState()); |
57 | 69 |
58 EXPECT_EQ(0, m_base->numObservers()); | 70 EXPECT_EQ(0, m_base->numObservers()); |
59 EXPECT_EQ(0, m_base->numActiveObservers()); | 71 EXPECT_EQ(0, m_base->numActiveObservers()); |
60 | 72 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 Vector<String> entryTypeVec; | 114 Vector<String> entryTypeVec; |
103 entryTypeVec.append("longtask"); | 115 entryTypeVec.append("longtask"); |
104 options.setEntryTypes(entryTypeVec); | 116 options.setEntryTypes(entryTypeVec); |
105 m_observer->observe(options, exceptionState); | 117 m_observer->observe(options, exceptionState); |
106 | 118 |
107 EXPECT_TRUE(m_base->hasPerformanceObserverFor(PerformanceEntry::LongTask)); | 119 EXPECT_TRUE(m_base->hasPerformanceObserverFor(PerformanceEntry::LongTask)); |
108 // Add a long task entry | 120 // Add a long task entry |
109 m_base->addLongTaskTiming(1234, 5678, "www.foo.com/bar", nullptr); | 121 m_base->addLongTaskTiming(1234, 5678, "www.foo.com/bar", nullptr); |
110 EXPECT_EQ(1, numPerformanceEntriesInObserver()); // added an entry | 122 EXPECT_EQ(1, numPerformanceEntriesInObserver()); // added an entry |
111 } | 123 } |
| 124 |
| 125 TEST_F(PerformanceBaseTest, GetNavigationType) { |
| 126 m_pageHolder->page().setVisibilityState(PageVisibilityStatePrerender, false); |
| 127 PerformanceNavigationTiming::NavigationType returnedType = |
| 128 getNavigationType(NavigationTypeBackForward, &m_pageHolder->document()); |
| 129 EXPECT_EQ(returnedType, |
| 130 PerformanceNavigationTiming::NavigationType::Prerender); |
| 131 |
| 132 m_pageHolder->page().setVisibilityState(PageVisibilityStateHidden, false); |
| 133 returnedType = |
| 134 getNavigationType(NavigationTypeBackForward, &m_pageHolder->document()); |
| 135 EXPECT_EQ(returnedType, |
| 136 PerformanceNavigationTiming::NavigationType::BackForward); |
| 137 |
| 138 m_pageHolder->page().setVisibilityState(PageVisibilityStateVisible, false); |
| 139 returnedType = getNavigationType(NavigationTypeFormResubmitted, |
| 140 &m_pageHolder->document()); |
| 141 EXPECT_EQ(returnedType, |
| 142 PerformanceNavigationTiming::NavigationType::Navigate); |
| 143 } |
112 } // namespace blink | 144 } // namespace blink |
OLD | NEW |