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

Side by Side Diff: third_party/WebKit/Source/core/workers/WorkerThreadTest.cpp

Issue 2718643002: Worker: Pass ParentFrameTaskRunners via WorkerThread::start() instead of the ctor (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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/workers/WorkerThread.h" 5 #include "core/workers/WorkerThread.h"
6 6
7 #include "core/workers/WorkerThreadTestHelper.h" 7 #include "core/workers/WorkerThreadTestHelper.h"
8 #include "platform/WaitableEvent.h" 8 #include "platform/WaitableEvent.h"
9 #include "platform/testing/UnitTestHelpers.h" 9 #include "platform/testing/UnitTestHelpers.h"
10 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 27 matching lines...) Expand all
38 38
39 class WorkerThreadTest : public ::testing::Test { 39 class WorkerThreadTest : public ::testing::Test {
40 public: 40 public:
41 WorkerThreadTest() {} 41 WorkerThreadTest() {}
42 42
43 void SetUp() override { 43 void SetUp() override {
44 m_loaderProxyProvider = WTF::makeUnique<MockWorkerLoaderProxyProvider>(); 44 m_loaderProxyProvider = WTF::makeUnique<MockWorkerLoaderProxyProvider>();
45 m_reportingProxy = WTF::makeUnique<MockWorkerReportingProxy>(); 45 m_reportingProxy = WTF::makeUnique<MockWorkerReportingProxy>();
46 m_securityOrigin = 46 m_securityOrigin =
47 SecurityOrigin::create(KURL(ParsedURLString, "http://fake.url/")); 47 SecurityOrigin::create(KURL(ParsedURLString, "http://fake.url/"));
48 m_workerThread = WTF::wrapUnique( 48 m_workerThread = WTF::wrapUnique(new WorkerThreadForTest(
49 new WorkerThreadForTest(m_loaderProxyProvider.get(), *m_reportingProxy, 49 m_loaderProxyProvider.get(), *m_reportingProxy));
50 ParentFrameTaskRunners::create(nullptr)));
51 m_lifecycleObserver = new MockWorkerThreadLifecycleObserver( 50 m_lifecycleObserver = new MockWorkerThreadLifecycleObserver(
52 m_workerThread->getWorkerThreadLifecycleContext()); 51 m_workerThread->getWorkerThreadLifecycleContext());
53 } 52 }
54 53
55 void TearDown() override { 54 void TearDown() override {
56 m_workerThread->workerLoaderProxy()->detachProvider( 55 m_workerThread->workerLoaderProxy()->detachProvider(
57 m_loaderProxyProvider.get()); 56 m_loaderProxyProvider.get());
58 } 57 }
59 58
60 void start() { 59 void start() {
61 m_workerThread->startWithSourceCode(m_securityOrigin.get(), 60 m_workerThread->startWithSourceCode(
62 "//fake source code"); 61 m_securityOrigin.get(), "//fake source code",
62 ParentFrameTaskRunners::create(nullptr));
63 } 63 }
64 64
65 void startWithSourceCodeNotToFinish() { 65 void startWithSourceCodeNotToFinish() {
66 // Use a JavaScript source code that makes an infinite loop so that we 66 // Use a JavaScript source code that makes an infinite loop so that we
67 // can catch some kind of issues as a timeout. 67 // can catch some kind of issues as a timeout.
68 m_workerThread->startWithSourceCode(m_securityOrigin.get(), 68 m_workerThread->startWithSourceCode(
69 "while(true) {}"); 69 m_securityOrigin.get(), "while(true) {}",
70 ParentFrameTaskRunners::create(nullptr));
70 } 71 }
71 72
72 void setForcibleTerminationDelayInMs(long long forcibleTerminationDelayInMs) { 73 void setForcibleTerminationDelayInMs(long long forcibleTerminationDelayInMs) {
73 m_workerThread->m_forcibleTerminationDelayInMs = 74 m_workerThread->m_forcibleTerminationDelayInMs =
74 forcibleTerminationDelayInMs; 75 forcibleTerminationDelayInMs;
75 } 76 }
76 77
77 bool isForcibleTerminationTaskScheduled() { 78 bool isForcibleTerminationTaskScheduled() {
78 return m_workerThread->m_forcibleTerminationTaskHandle.isActive(); 79 return m_workerThread->m_forcibleTerminationTaskHandle.isActive();
79 } 80 }
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // Specify PauseWorkerGlobalScopeOnStart so that the worker thread can pause 276 // Specify PauseWorkerGlobalScopeOnStart so that the worker thread can pause
276 // on initialziation to run debugger tasks. 277 // on initialziation to run debugger tasks.
277 std::unique_ptr<WorkerThreadStartupData> startupData = 278 std::unique_ptr<WorkerThreadStartupData> startupData =
278 WorkerThreadStartupData::create( 279 WorkerThreadStartupData::create(
279 KURL(ParsedURLString, "http://fake.url/"), "fake user agent", 280 KURL(ParsedURLString, "http://fake.url/"), "fake user agent",
280 "//fake source code", nullptr, /* cachedMetaData */ 281 "//fake source code", nullptr, /* cachedMetaData */
281 PauseWorkerGlobalScopeOnStart, headers.get(), "", 282 PauseWorkerGlobalScopeOnStart, headers.get(), "",
282 m_securityOrigin.get(), nullptr, /* workerClients */ 283 m_securityOrigin.get(), nullptr, /* workerClients */
283 WebAddressSpaceLocal, nullptr /* originTrialToken */, 284 WebAddressSpaceLocal, nullptr /* originTrialToken */,
284 nullptr /* WorkerSettings */, WorkerV8Settings::Default()); 285 nullptr /* WorkerSettings */, WorkerV8Settings::Default());
285 m_workerThread->start(std::move(startupData)); 286 m_workerThread->start(std::move(startupData),
287 ParentFrameTaskRunners::create(nullptr));
286 288
287 // Used to wait for worker thread termination in a debugger task on the 289 // Used to wait for worker thread termination in a debugger task on the
288 // worker thread. 290 // worker thread.
289 WaitableEvent waitableEvent; 291 WaitableEvent waitableEvent;
290 m_workerThread->appendDebuggerTask(crossThreadBind( 292 m_workerThread->appendDebuggerTask(crossThreadBind(
291 &waitForSignalTask, crossThreadUnretained(m_workerThread.get()), 293 &waitForSignalTask, crossThreadUnretained(m_workerThread.get()),
292 crossThreadUnretained(&waitableEvent))); 294 crossThreadUnretained(&waitableEvent)));
293 295
294 // Wait for the debugger task. 296 // Wait for the debugger task.
295 testing::enterRunLoop(); 297 testing::enterRunLoop();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 357
356 // Resume the debugger task. Shutdown starts after that. 358 // Resume the debugger task. Shutdown starts after that.
357 waitableEvent.signal(); 359 waitableEvent.signal();
358 m_workerThread->waitForShutdownForTesting(); 360 m_workerThread->waitForShutdownForTesting();
359 EXPECT_EQ(ExitCode::GracefullyTerminated, getExitCode()); 361 EXPECT_EQ(ExitCode::GracefullyTerminated, getExitCode());
360 } 362 }
361 363
362 // TODO(nhiroki): Add tests for terminateAndWaitForAllWorkers. 364 // TODO(nhiroki): Add tests for terminateAndWaitForAllWorkers.
363 365
364 } // namespace blink 366 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698