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 */
8 * Test the HTMLTooltip "doorhanger" type's arrow tip is precisely centered on
9 * the anchor when the anchor is small.
12 const HTML_NS = "http://www.w3.org/1999/xhtml";
13 const TEST_URI = CHROME_URL_ROOT + "doc_html_tooltip_doorhanger-02.xhtml";
17 } = require("resource://devtools/client/shared/widgets/tooltip/HTMLTooltip.js");
18 loadHelperScript("helper_html_tooltip.js");
22 add_task(async function () {
23 // Force the toolbox to be 200px high;
24 await pushPref("devtools.toolbox.footer.height", 200);
26 await addTab("about:blank");
27 const { doc } = await createHost("bottom", TEST_URI);
29 info("Run tests for a Tooltip without using a XUL panel");
30 useXulWrapper = false;
33 info("Run tests for a Tooltip with a XUL panel");
38 async function runTests(doc) {
39 info("Create HTML tooltip");
40 const tooltip = new HTMLTooltip(doc, { type: "doorhanger", useXulWrapper });
41 const div = doc.createElementNS(HTML_NS, "div");
42 div.style.width = "200px";
43 div.style.height = "35px";
44 tooltip.panel.appendChild(div);
46 const elements = [...doc.querySelectorAll(".anchor")];
47 for (const el of elements) {
48 info("Display the tooltip on an anchor.");
49 await showTooltip(tooltip, el);
51 const arrow = tooltip.arrow;
52 ok(arrow, "Tooltip has an arrow");
54 // Get the geometry of the anchor and arrow.
55 const anchorBounds = el.getBoxQuads({ relativeTo: doc })[0].getBounds();
56 const arrowBounds = arrow.getBoxQuads({ relativeTo: doc })[0].getBounds();
58 // Compare the centers
59 const center = bounds => bounds.left + bounds.width / 2;
60 const delta = Math.abs(center(anchorBounds) - center(arrowBounds));
61 const describeBounds = bounds =>
62 `${bounds.left}<--[${center(bounds)}]-->${bounds.right}`;
64 `anchor: ${describeBounds(anchorBounds)}, ` +
65 `arrow: ${describeBounds(arrowBounds)}`;
69 `Arrow center is roughly aligned with anchor center (${params})`
72 await hideTooltip(tooltip);