test_promise.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. <!--
  2. Any copyright is dedicated to the Public Domain.
  3. http://creativecommons.org/publicdomain/zero/1.0/
  4. -->
  5. <html>
  6. <head>
  7. <title>Basic Promise Test</title>
  8. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  10. </head>
  11. <body>
  12. <p id="display"></p>
  13. <div id="content" style="display: none">
  14. </div>
  15. <pre id="test">
  16. <script type="application/javascript"><!--
  17. function promiseResolve() {
  18. ok(Promise, "Promise object should exist");
  19. var promise = new Promise(function(resolve, reject) {
  20. ok(resolve, "Promise.resolve exists");
  21. ok(reject, "Promise.reject exists");
  22. resolve(42);
  23. }).then(function(what) {
  24. ok(true, "Then - resolveCb has been called");
  25. is(what, 42, "ResolveCb received 42");
  26. runTest();
  27. }, function() {
  28. ok(false, "Then - rejectCb has been called");
  29. runTest();
  30. });
  31. }
  32. function promiseResolveNoArg() {
  33. var promise = new Promise(function(resolve, reject) {
  34. ok(resolve, "Promise.resolve exists");
  35. ok(reject, "Promise.reject exists");
  36. resolve();
  37. }).then(function(what) {
  38. ok(true, "Then - resolveCb has been called");
  39. is(what, undefined, "ResolveCb received undefined");
  40. runTest();
  41. }, function() {
  42. ok(false, "Then - rejectCb has been called");
  43. runTest();
  44. });
  45. }
  46. function promiseReject() {
  47. var promise = new Promise(function(resolve, reject) {
  48. reject(42);
  49. }).then(function(what) {
  50. ok(false, "Then - resolveCb has been called");
  51. runTest();
  52. }, function(what) {
  53. ok(true, "Then - rejectCb has been called");
  54. is(what, 42, "RejectCb received 42");
  55. runTest();
  56. });
  57. }
  58. function promiseRejectNoHandler() {
  59. // This test only checks that the code that reports unhandled errors in the
  60. // Promises implementation does not crash or leak.
  61. var promise = new Promise(function(res, rej) {
  62. noSuchMethod();
  63. });
  64. runTest();
  65. }
  66. function promiseRejectNoArg() {
  67. var promise = new Promise(function(resolve, reject) {
  68. reject();
  69. }).then(function(what) {
  70. ok(false, "Then - resolveCb has been called");
  71. runTest();
  72. }, function(what) {
  73. ok(true, "Then - rejectCb has been called");
  74. is(what, undefined, "RejectCb received undefined");
  75. runTest();
  76. });
  77. }
  78. function promiseException() {
  79. var promise = new Promise(function(resolve, reject) {
  80. throw 42;
  81. }).then(function(what) {
  82. ok(false, "Then - resolveCb has been called");
  83. runTest();
  84. }, function(what) {
  85. ok(true, "Then - rejectCb has been called");
  86. is(what, 42, "RejectCb received 42");
  87. runTest();
  88. });
  89. }
  90. function promiseGC() {
  91. var resolve;
  92. var promise = new Promise(function(r1, r2) {
  93. resolve = r1;
  94. }).then(function(what) {
  95. ok(true, "Then - promise is still alive");
  96. runTest();
  97. });
  98. promise = null;
  99. SpecialPowers.gc();
  100. SpecialPowers.forceGC();
  101. SpecialPowers.forceCC();
  102. resolve(42);
  103. }
  104. function promiseAsync_TimeoutResolveThen() {
  105. var handlerExecuted = false;
  106. setTimeout(function() {
  107. ok(handlerExecuted, "Handler should have been called before the timeout.");
  108. // Allow other assertions to run so the test could fail before the next one.
  109. setTimeout(runTest, 0);
  110. }, 0);
  111. Promise.resolve().then(function() {
  112. handlerExecuted = true;
  113. });
  114. ok(!handlerExecuted, "Handlers are not called before 'then' returns.");
  115. }
  116. function promiseAsync_ResolveTimeoutThen() {
  117. var handlerExecuted = false;
  118. var promise = Promise.resolve();
  119. setTimeout(function() {
  120. ok(handlerExecuted, "Handler should have been called before the timeout.");
  121. // Allow other assertions to run so the test could fail before the next one.
  122. setTimeout(runTest, 0);
  123. }, 0);
  124. promise.then(function() {
  125. handlerExecuted = true;
  126. });
  127. ok(!handlerExecuted, "Handlers are not called before 'then' returns.");
  128. }
  129. function promiseAsync_ResolveThenTimeout() {
  130. var handlerExecuted = false;
  131. Promise.resolve().then(function() {
  132. handlerExecuted = true;
  133. });
  134. setTimeout(function() {
  135. ok(handlerExecuted, "Handler should have been called before the timeout.");
  136. // Allow other assertions to run so the test could fail before the next one.
  137. setTimeout(runTest, 0);
  138. }, 0);
  139. ok(!handlerExecuted, "Handlers are not called before 'then' returns.");
  140. }
  141. function promiseAsync_SyncXHR()
  142. {
  143. var handlerExecuted = false;
  144. Promise.resolve().then(function() {
  145. handlerExecuted = true;
  146. // Allow other assertions to run so the test could fail before the next one.
  147. setTimeout(runTest, 0);
  148. });
  149. ok(!handlerExecuted, "Handlers are not called until the next microtask.");
  150. var xhr = new XMLHttpRequest();
  151. xhr.open("GET", "testXHR.txt", false);
  152. xhr.send(null);
  153. todo(!handlerExecuted, "Sync XHR should not trigger microtask execution.");
  154. }
  155. function promiseDoubleThen() {
  156. var steps = 0;
  157. var promise = new Promise(function(r1, r2) {
  158. r1(42);
  159. });
  160. promise.then(function(what) {
  161. ok(true, "Then.resolve has been called");
  162. is(what, 42, "Value == 42");
  163. steps++;
  164. }, function(what) {
  165. ok(false, "Then.reject has been called");
  166. });
  167. promise.then(function(what) {
  168. ok(true, "Then.resolve has been called");
  169. is(steps, 1, "Then.resolve - step == 1");
  170. is(what, 42, "Value == 42");
  171. runTest();
  172. }, function(what) {
  173. ok(false, "Then.reject has been called");
  174. });
  175. }
  176. function promiseThenException() {
  177. var promise = new Promise(function(resolve, reject) {
  178. resolve(42);
  179. });
  180. promise.then(function(what) {
  181. ok(true, "Then.resolve has been called");
  182. throw "booh";
  183. }).catch(function(e) {
  184. ok(true, "window.onerror has been called!");
  185. runTest();
  186. });
  187. }
  188. function promiseThenCatchThen() {
  189. var promise = new Promise(function(resolve, reject) {
  190. resolve(42);
  191. });
  192. var promise2 = promise.then(function(what) {
  193. ok(true, "Then.resolve has been called");
  194. is(what, 42, "Value == 42");
  195. return what + 1;
  196. }, function(what) {
  197. ok(false, "Then.reject has been called");
  198. });
  199. isnot(promise, promise2, "These 2 promise objs are different");
  200. promise2.then(function(what) {
  201. ok(true, "Then.resolve has been called");
  202. is(what, 43, "Value == 43");
  203. return what + 1;
  204. }, function(what) {
  205. ok(false, "Then.reject has been called");
  206. }).catch(function() {
  207. ok(false, "Catch has been called");
  208. }).then(function(what) {
  209. ok(true, "Then.resolve has been called");
  210. is(what, 44, "Value == 44");
  211. runTest();
  212. }, function(what) {
  213. ok(false, "Then.reject has been called");
  214. });
  215. }
  216. function promiseThenNoArg() {
  217. var promise = new Promise(function(resolve, reject) {
  218. resolve(42);
  219. });
  220. var clone = promise.then();
  221. isnot(promise, clone, "These 2 promise objs are different");
  222. promise.then(function(v) {
  223. clone.then(function(cv) {
  224. is(v, cv, "Both resolve to the same value");
  225. runTest();
  226. });
  227. });
  228. }
  229. function promiseThenUndefinedResolveFunction() {
  230. var promise = new Promise(function(resolve, reject) {
  231. reject(42);
  232. });
  233. try {
  234. promise.then(undefined, function(v) {
  235. is(v, 42, "Promise rejected with 42");
  236. runTest();
  237. });
  238. } catch (e) {
  239. ok(false, "then should not throw on undefined resolve function");
  240. }
  241. }
  242. function promiseThenNullResolveFunction() {
  243. var promise = new Promise(function(resolve, reject) {
  244. reject(42);
  245. });
  246. try {
  247. promise.then(null, function(v) {
  248. is(v, 42, "Promise rejected with 42");
  249. runTest();
  250. });
  251. } catch (e) {
  252. ok(false, "then should not throw on null resolve function");
  253. }
  254. }
  255. function promiseRejectThenCatchThen() {
  256. var promise = new Promise(function(resolve, reject) {
  257. reject(42);
  258. });
  259. var promise2 = promise.then(function(what) {
  260. ok(false, "Then.resolve has been called");
  261. }, function(what) {
  262. ok(true, "Then.reject has been called");
  263. is(what, 42, "Value == 42");
  264. return what + 1;
  265. });
  266. isnot(promise, promise2, "These 2 promise objs are different");
  267. promise2.then(function(what) {
  268. ok(true, "Then.resolve has been called");
  269. is(what, 43, "Value == 43");
  270. return what+1;
  271. }).catch(function(what) {
  272. ok(false, "Catch has been called");
  273. }).then(function(what) {
  274. ok(true, "Then.resolve has been called");
  275. is(what, 44, "Value == 44");
  276. runTest();
  277. });
  278. }
  279. function promiseRejectThenCatchThen2() {
  280. var promise = new Promise(function(resolve, reject) {
  281. reject(42);
  282. });
  283. promise.then(function(what) {
  284. ok(true, "Then.resolve has been called");
  285. is(what, 42, "Value == 42");
  286. return what+1;
  287. }).catch(function(what) {
  288. is(what, 42, "Value == 42");
  289. ok(true, "Catch has been called");
  290. return what+1;
  291. }).then(function(what) {
  292. ok(true, "Then.resolve has been called");
  293. is(what, 43, "Value == 43");
  294. runTest();
  295. });
  296. }
  297. function promiseRejectThenCatchExceptionThen() {
  298. var promise = new Promise(function(resolve, reject) {
  299. reject(42);
  300. });
  301. promise.then(function(what) {
  302. ok(false, "Then.resolve has been called");
  303. }, function(what) {
  304. ok(true, "Then.reject has been called");
  305. is(what, 42, "Value == 42");
  306. throw(what + 1);
  307. }).catch(function(what) {
  308. ok(true, "Catch has been called");
  309. is(what, 43, "Value == 43");
  310. return what + 1;
  311. }).then(function(what) {
  312. ok(true, "Then.resolve has been called");
  313. is(what, 44, "Value == 44");
  314. runTest();
  315. });
  316. }
  317. function promiseThenCatchOrderingResolve() {
  318. var global = 0;
  319. var f = new Promise(function(r1, r2) {
  320. r1(42);
  321. });
  322. f.then(function() {
  323. f.then(function() {
  324. global++;
  325. });
  326. f.catch(function() {
  327. global++;
  328. });
  329. f.then(function() {
  330. global++;
  331. });
  332. setTimeout(function() {
  333. is(global, 2, "Many steps... should return 2");
  334. runTest();
  335. }, 0);
  336. });
  337. }
  338. function promiseThenCatchOrderingReject() {
  339. var global = 0;
  340. var f = new Promise(function(r1, r2) {
  341. r2(42);
  342. })
  343. f.then(function() {}, function() {
  344. f.then(function() {
  345. global++;
  346. });
  347. f.catch(function() {
  348. global++;
  349. });
  350. f.then(function() {}, function() {
  351. global++;
  352. });
  353. setTimeout(function() {
  354. is(global, 2, "Many steps... should return 2");
  355. runTest();
  356. }, 0);
  357. });
  358. }
  359. function promiseCatchNoArg() {
  360. var promise = new Promise(function(resolve, reject) {
  361. reject(42);
  362. });
  363. var clone = promise.catch();
  364. isnot(promise, clone, "These 2 promise objs are different");
  365. promise.catch(function(v) {
  366. clone.catch(function(cv) {
  367. is(v, cv, "Both reject to the same value");
  368. runTest();
  369. });
  370. });
  371. }
  372. function promiseNestedPromise() {
  373. new Promise(function(resolve, reject) {
  374. resolve(new Promise(function(resolve, reject) {
  375. ok(true, "Nested promise is executed");
  376. resolve(42);
  377. }));
  378. }).then(function(value) {
  379. is(value, 42, "Nested promise is executed and then == 42");
  380. runTest();
  381. });
  382. }
  383. function promiseNestedNestedPromise() {
  384. new Promise(function(resolve, reject) {
  385. resolve(new Promise(function(resolve, reject) {
  386. ok(true, "Nested promise is executed");
  387. resolve(42);
  388. }).then(function(what) { return what+1; }));
  389. }).then(function(value) {
  390. is(value, 43, "Nested promise is executed and then == 43");
  391. runTest();
  392. });
  393. }
  394. function promiseWrongNestedPromise() {
  395. new Promise(function(resolve, reject) {
  396. resolve(new Promise(function(r, r2) {
  397. ok(true, "Nested promise is executed");
  398. r(42);
  399. }));
  400. reject(42);
  401. }).then(function(value) {
  402. is(value, 42, "Nested promise is executed and then == 42");
  403. runTest();
  404. }, function(value) {
  405. ok(false, "This is wrong");
  406. });
  407. }
  408. function promiseLoop() {
  409. new Promise(function(resolve, reject) {
  410. resolve(new Promise(function(r1, r2) {
  411. ok(true, "Nested promise is executed");
  412. r1(new Promise(function(r1, r2) {
  413. ok(true, "Nested nested promise is executed");
  414. r1(42);
  415. }));
  416. }));
  417. }).then(function(value) {
  418. is(value, 42, "Nested nested promise is executed and then == 42");
  419. runTest();
  420. }, function(value) {
  421. ok(false, "This is wrong");
  422. });
  423. }
  424. function promiseStaticReject() {
  425. var promise = Promise.reject(42).then(function(what) {
  426. ok(false, "This should not be called");
  427. }, function(what) {
  428. is(what, 42, "Value == 42");
  429. runTest();
  430. });
  431. }
  432. function promiseStaticResolve() {
  433. var promise = Promise.resolve(42).then(function(what) {
  434. is(what, 42, "Value == 42");
  435. runTest();
  436. }, function() {
  437. ok(false, "This should not be called");
  438. });
  439. }
  440. function promiseResolveNestedPromise() {
  441. var promise = Promise.resolve(new Promise(function(r, r2) {
  442. ok(true, "Nested promise is executed");
  443. r(42);
  444. }, function() {
  445. ok(false, "This should not be called");
  446. })).then(function(what) {
  447. is(what, 42, "Value == 42");
  448. runTest();
  449. }, function() {
  450. ok(false, "This should not be called");
  451. });
  452. }
  453. function promiseSimpleThenableResolve() {
  454. var thenable = { then: function(resolve) { resolve(5); } };
  455. var promise = new Promise(function(resolve, reject) {
  456. resolve(thenable);
  457. });
  458. promise.then(function(v) {
  459. ok(v === 5, "promiseSimpleThenableResolve");
  460. runTest();
  461. }, function(e) {
  462. ok(false, "promiseSimpleThenableResolve: Should not reject");
  463. });
  464. }
  465. function promiseSimpleThenableReject() {
  466. var thenable = { then: function(resolve, reject) { reject(5); } };
  467. var promise = new Promise(function(resolve, reject) {
  468. resolve(thenable);
  469. });
  470. promise.then(function() {
  471. ok(false, "promiseSimpleThenableReject: Should not resolve");
  472. runTest();
  473. }, function(e) {
  474. ok(e === 5, "promiseSimpleThenableReject");
  475. runTest();
  476. });
  477. }
  478. function promiseThenableThrowsBeforeCallback() {
  479. var thenable = { then: function(resolve) {
  480. throw new TypeError("Hi there");
  481. resolve(5);
  482. }};
  483. var promise = Promise.resolve(thenable);
  484. promise.then(function(v) {
  485. ok(false, "promiseThenableThrowsBeforeCallback: Should've rejected");
  486. runTest();
  487. }, function(e) {
  488. ok(e instanceof TypeError, "promiseThenableThrowsBeforeCallback");
  489. runTest();
  490. });
  491. }
  492. function promiseThenableThrowsAfterCallback() {
  493. var thenable = { then: function(resolve) {
  494. resolve(5);
  495. throw new TypeError("Hi there");
  496. }};
  497. var promise = Promise.resolve(thenable);
  498. promise.then(function(v) {
  499. ok(v === 5, "promiseThenableThrowsAfterCallback");
  500. runTest();
  501. }, function(e) {
  502. ok(false, "promiseThenableThrowsAfterCallback: Should've resolved");
  503. runTest();
  504. });
  505. }
  506. function promiseThenableRejectThenResolve() {
  507. var thenable = { then: function(resolve, reject) {
  508. reject(new TypeError("Hi there"));
  509. resolve(5);
  510. }};
  511. var promise = Promise.resolve(thenable);
  512. promise.then(function(v) {
  513. ok(false, "promiseThenableRejectThenResolve should have rejected");
  514. runTest();
  515. }, function(e) {
  516. ok(e instanceof TypeError, "promiseThenableRejectThenResolve");
  517. runTest();
  518. });
  519. }
  520. function promiseWithThenReplaced() {
  521. // Ensure that we call the 'then' on the promise and not the internal then.
  522. var promise = new Promise(function(resolve, reject) {
  523. resolve(5);
  524. });
  525. // Rogue `then` always rejects.
  526. promise.then = function(onFulfill, onReject) {
  527. onReject(new TypeError("Foo"));
  528. }
  529. var promise2 = Promise.resolve(promise);
  530. promise2.then(function(v) {
  531. ok(false, "promiseWithThenReplaced: Should've rejected");
  532. runTest();
  533. }, function(e) {
  534. ok(e instanceof TypeError, "promiseWithThenReplaced");
  535. runTest();
  536. });
  537. }
  538. function promiseStrictHandlers() {
  539. var promise = Promise.resolve(5);
  540. promise.then(function() {
  541. "use strict";
  542. ok(this === undefined, "Strict mode callback should have this === undefined.");
  543. runTest();
  544. });
  545. }
  546. function promiseStrictExecutorThisArg() {
  547. var promise = new Promise(function(resolve, reject) {
  548. "use strict";
  549. ok(this === undefined, "thisArg should be undefined.");
  550. runTest();
  551. });
  552. }
  553. function promiseResolveArray() {
  554. var p = Promise.resolve([1,2,3]);
  555. ok(p instanceof Promise, "Should return a Promise.");
  556. p.then(function(v) {
  557. ok(Array.isArray(v), "Resolved value should be an Array");
  558. is(v.length, 3, "Length should match");
  559. is(v[0], 1, "Resolved value should match original");
  560. is(v[1], 2, "Resolved value should match original");
  561. is(v[2], 3, "Resolved value should match original");
  562. runTest();
  563. });
  564. }
  565. function promiseResolveThenable() {
  566. var p = Promise.resolve({ then: function(onFulfill, onReject) { onFulfill(2); } });
  567. ok(p instanceof Promise, "Should cast to a Promise.");
  568. p.then(function(v) {
  569. is(v, 2, "Should resolve to 2.");
  570. runTest();
  571. }, function(e) {
  572. ok(false, "promiseResolveThenable should've resolved");
  573. runTest();
  574. });
  575. }
  576. function promiseResolvePromise() {
  577. var original = Promise.resolve(true);
  578. var cast = Promise.resolve(original);
  579. ok(cast instanceof Promise, "Should cast to a Promise.");
  580. is(cast, original, "Should return original Promise.");
  581. cast.then(function(v) {
  582. is(v, true, "Should resolve to true.");
  583. runTest();
  584. });
  585. }
  586. // Bug 1009569.
  587. // Ensure that thenables are run on a clean stack asynchronously.
  588. // Test case adopted from
  589. // https://gist.github.com/getify/d64bb01751b50ed6b281#file-bug1-js.
  590. function promiseResolveThenableCleanStack() {
  591. function immed(s) { x++; s(); }
  592. function incX(){ x++; }
  593. var x = 0;
  594. var thenable = { then: immed };
  595. var results = [];
  596. var p = Promise.resolve(thenable).then(incX);
  597. results.push(x);
  598. // check what happens after all "next cycle" steps
  599. // have had a chance to complete
  600. setTimeout(function(){
  601. // Result should be [0, 2] since `thenable` will be called async.
  602. is(results[0], 0, "Expected thenable to be called asynchronously");
  603. // See Bug 1023547 comment 13 for why this check has to be gated on p.
  604. p.then(function() {
  605. results.push(x);
  606. is(results[1], 2, "Expected thenable to be called asynchronously");
  607. runTest();
  608. });
  609. },1000);
  610. }
  611. // Bug 1008467 - Promise fails with "too much recursion".
  612. // The bug was that the callbacks passed to a thenable would resolve the
  613. // promise synchronously when the fulfill handler returned a non-thenable.
  614. //
  615. // For example:
  616. // var p = new Promise(function(resolve) {
  617. // resolve(5);
  618. // });
  619. // var m = Promise.resolve(p);
  620. //
  621. // At this point `m` is a Promise that is resolved with a thenable `p`, so it
  622. // calls `p.then()` with two callbacks, both of which would synchronously resolve
  623. // `m` when `p` invoked them (on account of itself being resolved, possibly
  624. // synchronously. A chain of these 'Promise resolved by a Promise' would lead to
  625. // stack overflow.
  626. function promiseTestAsyncThenableResolution()
  627. {
  628. var k = 3000;
  629. Promise.resolve().then(function next() {
  630. k--;
  631. if (k > 0) return Promise.resolve().then(next);
  632. }).then(function () {
  633. ok(true, "Resolution of a chain of thenables should not be synchronous.");
  634. runTest();
  635. });
  636. }
  637. // Bug 1062323
  638. function promiseWrapperAsyncResolution()
  639. {
  640. var p = new Promise(function(resolve, reject){
  641. resolve();
  642. });
  643. var results = [];
  644. var q = p.then(function () {
  645. results.push("1-1");
  646. }).then(function () {
  647. results.push("1-2");
  648. }).then(function () {
  649. results.push("1-3");
  650. });
  651. var r = p.then(function () {
  652. results.push("2-1");
  653. }).then(function () {
  654. results.push("2-2");
  655. }).then(function () {
  656. results.push("2-3");
  657. });
  658. Promise.all([q, r]).then(function() {
  659. var match = results[0] == "1-1" &&
  660. results[1] == "2-1" &&
  661. results[2] == "1-2" &&
  662. results[3] == "2-2" &&
  663. results[4] == "1-3" &&
  664. results[5] == "2-3";
  665. info(results);
  666. ok(match, "Chained promises should resolve asynchronously.");
  667. runTest();
  668. }, function() {
  669. ok(false, "promiseWrapperAsyncResolution: One of the promises failed.");
  670. runTest();
  671. });
  672. }
  673. var tests = [ promiseResolve, promiseReject,
  674. promiseException, promiseGC,
  675. promiseAsync_TimeoutResolveThen,
  676. promiseAsync_ResolveTimeoutThen,
  677. promiseAsync_ResolveThenTimeout,
  678. promiseAsync_SyncXHR,
  679. promiseDoubleThen, promiseThenException,
  680. promiseThenCatchThen, promiseRejectThenCatchThen,
  681. promiseRejectThenCatchThen2,
  682. promiseRejectThenCatchExceptionThen,
  683. promiseThenCatchOrderingResolve,
  684. promiseThenCatchOrderingReject,
  685. promiseNestedPromise, promiseNestedNestedPromise,
  686. promiseWrongNestedPromise, promiseLoop,
  687. promiseStaticReject, promiseStaticResolve,
  688. promiseResolveNestedPromise,
  689. promiseResolveNoArg,
  690. promiseRejectNoArg,
  691. promiseThenNoArg,
  692. promiseThenUndefinedResolveFunction,
  693. promiseThenNullResolveFunction,
  694. promiseCatchNoArg,
  695. promiseRejectNoHandler,
  696. promiseSimpleThenableResolve,
  697. promiseSimpleThenableReject,
  698. promiseThenableThrowsBeforeCallback,
  699. promiseThenableThrowsAfterCallback,
  700. promiseThenableRejectThenResolve,
  701. promiseWithThenReplaced,
  702. promiseStrictHandlers,
  703. promiseStrictExecutorThisArg,
  704. promiseResolveArray,
  705. promiseResolveThenable,
  706. promiseResolvePromise,
  707. promiseResolveThenableCleanStack,
  708. promiseTestAsyncThenableResolution,
  709. promiseWrapperAsyncResolution,
  710. ];
  711. function runTest() {
  712. if (!tests.length) {
  713. SimpleTest.finish();
  714. return;
  715. }
  716. var test = tests.shift();
  717. test();
  718. }
  719. SimpleTest.waitForExplicitFinish();
  720. SimpleTest.requestFlakyTimeout("untriaged");
  721. runTest();
  722. // -->
  723. </script>
  724. </pre>
  725. </body>
  726. </html>