test_resolve.html 1.3 KB

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