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/CompositorWorkerThread.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" |
11 #include "core/testing/DummyPageHolder.h" | 11 #include "core/testing/DummyPageHolder.h" |
12 #include "core/workers/WorkerLoaderProxy.h" | 12 #include "core/workers/WorkerLoaderProxy.h" |
13 #include "core/workers/WorkerObjectProxy.h" | 13 #include "core/workers/WorkerObjectProxy.h" |
14 #include "core/workers/WorkerThreadStartupData.h" | 14 #include "core/workers/WorkerThreadStartupData.h" |
15 #include "modules/compositorworker/CompositorWorkerThread.h" | |
16 #include "platform/NotImplemented.h" | 15 #include "platform/NotImplemented.h" |
17 #include "platform/ThreadSafeFunctional.h" | 16 #include "platform/ThreadSafeFunctional.h" |
18 #include "platform/heap/Handle.h" | 17 #include "platform/heap/Handle.h" |
| 18 #include "platform/testing/TestingPlatformSupport.h" |
19 #include "platform/testing/UnitTestHelpers.h" | 19 #include "platform/testing/UnitTestHelpers.h" |
20 #include "public/platform/Platform.h" | 20 #include "public/platform/Platform.h" |
21 #include "public/platform/WebWaitableEvent.h" | 21 #include "public/platform/WebWaitableEvent.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 | 23 |
24 namespace blink { | 24 namespace blink { |
25 namespace { | 25 namespace { |
26 | 26 |
27 class TestCompositorWorkerThread : public CompositorWorkerThread { | 27 class TestCompositorWorkerThread : public CompositorWorkerThread { |
28 public: | 28 public: |
29 TestCompositorWorkerThread(WorkerLoaderProxyProvider* loaderProxyProvider, W
orkerObjectProxy& objectProxy, double timeOrigin, WebWaitableEvent* startEvent) | 29 TestCompositorWorkerThread(WorkerLoaderProxyProvider* loaderProxyProvider, W
orkerObjectProxy& objectProxy, double timeOrigin, WebWaitableEvent* startEvent) |
30 : CompositorWorkerThread(WorkerLoaderProxy::create(loaderProxyProvider),
objectProxy, timeOrigin) | 30 : CompositorWorkerThread(WorkerLoaderProxy::create(loaderProxyProvider),
objectProxy, timeOrigin) |
31 , m_startEvent(startEvent) | 31 , m_startEvent(startEvent) |
32 { | 32 { |
33 } | 33 } |
34 | 34 |
35 ~TestCompositorWorkerThread() override { } | 35 ~TestCompositorWorkerThread() override {} |
36 | 36 |
37 void setCallbackAfterV8Termination(PassOwnPtr<Function<void()>> callback) | 37 void setCallbackAfterV8Termination(PassOwnPtr<Function<void()>> callback) |
38 { | 38 { |
39 m_v8TerminationCallback = callback; | 39 m_v8TerminationCallback = callback; |
40 } | 40 } |
41 | 41 |
42 private: | 42 private: |
43 // WorkerThread: | 43 // WorkerThread: |
44 void didStartRunLoop() override | 44 void didStartRunLoop() override |
45 { | 45 { |
46 m_startEvent->signal(); | 46 m_startEvent->signal(); |
47 } | 47 } |
48 void terminateV8Execution() override | 48 void terminateV8Execution() override |
49 { | 49 { |
50 CompositorWorkerThread::terminateV8Execution(); | 50 CompositorWorkerThread::terminateV8Execution(); |
51 if (m_v8TerminationCallback) | 51 if (m_v8TerminationCallback) |
52 (*m_v8TerminationCallback)(); | 52 (*m_v8TerminationCallback)(); |
53 } | 53 } |
| 54 |
54 void willDestroyIsolate() override | 55 void willDestroyIsolate() override |
55 { | 56 { |
56 V8GCController::collectAllGarbageForTesting(v8::Isolate::GetCurrent()); | 57 v8::Isolate::GetCurrent()->RequestGarbageCollectionForTesting(v8::Isolat
e::kFullGarbageCollection); |
| 58 Heap::collectAllGarbage(); |
57 CompositorWorkerThread::willDestroyIsolate(); | 59 CompositorWorkerThread::willDestroyIsolate(); |
58 } | 60 } |
59 | 61 |
60 WebWaitableEvent* m_startEvent; | 62 WebWaitableEvent* m_startEvent; |
61 OwnPtr<Function<void()>> m_v8TerminationCallback; | 63 OwnPtr<Function<void()>> m_v8TerminationCallback; |
62 }; | 64 }; |
63 | 65 |
64 // A null WorkerObjectProxy, supplied when creating CompositorWorkerThreads. | 66 // A null WorkerObjectProxy, supplied when creating CompositorWorkerThreads. |
65 class TestCompositorWorkerObjectProxy : public WorkerObjectProxy { | 67 class TestCompositorWorkerObjectProxy : public WorkerObjectProxy { |
66 public: | 68 public: |
(...skipping 19 matching lines...) Expand all Loading... |
86 private: | 88 private: |
87 TestCompositorWorkerObjectProxy(ExecutionContext* context) | 89 TestCompositorWorkerObjectProxy(ExecutionContext* context) |
88 : WorkerObjectProxy(nullptr) | 90 : WorkerObjectProxy(nullptr) |
89 , m_executionContext(context) | 91 , m_executionContext(context) |
90 { | 92 { |
91 } | 93 } |
92 | 94 |
93 RefPtrWillBePersistent<ExecutionContext> m_executionContext; | 95 RefPtrWillBePersistent<ExecutionContext> m_executionContext; |
94 }; | 96 }; |
95 | 97 |
| 98 class CompositorWorkerTestPlatform : public TestingPlatformSupport { |
| 99 public: |
| 100 CompositorWorkerTestPlatform() |
| 101 : m_thread(adoptPtr(m_oldPlatform->createThread("Compositor"))) |
| 102 { |
| 103 } |
| 104 |
| 105 WebThread* compositorThread() const override |
| 106 { |
| 107 return m_thread.get(); |
| 108 } |
| 109 |
| 110 WebWaitableEvent* createWaitableEvent( |
| 111 WebWaitableEvent::ResetPolicy policy, |
| 112 WebWaitableEvent::InitialState state) override |
| 113 { |
| 114 return m_oldPlatform->createWaitableEvent(policy, state); |
| 115 } |
| 116 |
| 117 private: |
| 118 OwnPtr<WebThread> m_thread; |
| 119 }; |
| 120 |
96 } // namespace | 121 } // namespace |
97 | 122 |
98 class CompositorWorkerManagerTest : public ::testing::Test { | 123 class CompositorWorkerThreadTest : public ::testing::Test { |
99 public: | 124 public: |
100 void SetUp() override | 125 void SetUp() override |
101 { | 126 { |
102 m_page = DummyPageHolder::create(); | 127 m_page = DummyPageHolder::create(); |
103 m_objectProxy = TestCompositorWorkerObjectProxy::create(&m_page->documen
t()); | 128 m_objectProxy = TestCompositorWorkerObjectProxy::create(&m_page->documen
t()); |
104 m_securityOrigin = SecurityOrigin::create(KURL(ParsedURLString, "http://
fake.url/")); | 129 m_securityOrigin = SecurityOrigin::create(KURL(ParsedURLString, "http://
fake.url/")); |
105 } | 130 } |
106 | 131 |
107 void TearDown() override | 132 void TearDown() override |
108 { | 133 { |
109 ASSERT(!managerHasThread()); | 134 ASSERT(!hasThread()); |
110 ASSERT(!managerHasIsolate()); | 135 ASSERT(!hasIsolate()); |
111 m_page.clear(); | 136 m_page.clear(); |
112 } | 137 } |
113 | 138 |
114 PassRefPtr<TestCompositorWorkerThread> createCompositorWorker(WebWaitableEve
nt* startEvent) | 139 PassRefPtr<TestCompositorWorkerThread> createCompositorWorker(WebWaitableEve
nt* startEvent) |
115 { | 140 { |
116 TestCompositorWorkerThread* workerThread = new TestCompositorWorkerThrea
d(nullptr, *m_objectProxy, 0, startEvent); | 141 TestCompositorWorkerThread* workerThread = new TestCompositorWorkerThrea
d(nullptr, *m_objectProxy, 0, startEvent); |
117 OwnPtrWillBeRawPtr<WorkerClients> clients = nullptr; | 142 OwnPtrWillBeRawPtr<WorkerClients> clients = nullptr; |
118 workerThread->start(WorkerThreadStartupData::create( | 143 workerThread->start(WorkerThreadStartupData::create( |
119 KURL(ParsedURLString, "http://fake.url/"), | 144 KURL(ParsedURLString, "http://fake.url/"), |
120 "fake user agent", | 145 "fake user agent", |
121 "//fake source code", | 146 "//fake source code", |
122 nullptr, | 147 nullptr, |
123 DontPauseWorkerGlobalScopeOnStart, | 148 DontPauseWorkerGlobalScopeOnStart, |
124 adoptPtr(new Vector<CSPHeaderAndType>()), | 149 adoptPtr(new Vector<CSPHeaderAndType>()), |
125 m_securityOrigin.get(), | 150 m_securityOrigin.get(), |
126 clients.release(), | 151 clients.release(), |
127 V8CacheOptionsDefault)); | 152 V8CacheOptionsDefault)); |
128 return adoptRef(workerThread); | 153 return adoptRef(workerThread); |
129 } | 154 } |
130 | 155 |
131 void createWorkerAdapter(RefPtr<CompositorWorkerThread>* workerThread, WebWa
itableEvent* creationEvent) | 156 void createWorkerAdapter(RefPtr<CompositorWorkerThread>* workerThread, WebWa
itableEvent* creationEvent) |
132 { | 157 { |
133 *workerThread = createCompositorWorker(creationEvent); | 158 *workerThread = createCompositorWorker(creationEvent); |
134 } | 159 } |
135 | 160 |
136 // Attempts to run some simple script for |worker|. | 161 // Attempts to run some simple script for |worker|. |
137 void checkWorkerCanExecuteScript(WorkerThread* worker) | 162 void checkWorkerCanExecuteScript(WorkerThread* worker) |
138 { | 163 { |
139 OwnPtr<WebWaitableEvent> waitEvent = adoptPtr(Platform::current()->creat
eWaitableEvent()); | 164 OwnPtr<WebWaitableEvent> waitEvent = adoptPtr(Platform::current()->creat
eWaitableEvent()); |
140 worker->backingThread().platformThread().taskRunner()->postTask(BLINK_FR
OM_HERE, threadSafeBind(&CompositorWorkerManagerTest::executeScriptInWorker, All
owCrossThreadAccess(this), | 165 worker->backingThread().platformThread().taskRunner()->postTask(BLINK_FR
OM_HERE, threadSafeBind(&CompositorWorkerThreadTest::executeScriptInWorker, Allo
wCrossThreadAccess(this), |
141 AllowCrossThreadAccess(worker), AllowCrossThreadAccess(waitEvent.get
()))); | 166 AllowCrossThreadAccess(worker), AllowCrossThreadAccess(waitEvent.get
()))); |
142 waitEvent->wait(); | 167 waitEvent->wait(); |
143 } | 168 } |
144 | 169 |
145 void waitForWaitableEventAfterIteratingCurrentLoop(WebWaitableEvent* waitEve
nt) | 170 void waitForWaitableEventAfterIteratingCurrentLoop(WebWaitableEvent* waitEve
nt) |
146 { | 171 { |
147 testing::runPendingTasks(); | 172 testing::runPendingTasks(); |
148 waitEvent->wait(); | 173 waitEvent->wait(); |
149 } | 174 } |
150 | 175 |
151 bool managerHasThread() const | 176 bool hasThread() const |
152 { | 177 { |
153 return CompositorWorkerManager::instance()->m_thread; | 178 return CompositorWorkerThread::hasThreadForTest(); |
154 } | 179 } |
155 | 180 |
156 bool managerHasIsolate() const | 181 bool hasIsolate() const |
157 { | 182 { |
158 return CompositorWorkerManager::instance()->m_isolate; | 183 return CompositorWorkerThread::hasIsolateForTest(); |
159 } | 184 } |
160 | 185 |
161 private: | 186 private: |
162 void executeScriptInWorker(WorkerThread* worker, WebWaitableEvent* waitEvent
) | 187 void executeScriptInWorker(WorkerThread* worker, WebWaitableEvent* waitEvent
) |
163 { | 188 { |
164 WorkerScriptController* scriptController = worker->workerGlobalScope()->
script(); | 189 WorkerScriptController* scriptController = worker->workerGlobalScope()->
script(); |
165 bool evaluateResult = scriptController->evaluate(ScriptSourceCode("var c
ounter = 0; ++counter;")); | 190 bool evaluateResult = scriptController->evaluate(ScriptSourceCode("var c
ounter = 0; ++counter;")); |
166 ASSERT_UNUSED(evaluateResult, evaluateResult); | 191 ASSERT_UNUSED(evaluateResult, evaluateResult); |
167 waitEvent->signal(); | 192 waitEvent->signal(); |
168 } | 193 } |
169 | 194 |
170 OwnPtr<DummyPageHolder> m_page; | 195 OwnPtr<DummyPageHolder> m_page; |
171 RefPtr<SecurityOrigin> m_securityOrigin; | 196 RefPtr<SecurityOrigin> m_securityOrigin; |
172 OwnPtr<WorkerObjectProxy> m_objectProxy; | 197 OwnPtr<WorkerObjectProxy> m_objectProxy; |
| 198 CompositorWorkerTestPlatform m_testPlatform; |
173 }; | 199 }; |
174 | 200 |
175 TEST_F(CompositorWorkerManagerTest, Basic) | 201 TEST_F(CompositorWorkerThreadTest, Basic) |
176 { | 202 { |
177 OwnPtr<WebWaitableEvent> creationEvent = adoptPtr(Platform::current()->creat
eWaitableEvent()); | 203 OwnPtr<WebWaitableEvent> creationEvent = adoptPtr(Platform::current()->creat
eWaitableEvent()); |
178 RefPtr<CompositorWorkerThread> compositorWorker = createCompositorWorker(cre
ationEvent.get()); | 204 RefPtr<CompositorWorkerThread> compositorWorker = createCompositorWorker(cre
ationEvent.get()); |
179 waitForWaitableEventAfterIteratingCurrentLoop(creationEvent.get()); | 205 waitForWaitableEventAfterIteratingCurrentLoop(creationEvent.get()); |
180 checkWorkerCanExecuteScript(compositorWorker.get()); | 206 checkWorkerCanExecuteScript(compositorWorker.get()); |
181 compositorWorker->terminateAndWait(); | 207 compositorWorker->terminateAndWait(); |
182 } | 208 } |
183 | 209 |
184 // Tests that the same WebThread is used for new workers if the WebThread is sti
ll alive. | 210 // Tests that the same WebThread is used for new workers if the WebThread is sti
ll alive. |
185 TEST_F(CompositorWorkerManagerTest, CreateSecondAndTerminateFirst) | 211 TEST_F(CompositorWorkerThreadTest, CreateSecondAndTerminateFirst) |
186 { | 212 { |
187 // Create the first worker and wait until it is initialized. | 213 // Create the first worker and wait until it is initialized. |
188 OwnPtr<WebWaitableEvent> firstCreationEvent = adoptPtr(Platform::current()->
createWaitableEvent()); | 214 OwnPtr<WebWaitableEvent> firstCreationEvent = adoptPtr(Platform::current()->
createWaitableEvent()); |
189 RefPtr<CompositorWorkerThread> firstWorker = createCompositorWorker(firstCre
ationEvent.get()); | 215 RefPtr<CompositorWorkerThread> firstWorker = createCompositorWorker(firstCre
ationEvent.get()); |
190 WebThreadSupportingGC* firstThread = &CompositorWorkerManager::instance()->c
ompositorWorkerThread(); | 216 WebThreadSupportingGC* firstThread = CompositorWorkerThread::sharedBackingTh
read(); |
191 ASSERT(firstThread); | 217 ASSERT(firstThread); |
192 waitForWaitableEventAfterIteratingCurrentLoop(firstCreationEvent.get()); | 218 waitForWaitableEventAfterIteratingCurrentLoop(firstCreationEvent.get()); |
193 v8::Isolate* firstIsolate = firstWorker->isolate(); | 219 v8::Isolate* firstIsolate = firstWorker->isolate(); |
194 ASSERT(firstIsolate); | 220 ASSERT(firstIsolate); |
195 | 221 |
196 // Create the second worker and immediately destroy the first worker. | 222 // Create the second worker and immediately destroy the first worker. |
197 OwnPtr<WebWaitableEvent> secondCreationEvent = adoptPtr(Platform::current()-
>createWaitableEvent()); | 223 OwnPtr<WebWaitableEvent> secondCreationEvent = adoptPtr(Platform::current()-
>createWaitableEvent()); |
198 RefPtr<CompositorWorkerThread> secondWorker = createCompositorWorker(secondC
reationEvent.get()); | 224 RefPtr<CompositorWorkerThread> secondWorker = createCompositorWorker(secondC
reationEvent.get()); |
199 firstWorker->terminateAndWait(); | 225 firstWorker->terminateAndWait(); |
200 | 226 |
201 // Wait until the second worker is initialized. Verify that the second worke
r is using the same | 227 // Wait until the second worker is initialized. Verify that the second worke
r is using the same |
202 // thread and Isolate as the first worker. | 228 // thread and Isolate as the first worker. |
203 WebThreadSupportingGC* secondThread = &CompositorWorkerManager::instance()->
compositorWorkerThread(); | 229 WebThreadSupportingGC* secondThread = CompositorWorkerThread::sharedBackingT
hread(); |
204 ASSERT(secondThread); | 230 ASSERT(secondThread); |
205 waitForWaitableEventAfterIteratingCurrentLoop(secondCreationEvent.get()); | 231 waitForWaitableEventAfterIteratingCurrentLoop(secondCreationEvent.get()); |
206 EXPECT_EQ(firstThread, secondThread); | 232 EXPECT_EQ(firstThread, secondThread); |
207 | 233 |
208 v8::Isolate* secondIsolate = secondWorker->isolate(); | 234 v8::Isolate* secondIsolate = secondWorker->isolate(); |
209 ASSERT(secondIsolate); | 235 ASSERT(secondIsolate); |
210 EXPECT_EQ(firstIsolate, secondIsolate); | 236 EXPECT_EQ(firstIsolate, secondIsolate); |
211 | 237 |
212 // Verify that the worker can still successfully execute script. | 238 // Verify that the worker can still successfully execute script. |
213 checkWorkerCanExecuteScript(secondWorker.get()); | 239 checkWorkerCanExecuteScript(secondWorker.get()); |
214 | 240 |
215 secondWorker->terminateAndWait(); | 241 secondWorker->terminateAndWait(); |
216 } | 242 } |
217 | 243 |
218 static void checkCurrentIsolate(v8::Isolate* isolate, WebWaitableEvent* event) | 244 static void checkCurrentIsolate(v8::Isolate* isolate, WebWaitableEvent* event) |
219 { | 245 { |
220 EXPECT_EQ(v8::Isolate::GetCurrent(), isolate); | 246 EXPECT_EQ(v8::Isolate::GetCurrent(), isolate); |
221 event->signal(); | 247 event->signal(); |
222 } | 248 } |
223 | 249 |
224 // Tests that a new WebThread is created if all existing workers are terminated
before a new worker is created. | 250 // Tests that a new WebThread is created if all existing workers are terminated
before a new worker is created. |
225 TEST_F(CompositorWorkerManagerTest, TerminateFirstAndCreateSecond) | 251 TEST_F(CompositorWorkerThreadTest, TerminateFirstAndCreateSecond) |
226 { | 252 { |
227 // Create the first worker, wait until it is initialized, and terminate it. | 253 // Create the first worker, wait until it is initialized, and terminate it. |
228 OwnPtr<WebWaitableEvent> creationEvent = adoptPtr(Platform::current()->creat
eWaitableEvent()); | 254 OwnPtr<WebWaitableEvent> creationEvent = adoptPtr(Platform::current()->creat
eWaitableEvent()); |
229 RefPtr<CompositorWorkerThread> compositorWorker = createCompositorWorker(cre
ationEvent.get()); | 255 RefPtr<CompositorWorkerThread> compositorWorker = createCompositorWorker(cre
ationEvent.get()); |
230 WebThreadSupportingGC* firstThread = &CompositorWorkerManager::instance()->c
ompositorWorkerThread(); | 256 WebThreadSupportingGC* firstThread = CompositorWorkerThread::sharedBackingTh
read(); |
231 waitForWaitableEventAfterIteratingCurrentLoop(creationEvent.get()); | 257 waitForWaitableEventAfterIteratingCurrentLoop(creationEvent.get()); |
232 ASSERT(compositorWorker->isolate()); | 258 ASSERT(compositorWorker->isolate()); |
233 compositorWorker->terminateAndWait(); | 259 compositorWorker->terminateAndWait(); |
234 | 260 |
235 // Create the second worker. Verify that the second worker lives in a differ
ent WebThread since the first | 261 // Create the second worker. Verify that the second worker lives in a differ
ent WebThread since the first |
236 // thread will have been destroyed after destroying the first worker. | 262 // thread will have been destroyed after destroying the first worker. |
237 creationEvent = adoptPtr(Platform::current()->createWaitableEvent()); | 263 creationEvent = adoptPtr(Platform::current()->createWaitableEvent()); |
238 compositorWorker = createCompositorWorker(creationEvent.get()); | 264 compositorWorker = createCompositorWorker(creationEvent.get()); |
239 WebThreadSupportingGC* secondThread = &CompositorWorkerManager::instance()->
compositorWorkerThread(); | 265 WebThreadSupportingGC* secondThread = CompositorWorkerThread::sharedBackingT
hread(); |
240 EXPECT_NE(firstThread, secondThread); | 266 EXPECT_NE(firstThread, secondThread); |
241 waitForWaitableEventAfterIteratingCurrentLoop(creationEvent.get()); | 267 waitForWaitableEventAfterIteratingCurrentLoop(creationEvent.get()); |
242 | 268 |
243 // Jump over to the worker's thread to verify that the Isolate is set up cor
rectly and execute script. | 269 // Jump over to the worker's thread to verify that the Isolate is set up cor
rectly and execute script. |
244 OwnPtr<WebWaitableEvent> checkEvent = adoptPtr(Platform::current()->createWa
itableEvent()); | 270 OwnPtr<WebWaitableEvent> checkEvent = adoptPtr(Platform::current()->createWa
itableEvent()); |
245 secondThread->platformThread().taskRunner()->postTask(BLINK_FROM_HERE, threa
dSafeBind(&checkCurrentIsolate, AllowCrossThreadAccess(compositorWorker->isolate
()), AllowCrossThreadAccess(checkEvent.get()))); | 271 secondThread->platformThread().taskRunner()->postTask(BLINK_FROM_HERE, threa
dSafeBind(&checkCurrentIsolate, AllowCrossThreadAccess(compositorWorker->isolate
()), AllowCrossThreadAccess(checkEvent.get()))); |
246 waitForWaitableEventAfterIteratingCurrentLoop(checkEvent.get()); | 272 waitForWaitableEventAfterIteratingCurrentLoop(checkEvent.get()); |
247 checkWorkerCanExecuteScript(compositorWorker.get()); | 273 checkWorkerCanExecuteScript(compositorWorker.get()); |
248 | 274 |
249 compositorWorker->terminateAndWait(); | 275 compositorWorker->terminateAndWait(); |
250 } | 276 } |
251 | 277 |
252 // Tests that v8::Isolate and WebThread are correctly set-up if a worker is crea
ted while another is terminating. | 278 // Tests that v8::Isolate and WebThread are correctly set-up if a worker is crea
ted while another is terminating. |
253 TEST_F(CompositorWorkerManagerTest, CreatingSecondDuringTerminationOfFirst) | 279 TEST_F(CompositorWorkerThreadTest, CreatingSecondDuringTerminationOfFirst) |
254 { | 280 { |
255 OwnPtr<WebWaitableEvent> firstCreationEvent = adoptPtr(Platform::current()->
createWaitableEvent()); | 281 OwnPtr<WebWaitableEvent> firstCreationEvent = adoptPtr(Platform::current()->
createWaitableEvent()); |
256 RefPtr<TestCompositorWorkerThread> firstWorker = createCompositorWorker(firs
tCreationEvent.get()); | 282 RefPtr<TestCompositorWorkerThread> firstWorker = createCompositorWorker(firs
tCreationEvent.get()); |
257 waitForWaitableEventAfterIteratingCurrentLoop(firstCreationEvent.get()); | 283 waitForWaitableEventAfterIteratingCurrentLoop(firstCreationEvent.get()); |
258 v8::Isolate* firstIsolate = firstWorker->isolate(); | 284 v8::Isolate* firstIsolate = firstWorker->isolate(); |
259 ASSERT(firstIsolate); | 285 ASSERT(firstIsolate); |
260 | 286 |
261 // Request termination of the first worker, and set-up to make sure the seco
nd worker is created right as | 287 // Request termination of the first worker, and set-up to make sure the seco
nd worker is created right as |
262 // the first worker terminates its isolate. | 288 // the first worker terminates its isolate. |
263 OwnPtr<WebWaitableEvent> secondCreationEvent = adoptPtr(Platform::current()-
>createWaitableEvent()); | 289 OwnPtr<WebWaitableEvent> secondCreationEvent = adoptPtr(Platform::current()-
>createWaitableEvent()); |
264 RefPtr<CompositorWorkerThread> secondWorker; | 290 RefPtr<CompositorWorkerThread> secondWorker; |
265 firstWorker->setCallbackAfterV8Termination(bind(&CompositorWorkerManagerTest
::createWorkerAdapter, this, &secondWorker, secondCreationEvent.get())); | 291 firstWorker->setCallbackAfterV8Termination(bind(&CompositorWorkerThreadTest:
:createWorkerAdapter, this, &secondWorker, secondCreationEvent.get())); |
266 firstWorker->terminateAndWait(); | 292 firstWorker->terminateAndWait(); |
267 ASSERT(secondWorker); | 293 ASSERT(secondWorker); |
268 | 294 |
269 waitForWaitableEventAfterIteratingCurrentLoop(secondCreationEvent.get()); | 295 waitForWaitableEventAfterIteratingCurrentLoop(secondCreationEvent.get()); |
270 v8::Isolate* secondIsolate = secondWorker->isolate(); | 296 v8::Isolate* secondIsolate = secondWorker->isolate(); |
271 ASSERT(secondIsolate); | 297 ASSERT(secondIsolate); |
272 EXPECT_EQ(firstIsolate, secondIsolate); | 298 EXPECT_EQ(firstIsolate, secondIsolate); |
273 | 299 |
274 // Verify that the isolate can run some scripts correctly in the second work
er. | 300 // Verify that the isolate can run some scripts correctly in the second work
er. |
275 checkWorkerCanExecuteScript(secondWorker.get()); | 301 checkWorkerCanExecuteScript(secondWorker.get()); |
276 secondWorker->terminateAndWait(); | 302 secondWorker->terminateAndWait(); |
277 } | 303 } |
278 | 304 |
279 } // namespace blink | 305 } // namespace blink |
OLD | NEW |