tor-browser

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

helper_zoomToFocusedInput_iframe-2.html (3316B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <meta name="viewport" content="width=2100,initial-scale=0.4"/>
      6  <title>Tests that zoomToFocusedInput in iframe works regardless whether cross-origin or not</title>
      7  <script src="apz_test_native_event_utils.js"></script>
      8  <script src="apz_test_utils.js"></script>
      9  <script src="/tests/SimpleTest/paint_listener.js"></script>
     10  <style>
     11  html {
     12    /* To avoid bug 1865573 */
     13    scrollbar-width: none;
     14  }
     15  iframe {
     16    position: absolute;
     17    top: 100px;
     18    left: 100px;
     19    border: none;
     20  }
     21  </style>
     22 </head>
     23 <body>
     24 <iframe width="500" height="500"></iframe>
     25 <script>
     26 async function setupIframe(aURL) {
     27  const iframe = document.querySelector("iframe");
     28  const iframeLoadPromise = promiseOneEvent(iframe, "load", null);
     29  iframe.src = aURL;
     30  await iframeLoadPromise;
     31  info(`${aURL} loaded`);
     32 
     33  await SpecialPowers.spawn(iframe, [], async () => {
     34    await content.wrappedJSObject.waitUntilApzStable();
     35    await SpecialPowers.contentTransformsReceived(content);
     36  });
     37 }
     38 
     39 let initial_resolution;
     40 async function test(aTestFile) {
     41  let iframeURL = SimpleTest.getTestFileURL(aTestFile);
     42 
     43  // Load the test document in the same origin.
     44  await setupIframe(iframeURL);
     45 
     46  initial_resolution = await getResolution();
     47  ok(initial_resolution > 0,
     48     "The initial_resolution is " + initial_resolution + ", which is some sane value");
     49 
     50  const iframe = document.querySelector("iframe");
     51  let transformEndPromise = promiseTransformEnd();
     52  await SpecialPowers.spawn(iframe, [], async () => {
     53    SpecialPowers.DOMWindowUtils.zoomToFocusedInput();
     54  });
     55  await transformEndPromise;
     56  await promiseApzFlushedRepaints();
     57 
     58  const zoomedInState = cloneVisualViewport();
     59 
     60  // Reset the scale to the initial value.
     61  SpecialPowers.DOMWindowUtils.setResolutionAndScaleTo(initial_resolution);
     62  await promiseApzFlushedRepaints();
     63 
     64  // Now load the document in an OOP iframe.
     65  iframeURL = iframeURL.replace(window.location.origin, "https://example.com");
     66  await setupIframe(iframeURL);
     67 
     68  transformEndPromise = promiseTransformEnd();
     69  await SpecialPowers.spawn(iframe, [], async () => {
     70    SpecialPowers.DOMWindowUtils.zoomToFocusedInput();
     71  });
     72  await transformEndPromise;
     73  await promiseApzFlushedRepaints();
     74 
     75  compareVisualViewport(zoomedInState, cloneVisualViewport(), "zoomed-in state");
     76 }
     77 
     78 async function moveIframe() {
     79  const iframe = document.querySelector("iframe");
     80  iframe.style.top = "500vh";
     81 
     82  // Scroll to the bottom to make the layout scroll offset non-zero.
     83  window.scrollTo(0, document.documentElement.scrollHeight);
     84  ok(window.scrollY > 0, "The root scroll position should be non-zero");
     85 
     86  await SpecialPowers.spawn(iframe, [], async () => {
     87    await SpecialPowers.contentTransformsReceived(content);
     88  });
     89 }
     90 
     91 waitUntilApzStable()
     92 .then(async () => test("helper_zoomToFocusedInput_iframe_subframe.html?margin-top=200vh"))
     93 .then(async () => {
     94  // Reset the scale to the initial value.
     95  SpecialPowers.DOMWindowUtils.setResolutionAndScaleTo(initial_resolution);
     96  await promiseApzFlushedRepaints();
     97 })
     98 // A test case where the layout scroll offset isn't zero.
     99 .then(async () => moveIframe())
    100 .then(async () => test("helper_zoomToFocusedInput_iframe_subframe.html"))
    101 .then(subtestDone, subtestFailed);
    102 </script>
    103 </body>
    104 </html>