OLD | NEW |
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 <memory> | 7 #include <memory> |
8 #include "core/workers/WorkerReportingProxy.h" | 8 #include "core/workers/WorkerReportingProxy.h" |
9 #include "core/workers/WorkerThreadTestHelper.h" | 9 #include "core/workers/WorkerThreadTestHelper.h" |
10 #include "platform/WaitableEvent.h" | 10 #include "platform/WaitableEvent.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 waitable_event->Wait(); | 60 waitable_event->Wait(); |
61 } | 61 } |
62 | 62 |
63 } // namespace | 63 } // namespace |
64 | 64 |
65 class WorkerThreadTest : public ::testing::Test { | 65 class WorkerThreadTest : public ::testing::Test { |
66 public: | 66 public: |
67 WorkerThreadTest() {} | 67 WorkerThreadTest() {} |
68 | 68 |
69 void SetUp() override { | 69 void SetUp() override { |
70 loader_proxy_provider_ = WTF::MakeUnique<MockWorkerLoaderProxyProvider>(); | 70 loader_proxy_provider_ = WTF::MakeUnique<WorkerLoaderProxyProvider>(); |
71 reporting_proxy_ = WTF::MakeUnique<MockWorkerReportingProxy>(); | 71 reporting_proxy_ = WTF::MakeUnique<MockWorkerReportingProxy>(); |
72 security_origin_ = | 72 security_origin_ = |
73 SecurityOrigin::Create(KURL(kParsedURLString, "http://fake.url/")); | 73 SecurityOrigin::Create(KURL(kParsedURLString, "http://fake.url/")); |
74 worker_thread_ = WTF::WrapUnique(new WorkerThreadForTest( | 74 worker_thread_ = WTF::WrapUnique(new WorkerThreadForTest( |
75 loader_proxy_provider_.get(), *reporting_proxy_)); | 75 loader_proxy_provider_.get(), *reporting_proxy_)); |
76 lifecycle_observer_ = new MockWorkerThreadLifecycleObserver( | 76 lifecycle_observer_ = new MockWorkerThreadLifecycleObserver( |
77 worker_thread_->GetWorkerThreadLifecycleContext()); | 77 worker_thread_->GetWorkerThreadLifecycleContext()); |
78 } | 78 } |
79 | 79 |
80 void TearDown() override { | 80 void TearDown() override { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 EXPECT_CALL(*reporting_proxy_, WillEvaluateWorkerScriptMock(_, _)).Times(1); | 136 EXPECT_CALL(*reporting_proxy_, WillEvaluateWorkerScriptMock(_, _)).Times(1); |
137 EXPECT_CALL(*reporting_proxy_, DidEvaluateWorkerScript(false)).Times(1); | 137 EXPECT_CALL(*reporting_proxy_, DidEvaluateWorkerScript(false)).Times(1); |
138 EXPECT_CALL(*reporting_proxy_, WillDestroyWorkerGlobalScope()).Times(1); | 138 EXPECT_CALL(*reporting_proxy_, WillDestroyWorkerGlobalScope()).Times(1); |
139 EXPECT_CALL(*reporting_proxy_, DidTerminateWorkerThread()).Times(1); | 139 EXPECT_CALL(*reporting_proxy_, DidTerminateWorkerThread()).Times(1); |
140 EXPECT_CALL(*lifecycle_observer_, ContextDestroyed(_)).Times(1); | 140 EXPECT_CALL(*lifecycle_observer_, ContextDestroyed(_)).Times(1); |
141 } | 141 } |
142 | 142 |
143 ExitCode GetExitCode() { return worker_thread_->GetExitCodeForTesting(); } | 143 ExitCode GetExitCode() { return worker_thread_->GetExitCodeForTesting(); } |
144 | 144 |
145 RefPtr<SecurityOrigin> security_origin_; | 145 RefPtr<SecurityOrigin> security_origin_; |
146 std::unique_ptr<MockWorkerLoaderProxyProvider> loader_proxy_provider_; | 146 std::unique_ptr<WorkerLoaderProxyProvider> loader_proxy_provider_; |
147 std::unique_ptr<MockWorkerReportingProxy> reporting_proxy_; | 147 std::unique_ptr<MockWorkerReportingProxy> reporting_proxy_; |
148 std::unique_ptr<WorkerThreadForTest> worker_thread_; | 148 std::unique_ptr<WorkerThreadForTest> worker_thread_; |
149 Persistent<MockWorkerThreadLifecycleObserver> lifecycle_observer_; | 149 Persistent<MockWorkerThreadLifecycleObserver> lifecycle_observer_; |
150 }; | 150 }; |
151 | 151 |
152 TEST_F(WorkerThreadTest, ShouldScheduleToTerminateExecution) { | 152 TEST_F(WorkerThreadTest, ShouldScheduleToTerminateExecution) { |
153 using ThreadState = WorkerThread::ThreadState; | 153 using ThreadState = WorkerThread::ThreadState; |
154 MutexLocker dummy_lock(worker_thread_->thread_state_mutex_); | 154 MutexLocker dummy_lock(worker_thread_->thread_state_mutex_); |
155 | 155 |
156 EXPECT_EQ(ThreadState::kNotStarted, worker_thread_->thread_state_); | 156 EXPECT_EQ(ThreadState::kNotStarted, worker_thread_->thread_state_); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 | 380 |
381 // Resume the debugger task. Shutdown starts after that. | 381 // Resume the debugger task. Shutdown starts after that. |
382 waitable_event.Signal(); | 382 waitable_event.Signal(); |
383 worker_thread_->WaitForShutdownForTesting(); | 383 worker_thread_->WaitForShutdownForTesting(); |
384 EXPECT_EQ(ExitCode::kGracefullyTerminated, GetExitCode()); | 384 EXPECT_EQ(ExitCode::kGracefullyTerminated, GetExitCode()); |
385 } | 385 } |
386 | 386 |
387 // TODO(nhiroki): Add tests for terminateAndWaitForAllWorkers. | 387 // TODO(nhiroki): Add tests for terminateAndWaitForAllWorkers. |
388 | 388 |
389 } // namespace blink | 389 } // namespace blink |
OLD | NEW |