tor-browser

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

browser_html_tooltip_hover.js (1984B)


      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 TooltipToggle helper class for HTMLTooltip
      9 */
     10 
     11 const HTML_NS = "http://www.w3.org/1999/xhtml";
     12 const TEST_URI = CHROME_URL_ROOT + "doc_html_tooltip_hover.xhtml";
     13 
     14 const {
     15  HTMLTooltip,
     16 } = require("resource://devtools/client/shared/widgets/tooltip/HTMLTooltip.js");
     17 loadHelperScript("helper_html_tooltip.js");
     18 
     19 add_task(async function () {
     20  const { doc } = await createHost("bottom", TEST_URI);
     21  // Wait for full page load before synthesizing events on the page.
     22  await waitUntil(() => doc.readyState === "complete");
     23 
     24  const width = 100,
     25    height = 50;
     26  const tooltipContent = doc.createElementNS(HTML_NS, "div");
     27  tooltipContent.textContent = "tooltip";
     28  const tooltip = new HTMLTooltip(doc, { useXulWrapper: false });
     29  tooltip.panel.appendChild(tooltipContent);
     30  tooltip.setContentSize({ width, height });
     31 
     32  const container = doc.getElementById("container");
     33  tooltip.startTogglingOnHover(container, () => true);
     34 
     35  info("Hover on each of the 4 boxes, expect the tooltip to appear");
     36  async function showAndCheck(boxId, position) {
     37    info(`Show tooltip on ${boxId}`);
     38    const box = doc.getElementById(boxId);
     39    const shown = tooltip.once("shown");
     40    EventUtils.synthesizeMouseAtCenter(
     41      box,
     42      { type: "mousemove" },
     43      doc.defaultView
     44    );
     45    await shown;
     46    checkTooltipGeometry(tooltip, box, { position, width, height });
     47  }
     48 
     49  await showAndCheck("box1", "bottom");
     50  await showAndCheck("box2", "bottom");
     51  await showAndCheck("box3", "top");
     52  await showAndCheck("box4", "top");
     53 
     54  info("Move out of the container");
     55  const hidden = tooltip.once("hidden");
     56  EventUtils.synthesizeMouseAtCenter(
     57    container,
     58    { type: "mousemove" },
     59    doc.defaultView
     60  );
     61  await hidden;
     62 
     63  info("Destroy the tooltip and finish");
     64  tooltip.destroy();
     65 });