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

Side by Side Diff: third_party/WebKit/Source/core/dom/ScriptRunnerTest.cpp

Issue 2574773002: Migrate WTF::Vector::append() to ::push_back() [part 4 of N] (Closed)
Patch Set: rebase Created 4 years 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 "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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 80
81 m_platform.runUntilIdle(); 81 m_platform.runUntilIdle();
82 } 82 }
83 83
84 TEST_F(ScriptRunnerTest, QueueMultipleScripts_InOrder) { 84 TEST_F(ScriptRunnerTest, QueueMultipleScripts_InOrder) {
85 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get()); 85 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get());
86 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get()); 86 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get());
87 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get()); 87 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get());
88 88
89 HeapVector<Member<MockScriptLoader>> scriptLoaders; 89 HeapVector<Member<MockScriptLoader>> scriptLoaders;
90 scriptLoaders.append(scriptLoader1); 90 scriptLoaders.push_back(scriptLoader1);
91 scriptLoaders.append(scriptLoader2); 91 scriptLoaders.push_back(scriptLoader2);
92 scriptLoaders.append(scriptLoader3); 92 scriptLoaders.push_back(scriptLoader3);
93 93
94 for (ScriptLoader* scriptLoader : scriptLoaders) { 94 for (ScriptLoader* scriptLoader : scriptLoaders) {
95 m_scriptRunner->queueScriptForExecution(scriptLoader, 95 m_scriptRunner->queueScriptForExecution(scriptLoader,
96 ScriptRunner::InOrder); 96 ScriptRunner::InOrder);
97 } 97 }
98 98
99 for (size_t i = 0; i < scriptLoaders.size(); ++i) { 99 for (size_t i = 0; i < scriptLoaders.size(); ++i) {
100 EXPECT_CALL(*scriptLoaders[i], execute()).WillOnce(Invoke([this, i] { 100 EXPECT_CALL(*scriptLoaders[i], execute()).WillOnce(Invoke([this, i] {
101 m_order.append(i + 1); 101 m_order.push_back(i + 1);
102 })); 102 }));
103 } 103 }
104 104
105 // Make the scripts become ready in reverse order. 105 // Make the scripts become ready in reverse order.
106 bool isReady[] = {false, false, false}; 106 bool isReady[] = {false, false, false};
107 107
108 for (size_t i = 0; i < scriptLoaders.size(); ++i) { 108 for (size_t i = 0; i < scriptLoaders.size(); ++i) {
109 EXPECT_CALL(*scriptLoaders[i], isReady()) 109 EXPECT_CALL(*scriptLoaders[i], isReady())
110 .WillRepeatedly(Invoke([&isReady, i] { return isReady[i]; })); 110 .WillRepeatedly(Invoke([&isReady, i] { return isReady[i]; }));
111 } 111 }
(...skipping 29 matching lines...) Expand all
141 EXPECT_CALL(*scriptLoader3, isReady()).WillRepeatedly(Return(false)); 141 EXPECT_CALL(*scriptLoader3, isReady()).WillRepeatedly(Return(false));
142 m_scriptRunner->notifyScriptReady(scriptLoader2, ScriptRunner::InOrder); 142 m_scriptRunner->notifyScriptReady(scriptLoader2, ScriptRunner::InOrder);
143 143
144 EXPECT_CALL(*scriptLoader3, isReady()).WillRepeatedly(Return(true)); 144 EXPECT_CALL(*scriptLoader3, isReady()).WillRepeatedly(Return(true));
145 m_scriptRunner->notifyScriptReady(scriptLoader3, ScriptRunner::InOrder); 145 m_scriptRunner->notifyScriptReady(scriptLoader3, ScriptRunner::InOrder);
146 146
147 m_scriptRunner->notifyScriptReady(scriptLoader4, ScriptRunner::Async); 147 m_scriptRunner->notifyScriptReady(scriptLoader4, ScriptRunner::Async);
148 m_scriptRunner->notifyScriptReady(scriptLoader5, ScriptRunner::Async); 148 m_scriptRunner->notifyScriptReady(scriptLoader5, ScriptRunner::Async);
149 149
150 EXPECT_CALL(*scriptLoader1, execute()).WillOnce(Invoke([this] { 150 EXPECT_CALL(*scriptLoader1, execute()).WillOnce(Invoke([this] {
151 m_order.append(1); 151 m_order.push_back(1);
152 })); 152 }));
153 EXPECT_CALL(*scriptLoader2, execute()).WillOnce(Invoke([this] { 153 EXPECT_CALL(*scriptLoader2, execute()).WillOnce(Invoke([this] {
154 m_order.append(2); 154 m_order.push_back(2);
155 })); 155 }));
156 EXPECT_CALL(*scriptLoader3, execute()).WillOnce(Invoke([this] { 156 EXPECT_CALL(*scriptLoader3, execute()).WillOnce(Invoke([this] {
157 m_order.append(3); 157 m_order.push_back(3);
158 })); 158 }));
159 EXPECT_CALL(*scriptLoader4, execute()).WillOnce(Invoke([this] { 159 EXPECT_CALL(*scriptLoader4, execute()).WillOnce(Invoke([this] {
160 m_order.append(4); 160 m_order.push_back(4);
161 })); 161 }));
162 EXPECT_CALL(*scriptLoader5, execute()).WillOnce(Invoke([this] { 162 EXPECT_CALL(*scriptLoader5, execute()).WillOnce(Invoke([this] {
163 m_order.append(5); 163 m_order.push_back(5);
164 })); 164 }));
165 165
166 m_platform.runUntilIdle(); 166 m_platform.runUntilIdle();
167 167
168 // Async tasks are expected to run first. 168 // Async tasks are expected to run first.
169 EXPECT_THAT(m_order, ElementsAre(4, 5, 1, 2, 3)); 169 EXPECT_THAT(m_order, ElementsAre(4, 5, 1, 2, 3));
170 } 170 }
171 171
172 TEST_F(ScriptRunnerTest, QueueReentrantScript_Async) { 172 TEST_F(ScriptRunnerTest, QueueReentrantScript_Async) {
173 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get()); 173 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get());
174 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get()); 174 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get());
175 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get()); 175 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get());
176 176
177 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::Async); 177 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::Async);
178 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::Async); 178 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::Async);
179 m_scriptRunner->queueScriptForExecution(scriptLoader3, ScriptRunner::Async); 179 m_scriptRunner->queueScriptForExecution(scriptLoader3, ScriptRunner::Async);
180 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::Async); 180 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::Async);
181 181
182 MockScriptLoader* scriptLoader = scriptLoader2; 182 MockScriptLoader* scriptLoader = scriptLoader2;
183 EXPECT_CALL(*scriptLoader1, execute()).WillOnce(Invoke([scriptLoader, this] { 183 EXPECT_CALL(*scriptLoader1, execute()).WillOnce(Invoke([scriptLoader, this] {
184 m_order.append(1); 184 m_order.push_back(1);
185 m_scriptRunner->notifyScriptReady(scriptLoader, ScriptRunner::Async); 185 m_scriptRunner->notifyScriptReady(scriptLoader, ScriptRunner::Async);
186 })); 186 }));
187 187
188 scriptLoader = scriptLoader3; 188 scriptLoader = scriptLoader3;
189 EXPECT_CALL(*scriptLoader2, execute()).WillOnce(Invoke([scriptLoader, this] { 189 EXPECT_CALL(*scriptLoader2, execute()).WillOnce(Invoke([scriptLoader, this] {
190 m_order.append(2); 190 m_order.push_back(2);
191 m_scriptRunner->notifyScriptReady(scriptLoader, ScriptRunner::Async); 191 m_scriptRunner->notifyScriptReady(scriptLoader, ScriptRunner::Async);
192 })); 192 }));
193 193
194 EXPECT_CALL(*scriptLoader3, execute()).WillOnce(Invoke([this] { 194 EXPECT_CALL(*scriptLoader3, execute()).WillOnce(Invoke([this] {
195 m_order.append(3); 195 m_order.push_back(3);
196 })); 196 }));
197 197
198 // Make sure that re-entrant calls to notifyScriptReady don't cause 198 // Make sure that re-entrant calls to notifyScriptReady don't cause
199 // ScriptRunner::execute to do more work than expected. 199 // ScriptRunner::execute to do more work than expected.
200 m_platform.runSingleTask(); 200 m_platform.runSingleTask();
201 EXPECT_THAT(m_order, ElementsAre(1)); 201 EXPECT_THAT(m_order, ElementsAre(1));
202 202
203 m_platform.runSingleTask(); 203 m_platform.runSingleTask();
204 EXPECT_THAT(m_order, ElementsAre(1, 2)); 204 EXPECT_THAT(m_order, ElementsAre(1, 2));
205 205
206 m_platform.runSingleTask(); 206 m_platform.runSingleTask();
207 EXPECT_THAT(m_order, ElementsAre(1, 2, 3)); 207 EXPECT_THAT(m_order, ElementsAre(1, 2, 3));
208 } 208 }
209 209
210 TEST_F(ScriptRunnerTest, QueueReentrantScript_InOrder) { 210 TEST_F(ScriptRunnerTest, QueueReentrantScript_InOrder) {
211 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get()); 211 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get());
212 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get()); 212 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get());
213 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get()); 213 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get());
214 214
215 EXPECT_CALL(*scriptLoader1, isReady()).WillRepeatedly(Return(true)); 215 EXPECT_CALL(*scriptLoader1, isReady()).WillRepeatedly(Return(true));
216 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(true)); 216 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(true));
217 EXPECT_CALL(*scriptLoader3, isReady()).WillRepeatedly(Return(true)); 217 EXPECT_CALL(*scriptLoader3, isReady()).WillRepeatedly(Return(true));
218 218
219 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::InOrder); 219 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::InOrder);
220 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::InOrder); 220 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::InOrder);
221 221
222 MockScriptLoader* scriptLoader = scriptLoader2; 222 MockScriptLoader* scriptLoader = scriptLoader2;
223 EXPECT_CALL(*scriptLoader1, execute()) 223 EXPECT_CALL(*scriptLoader1, execute())
224 .WillOnce(Invoke([scriptLoader, &scriptLoader2, this] { 224 .WillOnce(Invoke([scriptLoader, &scriptLoader2, this] {
225 m_order.append(1); 225 m_order.push_back(1);
226 m_scriptRunner->queueScriptForExecution(scriptLoader, 226 m_scriptRunner->queueScriptForExecution(scriptLoader,
227 ScriptRunner::InOrder); 227 ScriptRunner::InOrder);
228 m_scriptRunner->notifyScriptReady(scriptLoader2, ScriptRunner::InOrder); 228 m_scriptRunner->notifyScriptReady(scriptLoader2, ScriptRunner::InOrder);
229 })); 229 }));
230 230
231 scriptLoader = scriptLoader3; 231 scriptLoader = scriptLoader3;
232 EXPECT_CALL(*scriptLoader2, execute()) 232 EXPECT_CALL(*scriptLoader2, execute())
233 .WillOnce(Invoke([scriptLoader, &scriptLoader3, this] { 233 .WillOnce(Invoke([scriptLoader, &scriptLoader3, this] {
234 m_order.append(2); 234 m_order.push_back(2);
235 m_scriptRunner->queueScriptForExecution(scriptLoader, 235 m_scriptRunner->queueScriptForExecution(scriptLoader,
236 ScriptRunner::InOrder); 236 ScriptRunner::InOrder);
237 m_scriptRunner->notifyScriptReady(scriptLoader3, ScriptRunner::InOrder); 237 m_scriptRunner->notifyScriptReady(scriptLoader3, ScriptRunner::InOrder);
238 })); 238 }));
239 239
240 EXPECT_CALL(*scriptLoader3, execute()).WillOnce(Invoke([this] { 240 EXPECT_CALL(*scriptLoader3, execute()).WillOnce(Invoke([this] {
241 m_order.append(3); 241 m_order.push_back(3);
242 })); 242 }));
243 243
244 // Make sure that re-entrant calls to queueScriptForExecution don't cause 244 // Make sure that re-entrant calls to queueScriptForExecution don't cause
245 // ScriptRunner::execute to do more work than expected. 245 // ScriptRunner::execute to do more work than expected.
246 m_platform.runSingleTask(); 246 m_platform.runSingleTask();
247 EXPECT_THAT(m_order, ElementsAre(1)); 247 EXPECT_THAT(m_order, ElementsAre(1));
248 248
249 m_platform.runSingleTask(); 249 m_platform.runSingleTask();
250 EXPECT_THAT(m_order, ElementsAre(1, 2)); 250 EXPECT_THAT(m_order, ElementsAre(1, 2));
251 251
252 m_platform.runSingleTask(); 252 m_platform.runSingleTask();
253 EXPECT_THAT(m_order, ElementsAre(1, 2, 3)); 253 EXPECT_THAT(m_order, ElementsAre(1, 2, 3));
254 } 254 }
255 255
256 TEST_F(ScriptRunnerTest, QueueReentrantScript_ManyAsyncScripts) { 256 TEST_F(ScriptRunnerTest, QueueReentrantScript_ManyAsyncScripts) {
257 MockScriptLoader* scriptLoaders[20]; 257 MockScriptLoader* scriptLoaders[20];
258 for (int i = 0; i < 20; i++) 258 for (int i = 0; i < 20; i++)
259 scriptLoaders[i] = nullptr; 259 scriptLoaders[i] = nullptr;
260 260
261 for (int i = 0; i < 20; i++) { 261 for (int i = 0; i < 20; i++) {
262 scriptLoaders[i] = MockScriptLoader::create(m_element.get()); 262 scriptLoaders[i] = MockScriptLoader::create(m_element.get());
263 EXPECT_CALL(*scriptLoaders[i], isReady()).WillRepeatedly(Return(true)); 263 EXPECT_CALL(*scriptLoaders[i], isReady()).WillRepeatedly(Return(true));
264 264
265 m_scriptRunner->queueScriptForExecution(scriptLoaders[i], 265 m_scriptRunner->queueScriptForExecution(scriptLoaders[i],
266 ScriptRunner::Async); 266 ScriptRunner::Async);
267 267
268 if (i > 0) { 268 if (i > 0) {
269 EXPECT_CALL(*scriptLoaders[i], execute()).WillOnce(Invoke([this, i] { 269 EXPECT_CALL(*scriptLoaders[i], execute()).WillOnce(Invoke([this, i] {
270 m_order.append(i); 270 m_order.push_back(i);
271 })); 271 }));
272 } 272 }
273 } 273 }
274 274
275 m_scriptRunner->notifyScriptReady(scriptLoaders[0], ScriptRunner::Async); 275 m_scriptRunner->notifyScriptReady(scriptLoaders[0], ScriptRunner::Async);
276 m_scriptRunner->notifyScriptReady(scriptLoaders[1], ScriptRunner::Async); 276 m_scriptRunner->notifyScriptReady(scriptLoaders[1], ScriptRunner::Async);
277 277
278 EXPECT_CALL(*scriptLoaders[0], execute()) 278 EXPECT_CALL(*scriptLoaders[0], execute())
279 .WillOnce(Invoke([&scriptLoaders, this] { 279 .WillOnce(Invoke([&scriptLoaders, this] {
280 for (int i = 2; i < 20; i++) 280 for (int i = 2; i < 20; i++)
281 m_scriptRunner->notifyScriptReady(scriptLoaders[i], 281 m_scriptRunner->notifyScriptReady(scriptLoaders[i],
282 ScriptRunner::Async); 282 ScriptRunner::Async);
283 m_order.append(0); 283 m_order.push_back(0);
284 })); 284 }));
285 285
286 m_platform.runUntilIdle(); 286 m_platform.runUntilIdle();
287 287
288 int expected[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 288 int expected[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
289 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; 289 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
290 290
291 EXPECT_THAT(m_order, testing::ElementsAreArray(expected)); 291 EXPECT_THAT(m_order, testing::ElementsAreArray(expected));
292 } 292 }
293 293
294 TEST_F(ScriptRunnerTest, ResumeAndSuspend_InOrder) { 294 TEST_F(ScriptRunnerTest, ResumeAndSuspend_InOrder) {
295 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get()); 295 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get());
296 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get()); 296 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get());
297 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get()); 297 MockScriptLoader* scriptLoader3 = MockScriptLoader::create(m_element.get());
298 298
299 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::InOrder); 299 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::InOrder);
300 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::InOrder); 300 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::InOrder);
301 m_scriptRunner->queueScriptForExecution(scriptLoader3, ScriptRunner::InOrder); 301 m_scriptRunner->queueScriptForExecution(scriptLoader3, ScriptRunner::InOrder);
302 302
303 EXPECT_CALL(*scriptLoader1, execute()).WillOnce(Invoke([this] { 303 EXPECT_CALL(*scriptLoader1, execute()).WillOnce(Invoke([this] {
304 m_order.append(1); 304 m_order.push_back(1);
305 })); 305 }));
306 EXPECT_CALL(*scriptLoader2, execute()).WillOnce(Invoke([this] { 306 EXPECT_CALL(*scriptLoader2, execute()).WillOnce(Invoke([this] {
307 m_order.append(2); 307 m_order.push_back(2);
308 })); 308 }));
309 EXPECT_CALL(*scriptLoader3, execute()).WillOnce(Invoke([this] { 309 EXPECT_CALL(*scriptLoader3, execute()).WillOnce(Invoke([this] {
310 m_order.append(3); 310 m_order.push_back(3);
311 })); 311 }));
312 312
313 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(true)); 313 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(true));
314 EXPECT_CALL(*scriptLoader3, isReady()).WillRepeatedly(Return(true)); 314 EXPECT_CALL(*scriptLoader3, isReady()).WillRepeatedly(Return(true));
315 315
316 EXPECT_CALL(*scriptLoader1, isReady()).WillRepeatedly(Return(true)); 316 EXPECT_CALL(*scriptLoader1, isReady()).WillRepeatedly(Return(true));
317 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(false)); 317 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(false));
318 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::InOrder); 318 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::InOrder);
319 319
320 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(true)); 320 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(true));
(...skipping 19 matching lines...) Expand all
340 340
341 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::Async); 341 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::Async);
342 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::Async); 342 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::Async);
343 m_scriptRunner->queueScriptForExecution(scriptLoader3, ScriptRunner::Async); 343 m_scriptRunner->queueScriptForExecution(scriptLoader3, ScriptRunner::Async);
344 344
345 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::Async); 345 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::Async);
346 m_scriptRunner->notifyScriptReady(scriptLoader2, ScriptRunner::Async); 346 m_scriptRunner->notifyScriptReady(scriptLoader2, ScriptRunner::Async);
347 m_scriptRunner->notifyScriptReady(scriptLoader3, ScriptRunner::Async); 347 m_scriptRunner->notifyScriptReady(scriptLoader3, ScriptRunner::Async);
348 348
349 EXPECT_CALL(*scriptLoader1, execute()).WillOnce(Invoke([this] { 349 EXPECT_CALL(*scriptLoader1, execute()).WillOnce(Invoke([this] {
350 m_order.append(1); 350 m_order.push_back(1);
351 })); 351 }));
352 EXPECT_CALL(*scriptLoader2, execute()).WillOnce(Invoke([this] { 352 EXPECT_CALL(*scriptLoader2, execute()).WillOnce(Invoke([this] {
353 m_order.append(2); 353 m_order.push_back(2);
354 })); 354 }));
355 EXPECT_CALL(*scriptLoader3, execute()).WillOnce(Invoke([this] { 355 EXPECT_CALL(*scriptLoader3, execute()).WillOnce(Invoke([this] {
356 m_order.append(3); 356 m_order.push_back(3);
357 })); 357 }));
358 358
359 m_platform.runSingleTask(); 359 m_platform.runSingleTask();
360 m_scriptRunner->suspend(); 360 m_scriptRunner->suspend();
361 m_scriptRunner->resume(); 361 m_scriptRunner->resume();
362 m_platform.runUntilIdle(); 362 m_platform.runUntilIdle();
363 363
364 // Make sure elements are correct. 364 // Make sure elements are correct.
365 EXPECT_THAT(m_order, WhenSorted(ElementsAre(1, 2, 3))); 365 EXPECT_THAT(m_order, WhenSorted(ElementsAre(1, 2, 3)));
366 } 366 }
367 367
368 TEST_F(ScriptRunnerTest, LateNotifications) { 368 TEST_F(ScriptRunnerTest, LateNotifications) {
369 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get()); 369 MockScriptLoader* scriptLoader1 = MockScriptLoader::create(m_element.get());
370 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get()); 370 MockScriptLoader* scriptLoader2 = MockScriptLoader::create(m_element.get());
371 371
372 EXPECT_CALL(*scriptLoader1, isReady()).WillRepeatedly(Return(true)); 372 EXPECT_CALL(*scriptLoader1, isReady()).WillRepeatedly(Return(true));
373 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(true)); 373 EXPECT_CALL(*scriptLoader2, isReady()).WillRepeatedly(Return(true));
374 374
375 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::InOrder); 375 m_scriptRunner->queueScriptForExecution(scriptLoader1, ScriptRunner::InOrder);
376 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::InOrder); 376 m_scriptRunner->queueScriptForExecution(scriptLoader2, ScriptRunner::InOrder);
377 377
378 EXPECT_CALL(*scriptLoader1, execute()).WillOnce(Invoke([this] { 378 EXPECT_CALL(*scriptLoader1, execute()).WillOnce(Invoke([this] {
379 m_order.append(1); 379 m_order.push_back(1);
380 })); 380 }));
381 EXPECT_CALL(*scriptLoader2, execute()).WillOnce(Invoke([this] { 381 EXPECT_CALL(*scriptLoader2, execute()).WillOnce(Invoke([this] {
382 m_order.append(2); 382 m_order.push_back(2);
383 })); 383 }));
384 384
385 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::InOrder); 385 m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::InOrder);
386 m_platform.runUntilIdle(); 386 m_platform.runUntilIdle();
387 387
388 // At this moment all tasks can be already executed. Make sure that we do not 388 // At this moment all tasks can be already executed. Make sure that we do not
389 // crash here. 389 // crash here.
390 m_scriptRunner->notifyScriptReady(scriptLoader2, ScriptRunner::InOrder); 390 m_scriptRunner->notifyScriptReady(scriptLoader2, ScriptRunner::InOrder);
391 m_platform.runUntilIdle(); 391 m_platform.runUntilIdle();
392 392
(...skipping 21 matching lines...) Expand all
414 414
415 // m_scriptRunner is gone. We need to make sure that ScriptRunner::Task do not 415 // m_scriptRunner is gone. We need to make sure that ScriptRunner::Task do not
416 // access dead object. 416 // access dead object.
417 EXPECT_CALL(*scriptLoader1, execute()).Times(0); 417 EXPECT_CALL(*scriptLoader1, execute()).Times(0);
418 EXPECT_CALL(*scriptLoader2, execute()).Times(0); 418 EXPECT_CALL(*scriptLoader2, execute()).Times(0);
419 419
420 m_platform.runUntilIdle(); 420 m_platform.runUntilIdle();
421 } 421 }
422 422
423 } // namespace blink 423 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Range.cpp ('k') | third_party/WebKit/Source/core/dom/ScriptedAnimationController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698