tor-browser

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

browser_inspector_highlighter-measure_01.js (2773B)


      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 const TEST_URL = `data:text/html;charset=utf-8,
      8                    <div style='
      9                        position:absolute;
     10                        left: 0;
     11                        top: 0;
     12                        width: 40000px;
     13                        height: 8000px'>
     14                    </div>`;
     15 
     16 const PREFIX = "measuring-tool-";
     17 const { TYPES } = ChromeUtils.importESModule(
     18  "resource://devtools/shared/highlighters.mjs"
     19 );
     20 const HIGHLIGHTER_TYPE = TYPES.MEASURING;
     21 
     22 const X = 32;
     23 const Y = 20;
     24 
     25 add_task(async function () {
     26  const helper = await openInspectorForURL(TEST_URL).then(
     27    getHighlighterHelperFor(HIGHLIGHTER_TYPE)
     28  );
     29 
     30  const { finalize } = helper;
     31 
     32  helper.prefix = PREFIX;
     33 
     34  await isHiddenByDefault(helper);
     35  await areLabelsHiddenByDefaultWhenShows(helper);
     36  await areLabelsProperlyDisplayedWhenMouseMoved(helper);
     37 
     38  await finalize();
     39 });
     40 
     41 async function isHiddenByDefault({ isElementHidden }) {
     42  info("Checking the highlighter is hidden by default");
     43 
     44  let hidden = await isElementHidden("root");
     45  ok(hidden, "highlighter's root is hidden by default");
     46 
     47  hidden = await isElementHidden("label-size");
     48  ok(hidden, "highlighter's label size is hidden by default");
     49 
     50  hidden = await isElementHidden("label-position");
     51  ok(hidden, "highlighter's label position is hidden by default");
     52 }
     53 
     54 async function areLabelsHiddenByDefaultWhenShows({ isElementHidden, show }) {
     55  info("Checking the highlighter is displayed when asked");
     56 
     57  await show();
     58 
     59  let hidden = await isElementHidden("elements");
     60  is(hidden, false, "highlighter is visible after show");
     61 
     62  hidden = await isElementHidden("label-size");
     63  ok(hidden, "label's size still hidden");
     64 
     65  hidden = await isElementHidden("label-position");
     66  ok(hidden, "label's position still hidden");
     67 }
     68 
     69 async function areLabelsProperlyDisplayedWhenMouseMoved({
     70  isElementHidden,
     71  synthesizeMouse,
     72  getElementTextContent,
     73 }) {
     74  info("Checking labels are properly displayed when mouse moved");
     75 
     76  await synthesizeMouse({
     77    selector: ":root",
     78    options: { type: "mousemove" },
     79    x: X,
     80    y: Y,
     81  });
     82 
     83  let hidden = await isElementHidden("label-position");
     84  is(hidden, false, "label's position is displayed after the mouse is moved");
     85 
     86  hidden = await isElementHidden("label-size");
     87  ok(hidden, "label's size still hidden");
     88 
     89  const text = await getElementTextContent("label-position");
     90 
     91  const [x, y] = text.replace(/ /g, "").split(/\n/);
     92 
     93  is(+x, X, "label's position shows the proper X coord");
     94  is(+y, Y, "label's position shows the proper Y coord");
     95 }