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/loader/DocumentThreadableLoader.h" | 7 #include "core/loader/DocumentThreadableLoader.h" |
8 #include "core/loader/ThreadableLoaderClient.h" | 8 #include "core/loader/ThreadableLoaderClient.h" |
9 #include "core/loader/WorkerThreadableLoader.h" | 9 #include "core/loader/WorkerThreadableLoader.h" |
10 #include "core/testing/DummyPageHolder.h" | 10 #include "core/testing/DummyPageHolder.h" |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 BLINK_FROM_HERE, | 230 BLINK_FROM_HERE, |
231 crossThreadBind(&WorkerThreadableLoaderTestHelper::workerCallCheckpoint, | 231 crossThreadBind(&WorkerThreadableLoaderTestHelper::workerCallCheckpoint, |
232 crossThreadUnretained(this), | 232 crossThreadUnretained(this), |
233 crossThreadUnretained(completionEvent.get()), n)); | 233 crossThreadUnretained(completionEvent.get()), n)); |
234 completionEvent->wait(); | 234 completionEvent->wait(); |
235 } | 235 } |
236 | 236 |
237 void onSetUp() override { | 237 void onSetUp() override { |
238 m_mockWorkerReportingProxy = WTF::makeUnique<MockWorkerReportingProxy>(); | 238 m_mockWorkerReportingProxy = WTF::makeUnique<MockWorkerReportingProxy>(); |
239 m_securityOrigin = document().getSecurityOrigin(); | 239 m_securityOrigin = document().getSecurityOrigin(); |
240 m_parentFrameTaskRunners = | |
241 ParentFrameTaskRunners::create(&m_dummyPageHolder->frame()); | |
242 m_workerThread = WTF::wrapUnique( | 240 m_workerThread = WTF::wrapUnique( |
243 new WorkerThreadForTest(this, *m_mockWorkerReportingProxy)); | 241 new WorkerThreadForTest(this, *m_mockWorkerReportingProxy)); |
244 | 242 |
245 expectWorkerLifetimeReportingCalls(); | 243 expectWorkerLifetimeReportingCalls(); |
246 m_workerThread->startWithSourceCode(m_securityOrigin.get(), | 244 m_workerThread->startWithSourceCode( |
247 "//fake source code", | 245 m_securityOrigin.get(), "//fake source code", |
248 m_parentFrameTaskRunners.get()); | 246 FrameTaskRunnersHolder::create(&m_dummyPageHolder->frame())); |
249 m_workerThread->waitForInit(); | 247 m_workerThread->waitForInit(); |
250 } | 248 } |
251 | 249 |
252 void onServeRequests() override { testing::runPendingTasks(); } | 250 void onServeRequests() override { testing::runPendingTasks(); } |
253 | 251 |
254 void onTearDown() override { | 252 void onTearDown() override { |
255 postTaskToWorkerGlobalScope( | 253 postTaskToWorkerGlobalScope( |
256 BLINK_FROM_HERE, | 254 BLINK_FROM_HERE, |
257 crossThreadBind(&WorkerThreadableLoaderTestHelper::clearLoader, | 255 crossThreadBind(&WorkerThreadableLoaderTestHelper::clearLoader, |
258 crossThreadUnretained(this))); | 256 crossThreadUnretained(this))); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 m_checkpoint.Call(n); | 321 m_checkpoint.Call(n); |
324 event->signal(); | 322 event->signal(); |
325 } | 323 } |
326 | 324 |
327 // WorkerLoaderProxyProvider methods. | 325 // WorkerLoaderProxyProvider methods. |
328 void postTaskToLoader( | 326 void postTaskToLoader( |
329 const WebTraceLocation& location, | 327 const WebTraceLocation& location, |
330 std::unique_ptr<WTF::CrossThreadClosure> task) override { | 328 std::unique_ptr<WTF::CrossThreadClosure> task) override { |
331 DCHECK(m_workerThread); | 329 DCHECK(m_workerThread); |
332 DCHECK(m_workerThread->isCurrentThread()); | 330 DCHECK(m_workerThread->isCurrentThread()); |
333 m_parentFrameTaskRunners->get(TaskType::Networking) | 331 FrameTaskRunnerHelper::get(TaskType::Networking, m_workerThread.get()) |
334 ->postTask(BLINK_FROM_HERE, std::move(task)); | 332 ->postTask(BLINK_FROM_HERE, std::move(task)); |
335 } | 333 } |
336 | 334 |
337 void postTaskToWorkerGlobalScope( | 335 void postTaskToWorkerGlobalScope( |
338 const WebTraceLocation& location, | 336 const WebTraceLocation& location, |
339 std::unique_ptr<WTF::CrossThreadClosure> task) override { | 337 std::unique_ptr<WTF::CrossThreadClosure> task) override { |
340 DCHECK(m_workerThread); | 338 DCHECK(m_workerThread); |
341 m_workerThread->postTask(location, std::move(task)); | 339 m_workerThread->postTask(location, std::move(task)); |
342 } | 340 } |
343 | 341 |
344 ExecutionContext* getLoaderExecutionContext() override { return &document(); } | 342 ExecutionContext* getLoaderExecutionContext() override { return &document(); } |
345 | 343 |
346 RefPtr<SecurityOrigin> m_securityOrigin; | 344 RefPtr<SecurityOrigin> m_securityOrigin; |
347 std::unique_ptr<MockWorkerReportingProxy> m_mockWorkerReportingProxy; | 345 std::unique_ptr<MockWorkerReportingProxy> m_mockWorkerReportingProxy; |
348 std::unique_ptr<WorkerThreadForTest> m_workerThread; | 346 std::unique_ptr<WorkerThreadForTest> m_workerThread; |
349 | 347 |
350 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 348 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
351 // Accessed cross-thread when worker thread posts tasks to the parent. | |
352 CrossThreadPersistent<ParentFrameTaskRunners> m_parentFrameTaskRunners; | |
353 Checkpoint m_checkpoint; | 349 Checkpoint m_checkpoint; |
354 // |m_loader| must be touched only from the worker thread only. | 350 // |m_loader| must be touched only from the worker thread only. |
355 CrossThreadPersistent<ThreadableLoader> m_loader; | 351 CrossThreadPersistent<ThreadableLoader> m_loader; |
356 }; | 352 }; |
357 | 353 |
358 class ThreadableLoaderTest | 354 class ThreadableLoaderTest |
359 : public ::testing::TestWithParam<ThreadableLoaderToTest> { | 355 : public ::testing::TestWithParam<ThreadableLoaderToTest> { |
360 public: | 356 public: |
361 ThreadableLoaderTest() { | 357 ThreadableLoaderTest() { |
362 switch (GetParam()) { | 358 switch (GetParam()) { |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 // test is not saying that didFailAccessControlCheck should be dispatched | 879 // test is not saying that didFailAccessControlCheck should be dispatched |
884 // synchronously, but is saying that even when a response is served | 880 // synchronously, but is saying that even when a response is served |
885 // synchronously it should not lead to a crash. | 881 // synchronously it should not lead to a crash. |
886 startLoader(KURL(KURL(), "about:blank")); | 882 startLoader(KURL(KURL(), "about:blank")); |
887 callCheckpoint(2); | 883 callCheckpoint(2); |
888 } | 884 } |
889 | 885 |
890 } // namespace | 886 } // namespace |
891 | 887 |
892 } // namespace blink | 888 } // namespace blink |
OLD | NEW |