tor-browser

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

getdisplaymedia-after-discard.https.html (2082B)


      1 <!doctype html>
      2 <title>Test for rejected promise from getDisplayMedia() in a discarded browsing
      3  context</title>
      4 <script src=/resources/testharness.js></script>
      5 <script src=/resources/testharnessreport.js></script>
      6 <script src="/resources/testdriver.js"></script>
      7 <script src='/resources/testdriver-vendor.js'></script>
      8 <body></body>
      9 <script>
     10 // https://w3c.github.io/mediacapture-screen-share/#dom-mediadevices-getdisplaymedia
     11 // If the current settings object's responsible document is NOT fully active,
     12 // return a promise rejected with a DOMException object whose name attribute
     13 // has the value "InvalidStateError".
     14 promise_test(async () => {
     15  const frame = document.createElement('iframe');
     16  document.body.appendChild(frame);
     17  frame.srcdoc = '<html></html>';
     18  await new Promise(resolve => frame.onload = resolve);
     19  const child_window = frame.contentWindow;
     20  const devices = child_window.navigator.mediaDevices;
     21  const child_DOMException = child_window.DOMException;
     22  // transient activation of iframe content
     23  await test_driver.bless('getDisplayMedia()', undefined, child_window);
     24  frame.remove();
     25  // `catch()` is used rather than static Promise methods because microtasks
     26  // for `PromiseResolve()` do not run when Promises in inactive Documents are
     27  // involved.  Whether microtasks for `catch()` run depends on the realm of
     28  // the handler rather than the realm of the Promise.
     29  // See https://github.com/whatwg/html/issues/5319.
     30  let promise_already_rejected = false;
     31  let rejected_reason;
     32  devices.getDisplayMedia({video:true}).catch(reason => {
     33    promise_already_rejected = true;
     34    rejected_reason = reason;
     35  });
     36  // Race a settled promise to check that the returned promise is already
     37  // rejected.
     38  await Promise.reject().catch(() => {
     39    assert_true(promise_already_rejected,
     40                'should have returned an already-rejected promise.');
     41    assert_throws_dom('InvalidStateError', child_DOMException,
     42                      () => { throw rejected_reason });
     43  });
     44 }, 'getDisplayMedia() in a discarded browsing context');
     45 </script>