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

Side by Side Diff: third_party/WebKit/Source/modules/compositorworker/CompositorWorkerThreadTest.cpp

Issue 2588403002: TestingPlatformSupport: register Platform instance correctly (Closed)
Patch Set: review #32 Created 3 years, 11 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
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 "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
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 CompositorWorkerTestPlatform m_testPlatform;
147 }; 146 };
148 147
149 TEST_F(CompositorWorkerThreadTest, Basic) { 148 TEST_F(CompositorWorkerThreadTest, Basic) {
149 ScopedTestingPlatformSupport<CompositorWorkerTestPlatform> platform;
150
150 std::unique_ptr<CompositorWorkerThread> compositorWorker = 151 std::unique_ptr<CompositorWorkerThread> compositorWorker =
151 createCompositorWorker(); 152 createCompositorWorker();
152 checkWorkerCanExecuteScript(compositorWorker.get()); 153 checkWorkerCanExecuteScript(compositorWorker.get());
153 compositorWorker->terminateAndWait(); 154 compositorWorker->terminateAndWait();
154 } 155 }
155 156
156 // Tests that the same WebThread is used for new workers if the WebThread is 157 // Tests that the same WebThread is used for new workers if the WebThread is
157 // still alive. 158 // still alive.
158 TEST_F(CompositorWorkerThreadTest, CreateSecondAndTerminateFirst) { 159 TEST_F(CompositorWorkerThreadTest, CreateSecondAndTerminateFirst) {
160 ScopedTestingPlatformSupport<CompositorWorkerTestPlatform> platform;
161
159 // Create the first worker and wait until it is initialized. 162 // Create the first worker and wait until it is initialized.
160 std::unique_ptr<CompositorWorkerThread> firstWorker = 163 std::unique_ptr<CompositorWorkerThread> firstWorker =
161 createCompositorWorker(); 164 createCompositorWorker();
162 WebThreadSupportingGC* firstThread = 165 WebThreadSupportingGC* firstThread =
163 &firstWorker->workerBackingThread().backingThread(); 166 &firstWorker->workerBackingThread().backingThread();
164 checkWorkerCanExecuteScript(firstWorker.get()); 167 checkWorkerCanExecuteScript(firstWorker.get());
165 v8::Isolate* firstIsolate = firstWorker->isolate(); 168 v8::Isolate* firstIsolate = firstWorker->isolate();
166 ASSERT_TRUE(firstIsolate); 169 ASSERT_TRUE(firstIsolate);
167 170
168 // Create the second worker and immediately destroy the first worker. 171 // Create the second worker and immediately destroy the first worker.
(...skipping 15 matching lines...) Expand all
184 187
185 // Verify that the worker can still successfully execute script. 188 // Verify that the worker can still successfully execute script.
186 checkWorkerCanExecuteScript(secondWorker.get()); 189 checkWorkerCanExecuteScript(secondWorker.get());
187 190
188 secondWorker->terminateAndWait(); 191 secondWorker->terminateAndWait();
189 } 192 }
190 193
191 // Tests that a new WebThread is created if all existing workers are terminated 194 // Tests that a new WebThread is created if all existing workers are terminated
192 // before a new worker is created. 195 // before a new worker is created.
193 TEST_F(CompositorWorkerThreadTest, TerminateFirstAndCreateSecond) { 196 TEST_F(CompositorWorkerThreadTest, TerminateFirstAndCreateSecond) {
197 ScopedTestingPlatformSupport<CompositorWorkerTestPlatform> platform;
198
194 // Create the first worker, wait until it is initialized, and terminate it. 199 // Create the first worker, wait until it is initialized, and terminate it.
195 std::unique_ptr<CompositorWorkerThread> compositorWorker = 200 std::unique_ptr<CompositorWorkerThread> compositorWorker =
196 createCompositorWorker(); 201 createCompositorWorker();
197 WebThreadSupportingGC* firstThread = 202 WebThreadSupportingGC* firstThread =
198 &compositorWorker->workerBackingThread().backingThread(); 203 &compositorWorker->workerBackingThread().backingThread();
199 checkWorkerCanExecuteScript(compositorWorker.get()); 204 checkWorkerCanExecuteScript(compositorWorker.get());
200 205
201 // We don't use terminateAndWait here to avoid forcible termination. 206 // We don't use terminateAndWait here to avoid forcible termination.
202 compositorWorker->terminate(); 207 compositorWorker->terminate();
203 compositorWorker->waitForShutdownForTesting(); 208 compositorWorker->waitForShutdownForTesting();
204 209
205 // Create the second worker. The backing thread is same. 210 // Create the second worker. The backing thread is same.
206 compositorWorker = createCompositorWorker(); 211 compositorWorker = createCompositorWorker();
207 WebThreadSupportingGC* secondThread = 212 WebThreadSupportingGC* secondThread =
208 &compositorWorker->workerBackingThread().backingThread(); 213 &compositorWorker->workerBackingThread().backingThread();
209 EXPECT_EQ(firstThread, secondThread); 214 EXPECT_EQ(firstThread, secondThread);
210 checkWorkerCanExecuteScript(compositorWorker.get()); 215 checkWorkerCanExecuteScript(compositorWorker.get());
211 216
212 compositorWorker->terminateAndWait(); 217 compositorWorker->terminateAndWait();
213 } 218 }
214 219
215 // Tests that v8::Isolate and WebThread are correctly set-up if a worker is 220 // Tests that v8::Isolate and WebThread are correctly set-up if a worker is
216 // created while another is terminating. 221 // created while another is terminating.
217 TEST_F(CompositorWorkerThreadTest, CreatingSecondDuringTerminationOfFirst) { 222 TEST_F(CompositorWorkerThreadTest, CreatingSecondDuringTerminationOfFirst) {
223 ScopedTestingPlatformSupport<CompositorWorkerTestPlatform> platform;
224
218 std::unique_ptr<CompositorWorkerThread> firstWorker = 225 std::unique_ptr<CompositorWorkerThread> firstWorker =
219 createCompositorWorker(); 226 createCompositorWorker();
220 checkWorkerCanExecuteScript(firstWorker.get()); 227 checkWorkerCanExecuteScript(firstWorker.get());
221 v8::Isolate* firstIsolate = firstWorker->isolate(); 228 v8::Isolate* firstIsolate = firstWorker->isolate();
222 ASSERT_TRUE(firstIsolate); 229 ASSERT_TRUE(firstIsolate);
223 230
224 // Request termination of the first worker and create the second worker 231 // Request termination of the first worker and create the second worker
225 // as soon as possible. 232 // as soon as possible.
226 firstWorker->terminate(); 233 firstWorker->terminate();
227 // We don't wait for its termination. 234 // We don't wait for its termination.
228 // Note: We rely on the assumption that the termination steps don't run 235 // Note: We rely on the assumption that the termination steps don't run
229 // on the worker thread so quickly. This could be a source of flakiness. 236 // on the worker thread so quickly. This could be a source of flakiness.
230 237
231 std::unique_ptr<CompositorWorkerThread> secondWorker = 238 std::unique_ptr<CompositorWorkerThread> secondWorker =
232 createCompositorWorker(); 239 createCompositorWorker();
233 240
234 v8::Isolate* secondIsolate = secondWorker->isolate(); 241 v8::Isolate* secondIsolate = secondWorker->isolate();
235 ASSERT_TRUE(secondIsolate); 242 ASSERT_TRUE(secondIsolate);
236 EXPECT_EQ(firstIsolate, secondIsolate); 243 EXPECT_EQ(firstIsolate, secondIsolate);
237 244
238 // Verify that the isolate can run some scripts correctly in the second 245 // Verify that the isolate can run some scripts correctly in the second
239 // worker. 246 // worker.
240 checkWorkerCanExecuteScript(secondWorker.get()); 247 checkWorkerCanExecuteScript(secondWorker.get());
241 secondWorker->terminateAndWait(); 248 secondWorker->terminateAndWait();
242 } 249 }
243 250
244 } // namespace blink 251 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698