tor-browser

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

test_bug1639328.html (3800B)


      1 <!DOCTYPE HTML>
      2 <meta charset="utf-8">
      3 <title>Test for bug 1639328</title>
      4 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      5 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
      6 <style>
      7  /* To ensure that they're all in the viewport when displayed */
      8  iframe {
      9    width: 10px;
     10    height: 10px;
     11  }
     12  iframe[id^=zero-size] {
     13    border: none;
     14    width: 0;
     15    height: 0;
     16  }
     17 </style>
     18 <!-- TODO(emilio): The iframes with id ending in "http" are intended to use the http:// protocol, but that causes issues with http2/http3 tests, see bug 1917297 -->
     19 <iframe id="http" src="https://example.com/tests/dom/base/test/file_bug1639328.html"></iframe>
     20 <iframe id="https" src="https://example.com/tests/dom/base/test/file_bug1639328.html"></iframe>
     21 <iframe id="same-origin" src="file_bug1639328.html"></iframe>
     22 <br>
     23 <iframe id="zero-size-http" src="https://example.com/tests/dom/base/test/file_bug1639328.html"></iframe>
     24 <iframe id="zero-size-https" src="https://example.com/tests/dom/base/test/file_bug1639328.html"></iframe>
     25 <iframe id="zero-size-same-origin" src="file_bug1639328.html"></iframe>
     26 <br>
     27 <iframe id="display-none-http" style="display: none" src="https://example.com/tests/dom/base/test/file_bug1639328.html"></iframe>
     28 <iframe id="display-none-https" style="display: none" src="https://example.com/tests/dom/base/test/file_bug1639328.html"></iframe>
     29 <iframe id="display-none-same-origin" style="display: none" src="file_bug1639328.html"></iframe>
     30 <br>
     31 <iframe id="vis-hidden-http" style="visibility: hidden" src="https://example.com/tests/dom/base/test/file_bug1639328.html"></iframe>
     32 <iframe id="vis-hidden-https" style="visibility: hidden" src="https://example.com/tests/dom/base/test/file_bug1639328.html"></iframe>
     33 <iframe id="vis-hidden-same-origin" style="visibility: hidden" src="file_bug1639328.html"></iframe>
     34 <script>
     35 SimpleTest.waitForExplicitFinish();
     36 
     37 function getOneMessage(frame) {
     38  info(`querying ${frame.src} (${frame.id})`);
     39  let resolve;
     40  let promise = new Promise(r => { resolve = r; });
     41  window.addEventListener("message", function(e) {
     42    info("got " + JSON.stringify(e.data));
     43    resolve(e.data);
     44  }, { once: true });
     45  frame.contentWindow.postMessage("ping", "*");
     46  return promise;
     47 }
     48 
     49 async function ticks(n) {
     50  for (let i = 0; i < n; ++i) {
     51    await new Promise(resolve => requestAnimationFrame(resolve));
     52  }
     53 }
     54 
     55 async function checkFrame(frame, shouldThrottle) {
     56  let message = null;
     57  do {
     58    if (message) {
     59      await ticks(2);
     60    }
     61    message = await getOneMessage(frame);
     62  } while (message.throttledFrameRequests != shouldThrottle);
     63  is(message.throttledFrameRequests, shouldThrottle, frame.id);
     64 }
     65 
     66 function shouldThrottle(frame) {
     67  return frame.style.display == "none" || frame.style.visibility == "hidden";
     68 }
     69 
     70 onload = async function() {
     71  await SimpleTest.promiseFocus(window);
     72  await ticks(2);
     73  is(SpecialPowers.DOMWindowUtils.effectivelyThrottlesFrameRequests, false, "Should not be throttling main page");
     74  for (let frame of document.querySelectorAll("iframe")) {
     75    let originalShouldThrottle = shouldThrottle(frame);
     76    await checkFrame(frame, originalShouldThrottle);
     77    for (let prop of ["display", "visibility"]) {
     78      info(`Switching ${prop} of ${frame.id}`);
     79      let orig = frame.style[prop];
     80      let throttledValue = prop == "display" ? "none" : "hidden";
     81      frame.style[prop] = orig == throttledValue ? "" : throttledValue;
     82      if (orig != throttledValue) {
     83        is(shouldThrottle(frame), true, `Should throttle for ${prop}: ${throttledValue}`);
     84      }
     85      await checkFrame(frame, shouldThrottle(frame));
     86      info(`Switching ${prop} back for ${frame.id}`);
     87      frame.style[prop] = orig;
     88      await checkFrame(frame, originalShouldThrottle);
     89    }
     90  }
     91 
     92  SimpleTest.finish();
     93 };
     94 </script>