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

Unified Diff: third_party/WebKit/Source/core/workers/WorkerThreadTest.cpp

Issue 2075243002: Worker: Early return if termination is requested while worker thread is starting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add a test Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/workers/WorkerThread.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/workers/WorkerThreadTest.cpp
diff --git a/third_party/WebKit/Source/core/workers/WorkerThreadTest.cpp b/third_party/WebKit/Source/core/workers/WorkerThreadTest.cpp
index e1c372ddc055f09fd98790154171ddfbbd056038..1d650348d1e4d3953d4cd13ef28d6cdbdd88bc3b 100644
--- a/third_party/WebKit/Source/core/workers/WorkerThreadTest.cpp
+++ b/third_party/WebKit/Source/core/workers/WorkerThreadTest.cpp
@@ -16,6 +16,21 @@ using testing::AtMost;
namespace blink {
+namespace {
+
+// Called from WorkerThread::startRunningDebuggerTasksOnPauseOnWorkerThread as a
+// debugger task.
+void waitForTermination(WorkerThread* workerThread)
+{
+ EXPECT_TRUE(workerThread->isCurrentThread());
+
+ // Notify the main thread that the debugger task is waiting for termination.
+ Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&testing::exitRunLoop));
+ workerThread->terminationEvent()->wait();
+}
+
+} // namespace
+
class WorkerThreadTest : public ::testing::Test {
public:
void SetUp() override
@@ -146,6 +161,45 @@ TEST_F(WorkerThreadTest, StartAndTerminateImmediately_SyncTerminate)
EXPECT_TRUE(WorkerThread::ExitCode::GracefullyTerminated == exitCode || WorkerThread::ExitCode::SyncForciblyTerminated == exitCode);
}
+TEST_F(WorkerThreadTest, StartAndTerminateOnInitialization_TerminateWhileDebuggerTaskIsRunning)
+{
+ EXPECT_CALL(*m_mockWorkerReportingProxy, workerGlobalScopeStarted(_)).Times(1);
+ EXPECT_CALL(*m_mockWorkerReportingProxy, workerThreadTerminated()).Times(1);
+ EXPECT_CALL(*m_mockWorkerReportingProxy, willDestroyWorkerGlobalScope()).Times(1);
+ EXPECT_CALL(*m_mockWorkerThreadLifecycleObserver, contextDestroyed()).Times(1);
+
+ std::unique_ptr<Vector<CSPHeaderAndType>> headers = wrapUnique(new Vector<CSPHeaderAndType>());
+ CSPHeaderAndType headerAndType("contentSecurityPolicy", ContentSecurityPolicyHeaderTypeReport);
+ headers->append(headerAndType);
+
+ // Specify PauseWorkerGlobalScopeOnStart so that the worker thread can pause
+ // on initialziation to run debugger tasks.
+ std::unique_ptr<WorkerThreadStartupData> startupData =
+ WorkerThreadStartupData::create(
+ KURL(ParsedURLString, "http://fake.url/"),
+ "fake user agent",
+ "//fake source code",
+ nullptr, /* cachedMetaData */
+ PauseWorkerGlobalScopeOnStart,
+ headers.get(),
+ m_securityOrigin.get(),
+ nullptr, /* workerClients */
+ WebAddressSpaceLocal,
+ nullptr /* originTrialToken */,
+ V8CacheOptionsDefault);
+ m_workerThread->start(std::move(startupData));
+
+ m_workerThread->appendDebuggerTask(threadSafeBind(&waitForTermination, AllowCrossThreadAccess(m_workerThread.get())));
+
+ // Wait for the debugger task.
+ testing::enterRunLoop();
+
+ // Start termination while the debugger task is running.
+ EXPECT_TRUE(m_workerThread->m_runningDebuggerTask);
+ m_workerThread->terminateAndWait();
+ EXPECT_EQ(WorkerThread::ExitCode::GracefullyTerminated, m_workerThread->getExitCode());
+}
+
TEST_F(WorkerThreadTest, StartAndTerminateOnScriptLoaded_SyncForciblyTerminate)
{
expectReportingCallsForWorkerForciblyTerminated();
« no previous file with comments | « third_party/WebKit/Source/core/workers/WorkerThread.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698