| 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/loader/ThreadableLoader.h" | 5 #include "core/loader/ThreadableLoader.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include "core/loader/DocumentThreadableLoader.h" | 8 #include "core/loader/DocumentThreadableLoader.h" |
| 8 #include "core/loader/ThreadableLoaderClient.h" | 9 #include "core/loader/ThreadableLoaderClient.h" |
| 10 #include "core/loader/ThreadableLoadingContext.h" |
| 9 #include "core/loader/WorkerThreadableLoader.h" | 11 #include "core/loader/WorkerThreadableLoader.h" |
| 10 #include "core/testing/DummyPageHolder.h" | 12 #include "core/testing/DummyPageHolder.h" |
| 11 #include "core/workers/WorkerLoaderProxy.h" | 13 #include "core/workers/WorkerLoaderProxy.h" |
| 12 #include "core/workers/WorkerThreadTestHelper.h" | 14 #include "core/workers/WorkerThreadTestHelper.h" |
| 13 #include "platform/WaitableEvent.h" | 15 #include "platform/WaitableEvent.h" |
| 14 #include "platform/geometry/IntSize.h" | 16 #include "platform/geometry/IntSize.h" |
| 15 #include "platform/loader/fetch/MemoryCache.h" | 17 #include "platform/loader/fetch/MemoryCache.h" |
| 16 #include "platform/loader/fetch/ResourceLoaderOptions.h" | 18 #include "platform/loader/fetch/ResourceLoaderOptions.h" |
| 17 #include "platform/network/ResourceError.h" | 19 #include "platform/network/ResourceError.h" |
| 18 #include "platform/network/ResourceRequest.h" | 20 #include "platform/network/ResourceRequest.h" |
| 19 #include "platform/network/ResourceResponse.h" | 21 #include "platform/network/ResourceResponse.h" |
| 20 #include "platform/network/ResourceTimingInfo.h" | 22 #include "platform/network/ResourceTimingInfo.h" |
| 21 #include "platform/testing/URLTestHelpers.h" | 23 #include "platform/testing/URLTestHelpers.h" |
| 22 #include "platform/testing/UnitTestHelpers.h" | 24 #include "platform/testing/UnitTestHelpers.h" |
| 23 #include "platform/weborigin/KURL.h" | 25 #include "platform/weborigin/KURL.h" |
| 24 #include "platform/weborigin/SecurityOrigin.h" | 26 #include "platform/weborigin/SecurityOrigin.h" |
| 25 #include "public/platform/Platform.h" | 27 #include "public/platform/Platform.h" |
| 26 #include "public/platform/WebURLLoadTiming.h" | 28 #include "public/platform/WebURLLoadTiming.h" |
| 27 #include "public/platform/WebURLLoaderMockFactory.h" | 29 #include "public/platform/WebURLLoaderMockFactory.h" |
| 28 #include "public/platform/WebURLResponse.h" | 30 #include "public/platform/WebURLResponse.h" |
| 29 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "wtf/Assertions.h" | 33 #include "wtf/Assertions.h" |
| 32 #include "wtf/Functional.h" | 34 #include "wtf/Functional.h" |
| 33 #include "wtf/PtrUtil.h" | 35 #include "wtf/PtrUtil.h" |
| 34 #include "wtf/RefPtr.h" | 36 #include "wtf/RefPtr.h" |
| 35 #include <memory> | |
| 36 | 37 |
| 37 namespace blink { | 38 namespace blink { |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 using ::testing::_; | 42 using ::testing::_; |
| 42 using ::testing::InSequence; | 43 using ::testing::InSequence; |
| 43 using ::testing::InvokeWithoutArgs; | 44 using ::testing::InvokeWithoutArgs; |
| 44 using ::testing::StrEq; | 45 using ::testing::StrEq; |
| 45 using ::testing::Truly; | 46 using ::testing::Truly; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 public: | 124 public: |
| 124 DocumentThreadableLoaderTestHelper() | 125 DocumentThreadableLoaderTestHelper() |
| 125 : m_dummyPageHolder(DummyPageHolder::create(IntSize(1, 1))) {} | 126 : m_dummyPageHolder(DummyPageHolder::create(IntSize(1, 1))) {} |
| 126 | 127 |
| 127 void createLoader( | 128 void createLoader( |
| 128 ThreadableLoaderClient* client, | 129 ThreadableLoaderClient* client, |
| 129 CrossOriginRequestPolicy crossOriginRequestPolicy) override { | 130 CrossOriginRequestPolicy crossOriginRequestPolicy) override { |
| 130 ThreadableLoaderOptions options; | 131 ThreadableLoaderOptions options; |
| 131 options.crossOriginRequestPolicy = crossOriginRequestPolicy; | 132 options.crossOriginRequestPolicy = crossOriginRequestPolicy; |
| 132 ResourceLoaderOptions resourceLoaderOptions; | 133 ResourceLoaderOptions resourceLoaderOptions; |
| 133 m_loader = DocumentThreadableLoader::create(document(), client, options, | 134 m_loader = DocumentThreadableLoader::create( |
| 134 resourceLoaderOptions); | 135 *ThreadableLoadingContext::create(document()), client, options, |
| 136 resourceLoaderOptions); |
| 135 } | 137 } |
| 136 | 138 |
| 137 void startLoader(const ResourceRequest& request) override { | 139 void startLoader(const ResourceRequest& request) override { |
| 138 m_loader->start(request); | 140 m_loader->start(request); |
| 139 } | 141 } |
| 140 | 142 |
| 141 void cancelLoader() override { m_loader->cancel(); } | 143 void cancelLoader() override { m_loader->cancel(); } |
| 142 void cancelAndClearLoader() override { | 144 void cancelAndClearLoader() override { |
| 143 m_loader->cancel(); | 145 m_loader->cancel(); |
| 144 m_loader = nullptr; | 146 m_loader = nullptr; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 completionEvent->wait(); | 236 completionEvent->wait(); |
| 235 } | 237 } |
| 236 | 238 |
| 237 void onSetUp() override { | 239 void onSetUp() override { |
| 238 m_mockWorkerReportingProxy = WTF::makeUnique<MockWorkerReportingProxy>(); | 240 m_mockWorkerReportingProxy = WTF::makeUnique<MockWorkerReportingProxy>(); |
| 239 m_securityOrigin = document().getSecurityOrigin(); | 241 m_securityOrigin = document().getSecurityOrigin(); |
| 240 m_parentFrameTaskRunners = | 242 m_parentFrameTaskRunners = |
| 241 ParentFrameTaskRunners::create(&m_dummyPageHolder->frame()); | 243 ParentFrameTaskRunners::create(&m_dummyPageHolder->frame()); |
| 242 m_workerThread = WTF::wrapUnique( | 244 m_workerThread = WTF::wrapUnique( |
| 243 new WorkerThreadForTest(this, *m_mockWorkerReportingProxy)); | 245 new WorkerThreadForTest(this, *m_mockWorkerReportingProxy)); |
| 246 m_loadingContext = ThreadableLoadingContext::create(document()); |
| 244 | 247 |
| 245 expectWorkerLifetimeReportingCalls(); | 248 expectWorkerLifetimeReportingCalls(); |
| 246 m_workerThread->startWithSourceCode(m_securityOrigin.get(), | 249 m_workerThread->startWithSourceCode(m_securityOrigin.get(), |
| 247 "//fake source code", | 250 "//fake source code", |
| 248 m_parentFrameTaskRunners.get()); | 251 m_parentFrameTaskRunners.get()); |
| 249 m_workerThread->waitForInit(); | 252 m_workerThread->waitForInit(); |
| 250 } | 253 } |
| 251 | 254 |
| 252 void onServeRequests() override { testing::runPendingTasks(); } | 255 void onServeRequests() override { testing::runPendingTasks(); } |
| 253 | 256 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 ->postTask(BLINK_FROM_HERE, std::move(task)); | 337 ->postTask(BLINK_FROM_HERE, std::move(task)); |
| 335 } | 338 } |
| 336 | 339 |
| 337 void postTaskToWorkerGlobalScope( | 340 void postTaskToWorkerGlobalScope( |
| 338 const WebTraceLocation& location, | 341 const WebTraceLocation& location, |
| 339 std::unique_ptr<WTF::CrossThreadClosure> task) override { | 342 std::unique_ptr<WTF::CrossThreadClosure> task) override { |
| 340 DCHECK(m_workerThread); | 343 DCHECK(m_workerThread); |
| 341 m_workerThread->postTask(location, std::move(task)); | 344 m_workerThread->postTask(location, std::move(task)); |
| 342 } | 345 } |
| 343 | 346 |
| 344 ExecutionContext* getLoaderExecutionContext() override { return &document(); } | 347 ThreadableLoadingContext* getThreadableLoadingContext() override { |
| 348 return m_loadingContext.get(); |
| 349 } |
| 345 | 350 |
| 346 RefPtr<SecurityOrigin> m_securityOrigin; | 351 RefPtr<SecurityOrigin> m_securityOrigin; |
| 347 std::unique_ptr<MockWorkerReportingProxy> m_mockWorkerReportingProxy; | 352 std::unique_ptr<MockWorkerReportingProxy> m_mockWorkerReportingProxy; |
| 348 std::unique_ptr<WorkerThreadForTest> m_workerThread; | 353 std::unique_ptr<WorkerThreadForTest> m_workerThread; |
| 349 | 354 |
| 350 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 355 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 351 // Accessed cross-thread when worker thread posts tasks to the parent. | 356 // Accessed cross-thread when worker thread posts tasks to the parent. |
| 352 CrossThreadPersistent<ParentFrameTaskRunners> m_parentFrameTaskRunners; | 357 CrossThreadPersistent<ParentFrameTaskRunners> m_parentFrameTaskRunners; |
| 353 Checkpoint m_checkpoint; | 358 Checkpoint m_checkpoint; |
| 354 // |m_loader| must be touched only from the worker thread only. | 359 // |m_loader| must be touched only from the worker thread only. |
| 355 CrossThreadPersistent<ThreadableLoader> m_loader; | 360 CrossThreadPersistent<ThreadableLoader> m_loader; |
| 361 |
| 362 Persistent<ThreadableLoadingContext> m_loadingContext; |
| 356 }; | 363 }; |
| 357 | 364 |
| 358 class ThreadableLoaderTest | 365 class ThreadableLoaderTest |
| 359 : public ::testing::TestWithParam<ThreadableLoaderToTest> { | 366 : public ::testing::TestWithParam<ThreadableLoaderToTest> { |
| 360 public: | 367 public: |
| 361 ThreadableLoaderTest() { | 368 ThreadableLoaderTest() { |
| 362 switch (GetParam()) { | 369 switch (GetParam()) { |
| 363 case DocumentThreadableLoaderTest: | 370 case DocumentThreadableLoaderTest: |
| 364 m_helper = WTF::wrapUnique(new DocumentThreadableLoaderTestHelper); | 371 m_helper = WTF::wrapUnique(new DocumentThreadableLoaderTestHelper); |
| 365 break; | 372 break; |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 // test is not saying that didFailAccessControlCheck should be dispatched | 890 // test is not saying that didFailAccessControlCheck should be dispatched |
| 884 // synchronously, but is saying that even when a response is served | 891 // synchronously, but is saying that even when a response is served |
| 885 // synchronously it should not lead to a crash. | 892 // synchronously it should not lead to a crash. |
| 886 startLoader(KURL(KURL(), "about:blank")); | 893 startLoader(KURL(KURL(), "about:blank")); |
| 887 callCheckpoint(2); | 894 callCheckpoint(2); |
| 888 } | 895 } |
| 889 | 896 |
| 890 } // namespace | 897 } // namespace |
| 891 | 898 |
| 892 } // namespace blink | 899 } // namespace blink |
| OLD | NEW |