| 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 "modules/compositorworker/CompositorWorkerThread.h" | 5 #include "modules/compositorworker/CompositorWorkerThread.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptSourceCode.h" | 7 #include "bindings/core/v8/ScriptSourceCode.h" |
| 8 #include "bindings/core/v8/SourceLocation.h" | 8 #include "bindings/core/v8/SourceLocation.h" |
| 9 #include "bindings/core/v8/V8GCController.h" | 9 #include "bindings/core/v8/V8GCController.h" |
| 10 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 10 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 WorkerOrWorkletScriptController* scriptController = | 136 WorkerOrWorkletScriptController* scriptController = |
| 137 worker->globalScope()->scriptController(); | 137 worker->globalScope()->scriptController(); |
| 138 bool evaluateResult = scriptController->evaluate( | 138 bool evaluateResult = scriptController->evaluate( |
| 139 ScriptSourceCode("var counter = 0; ++counter;")); | 139 ScriptSourceCode("var counter = 0; ++counter;")); |
| 140 DCHECK(evaluateResult); | 140 DCHECK(evaluateResult); |
| 141 waitEvent->signal(); | 141 waitEvent->signal(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 RefPtr<SecurityOrigin> m_securityOrigin; | 144 RefPtr<SecurityOrigin> m_securityOrigin; |
| 145 std::unique_ptr<InProcessWorkerObjectProxy> m_objectProxy; | 145 std::unique_ptr<InProcessWorkerObjectProxy> m_objectProxy; |
| 146 ScopedTestingPlatformSupport<CompositorWorkerTestPlatform> m_platform; |
| 146 }; | 147 }; |
| 147 | 148 |
| 148 TEST_F(CompositorWorkerThreadTest, Basic) { | 149 TEST_F(CompositorWorkerThreadTest, Basic) { |
| 149 ScopedTestingPlatformSupport<CompositorWorkerTestPlatform> platform; | |
| 150 | |
| 151 std::unique_ptr<CompositorWorkerThread> compositorWorker = | 150 std::unique_ptr<CompositorWorkerThread> compositorWorker = |
| 152 createCompositorWorker(); | 151 createCompositorWorker(); |
| 153 checkWorkerCanExecuteScript(compositorWorker.get()); | 152 checkWorkerCanExecuteScript(compositorWorker.get()); |
| 154 compositorWorker->terminateAndWait(); | 153 compositorWorker->terminateAndWait(); |
| 155 } | 154 } |
| 156 | 155 |
| 157 // Tests that the same WebThread is used for new workers if the WebThread is | 156 // Tests that the same WebThread is used for new workers if the WebThread is |
| 158 // still alive. | 157 // still alive. |
| 159 TEST_F(CompositorWorkerThreadTest, CreateSecondAndTerminateFirst) { | 158 TEST_F(CompositorWorkerThreadTest, CreateSecondAndTerminateFirst) { |
| 160 ScopedTestingPlatformSupport<CompositorWorkerTestPlatform> platform; | |
| 161 | |
| 162 // Create the first worker and wait until it is initialized. | 159 // Create the first worker and wait until it is initialized. |
| 163 std::unique_ptr<CompositorWorkerThread> firstWorker = | 160 std::unique_ptr<CompositorWorkerThread> firstWorker = |
| 164 createCompositorWorker(); | 161 createCompositorWorker(); |
| 165 WebThreadSupportingGC* firstThread = | 162 WebThreadSupportingGC* firstThread = |
| 166 &firstWorker->workerBackingThread().backingThread(); | 163 &firstWorker->workerBackingThread().backingThread(); |
| 167 checkWorkerCanExecuteScript(firstWorker.get()); | 164 checkWorkerCanExecuteScript(firstWorker.get()); |
| 168 v8::Isolate* firstIsolate = firstWorker->isolate(); | 165 v8::Isolate* firstIsolate = firstWorker->isolate(); |
| 169 ASSERT_TRUE(firstIsolate); | 166 ASSERT_TRUE(firstIsolate); |
| 170 | 167 |
| 171 // Create the second worker and immediately destroy the first worker. | 168 // Create the second worker and immediately destroy the first worker. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 187 | 184 |
| 188 // Verify that the worker can still successfully execute script. | 185 // Verify that the worker can still successfully execute script. |
| 189 checkWorkerCanExecuteScript(secondWorker.get()); | 186 checkWorkerCanExecuteScript(secondWorker.get()); |
| 190 | 187 |
| 191 secondWorker->terminateAndWait(); | 188 secondWorker->terminateAndWait(); |
| 192 } | 189 } |
| 193 | 190 |
| 194 // Tests that a new WebThread is created if all existing workers are terminated | 191 // Tests that a new WebThread is created if all existing workers are terminated |
| 195 // before a new worker is created. | 192 // before a new worker is created. |
| 196 TEST_F(CompositorWorkerThreadTest, TerminateFirstAndCreateSecond) { | 193 TEST_F(CompositorWorkerThreadTest, TerminateFirstAndCreateSecond) { |
| 197 ScopedTestingPlatformSupport<CompositorWorkerTestPlatform> platform; | |
| 198 | |
| 199 // Create the first worker, wait until it is initialized, and terminate it. | 194 // Create the first worker, wait until it is initialized, and terminate it. |
| 200 std::unique_ptr<CompositorWorkerThread> compositorWorker = | 195 std::unique_ptr<CompositorWorkerThread> compositorWorker = |
| 201 createCompositorWorker(); | 196 createCompositorWorker(); |
| 202 WebThreadSupportingGC* firstThread = | 197 WebThreadSupportingGC* firstThread = |
| 203 &compositorWorker->workerBackingThread().backingThread(); | 198 &compositorWorker->workerBackingThread().backingThread(); |
| 204 checkWorkerCanExecuteScript(compositorWorker.get()); | 199 checkWorkerCanExecuteScript(compositorWorker.get()); |
| 205 | 200 |
| 206 // We don't use terminateAndWait here to avoid forcible termination. | 201 // We don't use terminateAndWait here to avoid forcible termination. |
| 207 compositorWorker->terminate(); | 202 compositorWorker->terminate(); |
| 208 compositorWorker->waitForShutdownForTesting(); | 203 compositorWorker->waitForShutdownForTesting(); |
| 209 | 204 |
| 210 // Create the second worker. The backing thread is same. | 205 // Create the second worker. The backing thread is same. |
| 211 compositorWorker = createCompositorWorker(); | 206 compositorWorker = createCompositorWorker(); |
| 212 WebThreadSupportingGC* secondThread = | 207 WebThreadSupportingGC* secondThread = |
| 213 &compositorWorker->workerBackingThread().backingThread(); | 208 &compositorWorker->workerBackingThread().backingThread(); |
| 214 EXPECT_EQ(firstThread, secondThread); | 209 EXPECT_EQ(firstThread, secondThread); |
| 215 checkWorkerCanExecuteScript(compositorWorker.get()); | 210 checkWorkerCanExecuteScript(compositorWorker.get()); |
| 216 | 211 |
| 217 compositorWorker->terminateAndWait(); | 212 compositorWorker->terminateAndWait(); |
| 218 } | 213 } |
| 219 | 214 |
| 220 // Tests that v8::Isolate and WebThread are correctly set-up if a worker is | 215 // Tests that v8::Isolate and WebThread are correctly set-up if a worker is |
| 221 // created while another is terminating. | 216 // created while another is terminating. |
| 222 TEST_F(CompositorWorkerThreadTest, CreatingSecondDuringTerminationOfFirst) { | 217 TEST_F(CompositorWorkerThreadTest, CreatingSecondDuringTerminationOfFirst) { |
| 223 ScopedTestingPlatformSupport<CompositorWorkerTestPlatform> platform; | |
| 224 | |
| 225 std::unique_ptr<CompositorWorkerThread> firstWorker = | 218 std::unique_ptr<CompositorWorkerThread> firstWorker = |
| 226 createCompositorWorker(); | 219 createCompositorWorker(); |
| 227 checkWorkerCanExecuteScript(firstWorker.get()); | 220 checkWorkerCanExecuteScript(firstWorker.get()); |
| 228 v8::Isolate* firstIsolate = firstWorker->isolate(); | 221 v8::Isolate* firstIsolate = firstWorker->isolate(); |
| 229 ASSERT_TRUE(firstIsolate); | 222 ASSERT_TRUE(firstIsolate); |
| 230 | 223 |
| 231 // Request termination of the first worker and create the second worker | 224 // Request termination of the first worker and create the second worker |
| 232 // as soon as possible. | 225 // as soon as possible. |
| 233 firstWorker->terminate(); | 226 firstWorker->terminate(); |
| 234 // We don't wait for its termination. | 227 // We don't wait for its termination. |
| 235 // Note: We rely on the assumption that the termination steps don't run | 228 // Note: We rely on the assumption that the termination steps don't run |
| 236 // on the worker thread so quickly. This could be a source of flakiness. | 229 // on the worker thread so quickly. This could be a source of flakiness. |
| 237 | 230 |
| 238 std::unique_ptr<CompositorWorkerThread> secondWorker = | 231 std::unique_ptr<CompositorWorkerThread> secondWorker = |
| 239 createCompositorWorker(); | 232 createCompositorWorker(); |
| 240 | 233 |
| 241 v8::Isolate* secondIsolate = secondWorker->isolate(); | 234 v8::Isolate* secondIsolate = secondWorker->isolate(); |
| 242 ASSERT_TRUE(secondIsolate); | 235 ASSERT_TRUE(secondIsolate); |
| 243 EXPECT_EQ(firstIsolate, secondIsolate); | 236 EXPECT_EQ(firstIsolate, secondIsolate); |
| 244 | 237 |
| 245 // Verify that the isolate can run some scripts correctly in the second | 238 // Verify that the isolate can run some scripts correctly in the second |
| 246 // worker. | 239 // worker. |
| 247 checkWorkerCanExecuteScript(secondWorker.get()); | 240 checkWorkerCanExecuteScript(secondWorker.get()); |
| 248 secondWorker->terminateAndWait(); | 241 secondWorker->terminateAndWait(); |
| 249 } | 242 } |
| 250 | 243 |
| 251 } // namespace blink | 244 } // namespace blink |
| OLD | NEW |