Chromium Code Reviews| 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/testing/DummyPageHolder.h" |
| 10 #include "core/testing/NullExecutionContext.h" | |
| 10 #include "core/timing/PerformanceBase.h" | 11 #include "core/timing/PerformanceBase.h" |
| 11 #include "core/timing/PerformanceLongTaskTiming.h" | 12 #include "core/timing/PerformanceLongTaskTiming.h" |
| 12 #include "core/timing/PerformanceObserver.h" | 13 #include "core/timing/PerformanceObserver.h" |
| 13 #include "core/timing/PerformanceObserverInit.h" | 14 #include "core/timing/PerformanceObserverInit.h" |
| 15 #include "platform/network/ResourceResponse.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 17 |
| 16 namespace blink { | 18 namespace blink { |
| 17 | 19 |
| 18 class TestPerformanceBase : public PerformanceBase { | 20 class TestPerformanceBase : public PerformanceBase { |
| 19 public: | 21 public: |
| 20 TestPerformanceBase() : PerformanceBase(0) {} | 22 TestPerformanceBase() : PerformanceBase(0) {} |
| 21 ~TestPerformanceBase() {} | 23 ~TestPerformanceBase() {} |
| 22 | 24 |
| 23 ExecutionContext* getExecutionContext() const override { return nullptr; } | 25 ExecutionContext* getExecutionContext() const override { return nullptr; } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 51 int numPerformanceEntriesInObserver() { | 53 int numPerformanceEntriesInObserver() { |
| 52 return m_observer->m_performanceEntries.size(); | 54 return m_observer->m_performanceEntries.size(); |
| 53 } | 55 } |
| 54 | 56 |
| 55 PerformanceNavigationTiming::NavigationType getNavigationType( | 57 PerformanceNavigationTiming::NavigationType getNavigationType( |
| 56 NavigationType type, | 58 NavigationType type, |
| 57 Document* document) { | 59 Document* document) { |
| 58 return PerformanceBase::getNavigationType(type, document); | 60 return PerformanceBase::getNavigationType(type, document); |
| 59 } | 61 } |
| 60 | 62 |
| 63 static bool allowsTimingRedirect( | |
| 64 const Vector<ResourceResponse>& redirectChain, | |
| 65 const ResourceResponse& finalResponse, | |
| 66 const SecurityOrigin& initiatorSecurityOrigin, | |
| 67 ExecutionContext* context) { | |
| 68 return PerformanceBase::allowsTimingRedirect( | |
| 69 redirectChain, finalResponse, initiatorSecurityOrigin, context); | |
| 70 } | |
| 71 | |
| 61 Persistent<TestPerformanceBase> m_base; | 72 Persistent<TestPerformanceBase> m_base; |
| 62 Persistent<PerformanceObserver> m_observer; | 73 Persistent<PerformanceObserver> m_observer; |
| 63 std::unique_ptr<DummyPageHolder> m_pageHolder; | 74 std::unique_ptr<DummyPageHolder> m_pageHolder; |
| 64 Persistent<PerformanceObserverCallback> m_cb; | 75 Persistent<PerformanceObserverCallback> m_cb; |
| 65 }; | 76 }; |
| 66 | 77 |
| 67 TEST_F(PerformanceBaseTest, Register) { | 78 TEST_F(PerformanceBaseTest, Register) { |
| 68 V8TestingScope scope; | 79 V8TestingScope scope; |
| 69 initialize(scope.getScriptState()); | 80 initialize(scope.getScriptState()); |
| 70 | 81 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 getNavigationType(NavigationTypeBackForward, &m_pageHolder->document()); | 148 getNavigationType(NavigationTypeBackForward, &m_pageHolder->document()); |
| 138 EXPECT_EQ(returnedType, | 149 EXPECT_EQ(returnedType, |
| 139 PerformanceNavigationTiming::NavigationType::BackForward); | 150 PerformanceNavigationTiming::NavigationType::BackForward); |
| 140 | 151 |
| 141 m_pageHolder->page().setVisibilityState(PageVisibilityStateVisible, false); | 152 m_pageHolder->page().setVisibilityState(PageVisibilityStateVisible, false); |
| 142 returnedType = getNavigationType(NavigationTypeFormResubmitted, | 153 returnedType = getNavigationType(NavigationTypeFormResubmitted, |
| 143 &m_pageHolder->document()); | 154 &m_pageHolder->document()); |
| 144 EXPECT_EQ(returnedType, | 155 EXPECT_EQ(returnedType, |
| 145 PerformanceNavigationTiming::NavigationType::Navigate); | 156 PerformanceNavigationTiming::NavigationType::Navigate); |
| 146 } | 157 } |
| 158 | |
| 159 TEST_F(PerformanceBaseTest, AllowsTimingRedirect) { | |
| 160 // When there are no cross-origin redirects. | |
| 161 AtomicString originDomain = "http://127.0.0.1:8000"; | |
| 162 Vector<ResourceResponse> redirectChain; | |
| 163 KURL url(ParsedURLString, originDomain + "/foo.html"); | |
| 164 ResourceResponse finalResponse; | |
| 165 finalResponse.setURL(url); | |
| 166 ResourceResponse redirectResponse1; | |
| 167 redirectResponse1.setURL(url); | |
| 168 ResourceResponse redirectResponse2; | |
| 169 redirectResponse2.setURL(url); | |
| 170 redirectChain.append(redirectResponse1); | |
| 171 redirectChain.append(redirectResponse2); | |
| 172 RefPtr<SecurityOrigin> securityOrigin = SecurityOrigin::create(url); | |
| 173 NullExecutionContext nullExecutionContext; | |
|
panicker
2016/12/07 00:40:52
Nit: Make this a member in PerformanceBaseTest?
In
sunjian
2016/12/07 20:10:32
Done.
| |
| 174 const ExecutionContext* context = &nullExecutionContext; | |
| 175 EXPECT_TRUE(allowsTimingRedirect(redirectChain, finalResponse, | |
| 176 *securityOrigin.get(), | |
| 177 const_cast<ExecutionContext*>(context))); | |
| 178 // When there exist cross-origin redirects. | |
| 179 AtomicString crossOriginDomain = "http://126.0.0.1:8000"; | |
| 180 KURL redirectUrl(ParsedURLString, crossOriginDomain + "/bar.html"); | |
| 181 ResourceResponse redirectResponse3; | |
| 182 redirectResponse3.setURL(redirectUrl); | |
| 183 redirectChain.append(redirectResponse3); | |
| 184 EXPECT_FALSE(allowsTimingRedirect(redirectChain, finalResponse, | |
| 185 *securityOrigin.get(), | |
| 186 const_cast<ExecutionContext*>(context))); | |
| 187 | |
| 188 // When cross-origin redirect opts in. | |
| 189 redirectChain.back().setHTTPHeaderField(HTTPNames::Timing_Allow_Origin, | |
| 190 originDomain); | |
| 191 EXPECT_TRUE(allowsTimingRedirect(redirectChain, finalResponse, | |
| 192 *securityOrigin.get(), | |
| 193 const_cast<ExecutionContext*>(context))); | |
| 194 } | |
| 195 | |
| 147 } // namespace blink | 196 } // namespace blink |
| OLD | NEW |