tor-browser

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

browser_html_tooltip_zoom.js (2304B)


      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 is displayed correct position if content is zoomed in.
      9 */
     10 
     11 const HTML_NS = "http://www.w3.org/1999/xhtml";
     12 const TEST_URI = CHROME_URL_ROOT + "doc_html_tooltip.xhtml";
     13 
     14 const {
     15  HTMLTooltip,
     16 } = require("resource://devtools/client/shared/widgets/tooltip/HTMLTooltip.js");
     17 
     18 function getTooltipContent(doc) {
     19  const div = doc.createElementNS(HTML_NS, "div");
     20  div.style.height = "50px";
     21  div.style.boxSizing = "border-box";
     22  div.style.backgroundColor = "red";
     23  div.textContent = "tooltip";
     24  return div;
     25 }
     26 
     27 add_task(async function () {
     28  const { host, doc } = await createHost("window", TEST_URI);
     29 
     30  // Creating a window host is not correctly waiting when DevTools run in content frame
     31  // See Bug 1571421.
     32  await wait(1000);
     33 
     34  const zoom = 1.5;
     35  await pushPref("devtools.toolbox.zoomValue", zoom.toString(10));
     36 
     37  // Change this xul zoom to the x1.5 since this test doesn't use the toolbox preferences.
     38  host.frame.docShell.browsingContext.fullZoom = zoom;
     39  const tooltip = new HTMLTooltip(doc, { useXulWrapper: true });
     40 
     41  info("Set tooltip content");
     42  tooltip.panel.appendChild(getTooltipContent(doc));
     43  tooltip.setContentSize({ width: 100, height: 50 });
     44 
     45  is(tooltip.isVisible(), false, "Tooltip is not visible");
     46 
     47  info("Show the tooltip and check the expected events are fired.");
     48  const onShown = tooltip.once("shown");
     49  tooltip.show(doc.getElementById("box1"));
     50  await onShown;
     51 
     52  const menuRect = doc
     53    .querySelector(".tooltip-xul-wrapper > .tooltip-container")
     54    .getBoxQuads({ relativeTo: doc })[0]
     55    .getBounds();
     56  const anchorRect = doc
     57    .getElementById("box1")
     58    .getBoxQuads({ relativeTo: doc })[0]
     59    .getBounds();
     60  const xDelta = Math.abs(menuRect.left - anchorRect.left);
     61  const yDelta = Math.abs(menuRect.top - anchorRect.bottom);
     62 
     63  Assert.less(xDelta, 1, "xDelta: " + xDelta + ".");
     64  Assert.less(yDelta, 1, "yDelta: " + yDelta + ".");
     65 
     66  info("Hide the tooltip and check the expected events are fired.");
     67 
     68  const onPopupHidden = tooltip.once("hidden");
     69  tooltip.hide();
     70  await onPopupHidden;
     71 
     72  tooltip.destroy();
     73  await host.destroy();
     74 });