Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: third_party/WebKit/Source/core/loader/ThreadableLoaderTest.cpp

Issue 2715803004: Introduce ThreadableLoadingContext: make threaded loading code one step away from Document (Closed)
Patch Set: . Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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( 243 m_workerThread = WTF::wrapUnique(
243 new WorkerThreadForTest(this, *m_mockWorkerReportingProxy)); 244 new WorkerThreadForTest(this, *m_mockWorkerReportingProxy));
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_parentFrameTaskRunners.get()); 250 m_parentFrameTaskRunners.get());
249 m_workerThread->waitForInit(); 251 m_workerThread->waitForInit();
250 } 252 }
251 253
252 void onServeRequests() override { testing::runPendingTasks(); } 254 void onServeRequests() override { testing::runPendingTasks(); }
253 255
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 ->postTask(BLINK_FROM_HERE, std::move(task)); 336 ->postTask(BLINK_FROM_HERE, std::move(task));
335 } 337 }
336 338
337 void postTaskToWorkerGlobalScope( 339 void postTaskToWorkerGlobalScope(
338 const WebTraceLocation& location, 340 const WebTraceLocation& location,
339 std::unique_ptr<WTF::CrossThreadClosure> task) override { 341 std::unique_ptr<WTF::CrossThreadClosure> task) override {
340 DCHECK(m_workerThread); 342 DCHECK(m_workerThread);
341 m_workerThread->postTask(location, std::move(task)); 343 m_workerThread->postTask(location, std::move(task));
342 } 344 }
343 345
344 ExecutionContext* getLoaderExecutionContext() override { return &document(); } 346 LoadingContext* getLoadingContext() override {
347 return m_loadingContext.get();
348 }
345 349
346 RefPtr<SecurityOrigin> m_securityOrigin; 350 RefPtr<SecurityOrigin> m_securityOrigin;
347 std::unique_ptr<MockWorkerReportingProxy> m_mockWorkerReportingProxy; 351 std::unique_ptr<MockWorkerReportingProxy> m_mockWorkerReportingProxy;
348 std::unique_ptr<WorkerThreadForTest> m_workerThread; 352 std::unique_ptr<WorkerThreadForTest> m_workerThread;
349 353
350 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; 354 std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
351 // Accessed cross-thread when worker thread posts tasks to the parent. 355 // Accessed cross-thread when worker thread posts tasks to the parent.
352 CrossThreadPersistent<ParentFrameTaskRunners> m_parentFrameTaskRunners; 356 CrossThreadPersistent<ParentFrameTaskRunners> m_parentFrameTaskRunners;
353 Checkpoint m_checkpoint; 357 Checkpoint m_checkpoint;
354 // |m_loader| must be touched only from the worker thread only. 358 // |m_loader| must be touched only from the worker thread only.
355 CrossThreadPersistent<ThreadableLoader> m_loader; 359 CrossThreadPersistent<ThreadableLoader> m_loader;
360
361 Persistent<LoadingContext> m_loadingContext;
356 }; 362 };
357 363
358 class ThreadableLoaderTest 364 class ThreadableLoaderTest
359 : public ::testing::TestWithParam<ThreadableLoaderToTest> { 365 : public ::testing::TestWithParam<ThreadableLoaderToTest> {
360 public: 366 public:
361 ThreadableLoaderTest() { 367 ThreadableLoaderTest() {
362 switch (GetParam()) { 368 switch (GetParam()) {
363 case DocumentThreadableLoaderTest: 369 case DocumentThreadableLoaderTest:
364 m_helper = WTF::wrapUnique(new DocumentThreadableLoaderTestHelper); 370 m_helper = WTF::wrapUnique(new DocumentThreadableLoaderTestHelper);
365 break; 371 break;
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 // test is not saying that didFailAccessControlCheck should be dispatched 889 // test is not saying that didFailAccessControlCheck should be dispatched
884 // synchronously, but is saying that even when a response is served 890 // synchronously, but is saying that even when a response is served
885 // synchronously it should not lead to a crash. 891 // synchronously it should not lead to a crash.
886 startLoader(KURL(KURL(), "about:blank")); 892 startLoader(KURL(KURL(), "about:blank"));
887 callCheckpoint(2); 893 callCheckpoint(2);
888 } 894 }
889 895
890 } // namespace 896 } // namespace
891 897
892 } // namespace blink 898 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698