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

Side by Side Diff: third_party/WebKit/Source/core/dom/ScriptRunnerTest.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
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/compositorworker/AnimationWorkletThreadTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "core/dom/ScriptRunner.h" 5 #include "core/dom/ScriptRunner.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/Element.h" 8 #include "core/dom/Element.h"
9 #include "core/dom/ScriptLoader.h" 9 #include "core/dom/ScriptLoader.h"
10 #include "platform/heap/Handle.h" 10 #include "platform/heap/Handle.h"
(...skipping 25 matching lines...) Expand all
36 explicit MockScriptLoader(Element* element) 36 explicit MockScriptLoader(Element* element)
37 : ScriptLoader(element, false, false, false) {} 37 : ScriptLoader(element, false, false, false) {}
38 }; 38 };
39 39
40 class ScriptRunnerTest : public testing::Test { 40 class ScriptRunnerTest : public testing::Test {
41 public: 41 public:
42 ScriptRunnerTest() 42 ScriptRunnerTest()
43 : m_document(Document::create()), 43 : m_document(Document::create()),
44 m_element(m_document->createElement("foo")) {} 44 m_element(m_document->createElement("foo")) {}
45 45
46 void TearDown() override { m_scriptRunner.release(); } 46 void SetUp() override {
47
48 protected:
49 void initialize() {
50 // We have to create ScriptRunner after initializing platform, because we 47 // We have to create ScriptRunner after initializing platform, because we
51 // need Platform::current()->currentThread()->scheduler()-> 48 // need Platform::current()->currentThread()->scheduler()->
52 // loadingTaskRunner() to be initialized before creating ScriptRunner to 49 // loadingTaskRunner() to be initialized before creating ScriptRunner to
53 // save it in constructor. 50 // save it in constructor.
54 m_scriptRunner = ScriptRunner::create(m_document.get()); 51 m_scriptRunner = ScriptRunner::create(m_document.get());
55 } 52 }
53 void TearDown() override { m_scriptRunner.release(); }
56 54
55 protected:
57 Persistent<Document> m_document; 56 Persistent<Document> m_document;
58 Persistent<Element> m_element; 57 Persistent<Element> m_element;
59 Persistent<ScriptRunner> m_scriptRunner; 58 Persistent<ScriptRunner> m_scriptRunner;
60 WTF::Vector<int> m_order; 59 WTF::Vector<int> m_order;
60 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
61 m_platform;
61 }; 62 };
62 63
63 TEST_F(ScriptRunnerTest, QueueSingleScript_Async) { 64 TEST_F(ScriptRunnerTest, QueueSingleScript_Async) {
64 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
65 platform;
66 initialize();
67
68 MockScriptLoader* scriptLoader = MockScriptLoader::create(m_element.get()); 65 MockScriptLoader* scriptLoader = MockScriptLoader::create(m_element.get());
69 m_scriptRunner->queueScriptForExecution(scriptLoader, ScriptRunner::Async); 66 m_scriptRunner->queueScriptForExecution(scriptLoader, ScriptRunner::Async);
70 m_scriptRunner->notifyScriptReady(scriptLoader, ScriptRunner::Async); 67 m_scriptRunner->notifyScriptReady(scriptLoader, ScriptRunner::Async);
71 68
72 EXPECT_CALL(*scriptLoader, execute()); 69 EXPECT_CALL(*scriptLoader, execute());
73 platform->runUntilIdle(); 70 m_platform->runUntilIdle();
74 } 71 }
75 72
76 TEST_F(ScriptRunnerTest, QueueSingleScript_InOrder) { 73 TEST_F(ScriptRunnerTest, QueueSingleScript_InOrder) {
77 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
78 platform;
79 initialize();
80
81 MockScriptLoader* scriptLoader = MockScriptLoader::create(m_element.get()); 74 MockScriptLoader* scriptLoader = MockScriptLoader::create(m_element.get());
82 m_scriptRunner->queueScriptForExecution(scriptLoader, ScriptRunner::InOrder); 75 m_scriptRunner->queueScriptForExecution(scriptLoader, ScriptRunner::InOrder);
83 76
84 EXPECT_CALL(*scriptLoader, isReady()).WillOnce(Return(true)); 77 EXPECT_CALL(*scriptLoader, isReady()).WillOnce(Return(true));
85 EXPECT_CALL(*scriptLoader, execute()); 78 EXPECT_CALL(*scriptLoader, execute());
86 79
87 m_scriptRunner->notifyScriptReady(scriptLoader, ScriptRunner::InOrder); 80 m_scriptRunner->notifyScriptReady(scriptLoader, ScriptRunner::InOrder);
88 81
89 platform->runUntilIdle(); 82 m_platform->runUntilIdle();
90 } 83 }
91 84
92 TEST_F(ScriptRunnerTest, QueueMultipleScripts_InOrder) { 85 TEST_F(ScriptRunnerTest, QueueMultipleScripts_InOrder) {
93 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
94 platform;
95 initialize();
96
97 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get()); 86 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get());
98 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get()); 87 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get());
99 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get()); 88 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get());
100 89
101 HeapVector<Member<MockScriptLoader>> scriptLoaders; 90 HeapVector<Member<MockScriptLoader>> scriptLoaders;
102 scriptLoaders.push_back(scriptLoader1); 91 scriptLoaders.push_back(scriptLoader1);
103 scriptLoaders.push_back(scriptLoader2); 92 scriptLoaders.push_back(scriptLoader2);
104 scriptLoaders.push_back(scriptLoader3); 93 scriptLoaders.push_back(scriptLoader3);
105 94
106 for (ScriptLoader* scriptLoader : scriptLoaders) { 95 for (ScriptLoader* scriptLoader : scriptLoaders) {
(...skipping 11 matching lines...) Expand all
118 bool isReady[] = {false, false, false}; 107 bool isReady[] = {false, false, false};
119 108
120 for (size_t i = 0; i < scriptLoaders.size(); ++i) { 109 for (size_t i = 0; i < scriptLoaders.size(); ++i) {
121 EXPECT_CALL(*scriptLoaders[i], isReady()) 110 EXPECT_CALL(*scriptLoaders[i], isReady())
122 .WillRepeatedly(Invoke([&isReady, i] { return isReady[i]; })); 111 .WillRepeatedly(Invoke([&isReady, i] { return isReady[i]; }));
123 } 112 }
124 113
125 for (int i = 2; i >= 0; i--) { 114 for (int i = 2; i >= 0; i--) {
126 isReady[i] = true; 115 isReady[i] = true;
127 m_scriptRunner->notifyScriptReady(scriptLoaders[i], ScriptRunner::InOrder); 116 m_scriptRunner->notifyScriptReady(scriptLoaders[i], ScriptRunner::InOrder);
128 platform->runUntilIdle(); 117 m_platform->runUntilIdle();
129 } 118 }
130 119
131 // But ensure the scripts were run in the expected order. 120 // But ensure the scripts were run in the expected order.
132 EXPECT_THAT(m_order, ElementsAre(1, 2, 3)); 121 EXPECT_THAT(m_order, ElementsAre(1, 2, 3));
133 } 122 }
134 123
135 TEST_F(ScriptRunnerTest, QueueMixedScripts) { 124 TEST_F(ScriptRunnerTest, QueueMixedScripts) {
136 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
137 platform;
138 initialize();
139
140 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get()); 125 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get());
141 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get()); 126 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get());
142 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get()); 127 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get());
143 MockScriptLoader* scriptLoader4 = MockScriptLoader::create(m_element.get()); 128 MockScriptLoader* scriptLoader4 = MockScriptLoader::create(m_element.get());
144 MockScriptLoader* scriptLoader5 = MockScriptLoader::create(m_element.get()); 129 MockScriptLoader* scriptLoader5 = MockScriptLoader::create(m_element.get());
145 130
146 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::InOrder); 131 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::InOrder);
147 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::InOrder); 132 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::InOrder);
148 m_scriptRunner->queueScriptForExecution(scriptLoader3, ScriptRunner::InOrder); 133 m_scriptRunner->queueScriptForExecution(scriptLoader3, ScriptRunner::InOrder);
149 m_scriptRunner->queueScriptForExecution(scriptLoader4, ScriptRunner::Async); 134 m_scriptRunner->queueScriptForExecution(scriptLoader4, ScriptRunner::Async);
(...skipping 22 matching lines...) Expand all
172 EXPECT_CALL(*scriptLoader3, execute()).WillOnce(Invoke([this] { 157 EXPECT_CALL(*scriptLoader3, execute()).WillOnce(Invoke([this] {
173 m_order.push_back(3); 158 m_order.push_back(3);
174 })); 159 }));
175 EXPECT_CALL(*scriptLoader4, execute()).WillOnce(Invoke([this] { 160 EXPECT_CALL(*scriptLoader4, execute()).WillOnce(Invoke([this] {
176 m_order.push_back(4); 161 m_order.push_back(4);
177 })); 162 }));
178 EXPECT_CALL(*scriptLoader5, execute()).WillOnce(Invoke([this] { 163 EXPECT_CALL(*scriptLoader5, execute()).WillOnce(Invoke([this] {
179 m_order.push_back(5); 164 m_order.push_back(5);
180 })); 165 }));
181 166
182 platform->runUntilIdle(); 167 m_platform->runUntilIdle();
183 168
184 // Async tasks are expected to run first. 169 // Async tasks are expected to run first.
185 EXPECT_THAT(m_order, ElementsAre(4, 5, 1, 2, 3)); 170 EXPECT_THAT(m_order, ElementsAre(4, 5, 1, 2, 3));
186 } 171 }
187 172
188 TEST_F(ScriptRunnerTest, QueueReentrantScript_Async) { 173 TEST_F(ScriptRunnerTest, QueueReentrantScript_Async) {
189 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
190 platform;
191 initialize();
192
193 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get()); 174 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get());
194 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get()); 175 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get());
195 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get()); 176 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get());
196 177
197 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::Async); 178 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::Async);
198 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::Async); 179 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::Async);
199 m_scriptRunner->queueScriptForExecution(scriptLoader3, ScriptRunner::Async); 180 m_scriptRunner->queueScriptForExecution(scriptLoader3, ScriptRunner::Async);
200 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::Async); 181 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::Async);
201 182
202 MockScriptLoader* scriptLoader = scriptLoader2; 183 MockScriptLoader* scriptLoader = scriptLoader2;
203 EXPECT_CALL(*scriptLoader1, execute()).WillOnce(Invoke([scriptLoader, this] { 184 EXPECT_CALL(*scriptLoader1, execute()).WillOnce(Invoke([scriptLoader, this] {
204 m_order.push_back(1); 185 m_order.push_back(1);
205 m_scriptRunner->notifyScriptReady(scriptLoader, ScriptRunner::Async); 186 m_scriptRunner->notifyScriptReady(scriptLoader, ScriptRunner::Async);
206 })); 187 }));
207 188
208 scriptLoader = scriptLoader3; 189 scriptLoader = scriptLoader3;
209 EXPECT_CALL(*scriptLoader2, execute()).WillOnce(Invoke([scriptLoader, this] { 190 EXPECT_CALL(*scriptLoader2, execute()).WillOnce(Invoke([scriptLoader, this] {
210 m_order.push_back(2); 191 m_order.push_back(2);
211 m_scriptRunner->notifyScriptReady(scriptLoader, ScriptRunner::Async); 192 m_scriptRunner->notifyScriptReady(scriptLoader, ScriptRunner::Async);
212 })); 193 }));
213 194
214 EXPECT_CALL(*scriptLoader3, execute()).WillOnce(Invoke([this] { 195 EXPECT_CALL(*scriptLoader3, execute()).WillOnce(Invoke([this] {
215 m_order.push_back(3); 196 m_order.push_back(3);
216 })); 197 }));
217 198
218 // Make sure that re-entrant calls to notifyScriptReady don't cause 199 // Make sure that re-entrant calls to notifyScriptReady don't cause
219 // ScriptRunner::execute to do more work than expected. 200 // ScriptRunner::execute to do more work than expected.
220 platform->runSingleTask(); 201 m_platform->runSingleTask();
221 EXPECT_THAT(m_order, ElementsAre(1)); 202 EXPECT_THAT(m_order, ElementsAre(1));
222 203
223 platform->runSingleTask(); 204 m_platform->runSingleTask();
224 EXPECT_THAT(m_order, ElementsAre(1, 2)); 205 EXPECT_THAT(m_order, ElementsAre(1, 2));
225 206
226 platform->runSingleTask(); 207 m_platform->runSingleTask();
227 EXPECT_THAT(m_order, ElementsAre(1, 2, 3)); 208 EXPECT_THAT(m_order, ElementsAre(1, 2, 3));
228 } 209 }
229 210
230 TEST_F(ScriptRunnerTest, QueueReentrantScript_InOrder) { 211 TEST_F(ScriptRunnerTest, QueueReentrantScript_InOrder) {
231 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
232 platform;
233 initialize();
234
235 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get()); 212 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get());
236 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get()); 213 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get());
237 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get()); 214 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get());
238 215
239 EXPECT_CALL(*scriptLoader1, isReady()).WillRepeatedly(Return(true)); 216 EXPECT_CALL(*scriptLoader1, isReady()).WillRepeatedly(Return(true));
240 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(true)); 217 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(true));
241 EXPECT_CALL(*scriptLoader3, isReady()).WillRepeatedly(Return(true)); 218 EXPECT_CALL(*scriptLoader3, isReady()).WillRepeatedly(Return(true));
242 219
243 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::InOrder); 220 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::InOrder);
244 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::InOrder); 221 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::InOrder);
(...skipping 15 matching lines...) Expand all
260 ScriptRunner::InOrder); 237 ScriptRunner::InOrder);
261 m_scriptRunner->notifyScriptReady(scriptLoader3, ScriptRunner::InOrder); 238 m_scriptRunner->notifyScriptReady(scriptLoader3, ScriptRunner::InOrder);
262 })); 239 }));
263 240
264 EXPECT_CALL(*scriptLoader3, execute()).WillOnce(Invoke([this] { 241 EXPECT_CALL(*scriptLoader3, execute()).WillOnce(Invoke([this] {
265 m_order.push_back(3); 242 m_order.push_back(3);
266 })); 243 }));
267 244
268 // Make sure that re-entrant calls to queueScriptForExecution don't cause 245 // Make sure that re-entrant calls to queueScriptForExecution don't cause
269 // ScriptRunner::execute to do more work than expected. 246 // ScriptRunner::execute to do more work than expected.
270 platform->runSingleTask(); 247 m_platform->runSingleTask();
271 EXPECT_THAT(m_order, ElementsAre(1)); 248 EXPECT_THAT(m_order, ElementsAre(1));
272 249
273 platform->runSingleTask(); 250 m_platform->runSingleTask();
274 EXPECT_THAT(m_order, ElementsAre(1, 2)); 251 EXPECT_THAT(m_order, ElementsAre(1, 2));
275 252
276 platform->runSingleTask(); 253 m_platform->runSingleTask();
277 EXPECT_THAT(m_order, ElementsAre(1, 2, 3)); 254 EXPECT_THAT(m_order, ElementsAre(1, 2, 3));
278 } 255 }
279 256
280 TEST_F(ScriptRunnerTest, QueueReentrantScript_ManyAsyncScripts) { 257 TEST_F(ScriptRunnerTest, QueueReentrantScript_ManyAsyncScripts) {
281 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
282 platform;
283 initialize();
284
285 MockScriptLoader* scriptLoaders[20]; 258 MockScriptLoader* scriptLoaders[20];
286 for (int i = 0; i < 20; i++) 259 for (int i = 0; i < 20; i++)
287 scriptLoaders[i] = nullptr; 260 scriptLoaders[i] = nullptr;
288 261
289 for (int i = 0; i < 20; i++) { 262 for (int i = 0; i < 20; i++) {
290 scriptLoaders[i] = MockScriptLoader::create(m_element.get()); 263 scriptLoaders[i] = MockScriptLoader::create(m_element.get());
291 EXPECT_CALL(*scriptLoaders[i], isReady()).WillRepeatedly(Return(true)); 264 EXPECT_CALL(*scriptLoaders[i], isReady()).WillRepeatedly(Return(true));
292 265
293 m_scriptRunner->queueScriptForExecution(scriptLoaders[i], 266 m_scriptRunner->queueScriptForExecution(scriptLoaders[i],
294 ScriptRunner::Async); 267 ScriptRunner::Async);
295 268
296 if (i > 0) { 269 if (i > 0) {
297 EXPECT_CALL(*scriptLoaders[i], execute()).WillOnce(Invoke([this, i] { 270 EXPECT_CALL(*scriptLoaders[i], execute()).WillOnce(Invoke([this, i] {
298 m_order.push_back(i); 271 m_order.push_back(i);
299 })); 272 }));
300 } 273 }
301 } 274 }
302 275
303 m_scriptRunner->notifyScriptReady(scriptLoaders[0], ScriptRunner::Async); 276 m_scriptRunner->notifyScriptReady(scriptLoaders[0], ScriptRunner::Async);
304 m_scriptRunner->notifyScriptReady(scriptLoaders[1], ScriptRunner::Async); 277 m_scriptRunner->notifyScriptReady(scriptLoaders[1], ScriptRunner::Async);
305 278
306 EXPECT_CALL(*scriptLoaders[0], execute()) 279 EXPECT_CALL(*scriptLoaders[0], execute())
307 .WillOnce(Invoke([&scriptLoaders, this] { 280 .WillOnce(Invoke([&scriptLoaders, this] {
308 for (int i = 2; i < 20; i++) 281 for (int i = 2; i < 20; i++)
309 m_scriptRunner->notifyScriptReady(scriptLoaders[i], 282 m_scriptRunner->notifyScriptReady(scriptLoaders[i],
310 ScriptRunner::Async); 283 ScriptRunner::Async);
311 m_order.push_back(0); 284 m_order.push_back(0);
312 })); 285 }));
313 286
314 platform->runUntilIdle(); 287 m_platform->runUntilIdle();
315 288
316 int expected[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 289 int expected[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
317 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; 290 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
318 291
319 EXPECT_THAT(m_order, testing::ElementsAreArray(expected)); 292 EXPECT_THAT(m_order, testing::ElementsAreArray(expected));
320 } 293 }
321 294
322 TEST_F(ScriptRunnerTest, ResumeAndSuspend_InOrder) { 295 TEST_F(ScriptRunnerTest, ResumeAndSuspend_InOrder) {
323 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
324 platform;
325 initialize();
326
327 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get()); 296 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get());
328 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get()); 297 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get());
329 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get()); 298 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get());
330 299
331 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::InOrder); 300 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::InOrder);
332 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::InOrder); 301 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::InOrder);
333 m_scriptRunner->queueScriptForExecution(scriptLoader3, ScriptRunner::InOrder); 302 m_scriptRunner->queueScriptForExecution(scriptLoader3, ScriptRunner::InOrder);
334 303
335 EXPECT_CALL(*scriptLoader1, execute()).WillOnce(Invoke([this] { 304 EXPECT_CALL(*scriptLoader1, execute()).WillOnce(Invoke([this] {
336 m_order.push_back(1); 305 m_order.push_back(1);
(...skipping 12 matching lines...) Expand all
349 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(false)); 318 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(false));
350 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::InOrder); 319 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::InOrder);
351 320
352 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(true)); 321 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(true));
353 EXPECT_CALL(*scriptLoader3, isReady()).WillRepeatedly(Return(false)); 322 EXPECT_CALL(*scriptLoader3, isReady()).WillRepeatedly(Return(false));
354 m_scriptRunner->notifyScriptReady(scriptLoader2, ScriptRunner::InOrder); 323 m_scriptRunner->notifyScriptReady(scriptLoader2, ScriptRunner::InOrder);
355 324
356 EXPECT_CALL(*scriptLoader3, isReady()).WillRepeatedly(Return(true)); 325 EXPECT_CALL(*scriptLoader3, isReady()).WillRepeatedly(Return(true));
357 m_scriptRunner->notifyScriptReady(scriptLoader3, ScriptRunner::InOrder); 326 m_scriptRunner->notifyScriptReady(scriptLoader3, ScriptRunner::InOrder);
358 327
359 platform->runSingleTask(); 328 m_platform->runSingleTask();
360 m_scriptRunner->suspend(); 329 m_scriptRunner->suspend();
361 m_scriptRunner->resume(); 330 m_scriptRunner->resume();
362 platform->runUntilIdle(); 331 m_platform->runUntilIdle();
363 332
364 // Make sure elements are correct and in right order. 333 // Make sure elements are correct and in right order.
365 EXPECT_THAT(m_order, ElementsAre(1, 2, 3)); 334 EXPECT_THAT(m_order, ElementsAre(1, 2, 3));
366 } 335 }
367 336
368 TEST_F(ScriptRunnerTest, ResumeAndSuspend_Async) { 337 TEST_F(ScriptRunnerTest, ResumeAndSuspend_Async) {
369 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
370 platform;
371 initialize();
372
373 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get()); 338 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get());
374 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get()); 339 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get());
375 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get()); 340 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get());
376 341
377 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::Async); 342 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::Async);
378 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::Async); 343 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::Async);
379 m_scriptRunner->queueScriptForExecution(scriptLoader3, ScriptRunner::Async); 344 m_scriptRunner->queueScriptForExecution(scriptLoader3, ScriptRunner::Async);
380 345
381 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::Async); 346 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::Async);
382 m_scriptRunner->notifyScriptReady(scriptLoader2, ScriptRunner::Async); 347 m_scriptRunner->notifyScriptReady(scriptLoader2, ScriptRunner::Async);
383 m_scriptRunner->notifyScriptReady(scriptLoader3, ScriptRunner::Async); 348 m_scriptRunner->notifyScriptReady(scriptLoader3, ScriptRunner::Async);
384 349
385 EXPECT_CALL(*scriptLoader1, execute()).WillOnce(Invoke([this] { 350 EXPECT_CALL(*scriptLoader1, execute()).WillOnce(Invoke([this] {
386 m_order.push_back(1); 351 m_order.push_back(1);
387 })); 352 }));
388 EXPECT_CALL(*scriptLoader2, execute()).WillOnce(Invoke([this] { 353 EXPECT_CALL(*scriptLoader2, execute()).WillOnce(Invoke([this] {
389 m_order.push_back(2); 354 m_order.push_back(2);
390 })); 355 }));
391 EXPECT_CALL(*scriptLoader3, execute()).WillOnce(Invoke([this] { 356 EXPECT_CALL(*scriptLoader3, execute()).WillOnce(Invoke([this] {
392 m_order.push_back(3); 357 m_order.push_back(3);
393 })); 358 }));
394 359
395 platform->runSingleTask(); 360 m_platform->runSingleTask();
396 m_scriptRunner->suspend(); 361 m_scriptRunner->suspend();
397 m_scriptRunner->resume(); 362 m_scriptRunner->resume();
398 platform->runUntilIdle(); 363 m_platform->runUntilIdle();
399 364
400 // Make sure elements are correct. 365 // Make sure elements are correct.
401 EXPECT_THAT(m_order, WhenSorted(ElementsAre(1, 2, 3))); 366 EXPECT_THAT(m_order, WhenSorted(ElementsAre(1, 2, 3)));
402 } 367 }
403 368
404 TEST_F(ScriptRunnerTest, LateNotifications) { 369 TEST_F(ScriptRunnerTest, LateNotifications) {
405 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
406 platform;
407 initialize();
408
409 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get()); 370 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get());
410 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get()); 371 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get());
411 372
412 EXPECT_CALL(*scriptLoader1, isReady()).WillRepeatedly(Return(true)); 373 EXPECT_CALL(*scriptLoader1, isReady()).WillRepeatedly(Return(true));
413 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(true)); 374 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(true));
414 375
415 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::InOrder); 376 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::InOrder);
416 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::InOrder); 377 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::InOrder);
417 378
418 EXPECT_CALL(*scriptLoader1, execute()).WillOnce(Invoke([this] { 379 EXPECT_CALL(*scriptLoader1, execute()).WillOnce(Invoke([this] {
419 m_order.push_back(1); 380 m_order.push_back(1);
420 })); 381 }));
421 EXPECT_CALL(*scriptLoader2, execute()).WillOnce(Invoke([this] { 382 EXPECT_CALL(*scriptLoader2, execute()).WillOnce(Invoke([this] {
422 m_order.push_back(2); 383 m_order.push_back(2);
423 })); 384 }));
424 385
425 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::InOrder); 386 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::InOrder);
426 platform->runUntilIdle(); 387 m_platform->runUntilIdle();
427 388
428 // At this moment all tasks can be already executed. Make sure that we do not 389 // At this moment all tasks can be already executed. Make sure that we do not
429 // crash here. 390 // crash here.
430 m_scriptRunner->notifyScriptReady(scriptLoader2, ScriptRunner::InOrder); 391 m_scriptRunner->notifyScriptReady(scriptLoader2, ScriptRunner::InOrder);
431 platform->runUntilIdle(); 392 m_platform->runUntilIdle();
432 393
433 EXPECT_THAT(m_order, ElementsAre(1, 2)); 394 EXPECT_THAT(m_order, ElementsAre(1, 2));
434 } 395 }
435 396
436 TEST_F(ScriptRunnerTest, TasksWithDeadScriptRunner) { 397 TEST_F(ScriptRunnerTest, TasksWithDeadScriptRunner) {
437 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
438 platform;
439 initialize();
440
441 Persistent<MockScriptLoader> scriptLoader1 = 398 Persistent<MockScriptLoader> scriptLoader1 =
442 MockScriptLoader::create(m_element.get()); 399 MockScriptLoader::create(m_element.get());
443 Persistent<MockScriptLoader> scriptLoader2 = 400 Persistent<MockScriptLoader> scriptLoader2 =
444 MockScriptLoader::create(m_element.get()); 401 MockScriptLoader::create(m_element.get());
445 402
446 EXPECT_CALL(*scriptLoader1, isReady()).WillRepeatedly(Return(true)); 403 EXPECT_CALL(*scriptLoader1, isReady()).WillRepeatedly(Return(true));
447 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(true)); 404 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(true));
448 405
449 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::Async); 406 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::Async);
450 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::Async); 407 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::Async);
451 408
452 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::Async); 409 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::Async);
453 m_scriptRunner->notifyScriptReady(scriptLoader2, ScriptRunner::Async); 410 m_scriptRunner->notifyScriptReady(scriptLoader2, ScriptRunner::Async);
454 411
455 m_scriptRunner.release(); 412 m_scriptRunner.release();
456 413
457 ThreadState::current()->collectAllGarbage(); 414 ThreadState::current()->collectAllGarbage();
458 415
459 // m_scriptRunner is gone. We need to make sure that ScriptRunner::Task do not 416 // m_scriptRunner is gone. We need to make sure that ScriptRunner::Task do not
460 // access dead object. 417 // access dead object.
461 EXPECT_CALL(*scriptLoader1, execute()).Times(0); 418 EXPECT_CALL(*scriptLoader1, execute()).Times(0);
462 EXPECT_CALL(*scriptLoader2, execute()).Times(0); 419 EXPECT_CALL(*scriptLoader2, execute()).Times(0);
463 420
464 platform->runUntilIdle(); 421 m_platform->runUntilIdle();
465 } 422 }
466 423
467 } // namespace blink 424 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/compositorworker/AnimationWorkletThreadTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698