OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <script src="resources/js-test-pre.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 resolverSync; |
| 15 var promiseSync = new Promise(function(r) { resolverSync = r; }); |
| 16 var promiseSyncState = 'pending'; |
| 17 var promiseSyncResult = undefined; |
| 18 promiseSync.then(function(result) { |
| 19 promiseSyncState = 'fulfilled'; |
| 20 promiseSyncResult = result; |
| 21 }, function(result) { |
| 22 promiseSyncState = 'rejected'; |
| 23 promiseSyncResult = result; |
| 24 }); |
| 25 |
| 26 var resolverAsync; |
| 27 var promiseAsync = new Promise(function(r) { resolverAsync = r; }); |
| 28 var promiseAsyncState = 'pending'; |
| 29 var promiseAsyncResult = undefined; |
| 30 promiseAsync.then(function(result) { |
| 31 promiseAsyncState = 'fulfilled'; |
| 32 promiseAsyncResult = result; |
| 33 }, function(result) { |
| 34 promiseAsyncState = 'rejected'; |
| 35 promiseAsyncResult = result; |
| 36 }); |
| 37 |
| 38 shouldBeEqualToString('promiseSyncState', 'pending'); |
| 39 shouldBeEqualToString('promiseAsyncState', 'pending'); |
| 40 |
| 41 resolverSync.reject('hello', true); |
| 42 resolverAsync.reject('hello'); |
| 43 |
| 44 shouldBeEqualToString('promiseSyncState', 'rejected'); |
| 45 shouldBeEqualToString('promiseSyncResult', 'hello'); |
| 46 shouldBeEqualToString('promiseAsyncState', 'pending'); |
| 47 |
| 48 promiseAsync.then(function() { |
| 49 debug('FAIL promiseAsync is fulfilled.'); |
| 50 finishJSTest(); |
| 51 }, function() { |
| 52 shouldBeEqualToString('promiseAsyncState', 'rejected'); |
| 53 shouldBeEqualToString('promiseAsyncResult', 'hello'); |
| 54 finishJSTest(); |
| 55 }); |
| 56 |
| 57 </script> |
| 58 <script src="resources/js-test-post.js"></script> |
| 59 </body> |
| 60 </html> |
OLD | NEW |