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

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

Issue 2025783002: Worker: Introduce an observation mechanism for WorkerThread termination (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@delayed_task
Patch Set: Stop tracing CrossThread(Weak)Persistents 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 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/testing/UnitTestHelpers.h" 8 #include "platform/testing/UnitTestHelpers.h"
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 using testing::_; 12 using testing::_;
13 using testing::AtMost; 13 using testing::AtMost;
14 14
15 namespace blink { 15 namespace blink {
16 16
17 class WorkerThreadTest : public ::testing::Test { 17 class WorkerThreadTest : public ::testing::Test {
18 public: 18 public:
19 void SetUp() override 19 void SetUp() override
20 { 20 {
21 m_mockWorkerLoaderProxyProvider = adoptPtr(new MockWorkerLoaderProxyProv ider()); 21 m_mockWorkerLoaderProxyProvider = adoptPtr(new MockWorkerLoaderProxyProv ider());
22 m_mockWorkerReportingProxy = adoptPtr(new MockWorkerReportingProxy()); 22 m_mockWorkerReportingProxy = adoptPtr(new MockWorkerReportingProxy());
23 m_securityOrigin = SecurityOrigin::create(KURL(ParsedURLString, "http:// fake.url/")); 23 m_securityOrigin = SecurityOrigin::create(KURL(ParsedURLString, "http:// fake.url/"));
24 m_workerThread = adoptPtr(new WorkerThreadForTest( 24 m_workerThread = adoptPtr(new WorkerThreadForTest(
25 m_mockWorkerLoaderProxyProvider.get(), 25 m_mockWorkerLoaderProxyProvider.get(),
26 *m_mockWorkerReportingProxy)); 26 *m_mockWorkerReportingProxy));
27 m_mockWorkerThreadLifecycleObserver = new MockWorkerThreadLifecycleObser ver(m_workerThread->workerThreadContext());
27 } 28 }
28 29
29 void TearDown() override 30 void TearDown() override
30 { 31 {
31 m_workerThread->workerLoaderProxy()->detachProvider(m_mockWorkerLoaderPr oxyProvider.get()); 32 m_workerThread->workerLoaderProxy()->detachProvider(m_mockWorkerLoaderPr oxyProvider.get());
32 } 33 }
33 34
34 void start() 35 void start()
35 { 36 {
36 m_workerThread->startWithSourceCode(m_securityOrigin.get(), "//fake sour ce code"); 37 m_workerThread->startWithSourceCode(m_securityOrigin.get(), "//fake sour ce code");
(...skipping 21 matching lines...) Expand all
58 return m_workerThread->m_scheduledForceTerminationTask.get(); 59 return m_workerThread->m_scheduledForceTerminationTask.get();
59 } 60 }
60 61
61 protected: 62 protected:
62 void expectReportingCalls() 63 void expectReportingCalls()
63 { 64 {
64 EXPECT_CALL(*m_mockWorkerReportingProxy, workerGlobalScopeStarted(_)).Ti mes(1); 65 EXPECT_CALL(*m_mockWorkerReportingProxy, workerGlobalScopeStarted(_)).Ti mes(1);
65 EXPECT_CALL(*m_mockWorkerReportingProxy, didEvaluateWorkerScript(true)). Times(1); 66 EXPECT_CALL(*m_mockWorkerReportingProxy, didEvaluateWorkerScript(true)). Times(1);
66 EXPECT_CALL(*m_mockWorkerReportingProxy, workerThreadTerminated()).Times (1); 67 EXPECT_CALL(*m_mockWorkerReportingProxy, workerThreadTerminated()).Times (1);
67 EXPECT_CALL(*m_mockWorkerReportingProxy, willDestroyWorkerGlobalScope()) .Times(1); 68 EXPECT_CALL(*m_mockWorkerReportingProxy, willDestroyWorkerGlobalScope()) .Times(1);
69 EXPECT_CALL(*m_mockWorkerThreadLifecycleObserver, contextDestroyed()).Ti mes(1);
68 } 70 }
69 71
70 void expectReportingCallsForWorkerPossiblyTerminatedBeforeInitialization() 72 void expectReportingCallsForWorkerPossiblyTerminatedBeforeInitialization()
71 { 73 {
72 EXPECT_CALL(*m_mockWorkerReportingProxy, workerGlobalScopeStarted(_)).Ti mes(AtMost(1)); 74 EXPECT_CALL(*m_mockWorkerReportingProxy, workerGlobalScopeStarted(_)).Ti mes(AtMost(1));
73 EXPECT_CALL(*m_mockWorkerReportingProxy, didEvaluateWorkerScript(_)).Tim es(AtMost(1)); 75 EXPECT_CALL(*m_mockWorkerReportingProxy, didEvaluateWorkerScript(_)).Tim es(AtMost(1));
74 EXPECT_CALL(*m_mockWorkerReportingProxy, workerThreadTerminated()).Times (1); 76 EXPECT_CALL(*m_mockWorkerReportingProxy, workerThreadTerminated()).Times (1);
75 EXPECT_CALL(*m_mockWorkerReportingProxy, willDestroyWorkerGlobalScope()) .Times(AtMost(1)); 77 EXPECT_CALL(*m_mockWorkerReportingProxy, willDestroyWorkerGlobalScope()) .Times(AtMost(1));
78 EXPECT_CALL(*m_mockWorkerThreadLifecycleObserver, contextDestroyed()).Ti mes(1);
76 } 79 }
77 80
78 void expectReportingCallsForWorkerForciblyTerminated() 81 void expectReportingCallsForWorkerForciblyTerminated()
79 { 82 {
80 EXPECT_CALL(*m_mockWorkerReportingProxy, workerGlobalScopeStarted(_)).Ti mes(1); 83 EXPECT_CALL(*m_mockWorkerReportingProxy, workerGlobalScopeStarted(_)).Ti mes(1);
81 EXPECT_CALL(*m_mockWorkerReportingProxy, didEvaluateWorkerScript(false)) .Times(1); 84 EXPECT_CALL(*m_mockWorkerReportingProxy, didEvaluateWorkerScript(false)) .Times(1);
82 EXPECT_CALL(*m_mockWorkerReportingProxy, workerThreadTerminated()).Times (1); 85 EXPECT_CALL(*m_mockWorkerReportingProxy, workerThreadTerminated()).Times (1);
83 EXPECT_CALL(*m_mockWorkerReportingProxy, willDestroyWorkerGlobalScope()) .Times(1); 86 EXPECT_CALL(*m_mockWorkerReportingProxy, willDestroyWorkerGlobalScope()) .Times(1);
87 EXPECT_CALL(*m_mockWorkerThreadLifecycleObserver, contextDestroyed()).Ti mes(1);
84 } 88 }
85 89
86 RefPtr<SecurityOrigin> m_securityOrigin; 90 RefPtr<SecurityOrigin> m_securityOrigin;
87 OwnPtr<MockWorkerLoaderProxyProvider> m_mockWorkerLoaderProxyProvider; 91 OwnPtr<MockWorkerLoaderProxyProvider> m_mockWorkerLoaderProxyProvider;
88 OwnPtr<MockWorkerReportingProxy> m_mockWorkerReportingProxy; 92 OwnPtr<MockWorkerReportingProxy> m_mockWorkerReportingProxy;
89 OwnPtr<WorkerThreadForTest> m_workerThread; 93 OwnPtr<WorkerThreadForTest> m_workerThread;
94 Persistent<MockWorkerThreadLifecycleObserver> m_mockWorkerThreadLifecycleObs erver;
90 }; 95 };
91 96
92 TEST_F(WorkerThreadTest, StartAndTerminate_AsyncTerminate) 97 TEST_F(WorkerThreadTest, StartAndTerminate_AsyncTerminate)
93 { 98 {
94 expectReportingCalls(); 99 expectReportingCalls();
95 start(); 100 start();
96 m_workerThread->waitForInit(); 101 m_workerThread->waitForInit();
97 102
98 // The worker thread is not being blocked, so the worker thread should be 103 // The worker thread is not being blocked, so the worker thread should be
99 // gracefully shut down. 104 // gracefully shut down.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 221
217 // terminateAndWait() should overtake the scheduled force termination task. 222 // terminateAndWait() should overtake the scheduled force termination task.
218 m_workerThread->terminateAndWait(); 223 m_workerThread->terminateAndWait();
219 EXPECT_FALSE(isForceTerminationTaskScheduled()); 224 EXPECT_FALSE(isForceTerminationTaskScheduled());
220 EXPECT_EQ(WorkerThread::ExitCode::SyncForciblyTerminated, m_workerThread->ge tExitCode()); 225 EXPECT_EQ(WorkerThread::ExitCode::SyncForciblyTerminated, m_workerThread->ge tExitCode());
221 } 226 }
222 227
223 // TODO(nhiroki): Add tests for terminateAndWaitForAllWorkers. 228 // TODO(nhiroki): Add tests for terminateAndWaitForAllWorkers.
224 229
225 } // namespace blink 230 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698