tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_promise_rejections_from_jsimplemented.html (5967B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1107592
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 1107592</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11  <script type="application/javascript">
     12  /* global TestInterfaceJS, thereIsNoSuchContentFunction1, thereIsNoSuchContentFunction2, thereIsNoSuchContentFunction3 */
     13  /** Test for Bug 1107592 */
     14 
     15  SimpleTest.waitForExplicitFinish();
     16 
     17  function checkExn(lineNumber, name, message, code, filename, testNumber, stack, exn) {
     18    is(exn.lineNumber, lineNumber,
     19       "Should have the right line number in test " + testNumber);
     20    is(exn.name, name,
     21       "Should have the right exception name in test " + testNumber);
     22    is("filename" in exn ? exn.filename : exn.fileName, filename,
     23       "Should have the right file name in test " + testNumber);
     24    is(exn.message, message,
     25       "Should have the right message in test " + testNumber);
     26    is(exn.code, code, "Should have the right .code in test " + testNumber);
     27    if (message === "") {
     28      is(exn.name, "InternalError",
     29         "Should have one of our synthetic exceptions in test " + testNumber);
     30    }
     31    is(exn.stack, stack, "Should have the right stack in test " + testNumber);
     32  }
     33 
     34  function ensurePromiseFail(testNumber) {
     35    ok(false, "Test " + testNumber + " should not have a fulfilled promise");
     36  }
     37 
     38  function doTest() {
     39    var t = new TestInterfaceJS();
     40 
     41 
     42    var asyncStack = !SpecialPowers.getBoolPref("javascript.options.asyncstack_capture_debuggee_only");
     43    var ourFile = location.href;
     44    var unwrapError = "Promise rejection value is a non-unwrappable cross-compartment wrapper.";
     45    var parentFrame = asyncStack ? `Async*@${ourFile}:130:17
     46 ` : "";
     47 
     48    Promise.all([
     49      t.testPromiseWithThrowingChromePromiseInit().then(
     50          ensurePromiseFail.bind(null, 1),
     51          checkExn.bind(null, 49, "InternalError", unwrapError,
     52                        undefined, ourFile, 1,
     53                        `doTest@${ourFile}:49:9
     54 ` +
     55                        parentFrame)),
     56      t.testPromiseWithThrowingContentPromiseInit(function() {
     57          thereIsNoSuchContentFunction1();
     58        }).then(
     59          ensurePromiseFail.bind(null, 2),
     60          checkExn.bind(null, 57, "ReferenceError",
     61                        "thereIsNoSuchContentFunction1 is not defined",
     62                        undefined, ourFile, 2,
     63                        `doTest/<@${ourFile}:57:11
     64 doTest@${ourFile}:56:9
     65 ` +
     66                        parentFrame)),
     67      t.testPromiseWithThrowingChromeThenFunction().then(
     68          ensurePromiseFail.bind(null, 3),
     69          checkExn.bind(null, 0, "InternalError", unwrapError, undefined, "", 3, asyncStack ? (`Async*doTest@${ourFile}:67:9
     70 ` +
     71                        parentFrame) : "")),
     72      t.testPromiseWithThrowingContentThenFunction(function() {
     73          thereIsNoSuchContentFunction2();
     74        }).then(
     75          ensurePromiseFail.bind(null, 4),
     76          checkExn.bind(null, 73, "ReferenceError",
     77                        "thereIsNoSuchContentFunction2 is not defined",
     78                        undefined, ourFile, 4,
     79                        `doTest/<@${ourFile}:73:11
     80 ` +
     81                        (asyncStack ? `Async*doTest@${ourFile}:72:9
     82 ` : "") +
     83                        parentFrame)),
     84      t.testPromiseWithThrowingChromeThenable().then(
     85          ensurePromiseFail.bind(null, 5),
     86          checkExn.bind(null, 0, "InternalError", unwrapError, undefined, "", 5, asyncStack ? (`Async*doTest@${ourFile}:84:9
     87 ` +
     88                        parentFrame) : "")),
     89      t.testPromiseWithThrowingContentThenable({
     90            then() { thereIsNoSuchContentFunction3(); },
     91        }).then(
     92          ensurePromiseFail.bind(null, 6),
     93          checkExn.bind(null, 90, "ReferenceError",
     94                        "thereIsNoSuchContentFunction3 is not defined",
     95                        undefined, ourFile, 6,
     96                        `then@${ourFile}:90:22
     97 ` + (asyncStack ? `Async*doTest@${ourFile}:89:9\n` + parentFrame : ""))),
     98      t.testPromiseWithDOMExceptionThrowingPromiseInit().then(
     99          ensurePromiseFail.bind(null, 7),
    100          checkExn.bind(null, 98, "NotFoundError",
    101                        "We are a second DOMException",
    102                        DOMException.NOT_FOUND_ERR, ourFile, 7,
    103                        `doTest@${ourFile}:98:9
    104 ` +
    105                        parentFrame)),
    106      t.testPromiseWithDOMExceptionThrowingThenFunction().then(
    107          ensurePromiseFail.bind(null, 8),
    108          checkExn.bind(null, asyncStack ? 106 : 0, "NetworkError",
    109                         "We are a third DOMException",
    110                        DOMException.NETWORK_ERR, asyncStack ? ourFile : "", 8,
    111                        (asyncStack ? `Async*doTest@${ourFile}:106:9
    112 ` +
    113                         parentFrame : ""))),
    114      t.testPromiseWithDOMExceptionThrowingThenable().then(
    115          ensurePromiseFail.bind(null, 9),
    116          checkExn.bind(null, asyncStack ? 114 : 0, "TypeMismatchError",
    117                        "We are a fourth DOMException",
    118                        DOMException.TYPE_MISMATCH_ERR,
    119                        asyncStack ? ourFile : "", 9,
    120                        (asyncStack ? `Async*doTest@${ourFile}:114:9
    121 ` +
    122                         parentFrame : ""))),
    123    ]).then(SimpleTest.finish,
    124            function(err) {
    125              ok(false, "One of our catch statements totally failed with err" + err + ", stack: " + (err ? err.stack : ""));
    126              SimpleTest.finish();
    127            });
    128  }
    129 
    130  SpecialPowers.pushPrefEnv({set: [["dom.expose_test_interfaces", true]]},
    131                            doTest);
    132  </script>
    133 </head>
    134 <body>
    135 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1107592">Mozilla Bug 1107592</a>
    136 <p id="display"></p>
    137 <div id="content" style="display: none">
    138 
    139 </div>
    140 <pre id="test">
    141 </pre>
    142 </body>
    143 </html>