Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!-- |
michael@0 | 2 | Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 4 | --> |
michael@0 | 5 | <html> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Promise.resolve(anything) Test</title> |
michael@0 | 8 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 10 | </head> |
michael@0 | 11 | <body> |
michael@0 | 12 | <p id="display"></p> |
michael@0 | 13 | <div id="content" style="display: none"> |
michael@0 | 14 | |
michael@0 | 15 | </div> |
michael@0 | 16 | <pre id="test"> |
michael@0 | 17 | <script type="application/javascript"><!-- |
michael@0 | 18 | |
michael@0 | 19 | var tests = [ |
michael@0 | 20 | null, |
michael@0 | 21 | 42, |
michael@0 | 22 | "hello world", |
michael@0 | 23 | true, |
michael@0 | 24 | false, |
michael@0 | 25 | {}, |
michael@0 | 26 | { a: 42 }, |
michael@0 | 27 | [ 1, 2, 3, 4, null, true, "hello world" ], |
michael@0 | 28 | function() {}, |
michael@0 | 29 | window, |
michael@0 | 30 | undefined, |
michael@0 | 31 | document.createElement('input'), |
michael@0 | 32 | new Date(), |
michael@0 | 33 | ]; |
michael@0 | 34 | |
michael@0 | 35 | function cbError() { |
michael@0 | 36 | ok(false, "Nothing should arrive here!"); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | function runTest() { |
michael@0 | 40 | if (!tests.length) { |
michael@0 | 41 | SimpleTest.finish(); |
michael@0 | 42 | return; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | var test = tests.pop(); |
michael@0 | 46 | |
michael@0 | 47 | new Promise(function(resolve, reject) { |
michael@0 | 48 | resolve(test); |
michael@0 | 49 | }).then(function(what) { |
michael@0 | 50 | ok(test === what, "What is: " + what); |
michael@0 | 51 | }, cbError).then(function() { |
michael@0 | 52 | new Promise(function(resolve, reject) { |
michael@0 | 53 | reject(test) |
michael@0 | 54 | }).then(cbError, function(what) { |
michael@0 | 55 | ok(test === what, "What is: " + what); |
michael@0 | 56 | }).then(runTest, cbError); |
michael@0 | 57 | }); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 61 | runTest(); |
michael@0 | 62 | // --> |
michael@0 | 63 | </script> |
michael@0 | 64 | </pre> |
michael@0 | 65 | </body> |
michael@0 | 66 | </html> |
michael@0 | 67 |