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

Side by Side Diff: Source/modules/compositorworker/CompositorWorkerManagerTest.cpp

Issue 1274023003: compositor-worker: Get the thread to run compositor-workers from the Platform. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . Created 5 years, 4 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 | Annotate | Revision Log
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 "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 "core/inspector/ConsoleMessage.h" 9 #include "core/inspector/ConsoleMessage.h"
10 #include "core/testing/DummyPageHolder.h" 10 #include "core/testing/DummyPageHolder.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 117
118 void createWorkerAdapter(RefPtr<CompositorWorkerThread>* workerThread, WebWa itableEvent* creationEvent) 118 void createWorkerAdapter(RefPtr<CompositorWorkerThread>* workerThread, WebWa itableEvent* creationEvent)
119 { 119 {
120 *workerThread = createCompositorWorker(creationEvent); 120 *workerThread = createCompositorWorker(creationEvent);
121 } 121 }
122 122
123 // Attempts to run some simple script for |worker|. 123 // Attempts to run some simple script for |worker|.
124 void checkWorkerCanExecuteScript(WorkerThread* worker) 124 void checkWorkerCanExecuteScript(WorkerThread* worker)
125 { 125 {
126 OwnPtr<WebWaitableEvent> waitEvent = adoptPtr(Platform::current()->creat eWaitableEvent()); 126 OwnPtr<WebWaitableEvent> waitEvent = adoptPtr(Platform::current()->creat eWaitableEvent());
127 worker->backingThread().platformThread().postTask(FROM_HERE, threadSafeB ind(&CompositorWorkerManagerTest::executeScriptInWorker, AllowCrossThreadAccess( this), 127 worker->backingThread().postTask(FROM_HERE, threadSafeBind(&CompositorWo rkerManagerTest::executeScriptInWorker, AllowCrossThreadAccess(this),
128 AllowCrossThreadAccess(worker), AllowCrossThreadAccess(waitEvent.get ()))); 128 AllowCrossThreadAccess(worker), AllowCrossThreadAccess(waitEvent.get ())));
129 waitEvent->wait(); 129 waitEvent->wait();
130 } 130 }
131 131
132 void waitForWaitableEventAfterIteratingCurrentLoop(WebWaitableEvent* waitEve nt) 132 void waitForWaitableEventAfterIteratingCurrentLoop(WebWaitableEvent* waitEve nt)
133 { 133 {
134 testing::runPendingTasks(); 134 testing::runPendingTasks();
135 waitEvent->wait(); 135 waitEvent->wait();
136 } 136 }
137 137
(...skipping 29 matching lines...) Expand all
167 checkWorkerCanExecuteScript(compositorWorker.get()); 167 checkWorkerCanExecuteScript(compositorWorker.get());
168 compositorWorker->terminateAndWait(); 168 compositorWorker->terminateAndWait();
169 } 169 }
170 170
171 // Tests that the same WebThread is used for new workers if the WebThread is sti ll alive. 171 // Tests that the same WebThread is used for new workers if the WebThread is sti ll alive.
172 TEST_F(CompositorWorkerManagerTest, CreateSecondAndTerminateFirst) 172 TEST_F(CompositorWorkerManagerTest, CreateSecondAndTerminateFirst)
173 { 173 {
174 // Create the first worker and wait until it is initialized. 174 // Create the first worker and wait until it is initialized.
175 OwnPtr<WebWaitableEvent> firstCreationEvent = adoptPtr(Platform::current()-> createWaitableEvent()); 175 OwnPtr<WebWaitableEvent> firstCreationEvent = adoptPtr(Platform::current()-> createWaitableEvent());
176 RefPtr<CompositorWorkerThread> firstWorker = createCompositorWorker(firstCre ationEvent.get()); 176 RefPtr<CompositorWorkerThread> firstWorker = createCompositorWorker(firstCre ationEvent.get());
177 WebThreadSupportingGC* firstThread = &CompositorWorkerManager::instance()->c ompositorWorkerThread(); 177 WebThread* firstThread = &CompositorWorkerManager::instance()->compositorWor kerThread();
178 ASSERT(firstThread); 178 ASSERT(firstThread);
179 waitForWaitableEventAfterIteratingCurrentLoop(firstCreationEvent.get()); 179 waitForWaitableEventAfterIteratingCurrentLoop(firstCreationEvent.get());
180 v8::Isolate* firstIsolate = firstWorker->isolate(); 180 v8::Isolate* firstIsolate = firstWorker->isolate();
181 ASSERT(firstIsolate); 181 ASSERT(firstIsolate);
182 182
183 // Create the second worker and immediately destroy the first worker. 183 // Create the second worker and immediately destroy the first worker.
184 OwnPtr<WebWaitableEvent> secondCreationEvent = adoptPtr(Platform::current()- >createWaitableEvent()); 184 OwnPtr<WebWaitableEvent> secondCreationEvent = adoptPtr(Platform::current()- >createWaitableEvent());
185 RefPtr<CompositorWorkerThread> secondWorker = createCompositorWorker(secondC reationEvent.get()); 185 RefPtr<CompositorWorkerThread> secondWorker = createCompositorWorker(secondC reationEvent.get());
186 firstWorker->terminateAndWait(); 186 firstWorker->terminateAndWait();
187 187
188 // Wait until the second worker is initialized. Verify that the second worke r is using the same 188 // Wait until the second worker is initialized. Verify that the second worke r is using the same
189 // thread and Isolate as the first worker. 189 // thread and Isolate as the first worker.
190 WebThreadSupportingGC* secondThread = &CompositorWorkerManager::instance()-> compositorWorkerThread(); 190 WebThread* secondThread = &CompositorWorkerManager::instance()->compositorWo rkerThread();
191 ASSERT(secondThread); 191 ASSERT(secondThread);
192 waitForWaitableEventAfterIteratingCurrentLoop(secondCreationEvent.get()); 192 waitForWaitableEventAfterIteratingCurrentLoop(secondCreationEvent.get());
193 EXPECT_EQ(firstThread, secondThread); 193 EXPECT_EQ(firstThread, secondThread);
194 194
195 v8::Isolate* secondIsolate = secondWorker->isolate(); 195 v8::Isolate* secondIsolate = secondWorker->isolate();
196 ASSERT(secondIsolate); 196 ASSERT(secondIsolate);
197 EXPECT_EQ(firstIsolate, secondIsolate); 197 EXPECT_EQ(firstIsolate, secondIsolate);
198 198
199 // Verify that the worker can still successfully execute script. 199 // Verify that the worker can still successfully execute script.
200 checkWorkerCanExecuteScript(secondWorker.get()); 200 checkWorkerCanExecuteScript(secondWorker.get());
201 201
202 secondWorker->terminateAndWait(); 202 secondWorker->terminateAndWait();
203 } 203 }
204 204
205 static void checkCurrentIsolate(v8::Isolate* isolate, WebWaitableEvent* event) 205 static void checkCurrentIsolate(v8::Isolate* isolate, WebWaitableEvent* event)
206 { 206 {
207 EXPECT_EQ(v8::Isolate::GetCurrent(), isolate); 207 EXPECT_EQ(v8::Isolate::GetCurrent(), isolate);
208 event->signal(); 208 event->signal();
209 } 209 }
210 210
211 // Tests that a new WebThread is created if all existing workers are terminated before a new worker is created. 211 // Tests that a new WebThread is created if all existing workers are terminated before a new worker is created.
212 TEST_F(CompositorWorkerManagerTest, TerminateFirstAndCreateSecond) 212 TEST_F(CompositorWorkerManagerTest, TerminateFirstAndCreateSecond)
213 { 213 {
214 // Create the first worker, wait until it is initialized, and terminate it. 214 // Create the first worker, wait until it is initialized, and terminate it.
215 OwnPtr<WebWaitableEvent> creationEvent = adoptPtr(Platform::current()->creat eWaitableEvent()); 215 OwnPtr<WebWaitableEvent> creationEvent = adoptPtr(Platform::current()->creat eWaitableEvent());
216 RefPtr<CompositorWorkerThread> compositorWorker = createCompositorWorker(cre ationEvent.get()); 216 RefPtr<CompositorWorkerThread> compositorWorker = createCompositorWorker(cre ationEvent.get());
217 WebThreadSupportingGC* firstThread = &CompositorWorkerManager::instance()->c ompositorWorkerThread(); 217 WebThread* firstThread = &CompositorWorkerManager::instance()->compositorWor kerThread();
218 waitForWaitableEventAfterIteratingCurrentLoop(creationEvent.get()); 218 waitForWaitableEventAfterIteratingCurrentLoop(creationEvent.get());
219 ASSERT(compositorWorker->isolate()); 219 ASSERT(compositorWorker->isolate());
220 compositorWorker->terminateAndWait(); 220 compositorWorker->terminateAndWait();
221 221
222 // Create the second worker. Verify that the second worker lives in a differ ent WebThread since the first 222 // Create the second worker. Verify that the second worker lives in a differ ent WebThread since the first
223 // thread will have been destroyed after destroying the first worker. 223 // thread will have been destroyed after destroying the first worker.
224 creationEvent = adoptPtr(Platform::current()->createWaitableEvent()); 224 creationEvent = adoptPtr(Platform::current()->createWaitableEvent());
225 compositorWorker = createCompositorWorker(creationEvent.get()); 225 compositorWorker = createCompositorWorker(creationEvent.get());
226 WebThreadSupportingGC* secondThread = &CompositorWorkerManager::instance()-> compositorWorkerThread(); 226 WebThread* secondThread = &CompositorWorkerManager::instance()->compositorWo rkerThread();
227 EXPECT_NE(firstThread, secondThread); 227 EXPECT_NE(firstThread, secondThread);
228 waitForWaitableEventAfterIteratingCurrentLoop(creationEvent.get()); 228 waitForWaitableEventAfterIteratingCurrentLoop(creationEvent.get());
229 229
230 // Jump over to the worker's thread to verify that the Isolate is set up cor rectly and execute script. 230 // Jump over to the worker's thread to verify that the Isolate is set up cor rectly and execute script.
231 OwnPtr<WebWaitableEvent> checkEvent = adoptPtr(Platform::current()->createWa itableEvent()); 231 OwnPtr<WebWaitableEvent> checkEvent = adoptPtr(Platform::current()->createWa itableEvent());
232 secondThread->platformThread().postTask(FROM_HERE, threadSafeBind(&checkCurr entIsolate, AllowCrossThreadAccess(compositorWorker->isolate()), AllowCrossThrea dAccess(checkEvent.get()))); 232 secondThread->postTask(FROM_HERE, threadSafeBind(&checkCurrentIsolate, Allow CrossThreadAccess(compositorWorker->isolate()), AllowCrossThreadAccess(checkEven t.get())));
233 waitForWaitableEventAfterIteratingCurrentLoop(checkEvent.get()); 233 waitForWaitableEventAfterIteratingCurrentLoop(checkEvent.get());
234 checkWorkerCanExecuteScript(compositorWorker.get()); 234 checkWorkerCanExecuteScript(compositorWorker.get());
235 235
236 compositorWorker->terminateAndWait(); 236 compositorWorker->terminateAndWait();
237 } 237 }
238 238
239 // Tests that v8::Isolate and WebThread are correctly set-up if a worker is crea ted while another is terminating. 239 // Tests that v8::Isolate and WebThread are correctly set-up if a worker is crea ted while another is terminating.
240 TEST_F(CompositorWorkerManagerTest, CreatingSecondDuringTerminationOfFirst) 240 TEST_F(CompositorWorkerManagerTest, CreatingSecondDuringTerminationOfFirst)
241 { 241 {
242 OwnPtr<WebWaitableEvent> firstCreationEvent = adoptPtr(Platform::current()-> createWaitableEvent()); 242 OwnPtr<WebWaitableEvent> firstCreationEvent = adoptPtr(Platform::current()-> createWaitableEvent());
(...skipping 14 matching lines...) Expand all
257 v8::Isolate* secondIsolate = secondWorker->isolate(); 257 v8::Isolate* secondIsolate = secondWorker->isolate();
258 ASSERT(secondIsolate); 258 ASSERT(secondIsolate);
259 EXPECT_EQ(firstIsolate, secondIsolate); 259 EXPECT_EQ(firstIsolate, secondIsolate);
260 260
261 // Verify that the isolate can run some scripts correctly in the second work er. 261 // Verify that the isolate can run some scripts correctly in the second work er.
262 checkWorkerCanExecuteScript(secondWorker.get()); 262 checkWorkerCanExecuteScript(secondWorker.get());
263 secondWorker->terminateAndWait(); 263 secondWorker->terminateAndWait();
264 } 264 }
265 265
266 } // namespace blink 266 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698