| 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 "core/dom/ExecutionContextTask.h" | 7 #include "core/dom/ExecutionContextTask.h" |
| 8 #include "core/fetch/MemoryCache.h" | 8 #include "core/fetch/MemoryCache.h" |
| 9 #include "core/fetch/ResourceLoaderOptions.h" | 9 #include "core/fetch/ResourceLoaderOptions.h" |
| 10 #include "core/loader/DocumentThreadableLoader.h" | 10 #include "core/loader/DocumentThreadableLoader.h" |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 createCrossThreadTask( | 233 createCrossThreadTask( |
| 234 &WorkerThreadableLoaderTestHelper::workerCallCheckpoint, | 234 &WorkerThreadableLoaderTestHelper::workerCallCheckpoint, |
| 235 crossThreadUnretained(this), | 235 crossThreadUnretained(this), |
| 236 crossThreadUnretained(completionEvent.get()), n)); | 236 crossThreadUnretained(completionEvent.get()), n)); |
| 237 completionEvent->wait(); | 237 completionEvent->wait(); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void onSetUp() override { | 240 void onSetUp() override { |
| 241 m_mockWorkerReportingProxy = WTF::makeUnique<MockWorkerReportingProxy>(); | 241 m_mockWorkerReportingProxy = WTF::makeUnique<MockWorkerReportingProxy>(); |
| 242 m_securityOrigin = document().getSecurityOrigin(); | 242 m_securityOrigin = document().getSecurityOrigin(); |
| 243 m_parentFrameTaskRunners = |
| 244 ParentFrameTaskRunners::create(&m_dummyPageHolder->frame()); |
| 243 m_workerThread = WTF::wrapUnique(new WorkerThreadForTest( | 245 m_workerThread = WTF::wrapUnique(new WorkerThreadForTest( |
| 244 this, *m_mockWorkerReportingProxy, m_threadHeapMode)); | 246 this, *m_mockWorkerReportingProxy, m_threadHeapMode)); |
| 245 | 247 |
| 246 expectWorkerLifetimeReportingCalls(); | 248 expectWorkerLifetimeReportingCalls(); |
| 247 m_workerThread->startWithSourceCode(m_securityOrigin.get(), | 249 m_workerThread->startWithSourceCode(m_securityOrigin.get(), |
| 248 "//fake source code"); | 250 "//fake source code"); |
| 249 m_workerThread->waitForInit(); | 251 m_workerThread->waitForInit(); |
| 250 } | 252 } |
| 251 | 253 |
| 252 void onServeRequests() override { testing::runPendingTasks(); } | 254 void onServeRequests() override { testing::runPendingTasks(); } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 DCHECK(m_workerThread->isCurrentThread()); | 324 DCHECK(m_workerThread->isCurrentThread()); |
| 323 m_checkpoint.Call(n); | 325 m_checkpoint.Call(n); |
| 324 event->signal(); | 326 event->signal(); |
| 325 } | 327 } |
| 326 | 328 |
| 327 // WorkerLoaderProxyProvider methods. | 329 // WorkerLoaderProxyProvider methods. |
| 328 void postTaskToLoader(const WebTraceLocation& location, | 330 void postTaskToLoader(const WebTraceLocation& location, |
| 329 std::unique_ptr<ExecutionContextTask> task) override { | 331 std::unique_ptr<ExecutionContextTask> task) override { |
| 330 DCHECK(m_workerThread); | 332 DCHECK(m_workerThread); |
| 331 DCHECK(m_workerThread->isCurrentThread()); | 333 DCHECK(m_workerThread->isCurrentThread()); |
| 332 document().postTask(location, std::move(task)); | 334 m_parentFrameTaskRunners->get(TaskType::Networking) |
| 335 ->postTask( |
| 336 BLINK_FROM_HERE, |
| 337 crossThreadBind(&ExecutionContextTask::performTaskIfContextIsValid, |
| 338 WTF::passed(std::move(task)), |
| 339 wrapCrossThreadWeakPersistent(&document()))); |
| 333 } | 340 } |
| 334 | 341 |
| 335 void postTaskToWorkerGlobalScope( | 342 void postTaskToWorkerGlobalScope( |
| 336 const WebTraceLocation& location, | 343 const WebTraceLocation& location, |
| 337 std::unique_ptr<ExecutionContextTask> task) override { | 344 std::unique_ptr<ExecutionContextTask> task) override { |
| 338 DCHECK(m_workerThread); | 345 DCHECK(m_workerThread); |
| 339 m_workerThread->postTask(location, std::move(task)); | 346 m_workerThread->postTask(location, std::move(task)); |
| 340 } | 347 } |
| 341 | 348 |
| 342 RefPtr<SecurityOrigin> m_securityOrigin; | 349 RefPtr<SecurityOrigin> m_securityOrigin; |
| 343 std::unique_ptr<MockWorkerReportingProxy> m_mockWorkerReportingProxy; | 350 std::unique_ptr<MockWorkerReportingProxy> m_mockWorkerReportingProxy; |
| 344 std::unique_ptr<WorkerThreadForTest> m_workerThread; | 351 std::unique_ptr<WorkerThreadForTest> m_workerThread; |
| 345 | 352 |
| 346 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 353 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 354 Persistent<ParentFrameTaskRunners> m_parentFrameTaskRunners; |
| 347 Checkpoint m_checkpoint; | 355 Checkpoint m_checkpoint; |
| 348 // |m_loader| must be touched only from the worker thread only. | 356 // |m_loader| must be touched only from the worker thread only. |
| 349 CrossThreadPersistent<ThreadableLoader> m_loader; | 357 CrossThreadPersistent<ThreadableLoader> m_loader; |
| 350 const BlinkGC::ThreadHeapMode m_threadHeapMode; | 358 const BlinkGC::ThreadHeapMode m_threadHeapMode; |
| 351 }; | 359 }; |
| 352 | 360 |
| 353 class ThreadableLoaderTest | 361 class ThreadableLoaderTest |
| 354 : public ::testing::TestWithParam<ThreadableLoaderToTest> { | 362 : public ::testing::TestWithParam<ThreadableLoaderToTest> { |
| 355 public: | 363 public: |
| 356 ThreadableLoaderTest() { | 364 ThreadableLoaderTest() { |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 // test is not saying that didFailAccessControlCheck should be dispatched | 895 // test is not saying that didFailAccessControlCheck should be dispatched |
| 888 // synchronously, but is saying that even when a response is served | 896 // synchronously, but is saying that even when a response is served |
| 889 // synchronously it should not lead to a crash. | 897 // synchronously it should not lead to a crash. |
| 890 startLoader(KURL(KURL(), "about:blank")); | 898 startLoader(KURL(KURL(), "about:blank")); |
| 891 callCheckpoint(2); | 899 callCheckpoint(2); |
| 892 } | 900 } |
| 893 | 901 |
| 894 } // namespace | 902 } // namespace |
| 895 | 903 |
| 896 } // namespace blink | 904 } // namespace blink |
| OLD | NEW |