tor-browser

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

browser_test_select_zoom.js (5590B)


      1 /* This test is a a mash up of
      2     https://searchfox.org/mozilla-central/rev/559b25eb41c1cbffcb90a34e008b8288312fcd25/gfx/layers/apz/test/mochitest/browser_test_group_fission.js
      3     https://searchfox.org/mozilla-central/rev/559b25eb41c1cbffcb90a34e008b8288312fcd25/gfx/layers/apz/test/mochitest/helper_basic_zoom.html
      4     https://searchfox.org/mozilla-central/rev/559b25eb41c1cbffcb90a34e008b8288312fcd25/browser/base/content/test/forms/browser_selectpopup.js
      5 */
      6 
      7 /* import-globals-from helper_browser_test_utils.js */
      8 Services.scriptloader.loadSubScript(
      9  new URL("helper_browser_test_utils.js", gTestPath).href,
     10  this
     11 );
     12 
     13 add_task(async function setup_pref() {
     14  await SpecialPowers.pushPrefEnv({
     15    set: [
     16      ["test.wait300msAfterTabSwitch", true],
     17      // Dropping the touch slop to 0 makes the tests easier to write because
     18      // we can just do a one-pixel drag to get over the pan threshold rather
     19      // than having to hard-code some larger value.
     20      ["apz.touch_start_tolerance", "0.0"],
     21      // The subtests in this test do touch-drags to pan the page, but we don't
     22      // want those pans to turn into fling animations, so we increase the
     23      // fling-min threshold velocity to an arbitrarily large value.
     24      ["apz.fling_min_velocity_threshold", "10000"],
     25    ],
     26  });
     27 });
     28 
     29 // This test opens a select popup after pinch (apz) zooming has happened.
     30 add_task(async function () {
     31  function httpURL(filename) {
     32    let chromeURL = getRootDirectory(gTestPath) + filename;
     33    //return chromeURL;
     34    return chromeURL.replace(
     35      "chrome://mochitests/content/",
     36      "http://mochi.test:8888/"
     37    );
     38  }
     39 
     40  const pageUrl = httpURL("helper_test_select_zoom.html");
     41  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, pageUrl);
     42 
     43  await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
     44    const input = content.document.getElementById("select");
     45    const focusPromise = new Promise(resolve => {
     46      input.addEventListener("focus", resolve, { once: true });
     47    });
     48    input.focus();
     49    await focusPromise;
     50  });
     51 
     52  await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
     53    await content.wrappedJSObject.waitUntilApzStable();
     54  });
     55 
     56  const initial_resolution = await SpecialPowers.spawn(
     57    tab.linkedBrowser,
     58    [],
     59    () => {
     60      return content.window.windowUtils.getResolution();
     61    }
     62  );
     63 
     64  const initial_rect = await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
     65    return content.wrappedJSObject.getSelectRect();
     66  });
     67 
     68  ok(
     69    initial_resolution > 0,
     70    "The initial_resolution is " +
     71      initial_resolution +
     72      ", which is some sane value"
     73  );
     74 
     75  // First, get the position of the select popup when no translations have been applied.
     76  const selectPopup = await openSelectPopup();
     77 
     78  let popup_initial_rect = selectPopup.getBoundingClientRect();
     79  let popupInitialX = popup_initial_rect.left;
     80  let popupInitialY = popup_initial_rect.top;
     81 
     82  await hideSelectPopup();
     83 
     84  ok(popupInitialX > 0, "select position before zooming (x) " + popupInitialX);
     85  ok(popupInitialY > 0, "select position before zooming (y) " + popupInitialY);
     86 
     87  await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
     88    await content.wrappedJSObject.pinchZoomInWithTouch(150, 300);
     89  });
     90 
     91  // Flush state and get the resolution we're at now
     92  await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
     93    await content.wrappedJSObject.promiseApzFlushedRepaints();
     94  });
     95 
     96  const final_resolution = await SpecialPowers.spawn(
     97    tab.linkedBrowser,
     98    [],
     99    () => {
    100      return content.window.windowUtils.getResolution();
    101    }
    102  );
    103 
    104  ok(
    105    final_resolution > initial_resolution,
    106    "The final resolution (" +
    107      final_resolution +
    108      ") is greater after zooming in"
    109  );
    110 
    111  const final_rect = await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
    112    return content.wrappedJSObject.getSelectRect();
    113  });
    114 
    115  await openSelectPopup();
    116 
    117  let popupRect = selectPopup.getBoundingClientRect();
    118  ok(
    119    Math.abs(popupRect.left - popupInitialX) > 1,
    120    "popup should have moved by more than one pixel (x) " +
    121      popupRect.left +
    122      " " +
    123      popupInitialX
    124  );
    125  ok(
    126    Math.abs(popupRect.top - popupInitialY) > 1,
    127    "popup should have moved by more than one pixel (y) " +
    128      popupRect.top +
    129      " " +
    130      popupInitialY
    131  );
    132 
    133  ok(
    134    Math.abs(
    135      final_rect.left - initial_rect.left - (popupRect.left - popupInitialX)
    136    ) < 1,
    137    "popup should have moved approximately the same as the element (x)"
    138  );
    139  let tolerance = navigator.platform.includes("Linux") ? final_rect.height : 1;
    140  ok(
    141    Math.abs(
    142      final_rect.top - initial_rect.top - (popupRect.top - popupInitialY)
    143    ) < tolerance,
    144    "popup should have moved approximately the same as the element (y)"
    145  );
    146 
    147  ok(
    148    true,
    149    "initial " +
    150      initial_rect.left +
    151      " " +
    152      initial_rect.top +
    153      " " +
    154      initial_rect.width +
    155      " " +
    156      initial_rect.height
    157  );
    158  ok(
    159    true,
    160    "final " +
    161      final_rect.left +
    162      " " +
    163      final_rect.top +
    164      " " +
    165      final_rect.width +
    166      " " +
    167      final_rect.height
    168  );
    169 
    170  ok(
    171    true,
    172    "initial popup " +
    173      popup_initial_rect.left +
    174      " " +
    175      popup_initial_rect.top +
    176      " " +
    177      popup_initial_rect.width +
    178      " " +
    179      popup_initial_rect.height
    180  );
    181  ok(
    182    true,
    183    "final popup " +
    184      popupRect.left +
    185      " " +
    186      popupRect.top +
    187      " " +
    188      popupRect.width +
    189      " " +
    190      popupRect.height
    191  );
    192 
    193  await hideSelectPopup();
    194 
    195  BrowserTestUtils.removeTab(tab);
    196 });