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 "config.h" | 5 #include "config.h" |
6 #include "modules/compositorworker/CompositorWorkerManager.h" | 6 #include "modules/compositorworker/CompositorWorkerManager.h" |
7 | 7 |
8 #include "bindings/core/v8/ScriptSourceCode.h" | 8 #include "bindings/core/v8/ScriptSourceCode.h" |
9 #include "bindings/core/v8/V8GCController.h" | 9 #include "bindings/core/v8/V8GCController.h" |
10 #include "core/inspector/ConsoleMessage.h" | 10 #include "core/inspector/ConsoleMessage.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 124 |
125 void createWorkerAdapter(RefPtr<CompositorWorkerThread>* workerThread, WebWa
itableEvent* creationEvent) | 125 void createWorkerAdapter(RefPtr<CompositorWorkerThread>* workerThread, WebWa
itableEvent* creationEvent) |
126 { | 126 { |
127 *workerThread = createCompositorWorker(creationEvent); | 127 *workerThread = createCompositorWorker(creationEvent); |
128 } | 128 } |
129 | 129 |
130 // Attempts to run some simple script for |worker|. | 130 // Attempts to run some simple script for |worker|. |
131 void checkWorkerCanExecuteScript(WorkerThread* worker) | 131 void checkWorkerCanExecuteScript(WorkerThread* worker) |
132 { | 132 { |
133 OwnPtr<WebWaitableEvent> waitEvent = adoptPtr(Platform::current()->creat
eWaitableEvent()); | 133 OwnPtr<WebWaitableEvent> waitEvent = adoptPtr(Platform::current()->creat
eWaitableEvent()); |
134 worker->backingThread().platformThread().taskRunner()->postTask(FROM_HER
E, threadSafeBind(&CompositorWorkerManagerTest::executeScriptInWorker, AllowCros
sThreadAccess(this), | 134 worker->backingThread().platformThread().taskRunner()->postTask(BLINK_FR
OM_HERE, threadSafeBind(&CompositorWorkerManagerTest::executeScriptInWorker, All
owCrossThreadAccess(this), |
135 AllowCrossThreadAccess(worker), AllowCrossThreadAccess(waitEvent.get
()))); | 135 AllowCrossThreadAccess(worker), AllowCrossThreadAccess(waitEvent.get
()))); |
136 waitEvent->wait(); | 136 waitEvent->wait(); |
137 } | 137 } |
138 | 138 |
139 void waitForWaitableEventAfterIteratingCurrentLoop(WebWaitableEvent* waitEve
nt) | 139 void waitForWaitableEventAfterIteratingCurrentLoop(WebWaitableEvent* waitEve
nt) |
140 { | 140 { |
141 testing::runPendingTasks(); | 141 testing::runPendingTasks(); |
142 waitEvent->wait(); | 142 waitEvent->wait(); |
143 } | 143 } |
144 | 144 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 // Create the second worker. Verify that the second worker lives in a differ
ent WebThread since the first | 229 // Create the second worker. Verify that the second worker lives in a differ
ent WebThread since the first |
230 // thread will have been destroyed after destroying the first worker. | 230 // thread will have been destroyed after destroying the first worker. |
231 creationEvent = adoptPtr(Platform::current()->createWaitableEvent()); | 231 creationEvent = adoptPtr(Platform::current()->createWaitableEvent()); |
232 compositorWorker = createCompositorWorker(creationEvent.get()); | 232 compositorWorker = createCompositorWorker(creationEvent.get()); |
233 WebThreadSupportingGC* secondThread = &CompositorWorkerManager::instance()->
compositorWorkerThread(); | 233 WebThreadSupportingGC* secondThread = &CompositorWorkerManager::instance()->
compositorWorkerThread(); |
234 EXPECT_NE(firstThread, secondThread); | 234 EXPECT_NE(firstThread, secondThread); |
235 waitForWaitableEventAfterIteratingCurrentLoop(creationEvent.get()); | 235 waitForWaitableEventAfterIteratingCurrentLoop(creationEvent.get()); |
236 | 236 |
237 // Jump over to the worker's thread to verify that the Isolate is set up cor
rectly and execute script. | 237 // Jump over to the worker's thread to verify that the Isolate is set up cor
rectly and execute script. |
238 OwnPtr<WebWaitableEvent> checkEvent = adoptPtr(Platform::current()->createWa
itableEvent()); | 238 OwnPtr<WebWaitableEvent> checkEvent = adoptPtr(Platform::current()->createWa
itableEvent()); |
239 secondThread->platformThread().taskRunner()->postTask(FROM_HERE, threadSafeB
ind(&checkCurrentIsolate, AllowCrossThreadAccess(compositorWorker->isolate()), A
llowCrossThreadAccess(checkEvent.get()))); | 239 secondThread->platformThread().taskRunner()->postTask(BLINK_FROM_HERE, threa
dSafeBind(&checkCurrentIsolate, AllowCrossThreadAccess(compositorWorker->isolate
()), AllowCrossThreadAccess(checkEvent.get()))); |
240 waitForWaitableEventAfterIteratingCurrentLoop(checkEvent.get()); | 240 waitForWaitableEventAfterIteratingCurrentLoop(checkEvent.get()); |
241 checkWorkerCanExecuteScript(compositorWorker.get()); | 241 checkWorkerCanExecuteScript(compositorWorker.get()); |
242 | 242 |
243 compositorWorker->terminateAndWait(); | 243 compositorWorker->terminateAndWait(); |
244 } | 244 } |
245 | 245 |
246 // Tests that v8::Isolate and WebThread are correctly set-up if a worker is crea
ted while another is terminating. | 246 // Tests that v8::Isolate and WebThread are correctly set-up if a worker is crea
ted while another is terminating. |
247 TEST_F(CompositorWorkerManagerTest, CreatingSecondDuringTerminationOfFirst) | 247 TEST_F(CompositorWorkerManagerTest, CreatingSecondDuringTerminationOfFirst) |
248 { | 248 { |
249 OwnPtr<WebWaitableEvent> firstCreationEvent = adoptPtr(Platform::current()->
createWaitableEvent()); | 249 OwnPtr<WebWaitableEvent> firstCreationEvent = adoptPtr(Platform::current()->
createWaitableEvent()); |
(...skipping 14 matching lines...) Expand all Loading... |
264 v8::Isolate* secondIsolate = secondWorker->isolate(); | 264 v8::Isolate* secondIsolate = secondWorker->isolate(); |
265 ASSERT(secondIsolate); | 265 ASSERT(secondIsolate); |
266 EXPECT_EQ(firstIsolate, secondIsolate); | 266 EXPECT_EQ(firstIsolate, secondIsolate); |
267 | 267 |
268 // Verify that the isolate can run some scripts correctly in the second work
er. | 268 // Verify that the isolate can run some scripts correctly in the second work
er. |
269 checkWorkerCanExecuteScript(secondWorker.get()); | 269 checkWorkerCanExecuteScript(secondWorker.get()); |
270 secondWorker->terminateAndWait(); | 270 secondWorker->terminateAndWait(); |
271 } | 271 } |
272 | 272 |
273 } // namespace blink | 273 } // namespace blink |
OLD | NEW |