tor-browser

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

browser_viewport_resizing_fixed_width.js (2032B)


      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=300"/></head>' +
     12  "<body>meta viewport width 300</body>";
     13 addRDMTask(TEST_URL, async function ({ ui, manager }) {
     14  info("--- Starting viewport test output ---");
     15 
     16  // We're going to take a 600,300 viewport (before) and resize it
     17  // to 50,50 (after) and then resize it back. At the before and
     18  // after points, we'll measure zoom and the layout viewport width
     19  // and height.
     20  const expected = [
     21    {
     22      metaSupport: false,
     23      before: [2.0, 300, 150],
     24      after: [0.25, 300, 300], // This checks that min-zoom is active.
     25    },
     26    {
     27      metaSupport: true,
     28      before: [2.0, 300, 150],
     29      after: [0.25, 300, 300], // This checks that min-zoom is active.
     30    },
     31  ];
     32 
     33  for (const e of expected) {
     34    const b = e.before;
     35    const a = e.after;
     36 
     37    const message = "Meta Viewport " + (e.metaSupport ? "ON" : "OFF");
     38 
     39    // Ensure meta viewport is set.
     40    info(message + " setting meta viewport support.");
     41    await setTouchAndMetaViewportSupport(ui, e.metaSupport);
     42 
     43    // Get to the initial size and check values.
     44    await setViewportSizeAndAwaitReflow(ui, manager, 600, 300);
     45    await testViewportZoomWidthAndHeight(
     46      message + " before resize",
     47      ui,
     48      b[0],
     49      b[1],
     50      b[2]
     51    );
     52 
     53    // Move to the smaller size.
     54    await setViewportSizeAndAwaitReflow(ui, manager, 50, 50);
     55    await testViewportZoomWidthAndHeight(
     56      message + " after resize",
     57      ui,
     58      a[0],
     59      a[1],
     60      a[2]
     61    );
     62 
     63    // Go back to the initial size and check again.
     64    await setViewportSizeAndAwaitReflow(ui, manager, 600, 300);
     65    await testViewportZoomWidthAndHeight(
     66      message + " return to initial size",
     67      ui,
     68      b[0],
     69      b[1],
     70      b[2]
     71    );
     72  }
     73 });