summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/js/Promise-resolve-chain.html
blob: c3c0750b6e6d7da4e59c5ecea531b1cf7c62214e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
description('Test Promise.');

window.jsTestIsAsync = true;

var resolve1, resolve2, resolve3;
var reject4, resolve5, resolve6;
var promise1 = new Promise(function(r) { resolve1 = r; });
var promise2 = new Promise(function(r) { resolve2 = r; });
var promise3 = new Promise(function(r) { resolve3 = r; });
var promise4 = new Promise(function(_, r) { reject4 = r; });
var promise5 = new Promise(function(r) { resolve5 = r; });
var promise6 = new Promise(function(r) { resolve6 = r; });

resolve3(promise2);
resolve2(promise1);
resolve6(promise5);
resolve5(promise4);

promise3.then(function(result) {
  window.result = result;
  shouldBeEqualToString('result', 'hello');
}, function() {
  testFailed('rejected');
});

promise6.then(function() {
  testFailed('fulfilled');
  finishJSTest();
}, function(result) {
  window.result = result;
  shouldBeEqualToString('result', 'bye');
  finishJSTest();
});

resolve1('hello');
reject4('bye');

</script>
</body>
</html>