tor-browser

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

browser_inspector_highlighter-rulers_03.js (3699B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 // Test the creation of the viewport infobar and makes sure if resizes correctly
      8 
      9 const TEST_URL =
     10  "data:text/html;charset=utf-8," +
     11  "<div style='position:absolute;left: 0; top: 0; " +
     12  "width: 20px; height: 50px'></div>";
     13 
     14 const ID = "viewport-size-highlighter-";
     15 const { TYPES } = ChromeUtils.importESModule(
     16  "resource://devtools/shared/highlighters.mjs"
     17 );
     18 
     19 var { Toolbox } = require("resource://devtools/client/framework/toolbox.js");
     20 
     21 add_task(async function () {
     22  const { inspector, highlighterTestFront } =
     23    await openInspectorForURL(TEST_URL);
     24  const front = inspector.inspectorFront;
     25 
     26  const highlighter = await front.getHighlighterByType(TYPES.VIEWPORT_SIZE);
     27 
     28  await isVisibleAfterShow(highlighter, inspector, highlighterTestFront);
     29  await hasRightLabelsContent(highlighter, highlighterTestFront);
     30  await resizeInspector(inspector);
     31  await hasRightLabelsContent(highlighter, highlighterTestFront);
     32  await isHiddenAfterHide(highlighter, inspector, highlighterTestFront);
     33 
     34  await highlighter.finalize();
     35 });
     36 
     37 async function isVisibleAfterShow(
     38  highlighterFront,
     39  inspector,
     40  highlighterTestFront
     41 ) {
     42  info("Checking that the viewport infobar is displayed");
     43  // the rulers doesn't need any node, but as highligher it seems mandatory
     44  // ones, so the body is given
     45  const body = await getNodeFront("body", inspector);
     46  await highlighterFront.show(body);
     47 
     48  const hidden = await isViewportInfobarHidden(
     49    highlighterFront,
     50    highlighterTestFront
     51  );
     52  ok(!hidden, "viewport infobar is visible after show");
     53 }
     54 
     55 async function isHiddenAfterHide(
     56  highlighterFront,
     57  inspector,
     58  highlighterTestFront
     59 ) {
     60  info("Checking that the viewport infobar is hidden after disabling");
     61  await highlighterFront.hide();
     62 
     63  const hidden = await isViewportInfobarHidden(
     64    highlighterFront,
     65    highlighterTestFront
     66  );
     67  ok(hidden, "viewport infobar is hidden after hide");
     68 }
     69 
     70 async function hasRightLabelsContent(highlighterFront, highlighterTestFront) {
     71  const windowDimensions = await SpecialPowers.spawn(
     72    gBrowser.selectedBrowser,
     73    [],
     74    () => {
     75      const { require } = ChromeUtils.importESModule(
     76        "resource://devtools/shared/loader/Loader.sys.mjs"
     77      );
     78      const {
     79        getWindowDimensions,
     80      } = require("resource://devtools/shared/layout/utils.js");
     81      return getWindowDimensions(content);
     82    }
     83  );
     84  const windowHeight = Math.round(windowDimensions.height);
     85  const windowWidth = Math.round(windowDimensions.width);
     86  const windowText = windowWidth + "px \u00D7 " + windowHeight + "px";
     87 
     88  info("Wait until the rulers dimension tooltip have the proper text");
     89  await asyncWaitUntil(async () => {
     90    const dimensionText =
     91      await highlighterTestFront.getHighlighterNodeTextContent(
     92        `${ID}viewport-infobar-container`,
     93        highlighterFront
     94      );
     95    return dimensionText == windowText;
     96  }, 100);
     97 }
     98 
     99 async function resizeInspector(inspector) {
    100  info(
    101    "Docking the toolbox to the side of the browser to change the window size"
    102  );
    103  const toolbox = inspector.toolbox;
    104  await toolbox.switchHost(Toolbox.HostType.RIGHT);
    105 
    106  // Wait for some time to avoid measuring outdated window dimensions.
    107  await wait(100);
    108 }
    109 
    110 async function isViewportInfobarHidden(highlighterFront, highlighterTestFront) {
    111  const hidden = await highlighterTestFront.getHighlighterNodeAttribute(
    112    `${ID}viewport-infobar-container`,
    113    "hidden",
    114    highlighterFront
    115  );
    116  return hidden === "true";
    117 }