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.'); | |
11 | |
12 window.jsTestIsAsync = true; | |
13 | |
14 var resolve; | |
15 | |
16 var firstPromise = new Promise(function(newResolve) { | |
17 window.thisInInit = this; | |
18 resolve = newResolve; | |
19 }); | |
20 | |
21 var secondPromise = firstPromise.then(function(result) { | |
22 window.thisInFulfillCallback = this; | |
23 shouldBeFalse('thisInFulfillCallback === firstPromise'); | |
24 shouldBeFalse('thisInFulfillCallback === secondPromise'); | |
25 shouldBeTrue('thisInFulfillCallback === window'); | |
26 window.result = result; | |
27 shouldBeEqualToString('result', 'hello'); | |
28 return 'world'; | |
29 }); | |
30 | |
31 shouldBeFalse('thisInInit === firstPromise'); | |
32 shouldBeTrue('thisInInit === window'); | |
33 shouldBeTrue('firstPromise instanceof Promise'); | |
34 shouldBeTrue('secondPromise instanceof Promise'); | |
35 | |
36 secondPromise.then(null, 37).then(function(result) { | |
37 window.result = result; | |
38 shouldBeEqualToString('result', 'world'); | |
39 throw 'exception' | |
40 }).then(1, 2).then(function() { | |
41 testFailed('resolved'); | |
42 }, function(result) { | |
43 testPassed('rejected'); | |
44 window.result = result; | |
45 shouldBeEqualToString('result', 'exception'); | |
46 }).then(function() { | |
47 testPassed('resolved'); | |
48 finishJSTest(); | |
49 }, function() { | |
50 testFailed('rejected'); | |
51 finishJSTest(); | |
52 }); | |
53 | |
54 resolve('hello'); | |
55 | |
56 </script> | |
57 </body> | |
58 </html> | |
OLD | NEW |