tor-browser

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

promise-rejection-event-constructor.html (2620B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <link rel="help" href="https://html.spec.whatwg.org/#the-promiserejectionevent-interface">
      6 <script>
      7 'use strict';
      8 
      9 test(function() {
     10  var p = new Promise(function(resolve, reject) {});
     11 
     12  assert_throws_js(TypeError,
     13                   function() {
     14                     PromiseRejectionEvent('', { promise: p });
     15                   },
     16                   "Calling PromiseRejectionEvent constructor without 'new' must throw");
     17 
     18  // No custom options are passed (besides required promise).
     19  assert_equals(new PromiseRejectionEvent('eventType', { promise: p }).bubbles, false);
     20  assert_equals(new PromiseRejectionEvent('eventType', { promise: p }).cancelable, false);
     21  assert_equals(new PromiseRejectionEvent('eventType', { promise: p }).promise, p);
     22  assert_equals(new PromiseRejectionEvent('eventType', { promise: p }).reason, undefined);
     23 
     24  // No promise is passed.
     25  assert_throws_js(TypeError,
     26                   function() {
     27                     new PromiseRejectionEvent('eventType', { bubbles: false });
     28                   },
     29                   'Cannot construct PromiseRejectionEventInit without promise');
     30 
     31  // bubbles is passed.
     32  assert_equals(new PromiseRejectionEvent('eventType', { bubbles: false, promise: p }).bubbles, false);
     33  assert_equals(new PromiseRejectionEvent('eventType', { bubbles: true, promise: p }).bubbles, true);
     34 
     35  // cancelable is passed.
     36  assert_equals(new PromiseRejectionEvent('eventType', { cancelable: false, promise: p }).cancelable, false);
     37  assert_equals(new PromiseRejectionEvent('eventType', { cancelable: true, promise: p }).cancelable, true);
     38 
     39  // reason is passed.
     40  var r = new Error();
     41  assert_equals(new PromiseRejectionEvent('eventType', { promise: p, reason: r }).reason, r);
     42  assert_equals(new PromiseRejectionEvent('eventType', { promise: p, reason: null }).reason, null);
     43 
     44  // All initializers are passed.
     45  assert_equals(new PromiseRejectionEvent('eventType', { bubbles: true, cancelable: true, promise: p, reason: r }).bubbles, true);
     46  assert_equals(new PromiseRejectionEvent('eventType', { bubbles: true, cancelable: true, promise: p, reason: r }).cancelable, true);
     47  assert_equals(new PromiseRejectionEvent('eventType', { bubbles: true, cancelable: true, promise: p, reason: r }).promise, p);
     48  assert_equals(new PromiseRejectionEvent('eventType', { bubbles: true, cancelable: true, promise: p, reason: r }).reason, r);
     49 }, "This tests the constructor for the PromiseRejectionEvent DOM class.");
     50 </script>