tor-browser

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

browser_test_displayport_in_popup.js (3380B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 Services.scriptloader.loadSubScript(
      7  "chrome://mochikit/content/tests/SimpleTest/paint_listener.js",
      8  this
      9 );
     10 
     11 Services.scriptloader.loadSubScript(
     12  new URL("apz_test_utils.js", gTestPath).href,
     13  this
     14 );
     15 
     16 Services.scriptloader.loadSubScript(
     17  new URL("apz_test_native_event_utils.js", gTestPath).href,
     18  this
     19 );
     20 
     21 // Cleanup for paint_listener.js and hitTestConfig.
     22 add_task(() => {
     23  registerCleanupFunction(() => {
     24    delete window.waitForAllPaintsFlushed;
     25    delete window.waitForAllPaints;
     26    delete window.promiseAllPaintsDone;
     27    delete window.hitTestConfig;
     28  });
     29 });
     30 
     31 // Setup preferences.
     32 add_task(async () => {
     33  await SpecialPowers.pushPrefEnv({
     34    set: [
     35      ["apz.popups.enabled", true],
     36      ["apz.popups_without_remote.enabled", true],
     37      ["apz.test.logging_enabled", true],
     38    ],
     39  });
     40 });
     41 
     42 // Create a popup having a sub scroll container.
     43 function setupPopup(aWindow) {
     44  const popupset = aWindow.document.createXULElement("popupset");
     45  aWindow.document.documentElement.appendChild(popupset);
     46  const popup = aWindow.document.createXULElement("menupopup");
     47  popupset.appendChild(popup);
     48 
     49  const scroller = aWindow.document.createElement("div");
     50  // To make this test fail without the proper fix, this scroll container
     51  // height needs to be slightly taller than a value multiplying by 128px
     52  // (i.e. displayport alignment).
     53  scroller.style =
     54    "width: 100px; height: 550px; overflow: auto; background-color: white;";
     55  scroller.setAttribute("id", "bug1948522");
     56  popup.appendChild(scroller);
     57 
     58  const spacer = aWindow.document.createElement("div");
     59  spacer.style = "width: 200px; height: 600px; background-color: green;";
     60  scroller.appendChild(spacer);
     61 
     62  return popup;
     63 }
     64 
     65 add_task(async () => {
     66  const dialogWindow = window.openDialog(
     67    // Whatever document loaded in this test would be okay, because this test
     68    // creates dynamically a popup element and relevant elements, but data URI
     69    // can not be loaded in the parent process.
     70    getRootDirectory(gTestPath) + "helper_popup_menu_in_parent_process-1.html",
     71    null,
     72    "dialog=no,innerWidth=200,innerHeight=20"
     73  );
     74  await Promise.all([
     75    BrowserTestUtils.waitForEvent(dialogWindow, "load"),
     76    BrowserTestUtils.waitForEvent(dialogWindow, "focus"),
     77    BrowserTestUtils.waitForEvent(dialogWindow, "activate"),
     78  ]);
     79 
     80  await promiseOnlyApzControllerFlushed(dialogWindow);
     81 
     82  const popup = setupPopup(dialogWindow);
     83 
     84  // Open the popup.
     85  const popupshownPromise = new Promise(resolve => {
     86    popup.addEventListener("popupshown", resolve());
     87  });
     88  popup.openPopupAtScreen(
     89    dialogWindow.mozInnerScreenX,
     90    dialogWindow.mozInnerScreenY
     91  );
     92  await popupshownPromise;
     93 
     94  await ensureApzReadyForPopup(popup, dialogWindow);
     95  await promiseApzFlushedRepaints(popup);
     96 
     97  let displayport = getLastContentDisplayportFor("bug1948522", {
     98    popupElement: popup,
     99  });
    100  is(
    101    displayport.height,
    102    600,
    103    `the height of the displayport ${displayport.height}px should equal to 600px`
    104  );
    105 
    106  // Close the popup.
    107  const popuphiddenPromise = new Promise(resolve => {
    108    popup.addEventListener("popuphidden", resolve());
    109  });
    110  popup.hidePopup();
    111  await popuphiddenPromise;
    112 
    113  await BrowserTestUtils.closeWindow(dialogWindow);
    114 });