tor-browser

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

file_promise_retval_tests.js (1897B)


      1 /*
      2 * This file is meant to provide common infrastructure for several consumers.
      3 * The consumer is expected to define the following things:
      4 *
      5 * 1) A verifyPromiseGlobal function which does whatever test the consumer
      6 *    wants.  This function is passed a promise and the global whose
      7 *    TestFunctions was used to get the promise.
      8 * 2) A expectedExceptionGlobal function which is handed the global whose
      9 *    TestFunctions was used to trigger the exception and should return the
     10 *    global the exception is expected to live in.
     11 * 3) A subframe (frames[0]) which can be used as a second global for creating
     12 *    promises.
     13 */
     14 
     15 /* global verifyPromiseGlobal, expectedExceptionGlobal */
     16 
     17 var label = "parent";
     18 
     19 function testThrownException(global) {
     20  var p = global.TestFunctions.throwToRejectPromise();
     21  verifyPromiseGlobal(p, global, "throwToRejectPromise return value");
     22  return p
     23    .then(() => {})
     24    .catch(err => {
     25      var expected = expectedExceptionGlobal(global);
     26      is(
     27        SpecialPowers.unwrap(SpecialPowers.Cu.getGlobalForObject(err)),
     28        expected,
     29        "Should have an exception object from the right global too"
     30      );
     31      ok(
     32        err instanceof expected.DOMException,
     33        "Should have a DOMException here"
     34      );
     35      is(
     36        Object.getPrototypeOf(err),
     37        expected.DOMException.prototype,
     38        "Should have a DOMException from the right global"
     39      );
     40      is(err.name, "InvalidStateError", "Should have the right DOMException");
     41    });
     42 }
     43 
     44 function runPromiseRetvalTests(finishFunc) {
     45  Promise.resolve()
     46    .then(testThrownException.bind(undefined, window))
     47    .then(testThrownException.bind(undefined, frames[0]))
     48    .then(finishFunc)
     49    .catch(function (e) {
     50      ok(
     51        false,
     52        `Exception thrown: ${e}@${location.pathname}:${e.lineNumber}:${e.columnNumber}`
     53      );
     54      finishFunc();
     55    });
     56 }