dom/promise/tests/test_resolve.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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">
    15 </div>
    16 <pre id="test">
    17 <script type="application/javascript"><!--
    19 var tests = [
    20   null,
    21   42,
    22   "hello world",
    23   true,
    24   false,
    25   {},
    26   { a: 42 },
    27   [ 1, 2, 3, 4, null, true, "hello world" ],
    28   function() {},
    29   window,
    30   undefined,
    31   document.createElement('input'),
    32   new Date(),
    33 ];
    35 function cbError() {
    36   ok(false, "Nothing should arrive here!");
    37 }
    39 function runTest() {
    40   if (!tests.length) {
    41     SimpleTest.finish();
    42     return;
    43   }
    45   var test = tests.pop();
    47   new Promise(function(resolve, reject) {
    48     resolve(test);
    49   }).then(function(what) {
    50     ok(test === what, "What is: " + what);
    51   }, cbError).then(function() {
    52     new Promise(function(resolve, reject) {
    53       reject(test)
    54     }).then(cbError, function(what) {
    55       ok(test === what, "What is: " + what);
    56     }).then(runTest, cbError);
    57   });
    58 }
    60 SimpleTest.waitForExplicitFinish();
    61 runTest();
    62 // -->
    63 </script>
    64 </pre>
    65 </body>
    66 </html>

mercurial