browser_html_tooltip_doorhanger-01.js (2340B)
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 "doorhanger" type's hang direction. It should hang 9 * along the flow of text e.g. in RTL mode it should hang left and in LTR mode 10 * it should hang right. 11 */ 12 13 const HTML_NS = "http://www.w3.org/1999/xhtml"; 14 const TEST_URI = CHROME_URL_ROOT + "doc_html_tooltip_doorhanger-01.xhtml"; 15 16 const { 17 HTMLTooltip, 18 } = require("resource://devtools/client/shared/widgets/tooltip/HTMLTooltip.js"); 19 loadHelperScript("helper_html_tooltip.js"); 20 21 let useXulWrapper; 22 23 add_task(async function () { 24 // Force the toolbox to be 200px high; 25 await pushPref("devtools.toolbox.footer.height", 200); 26 27 await addTab("about:blank"); 28 const { doc } = await createHost("bottom", TEST_URI); 29 30 info("Run tests for a Tooltip without using a XUL panel"); 31 useXulWrapper = false; 32 await runTests(doc); 33 }); 34 35 async function runTests(doc) { 36 info("Create HTML tooltip"); 37 const tooltip = new HTMLTooltip(doc, { type: "doorhanger", useXulWrapper }); 38 const div = doc.createElementNS(HTML_NS, "div"); 39 div.style.width = "200px"; 40 div.style.height = "35px"; 41 tooltip.panel.appendChild(div); 42 43 const anchors = [...doc.querySelectorAll(".anchor")]; 44 for (const anchor of anchors) { 45 const hangDirection = anchor.getAttribute("data-hang"); 46 47 info("Display the tooltip on an anchor."); 48 await showTooltip(tooltip, anchor); 49 50 const arrow = tooltip.arrow; 51 ok(arrow, "Tooltip has an arrow"); 52 53 // Get the geometry of the the tooltip panel & arrow. 54 const panelBounds = tooltip.panel 55 .getBoxQuads({ relativeTo: doc })[0] 56 .getBounds(); 57 const arrowBounds = arrow.getBoxQuads({ relativeTo: doc })[0].getBounds(); 58 const panelBoundsCentre = (panelBounds.left + panelBounds.right) / 2; 59 const arrowCentre = (arrowBounds.left + arrowBounds.right) / 2; 60 61 if (hangDirection === "left") { 62 Assert.greater( 63 arrowCentre, 64 panelBoundsCentre, 65 `tooltip hangs to the left for ${anchor.id}` 66 ); 67 } else { 68 Assert.less( 69 arrowCentre, 70 panelBoundsCentre, 71 `tooltip hangs to the right for ${anchor.id}` 72 ); 73 } 74 75 await hideTooltip(tooltip); 76 } 77 78 tooltip.destroy(); 79 }