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

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

Issue 2645733003: Remove STACK_ALLOCATED() from ScopedTestingPlatformSupport (Closed)
Patch Set: 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 ScopedTestingPlatformSupport<AnimationWorkletTestPlatform> m_platform;
131 }; 132 };
132 133
133 TEST_F(AnimationWorkletThreadTest, Basic) { 134 TEST_F(AnimationWorkletThreadTest, Basic) {
134 ScopedTestingPlatformSupport<AnimationWorkletTestPlatform> platform; 135 ScopedTestingPlatformSupport<AnimationWorkletTestPlatform> platform;
135 136
136 std::unique_ptr<AnimationWorkletThread> worklet = 137 std::unique_ptr<AnimationWorkletThread> worklet =
137 createAnimationWorkletThread(); 138 createAnimationWorkletThread();
138 checkWorkletCanExecuteScript(worklet.get()); 139 checkWorkletCanExecuteScript(worklet.get());
139 worklet->terminateAndWait(); 140 worklet->terminateAndWait();
140 } 141 }
141 142
142 // Tests that the same WebThread is used for new worklets if the WebThread is 143 // Tests that the same WebThread is used for new worklets if the WebThread is
143 // still alive. 144 // still alive.
144 TEST_F(AnimationWorkletThreadTest, CreateSecondAndTerminateFirst) { 145 TEST_F(AnimationWorkletThreadTest, CreateSecondAndTerminateFirst) {
145 ScopedTestingPlatformSupport<AnimationWorkletTestPlatform> platform;
146
147 // Create the first worklet and wait until it is initialized. 146 // Create the first worklet and wait until it is initialized.
148 std::unique_ptr<AnimationWorkletThread> firstWorklet = 147 std::unique_ptr<AnimationWorkletThread> firstWorklet =
149 createAnimationWorkletThread(); 148 createAnimationWorkletThread();
150 WebThreadSupportingGC* firstThread = 149 WebThreadSupportingGC* firstThread =
151 &firstWorklet->workerBackingThread().backingThread(); 150 &firstWorklet->workerBackingThread().backingThread();
152 checkWorkletCanExecuteScript(firstWorklet.get()); 151 checkWorkletCanExecuteScript(firstWorklet.get());
153 v8::Isolate* firstIsolate = firstWorklet->isolate(); 152 v8::Isolate* firstIsolate = firstWorklet->isolate();
154 ASSERT_TRUE(firstIsolate); 153 ASSERT_TRUE(firstIsolate);
155 154
156 // Create the second worklet and immediately destroy the first worklet. 155 // Create the second worklet and immediately destroy the first worklet.
(...skipping 15 matching lines...) Expand all
172 171
173 // Verify that the worklet can still successfully execute script. 172 // Verify that the worklet can still successfully execute script.
174 checkWorkletCanExecuteScript(secondWorklet.get()); 173 checkWorkletCanExecuteScript(secondWorklet.get());
175 174
176 secondWorklet->terminateAndWait(); 175 secondWorklet->terminateAndWait();
177 } 176 }
178 177
179 // Tests that a new WebThread is created if all existing worklets are 178 // Tests that a new WebThread is created if all existing worklets are
180 // terminated before a new worklet is created. 179 // terminated before a new worklet is created.
181 TEST_F(AnimationWorkletThreadTest, TerminateFirstAndCreateSecond) { 180 TEST_F(AnimationWorkletThreadTest, TerminateFirstAndCreateSecond) {
182 ScopedTestingPlatformSupport<AnimationWorkletTestPlatform> platform;
183
184 // Create the first worklet, wait until it is initialized, and terminate it. 181 // Create the first worklet, wait until it is initialized, and terminate it.
185 std::unique_ptr<AnimationWorkletThread> worklet = 182 std::unique_ptr<AnimationWorkletThread> worklet =
186 createAnimationWorkletThread(); 183 createAnimationWorkletThread();
187 WebThreadSupportingGC* firstThread = 184 WebThreadSupportingGC* firstThread =
188 &worklet->workerBackingThread().backingThread(); 185 &worklet->workerBackingThread().backingThread();
189 checkWorkletCanExecuteScript(worklet.get()); 186 checkWorkletCanExecuteScript(worklet.get());
190 187
191 // We don't use terminateAndWait here to avoid forcible termination. 188 // We don't use terminateAndWait here to avoid forcible termination.
192 worklet->terminate(); 189 worklet->terminate();
193 worklet->waitForShutdownForTesting(); 190 worklet->waitForShutdownForTesting();
194 191
195 // Create the second worklet. The backing thread is same. 192 // Create the second worklet. The backing thread is same.
196 worklet = createAnimationWorkletThread(); 193 worklet = createAnimationWorkletThread();
197 WebThreadSupportingGC* secondThread = 194 WebThreadSupportingGC* secondThread =
198 &worklet->workerBackingThread().backingThread(); 195 &worklet->workerBackingThread().backingThread();
199 EXPECT_EQ(firstThread, secondThread); 196 EXPECT_EQ(firstThread, secondThread);
200 checkWorkletCanExecuteScript(worklet.get()); 197 checkWorkletCanExecuteScript(worklet.get());
201 198
202 worklet->terminateAndWait(); 199 worklet->terminateAndWait();
203 } 200 }
204 201
205 // Tests that v8::Isolate and WebThread are correctly set-up if a worklet is 202 // Tests that v8::Isolate and WebThread are correctly set-up if a worklet is
206 // created while another is terminating. 203 // created while another is terminating.
207 TEST_F(AnimationWorkletThreadTest, CreatingSecondDuringTerminationOfFirst) { 204 TEST_F(AnimationWorkletThreadTest, CreatingSecondDuringTerminationOfFirst) {
208 ScopedTestingPlatformSupport<AnimationWorkletTestPlatform> platform;
209
210 std::unique_ptr<AnimationWorkletThread> firstWorklet = 205 std::unique_ptr<AnimationWorkletThread> firstWorklet =
211 createAnimationWorkletThread(); 206 createAnimationWorkletThread();
212 checkWorkletCanExecuteScript(firstWorklet.get()); 207 checkWorkletCanExecuteScript(firstWorklet.get());
213 v8::Isolate* firstIsolate = firstWorklet->isolate(); 208 v8::Isolate* firstIsolate = firstWorklet->isolate();
214 ASSERT_TRUE(firstIsolate); 209 ASSERT_TRUE(firstIsolate);
215 210
216 // Request termination of the first worklet and create the second worklet 211 // Request termination of the first worklet and create the second worklet
217 // as soon as possible. 212 // as soon as possible.
218 firstWorklet->terminate(); 213 firstWorklet->terminate();
219 // We don't wait for its termination. 214 // We don't wait for its termination.
220 // Note: We rely on the assumption that the termination steps don't run 215 // Note: We rely on the assumption that the termination steps don't run
221 // on the worklet thread so quickly. This could be a source of flakiness. 216 // on the worklet thread so quickly. This could be a source of flakiness.
222 217
223 std::unique_ptr<AnimationWorkletThread> secondWorklet = 218 std::unique_ptr<AnimationWorkletThread> secondWorklet =
224 createAnimationWorkletThread(); 219 createAnimationWorkletThread();
225 220
226 v8::Isolate* secondIsolate = secondWorklet->isolate(); 221 v8::Isolate* secondIsolate = secondWorklet->isolate();
227 ASSERT_TRUE(secondIsolate); 222 ASSERT_TRUE(secondIsolate);
228 EXPECT_EQ(firstIsolate, secondIsolate); 223 EXPECT_EQ(firstIsolate, secondIsolate);
229 224
230 // Verify that the isolate can run some scripts correctly in the second 225 // Verify that the isolate can run some scripts correctly in the second
231 // worklet. 226 // worklet.
232 checkWorkletCanExecuteScript(secondWorklet.get()); 227 checkWorkletCanExecuteScript(secondWorklet.get());
233 secondWorklet->terminateAndWait(); 228 secondWorklet->terminateAndWait();
234 } 229 }
235 230
236 } // namespace blink 231 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698