tor-browser

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

returns-window-with-document.https.html (3057B)


      1 <!DOCTYPE html>
      2 <title>Test that documentPictureInPicture.requestWindow()
      3  returns a Window object</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>
      9  <div id="div"></div>
     10 <script>
     11 
     12 function waitForEnter() {
     13  return new Promise(resolve =>
     14    documentPictureInPicture.addEventListener("enter", resolve, { once: true })
     15  );
     16 }
     17 
     18 promise_test(async (t) => {
     19  const enter = waitForEnter();
     20 
     21  await test_driver.bless('request PiP window');
     22  const pipWindow = await documentPictureInPicture.requestWindow();
     23 
     24  assert_true(!!pipWindow.document,
     25          'Window should contain a document');
     26  assert_true(documentPictureInPicture.window === pipWindow,
     27      'DocumentPictureInPicture.window should match the current window');
     28 
     29  await enter;  // avoid issues in the next subtest
     30 }, 'requestWindow resolves with the PiP window');
     31 
     32 promise_test(async (t) => {
     33  const enter = waitForEnter();
     34 
     35  await test_driver.bless('request PiP window');
     36  const pipWindow = await documentPictureInPicture.requestWindow();
     37  const div = document.getElementById('div');
     38 
     39  // We should be able to move an element to that document.
     40  assert_true(document.body.contains(div),
     41      'The original document should start with the div');
     42  assert_false(pipWindow.document.body.contains(div),
     43      'The PiP document should not start with the div');
     44  pipWindow.document.body.append(div);
     45  assert_false(document.body.contains(div),
     46      'The div should have moved away from the original document');
     47  assert_true(pipWindow.document.body.contains(div),
     48      'The div should have moved to the PiP document');
     49 
     50  await enter;  // avoid issues in the next subtest
     51 }, 'Elements can be moved from opener to PiP document');
     52 
     53 promise_test(async (t) => {
     54  const enter = waitForEnter();
     55 
     56  await test_driver.bless('request PiP window');
     57  const pipWindow = await documentPictureInPicture.requestWindow();
     58  assert_equals(pipWindow.document.readyState, "complete", "PiP document ready state is complete");
     59 
     60  await enter;  // avoid issues in the next subtest
     61 }, 'PiP document is fully loaded');
     62 
     63 promise_test(async (t) => {
     64  let events = [];
     65 
     66  const enter = new Promise(resolve => {
     67    documentPictureInPicture.onenter = () => {
     68      events.push("enter");
     69      resolve();
     70    }
     71  });
     72 
     73  await test_driver.bless('request PiP window');
     74  const request = documentPictureInPicture.requestWindow()
     75    .then(() => {
     76      events.push("requestWindow");
     77    });
     78 
     79    // Microtask to resolve request should already be queued
     80  const microtask = Promise.resolve().then(() => events.push("microtask"));
     81 
     82  assert_true(!!documentPictureInPicture.window, "window property should be set synchronous");
     83 
     84  await Promise.all([enter, request, microtask]);
     85 
     86  assert_equals(
     87    events.join(),
     88    "requestWindow,microtask,enter",
     89    "Got the expected order of actions"
     90  );
     91 
     92 }, "requestWindow timing");
     93 </script>
     94 </body>