| 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" |
| 9 #include "core/loader/LoadingContext.h" |
| 8 #include "core/loader/ThreadableLoaderClient.h" | 10 #include "core/loader/ThreadableLoaderClient.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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 completionEvent->wait(); | 235 completionEvent->wait(); |
| 235 } | 236 } |
| 236 | 237 |
| 237 void onSetUp() override { | 238 void onSetUp() override { |
| 238 m_mockWorkerReportingProxy = WTF::makeUnique<MockWorkerReportingProxy>(); | 239 m_mockWorkerReportingProxy = WTF::makeUnique<MockWorkerReportingProxy>(); |
| 239 m_securityOrigin = document().getSecurityOrigin(); | 240 m_securityOrigin = document().getSecurityOrigin(); |
| 240 m_parentFrameTaskRunners = | 241 m_parentFrameTaskRunners = |
| 241 ParentFrameTaskRunners::create(&m_dummyPageHolder->frame()); | 242 ParentFrameTaskRunners::create(&m_dummyPageHolder->frame()); |
| 242 m_workerThread = WTF::wrapUnique(new WorkerThreadForTest( | 243 m_workerThread = WTF::wrapUnique(new WorkerThreadForTest( |
| 243 this, *m_mockWorkerReportingProxy, m_parentFrameTaskRunners.get())); | 244 this, *m_mockWorkerReportingProxy, m_parentFrameTaskRunners.get())); |
| 245 m_loadingContext = LoadingContext::create(document()); |
| 244 | 246 |
| 245 expectWorkerLifetimeReportingCalls(); | 247 expectWorkerLifetimeReportingCalls(); |
| 246 m_workerThread->startWithSourceCode(m_securityOrigin.get(), | 248 m_workerThread->startWithSourceCode(m_securityOrigin.get(), |
| 247 "//fake source code"); | 249 "//fake source code"); |
| 248 m_workerThread->waitForInit(); | 250 m_workerThread->waitForInit(); |
| 249 } | 251 } |
| 250 | 252 |
| 251 void onServeRequests() override { testing::runPendingTasks(); } | 253 void onServeRequests() override { testing::runPendingTasks(); } |
| 252 | 254 |
| 253 void onTearDown() override { | 255 void onTearDown() override { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 ->postTask(BLINK_FROM_HERE, std::move(task)); | 335 ->postTask(BLINK_FROM_HERE, std::move(task)); |
| 334 } | 336 } |
| 335 | 337 |
| 336 void postTaskToWorkerGlobalScope( | 338 void postTaskToWorkerGlobalScope( |
| 337 const WebTraceLocation& location, | 339 const WebTraceLocation& location, |
| 338 std::unique_ptr<WTF::CrossThreadClosure> task) override { | 340 std::unique_ptr<WTF::CrossThreadClosure> task) override { |
| 339 DCHECK(m_workerThread); | 341 DCHECK(m_workerThread); |
| 340 m_workerThread->postTask(location, std::move(task)); | 342 m_workerThread->postTask(location, std::move(task)); |
| 341 } | 343 } |
| 342 | 344 |
| 343 ExecutionContext* getLoaderExecutionContext() override { return &document(); } | 345 LoadingContext* getLoadingContext() override { |
| 346 return m_loadingContext.get(); |
| 347 } |
| 344 | 348 |
| 345 RefPtr<SecurityOrigin> m_securityOrigin; | 349 RefPtr<SecurityOrigin> m_securityOrigin; |
| 346 std::unique_ptr<MockWorkerReportingProxy> m_mockWorkerReportingProxy; | 350 std::unique_ptr<MockWorkerReportingProxy> m_mockWorkerReportingProxy; |
| 347 std::unique_ptr<WorkerThreadForTest> m_workerThread; | 351 std::unique_ptr<WorkerThreadForTest> m_workerThread; |
| 348 | 352 |
| 349 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 353 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 350 // Accessed cross-thread when worker thread posts tasks to the parent. | 354 // Accessed cross-thread when worker thread posts tasks to the parent. |
| 351 CrossThreadPersistent<ParentFrameTaskRunners> m_parentFrameTaskRunners; | 355 CrossThreadPersistent<ParentFrameTaskRunners> m_parentFrameTaskRunners; |
| 352 Checkpoint m_checkpoint; | 356 Checkpoint m_checkpoint; |
| 353 // |m_loader| must be touched only from the worker thread only. | 357 // |m_loader| must be touched only from the worker thread only. |
| 354 CrossThreadPersistent<ThreadableLoader> m_loader; | 358 CrossThreadPersistent<ThreadableLoader> m_loader; |
| 359 |
| 360 Persistent<LoadingContext> m_loadingContext; |
| 355 }; | 361 }; |
| 356 | 362 |
| 357 class ThreadableLoaderTest | 363 class ThreadableLoaderTest |
| 358 : public ::testing::TestWithParam<ThreadableLoaderToTest> { | 364 : public ::testing::TestWithParam<ThreadableLoaderToTest> { |
| 359 public: | 365 public: |
| 360 ThreadableLoaderTest() { | 366 ThreadableLoaderTest() { |
| 361 switch (GetParam()) { | 367 switch (GetParam()) { |
| 362 case DocumentThreadableLoaderTest: | 368 case DocumentThreadableLoaderTest: |
| 363 m_helper = WTF::wrapUnique(new DocumentThreadableLoaderTestHelper); | 369 m_helper = WTF::wrapUnique(new DocumentThreadableLoaderTestHelper); |
| 364 break; | 370 break; |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 // test is not saying that didFailAccessControlCheck should be dispatched | 888 // test is not saying that didFailAccessControlCheck should be dispatched |
| 883 // synchronously, but is saying that even when a response is served | 889 // synchronously, but is saying that even when a response is served |
| 884 // synchronously it should not lead to a crash. | 890 // synchronously it should not lead to a crash. |
| 885 startLoader(KURL(KURL(), "about:blank")); | 891 startLoader(KURL(KURL(), "about:blank")); |
| 886 callCheckpoint(2); | 892 callCheckpoint(2); |
| 887 } | 893 } |
| 888 | 894 |
| 889 } // namespace | 895 } // namespace |
| 890 | 896 |
| 891 } // namespace blink | 897 } // namespace blink |
| OLD | NEW |