tor-browser

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

browser_inspector_highlighter-measure_02.js (3988B)


      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 SIDES = ["top", "right", "bottom", "left"];
     23 
     24 const X = 32;
     25 const Y = 20;
     26 const WIDTH = 160;
     27 const HEIGHT = 100;
     28 const HYPOTENUSE = Math.hypot(WIDTH, HEIGHT).toFixed(2);
     29 
     30 add_task(async function () {
     31  const helper = await openInspectorForURL(TEST_URL).then(
     32    getHighlighterHelperFor(HIGHLIGHTER_TYPE)
     33  );
     34 
     35  const { show, finalize } = helper;
     36 
     37  helper.prefix = PREFIX;
     38 
     39  await show();
     40 
     41  await hasNoLabelsWhenStarts(helper);
     42  await hasSizeLabelWhenMoved(helper);
     43  await hasCorrectSizeLabelValue(helper);
     44  await hasSizeLabelAndGuidesWhenStops(helper);
     45  await hasCorrectSizeLabelValue(helper);
     46 
     47  await finalize();
     48 });
     49 
     50 async function hasNoLabelsWhenStarts({ isElementHidden, synthesizeMouse }) {
     51  info("Checking highlighter has no labels when we start to select");
     52 
     53  await synthesizeMouse({
     54    selector: ":root",
     55    options: { type: "mousedown" },
     56    x: X,
     57    y: Y,
     58  });
     59 
     60  let hidden = await isElementHidden("label-size");
     61  ok(hidden, "label's size still hidden");
     62 
     63  hidden = await isElementHidden("label-position");
     64  ok(hidden, "label's position still hidden");
     65 
     66  info("Checking highlighter has no guides when we start to select");
     67 
     68  let guidesHidden = true;
     69  for (const side of SIDES) {
     70    guidesHidden = guidesHidden && (await isElementHidden("guide-" + side));
     71  }
     72 
     73  ok(guidesHidden, "guides are hidden during dragging");
     74 }
     75 
     76 async function hasSizeLabelWhenMoved({ isElementHidden, synthesizeMouse }) {
     77  info("Checking highlighter has size label when we select the area");
     78 
     79  await synthesizeMouse({
     80    selector: ":root",
     81    options: { type: "mousemove" },
     82    x: X + WIDTH,
     83    y: Y + HEIGHT,
     84  });
     85 
     86  let hidden = await isElementHidden("label-size");
     87  is(hidden, false, "label's size is visible during selection");
     88 
     89  hidden = await isElementHidden("label-position");
     90  ok(hidden, "label's position still hidden");
     91 
     92  info("Checking highlighter has no guides when we select the area");
     93 
     94  let guidesHidden = true;
     95  for (const side of SIDES) {
     96    guidesHidden = guidesHidden && (await isElementHidden("guide-" + side));
     97  }
     98 
     99  ok(guidesHidden, "guides are hidden during selection");
    100 }
    101 
    102 async function hasSizeLabelAndGuidesWhenStops({
    103  isElementHidden,
    104  synthesizeMouse,
    105 }) {
    106  info("Checking highlighter has size label and guides when we stop");
    107 
    108  await synthesizeMouse({
    109    selector: ":root",
    110    options: { type: "mouseup" },
    111    x: X + WIDTH,
    112    y: Y + HEIGHT,
    113  });
    114 
    115  let hidden = await isElementHidden("label-size");
    116  is(hidden, false, "label's size is visible when the selection is done");
    117 
    118  hidden = await isElementHidden("label-position");
    119  ok(hidden, "label's position still hidden");
    120 
    121  let guidesVisible = true;
    122  for (const side of SIDES) {
    123    guidesVisible = guidesVisible && !(await isElementHidden("guide-" + side));
    124  }
    125 
    126  ok(guidesVisible, "guides are visible when the selection is done");
    127 }
    128 
    129 async function hasCorrectSizeLabelValue({ getElementTextContent }) {
    130  const text = await getElementTextContent("label-size");
    131 
    132  const [width, height, hypot] = text.match(/\d.*px/g);
    133 
    134  is(parseFloat(width), WIDTH, "width on label's size is correct");
    135  is(parseFloat(height), HEIGHT, "height on label's size is correct");
    136  is(
    137    parseFloat(hypot),
    138    parseFloat(HYPOTENUSE),
    139    "hypotenuse on label's size is correct"
    140  );
    141 }