OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <html> | |
3 <head> | |
4 <script src="../../resources/js-test.js"></script> | |
5 </head> | |
6 <body> | |
7 <div id="description"></div> | |
8 <div id="console"></div> | |
9 <script> | |
10 description('Test Promise.all'); | |
11 | |
12 window.jsTestIsAsync = true; | |
13 result = undefined; | |
14 | |
15 var p1 = new Promise(function(resolve) { resolve('p1'); }); | |
16 var p2 = new Promise(function(resolve) { resolve('p2'); }); | |
17 var p3 = new Promise(function(resolve) { resolve('p3'); }); | |
18 var p4 = new Promise(function() {}); | |
19 var p5 = new Promise(function() {}); | |
20 var p6 = new Promise(function(_, reject) { reject('p6'); }); | |
21 var p7 = new Promise(function(_, reject) { reject('p7'); }); | |
22 var p8 = new Promise(function(_, reject) { reject('p8'); }); | |
23 var p9 = new Promise(function(resolve) { resolve(p2); }); | |
24 | |
25 Promise.all([p1, p2, p5]).then(function(result) { | |
26 testFailed('Promise.all([p1, p2, p5]) is fulfilled.'); | |
27 }, function() { | |
28 testFailed('Promise.all([p1, p2, p5]) is rejected.'); | |
29 }); | |
30 | |
31 Promise.all().then(function(result) { | |
32 testPassed('Promise.all() is fulfilled.'); | |
33 window.result = result; | |
34 shouldBe('result.length', '0'); | |
35 }, function() { | |
36 testFailed('Promise.all() is rejected.'); | |
37 }).then(function() { | |
38 return Promise.all([p1, p2, p3]).then(function(result) { | |
39 testPassed('Promise.all([p1, p2, p3]) is fulfilled.'); | |
40 window.result = result; | |
41 shouldBe('result.length', '3'); | |
42 shouldBeEqualToString('result[0]', 'p1'); | |
43 shouldBeEqualToString('result[1]', 'p2'); | |
44 shouldBeEqualToString('result[2]', 'p3'); | |
45 }, function() { | |
46 testFailed('Promise.all([p1, p2, p3]) is rejected.'); | |
47 }); | |
48 }).then(function() { | |
49 return Promise.all([p1, p6, p5]).then(function(result) { | |
50 testFailed('Promise.all([p1, p6, p5]) is fulfilled.'); | |
51 }, function(result) { | |
52 testPassed('Promise.all([p1, p6, p5]) is rejected.'); | |
53 window.result = result; | |
54 shouldBeEqualToString('result', 'p6'); | |
55 }); | |
56 }).then(function() { | |
57 return Promise.all([p9]).then(function(result) { | |
58 testPassed('Promise.all([p9]) is fulfilled.'); | |
59 window.result = result; | |
60 shouldBe('result.length', '1'); | |
61 shouldBeEqualToString('result[0]', 'p2'); | |
62 }, function(result) { | |
63 testFailed('Promise.all([p9]) is rejected.'); | |
64 }); | |
65 }).then(function() { | |
66 // Array hole should not be skipped. | |
67 return Promise.all([p9,,,]).then(function(result) { | |
68 testPassed('Promise.all([p9,,,]) is fulfilled.'); | |
69 window.result = result; | |
70 shouldBe('result.length', '3'); | |
71 shouldBeEqualToString('result[0]', 'p2'); | |
72 shouldBe('result[1]', 'undefined'); | |
73 shouldBe('result[2]', 'undefined'); | |
74 }, function(result) { | |
75 testFailed('Promise.all([p9,,,]) is rejected.'); | |
76 }); | |
77 }).then(function() { | |
78 // Immediate value should be converted to a promise object by the | |
79 // ToPromise operation. | |
80 return Promise.all([p9,42]).then(function(result) { | |
81 testPassed('Promise.all([p9,42]) is fulfilled.'); | |
82 window.result = result; | |
83 shouldBe('result.length', '2'); | |
84 shouldBeEqualToString('result[0]', 'p2'); | |
85 shouldBe('result[1]', '42'); | |
86 }, function(result) { | |
87 testFailed('Promise.all([p9,42]) is rejected.'); | |
88 }); | |
89 }).then(function() { | |
90 // Not iterable object case. | |
91 return Promise.all({}).then(function(result) { | |
92 testPassed('Promise.all({}) is fulfilled.'); | |
93 window.result = result; | |
94 shouldBe('result.length', '0'); | |
95 }, function(result) { | |
96 testFailed('Promise.all({}) is rejected.'); | |
97 }); | |
98 }).then(finishJSTest, finishJSTest); | |
99 | |
100 shouldBe('result', 'undefined'); | |
101 | |
102 </script> | |
103 </body> | |
104 </html> | |
OLD | NEW |