| 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/dom/TaskRunnerHelper.h" | 9 #include "core/dom/TaskRunnerHelper.h" |
| 10 #include "core/testing/DummyPageHolder.h" | 10 #include "core/testing/DummyPageHolder.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 m_executionContext = new NullExecutionContext(); | 56 m_executionContext = new NullExecutionContext(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 ExecutionContext* getExecutionContext() { return m_executionContext.get(); } | 59 ExecutionContext* getExecutionContext() { return m_executionContext.get(); } |
| 60 | 60 |
| 61 int numPerformanceEntriesInObserver() { | 61 int numPerformanceEntriesInObserver() { |
| 62 return m_observer->m_performanceEntries.size(); | 62 return m_observer->m_performanceEntries.size(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 PerformanceNavigationTiming::NavigationType getNavigationType( | 65 PerformanceNavigationTiming::NavigationType getNavigationType( |
| 66 NavigationType type, | 66 FrameLoadType type, |
| 67 Document* document) { | 67 Document* document) { |
| 68 return PerformanceBase::getNavigationType(type, document); | 68 return PerformanceBase::getNavigationType(type, document); |
| 69 } | 69 } |
| 70 | 70 |
| 71 static bool allowsTimingRedirect( | 71 static bool allowsTimingRedirect( |
| 72 const Vector<ResourceResponse>& redirectChain, | 72 const Vector<ResourceResponse>& redirectChain, |
| 73 const ResourceResponse& finalResponse, | 73 const ResourceResponse& finalResponse, |
| 74 const SecurityOrigin& initiatorSecurityOrigin, | 74 const SecurityOrigin& initiatorSecurityOrigin, |
| 75 ExecutionContext* context) { | 75 ExecutionContext* context) { |
| 76 return PerformanceBase::allowsTimingRedirect( | 76 return PerformanceBase::allowsTimingRedirect( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 EXPECT_TRUE(m_base->hasPerformanceObserverFor(PerformanceEntry::LongTask)); | 141 EXPECT_TRUE(m_base->hasPerformanceObserverFor(PerformanceEntry::LongTask)); |
| 142 // Add a long task entry | 142 // Add a long task entry |
| 143 m_base->addLongTaskTiming(1234, 5678, "same-origin", "www.foo.com/bar", "", | 143 m_base->addLongTaskTiming(1234, 5678, "same-origin", "www.foo.com/bar", "", |
| 144 ""); | 144 ""); |
| 145 EXPECT_EQ(1, numPerformanceEntriesInObserver()); // added an entry | 145 EXPECT_EQ(1, numPerformanceEntriesInObserver()); // added an entry |
| 146 } | 146 } |
| 147 | 147 |
| 148 TEST_F(PerformanceBaseTest, GetNavigationType) { | 148 TEST_F(PerformanceBaseTest, GetNavigationType) { |
| 149 m_pageHolder->page().setVisibilityState(PageVisibilityStatePrerender, false); | 149 m_pageHolder->page().setVisibilityState(PageVisibilityStatePrerender, false); |
| 150 PerformanceNavigationTiming::NavigationType returnedType = | 150 PerformanceNavigationTiming::NavigationType returnedType = |
| 151 getNavigationType(NavigationTypeBackForward, &m_pageHolder->document()); | 151 getNavigationType(FrameLoadTypeBackForward, &m_pageHolder->document()); |
| 152 EXPECT_EQ(returnedType, | 152 EXPECT_EQ(returnedType, |
| 153 PerformanceNavigationTiming::NavigationType::Prerender); | 153 PerformanceNavigationTiming::NavigationType::Prerender); |
| 154 | 154 |
| 155 m_pageHolder->page().setVisibilityState(PageVisibilityStateHidden, false); | 155 m_pageHolder->page().setVisibilityState(PageVisibilityStateHidden, false); |
| 156 returnedType = | 156 returnedType = |
| 157 getNavigationType(NavigationTypeBackForward, &m_pageHolder->document()); | 157 getNavigationType(FrameLoadTypeBackForward, &m_pageHolder->document()); |
| 158 EXPECT_EQ(returnedType, | 158 EXPECT_EQ(returnedType, |
| 159 PerformanceNavigationTiming::NavigationType::BackForward); | 159 PerformanceNavigationTiming::NavigationType::BackForward); |
| 160 | 160 |
| 161 m_pageHolder->page().setVisibilityState(PageVisibilityStateVisible, false); | 161 m_pageHolder->page().setVisibilityState(PageVisibilityStateVisible, false); |
| 162 returnedType = getNavigationType(NavigationTypeFormResubmitted, | 162 returnedType = |
| 163 &m_pageHolder->document()); | 163 getNavigationType(FrameLoadTypeStandard, &m_pageHolder->document()); |
| 164 EXPECT_EQ(returnedType, | 164 EXPECT_EQ(returnedType, |
| 165 PerformanceNavigationTiming::NavigationType::Navigate); | 165 PerformanceNavigationTiming::NavigationType::Navigate); |
| 166 } | 166 } |
| 167 | 167 |
| 168 TEST_F(PerformanceBaseTest, AllowsTimingRedirect) { | 168 TEST_F(PerformanceBaseTest, AllowsTimingRedirect) { |
| 169 // When there are no cross-origin redirects. | 169 // When there are no cross-origin redirects. |
| 170 AtomicString originDomain = "http://127.0.0.1:8000"; | 170 AtomicString originDomain = "http://127.0.0.1:8000"; |
| 171 Vector<ResourceResponse> redirectChain; | 171 Vector<ResourceResponse> redirectChain; |
| 172 KURL url(ParsedURLString, originDomain + "/foo.html"); | 172 KURL url(ParsedURLString, originDomain + "/foo.html"); |
| 173 ResourceResponse finalResponse; | 173 ResourceResponse finalResponse; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 194 | 194 |
| 195 // When cross-origin redirect opts in. | 195 // When cross-origin redirect opts in. |
| 196 redirectChain.back().setHTTPHeaderField(HTTPNames::Timing_Allow_Origin, | 196 redirectChain.back().setHTTPHeaderField(HTTPNames::Timing_Allow_Origin, |
| 197 originDomain); | 197 originDomain); |
| 198 EXPECT_TRUE(allowsTimingRedirect(redirectChain, finalResponse, | 198 EXPECT_TRUE(allowsTimingRedirect(redirectChain, finalResponse, |
| 199 *securityOrigin.get(), | 199 *securityOrigin.get(), |
| 200 getExecutionContext())); | 200 getExecutionContext())); |
| 201 } | 201 } |
| 202 | 202 |
| 203 } // namespace blink | 203 } // namespace blink |
| OLD | NEW |