tor-browser

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

browser_html_tooltip_arrow-02.js (2570B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 /* import-globals-from helper_html_tooltip.js */
      4 
      5 "use strict";
      6 
      7 /**
      8 * Test the HTMLTooltip "arrow" type on wide anchors. The arrow should remain
      9 * aligned with the anchors as much as possible
     10 */
     11 
     12 const HTML_NS = "http://www.w3.org/1999/xhtml";
     13 const TEST_URI = CHROME_URL_ROOT + "doc_html_tooltip_arrow-02.xhtml";
     14 
     15 const {
     16  HTMLTooltip,
     17 } = require("resource://devtools/client/shared/widgets/tooltip/HTMLTooltip.js");
     18 loadHelperScript("helper_html_tooltip.js");
     19 
     20 let useXulWrapper;
     21 
     22 add_task(async function () {
     23  // Force the toolbox to be 200px high;
     24  await pushPref("devtools.toolbox.footer.height", 200);
     25 
     26  const { doc } = await createHost("bottom", TEST_URI);
     27 
     28  info("Run tests for a Tooltip without using a XUL panel");
     29  useXulWrapper = false;
     30  await runTests(doc);
     31 
     32  info("Run tests for a Tooltip with a XUL panel");
     33  useXulWrapper = true;
     34  await runTests(doc);
     35 });
     36 
     37 async function runTests(doc) {
     38  info("Create HTML tooltip");
     39  const tooltip = new HTMLTooltip(doc, { type: "arrow", useXulWrapper });
     40  const div = doc.createElementNS(HTML_NS, "div");
     41  div.style.height = "35px";
     42  tooltip.panel.appendChild(div);
     43  tooltip.setContentSize({ width: 200, height: 35 });
     44 
     45  const { right: docRight } = doc.documentElement.getBoundingClientRect();
     46 
     47  const elements = [...doc.querySelectorAll(".anchor")];
     48  for (const el of elements) {
     49    info("Display the tooltip on an anchor.");
     50    await showTooltip(tooltip, el);
     51 
     52    const arrow = tooltip.arrow;
     53    ok(arrow, "Tooltip has an arrow");
     54 
     55    // Get the geometry of the anchor, the tooltip panel & arrow.
     56    const arrowBounds = arrow.getBoxQuads({ relativeTo: doc })[0].getBounds();
     57    const panelBounds = tooltip.panel
     58      .getBoxQuads({ relativeTo: doc })[0]
     59      .getBounds();
     60    const anchorBounds = el.getBoxQuads({ relativeTo: doc })[0].getBounds();
     61 
     62    const intersects =
     63      arrowBounds.left <= anchorBounds.right &&
     64      arrowBounds.right >= anchorBounds.left;
     65    const isBlockedByViewport =
     66      arrowBounds.left == 0 || arrowBounds.right == docRight;
     67    ok(
     68      intersects || isBlockedByViewport,
     69      "Tooltip arrow is aligned with the anchor, or stuck on viewport's edge."
     70    );
     71 
     72    const isInPanel =
     73      arrowBounds.left >= panelBounds.left &&
     74      arrowBounds.right <= panelBounds.right;
     75    ok(
     76      isInPanel,
     77      "The tooltip arrow remains inside the tooltip panel horizontally"
     78    );
     79    await hideTooltip(tooltip);
     80  }
     81 
     82  tooltip.destroy();
     83 }