tor-browser

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

browser_viewport_resizing_after_reload.js (2361B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test viewport resizing, with and without meta viewport support.
      7 
      8 const TEST_URL =
      9  "data:text/html;charset=utf-8," +
     10  "<!DOCTYPE html>" +
     11  '<head><meta name="viewport" content="width=device-width"/></head>' +
     12  '<body style="margin:0px;min-width:600px">' +
     13  '<div style="width:100%;height:100px;background-color:black"></div>' +
     14  '<div style="width:100%;height:1100px;background-color:lightblue"></div>' +
     15  "</body>";
     16 
     17 addRDMTask(TEST_URL, async function ({ ui, manager }) {
     18  info("--- Starting viewport test output ---");
     19 
     20  // We're going to take a 300,600 viewport (before), reload it,
     21  // then resize it to 600,300 (after) and then resize it back.
     22  // At the before and after points, we'll measure zoom and the
     23  // layout viewport width and height.
     24  const expected = [
     25    {
     26      metaSupport: false,
     27      before: [0.5, 300, 600],
     28      after: [1.0, 600, 300],
     29    },
     30    {
     31      metaSupport: true,
     32      before: [0.5, 300, 600],
     33      after: [1.0, 600, 300],
     34    },
     35  ];
     36 
     37  for (const e of expected) {
     38    const b = e.before;
     39    const a = e.after;
     40 
     41    const message = "Meta Viewport " + (e.metaSupport ? "ON" : "OFF");
     42 
     43    // Ensure meta viewport is set.
     44    info(message + " setting meta viewport support.");
     45    await setTouchAndMetaViewportSupport(ui, e.metaSupport);
     46 
     47    // Get to the initial size and check values.
     48    await setViewportSizeAndAwaitReflow(ui, manager, 300, 600);
     49    await testViewportZoomWidthAndHeight(
     50      message + " before resize",
     51      ui,
     52      b[0],
     53      b[1],
     54      b[2]
     55    );
     56 
     57    // Force a reload.
     58    await reloadBrowser();
     59 
     60    // Check initial values again.
     61    await testViewportZoomWidthAndHeight(
     62      message + " after reload",
     63      ui,
     64      b[0],
     65      b[1],
     66      b[2]
     67    );
     68 
     69    // Move to the smaller size.
     70    await setViewportSizeAndAwaitReflow(ui, manager, 600, 300);
     71    await testViewportZoomWidthAndHeight(
     72      message + " after resize",
     73      ui,
     74      a[0],
     75      a[1],
     76      a[2]
     77    );
     78 
     79    // Go back to the initial size and check again.
     80    await setViewportSizeAndAwaitReflow(ui, manager, 300, 600);
     81    await testViewportZoomWidthAndHeight(
     82      message + " return to initial size",
     83      ui,
     84      b[0],
     85      b[1],
     86      b[2]
     87    );
     88  }
     89 });