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

Side by Side Diff: third_party/WebKit/Source/modules/compositorworker/AnimationWorkletThreadTest.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/AnimationWorkletThread.h" 5 #include "modules/compositorworker/AnimationWorkletThread.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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 private: 121 private:
122 void executeScriptInWorklet(WorkerThread* thread, WaitableEvent* waitEvent) { 122 void executeScriptInWorklet(WorkerThread* thread, WaitableEvent* waitEvent) {
123 WorkerOrWorkletScriptController* scriptController = 123 WorkerOrWorkletScriptController* scriptController =
124 thread->globalScope()->scriptController(); 124 thread->globalScope()->scriptController();
125 scriptController->evaluate(ScriptSourceCode("var counter = 0; ++counter;")); 125 scriptController->evaluate(ScriptSourceCode("var counter = 0; ++counter;"));
126 waitEvent->signal(); 126 waitEvent->signal();
127 } 127 }
128 128
129 RefPtr<SecurityOrigin> m_securityOrigin; 129 RefPtr<SecurityOrigin> m_securityOrigin;
130 std::unique_ptr<WorkerReportingProxy> m_reportingProxy; 130 std::unique_ptr<WorkerReportingProxy> m_reportingProxy;
131 AnimationWorkletTestPlatform m_testPlatform;
132 }; 131 };
133 132
134 TEST_F(AnimationWorkletThreadTest, Basic) { 133 TEST_F(AnimationWorkletThreadTest, Basic) {
134 ScopedTestingPlatformSupport<AnimationWorkletTestPlatform> platform;
135
135 std::unique_ptr<AnimationWorkletThread> worklet = 136 std::unique_ptr<AnimationWorkletThread> worklet =
136 createAnimationWorkletThread(); 137 createAnimationWorkletThread();
137 checkWorkletCanExecuteScript(worklet.get()); 138 checkWorkletCanExecuteScript(worklet.get());
138 worklet->terminateAndWait(); 139 worklet->terminateAndWait();
139 } 140 }
140 141
141 // Tests that the same WebThread is used for new worklets if the WebThread is 142 // Tests that the same WebThread is used for new worklets if the WebThread is
142 // still alive. 143 // still alive.
143 TEST_F(AnimationWorkletThreadTest, CreateSecondAndTerminateFirst) { 144 TEST_F(AnimationWorkletThreadTest, CreateSecondAndTerminateFirst) {
145 ScopedTestingPlatformSupport<AnimationWorkletTestPlatform> platform;
146
144 // Create the first worklet and wait until it is initialized. 147 // Create the first worklet and wait until it is initialized.
145 std::unique_ptr<AnimationWorkletThread> firstWorklet = 148 std::unique_ptr<AnimationWorkletThread> firstWorklet =
146 createAnimationWorkletThread(); 149 createAnimationWorkletThread();
147 WebThreadSupportingGC* firstThread = 150 WebThreadSupportingGC* firstThread =
148 &firstWorklet->workerBackingThread().backingThread(); 151 &firstWorklet->workerBackingThread().backingThread();
149 checkWorkletCanExecuteScript(firstWorklet.get()); 152 checkWorkletCanExecuteScript(firstWorklet.get());
150 v8::Isolate* firstIsolate = firstWorklet->isolate(); 153 v8::Isolate* firstIsolate = firstWorklet->isolate();
151 ASSERT_TRUE(firstIsolate); 154 ASSERT_TRUE(firstIsolate);
152 155
153 // Create the second worklet and immediately destroy the first worklet. 156 // Create the second worklet and immediately destroy the first worklet.
(...skipping 15 matching lines...) Expand all
169 172
170 // Verify that the worklet can still successfully execute script. 173 // Verify that the worklet can still successfully execute script.
171 checkWorkletCanExecuteScript(secondWorklet.get()); 174 checkWorkletCanExecuteScript(secondWorklet.get());
172 175
173 secondWorklet->terminateAndWait(); 176 secondWorklet->terminateAndWait();
174 } 177 }
175 178
176 // Tests that a new WebThread is created if all existing worklets are 179 // Tests that a new WebThread is created if all existing worklets are
177 // terminated before a new worklet is created. 180 // terminated before a new worklet is created.
178 TEST_F(AnimationWorkletThreadTest, TerminateFirstAndCreateSecond) { 181 TEST_F(AnimationWorkletThreadTest, TerminateFirstAndCreateSecond) {
182 ScopedTestingPlatformSupport<AnimationWorkletTestPlatform> platform;
183
179 // Create the first worklet, wait until it is initialized, and terminate it. 184 // Create the first worklet, wait until it is initialized, and terminate it.
180 std::unique_ptr<AnimationWorkletThread> worklet = 185 std::unique_ptr<AnimationWorkletThread> worklet =
181 createAnimationWorkletThread(); 186 createAnimationWorkletThread();
182 WebThreadSupportingGC* firstThread = 187 WebThreadSupportingGC* firstThread =
183 &worklet->workerBackingThread().backingThread(); 188 &worklet->workerBackingThread().backingThread();
184 checkWorkletCanExecuteScript(worklet.get()); 189 checkWorkletCanExecuteScript(worklet.get());
185 190
186 // We don't use terminateAndWait here to avoid forcible termination. 191 // We don't use terminateAndWait here to avoid forcible termination.
187 worklet->terminate(); 192 worklet->terminate();
188 worklet->waitForShutdownForTesting(); 193 worklet->waitForShutdownForTesting();
189 194
190 // Create the second worklet. The backing thread is same. 195 // Create the second worklet. The backing thread is same.
191 worklet = createAnimationWorkletThread(); 196 worklet = createAnimationWorkletThread();
192 WebThreadSupportingGC* secondThread = 197 WebThreadSupportingGC* secondThread =
193 &worklet->workerBackingThread().backingThread(); 198 &worklet->workerBackingThread().backingThread();
194 EXPECT_EQ(firstThread, secondThread); 199 EXPECT_EQ(firstThread, secondThread);
195 checkWorkletCanExecuteScript(worklet.get()); 200 checkWorkletCanExecuteScript(worklet.get());
196 201
197 worklet->terminateAndWait(); 202 worklet->terminateAndWait();
198 } 203 }
199 204
200 // Tests that v8::Isolate and WebThread are correctly set-up if a worklet is 205 // Tests that v8::Isolate and WebThread are correctly set-up if a worklet is
201 // created while another is terminating. 206 // created while another is terminating.
202 TEST_F(AnimationWorkletThreadTest, CreatingSecondDuringTerminationOfFirst) { 207 TEST_F(AnimationWorkletThreadTest, CreatingSecondDuringTerminationOfFirst) {
208 ScopedTestingPlatformSupport<AnimationWorkletTestPlatform> platform;
209
203 std::unique_ptr<AnimationWorkletThread> firstWorklet = 210 std::unique_ptr<AnimationWorkletThread> firstWorklet =
204 createAnimationWorkletThread(); 211 createAnimationWorkletThread();
205 checkWorkletCanExecuteScript(firstWorklet.get()); 212 checkWorkletCanExecuteScript(firstWorklet.get());
206 v8::Isolate* firstIsolate = firstWorklet->isolate(); 213 v8::Isolate* firstIsolate = firstWorklet->isolate();
207 ASSERT_TRUE(firstIsolate); 214 ASSERT_TRUE(firstIsolate);
208 215
209 // Request termination of the first worklet and create the second worklet 216 // Request termination of the first worklet and create the second worklet
210 // as soon as possible. 217 // as soon as possible.
211 firstWorklet->terminate(); 218 firstWorklet->terminate();
212 // We don't wait for its termination. 219 // We don't wait for its termination.
213 // Note: We rely on the assumption that the termination steps don't run 220 // Note: We rely on the assumption that the termination steps don't run
214 // on the worklet thread so quickly. This could be a source of flakiness. 221 // on the worklet thread so quickly. This could be a source of flakiness.
215 222
216 std::unique_ptr<AnimationWorkletThread> secondWorklet = 223 std::unique_ptr<AnimationWorkletThread> secondWorklet =
217 createAnimationWorkletThread(); 224 createAnimationWorkletThread();
218 225
219 v8::Isolate* secondIsolate = secondWorklet->isolate(); 226 v8::Isolate* secondIsolate = secondWorklet->isolate();
220 ASSERT_TRUE(secondIsolate); 227 ASSERT_TRUE(secondIsolate);
221 EXPECT_EQ(firstIsolate, secondIsolate); 228 EXPECT_EQ(firstIsolate, secondIsolate);
222 229
223 // Verify that the isolate can run some scripts correctly in the second 230 // Verify that the isolate can run some scripts correctly in the second
224 // worklet. 231 // worklet.
225 checkWorkletCanExecuteScript(secondWorklet.get()); 232 checkWorkletCanExecuteScript(secondWorklet.get());
226 secondWorklet->terminateAndWait(); 233 secondWorklet->terminateAndWait();
227 } 234 }
228 235
229 } // namespace blink 236 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698