tor-browser

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

frame_visibility_in_iframe.html (2042B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4 <meta charset="utf-8">
      5 <title>Video element visibility in iframe</title>
      6 </head>
      7 <body>
      8 <div style="width: 100%; height: calc(100vh - 100px);"></div>
      9 <div style="height: 100px; overflow: scroll;">
     10  <!-- Must be larger than the IntersectionObserver margin used in DOMIntersectionObserver::ComputeInputForIframeThrottling -->
     11  <div style="width: 100%; height: 800px;"></div>
     12  <iframe id="iframe" style="height: 100px; border: none;"></iframe>
     13 </div>
     14 <script>
     15 const add_task = window.opener.add_task;
     16 const SimpleTest = window.opener.SimpleTest;
     17 const original_finish = window.opener.SimpleTest.finish;
     18 
     19 // add_task calls SimpleTest.finish() when it finished, we want to close this
     20 // window before SimpleTest.finish() gets called.
     21 SimpleTest.finish = function finish() {
     22  self.close();
     23  original_finish();
     24 }
     25 
     26 add_task(async () => {
     27  const iframe = document.getElementById("iframe");
     28  await new Promise(resolve => {
     29    iframe.addEventListener("load", () => { resolve(); }, { once: true });
     30    iframe.src = "http://example.org/tests/layout/generic/test/frame_visibility_in_iframe_child.html";
     31  });
     32 
     33  await SpecialPowers.spawn(iframe, [], async () => {
     34    // With layout.visibility.min-recompute-interval-ms=0 value, flushing layout
     35    // and waiting two frames would be sufficient to make sure at least one
     36    // RebuildApproximateFrameVisibility call was done. This would avoid the
     37    // situation we consider the video element is invisible without doing any
     38    // frame visibility tracking stuff.
     39    content.document.documentElement.getBoundingClientRect();
     40    await new Promise(resolve => content.window.requestAnimationFrame(resolve));
     41    await new Promise(resolve => content.window.requestAnimationFrame(resolve));
     42  });
     43 
     44  await SpecialPowers.spawn(iframe, [], async () => {
     45    const video = content.document.querySelector("video");
     46    Assert.ok(!SpecialPowers.wrap(video).isInViewPort,
     47              "The video element should not be in the viewport");
     48  });
     49 });
     50 </script>
     51 </body>
     52 </html>