tor-browser

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

browser_inspector_highlighter-geometry_04.js (2866B)


      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 /* Globals defined in: devtools/client/inspector/test/head.js */
      6 
      7 "use strict";
      8 
      9 // Test that the arrows and handlers are positioned correctly and have the right
     10 // size.
     11 
     12 const TEST_URL = URL_ROOT + "doc_inspector_highlighter-geometry_01.html";
     13 const ID = "geometry-editor-";
     14 const { TYPES } = ChromeUtils.importESModule(
     15  "resource://devtools/shared/highlighters.mjs"
     16 );
     17 const HIGHLIGHTER_TYPE = TYPES.GEOMETRY;
     18 
     19 const handlerMap = {
     20  top: { cx: "x2", cy: "y2" },
     21  bottom: { cx: "x2", cy: "y2" },
     22  left: { cx: "x2", cy: "y2" },
     23  right: { cx: "x2", cy: "y2" },
     24 };
     25 
     26 add_task(async function () {
     27  const helper = await openInspectorForURL(TEST_URL).then(
     28    getHighlighterHelperFor(HIGHLIGHTER_TYPE)
     29  );
     30 
     31  helper.prefix = ID;
     32 
     33  const { hide, finalize } = helper;
     34 
     35  await checkArrowsAndHandlers(helper, ".absolute-all-4", {
     36    top: { x1: 506, y1: 51, x2: 506, y2: 61 },
     37    bottom: { x1: 506, y1: 451, x2: 506, y2: 251 },
     38    left: { x1: 401, y1: 156, x2: 411, y2: 156 },
     39    right: { x1: 901, y1: 156, x2: 601, y2: 156 },
     40  });
     41 
     42  await checkArrowsAndHandlers(helper, ".relative", {
     43    top: { x1: 901, y1: 51, x2: 901, y2: 91 },
     44    left: { x1: 401, y1: 97, x2: 651, y2: 97 },
     45  });
     46 
     47  await checkArrowsAndHandlers(helper, ".fixed", {
     48    top: { x1: 25, y1: 0, x2: 25, y2: 400 },
     49    left: { x1: 0, y1: 425, x2: 0, y2: 425 },
     50  });
     51 
     52  info("Hiding the highlighter");
     53  await hide();
     54  await finalize();
     55 });
     56 
     57 async function checkArrowsAndHandlers(helper, selector, arrows) {
     58  info("Highlighting the test node " + selector);
     59 
     60  await helper.show(selector);
     61 
     62  for (const side in arrows) {
     63    await checkArrowAndHandler(helper, side, arrows[side]);
     64  }
     65 }
     66 
     67 async function checkArrowAndHandler(
     68  { getElementAttribute },
     69  name,
     70  expectedCoords
     71 ) {
     72  info("Checking " + name + "arrow and handler coordinates are correct");
     73 
     74  const handlerX = await getElementAttribute("handler-" + name, "cx");
     75  const handlerY = await getElementAttribute("handler-" + name, "cy");
     76 
     77  const expectedHandlerX = await getElementAttribute(
     78    "arrow-" + name,
     79    handlerMap[name].cx
     80  );
     81  const expectedHandlerY = await getElementAttribute(
     82    "arrow-" + name,
     83    handlerMap[name].cy
     84  );
     85 
     86  is(
     87    handlerX,
     88    expectedHandlerX,
     89    "coordinate X for handler " + name + " is correct."
     90  );
     91  is(
     92    handlerY,
     93    expectedHandlerY,
     94    "coordinate Y for handler " + name + " is correct."
     95  );
     96 
     97  for (const coordinate in expectedCoords) {
     98    const value = await getElementAttribute("arrow-" + name, coordinate);
     99 
    100    is(
    101      Math.floor(value),
    102      expectedCoords[coordinate],
    103      coordinate + " coordinate for arrow " + name + " is correct"
    104    );
    105  }
    106 }