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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptPromiseTest.cpp

Issue 2554693003: Migrate WTF::Vector::append() to ::push_back() [part 1 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 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 EXPECT_TRUE(toStringArray(scope.isolate(), onFulfilled).isEmpty()); 305 EXPECT_TRUE(toStringArray(scope.isolate(), onFulfilled).isEmpty());
306 EXPECT_TRUE(onRejected.isEmpty()); 306 EXPECT_TRUE(onRejected.isEmpty());
307 } 307 }
308 308
309 TEST(ScriptPromiseTest, allWithResolvedPromises) { 309 TEST(ScriptPromiseTest, allWithResolvedPromises) {
310 V8TestingScope scope; 310 V8TestingScope scope;
311 TryCatchScope tryCatchScope(scope.isolate()); 311 TryCatchScope tryCatchScope(scope.isolate());
312 ScriptValue onFulfilled, onRejected; 312 ScriptValue onFulfilled, onRejected;
313 313
314 Vector<ScriptPromise> promises; 314 Vector<ScriptPromise> promises;
315 promises.append(ScriptPromise::cast(scope.getScriptState(), 315 promises.push_back(ScriptPromise::cast(scope.getScriptState(),
316 v8String(scope.isolate(), "hello"))); 316 v8String(scope.isolate(), "hello")));
317 promises.append(ScriptPromise::cast(scope.getScriptState(), 317 promises.push_back(ScriptPromise::cast(scope.getScriptState(),
318 v8String(scope.isolate(), "world"))); 318 v8String(scope.isolate(), "world")));
319 319
320 ScriptPromise promise = ScriptPromise::all(scope.getScriptState(), promises); 320 ScriptPromise promise = ScriptPromise::all(scope.getScriptState(), promises);
321 ASSERT_FALSE(promise.isEmpty()); 321 ASSERT_FALSE(promise.isEmpty());
322 promise.then(Function::createFunction(scope.getScriptState(), &onFulfilled), 322 promise.then(Function::createFunction(scope.getScriptState(), &onFulfilled),
323 Function::createFunction(scope.getScriptState(), &onRejected)); 323 Function::createFunction(scope.getScriptState(), &onRejected));
324 324
325 EXPECT_TRUE(onFulfilled.isEmpty()); 325 EXPECT_TRUE(onFulfilled.isEmpty());
326 EXPECT_TRUE(onRejected.isEmpty()); 326 EXPECT_TRUE(onRejected.isEmpty());
327 327
328 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); 328 v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
329 329
330 EXPECT_FALSE(onFulfilled.isEmpty()); 330 EXPECT_FALSE(onFulfilled.isEmpty());
331 Vector<String> values = toStringArray(scope.isolate(), onFulfilled); 331 Vector<String> values = toStringArray(scope.isolate(), onFulfilled);
332 EXPECT_EQ(2u, values.size()); 332 EXPECT_EQ(2u, values.size());
333 EXPECT_EQ("hello", values[0]); 333 EXPECT_EQ("hello", values[0]);
334 EXPECT_EQ("world", values[1]); 334 EXPECT_EQ("world", values[1]);
335 EXPECT_TRUE(onRejected.isEmpty()); 335 EXPECT_TRUE(onRejected.isEmpty());
336 } 336 }
337 337
338 TEST(ScriptPromiseTest, allWithRejectedPromise) { 338 TEST(ScriptPromiseTest, allWithRejectedPromise) {
339 V8TestingScope scope; 339 V8TestingScope scope;
340 TryCatchScope tryCatchScope(scope.isolate()); 340 TryCatchScope tryCatchScope(scope.isolate());
341 ScriptValue onFulfilled, onRejected; 341 ScriptValue onFulfilled, onRejected;
342 342
343 Vector<ScriptPromise> promises; 343 Vector<ScriptPromise> promises;
344 promises.append(ScriptPromise::cast(scope.getScriptState(), 344 promises.push_back(ScriptPromise::cast(scope.getScriptState(),
345 v8String(scope.isolate(), "hello"))); 345 v8String(scope.isolate(), "hello")));
346 promises.append(ScriptPromise::reject(scope.getScriptState(), 346 promises.push_back(ScriptPromise::reject(scope.getScriptState(),
347 v8String(scope.isolate(), "world"))); 347 v8String(scope.isolate(), "world")));
348 348
349 ScriptPromise promise = ScriptPromise::all(scope.getScriptState(), promises); 349 ScriptPromise promise = ScriptPromise::all(scope.getScriptState(), promises);
350 ASSERT_FALSE(promise.isEmpty()); 350 ASSERT_FALSE(promise.isEmpty());
351 promise.then(Function::createFunction(scope.getScriptState(), &onFulfilled), 351 promise.then(Function::createFunction(scope.getScriptState(), &onFulfilled),
352 Function::createFunction(scope.getScriptState(), &onRejected)); 352 Function::createFunction(scope.getScriptState(), &onRejected));
353 353
354 EXPECT_TRUE(onFulfilled.isEmpty()); 354 EXPECT_TRUE(onFulfilled.isEmpty());
355 EXPECT_TRUE(onRejected.isEmpty()); 355 EXPECT_TRUE(onRejected.isEmpty());
356 356
357 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); 357 v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
358 358
359 EXPECT_TRUE(onFulfilled.isEmpty()); 359 EXPECT_TRUE(onFulfilled.isEmpty());
360 EXPECT_FALSE(onRejected.isEmpty()); 360 EXPECT_FALSE(onRejected.isEmpty());
361 EXPECT_EQ("world", toString(scope.context(), onRejected)); 361 EXPECT_EQ("world", toString(scope.context(), onRejected));
362 } 362 }
363 363
364 } // namespace 364 } // namespace
365 365
366 } // namespace blink 366 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698