browser_html_tooltip_width-auto.js (1635B)
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 content can automatically calculate its width based on content. 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 loadHelperScript("helper_html_tooltip.js"); 18 19 let useXulWrapper; 20 21 add_task(async function () { 22 await addTab("about:blank"); 23 const { doc } = await createHost("bottom", TEST_URI); 24 25 info("Run tests for a Tooltip without using a XUL panel"); 26 useXulWrapper = false; 27 await runTests(doc); 28 29 info("Run tests for a Tooltip with a XUL panel"); 30 useXulWrapper = true; 31 await runTests(doc); 32 }); 33 34 async function runTests(doc) { 35 const tooltip = new HTMLTooltip(doc, { useXulWrapper }); 36 info("Create tooltip content width to 150px"); 37 const tooltipContent = doc.createElementNS(HTML_NS, "div"); 38 tooltipContent.style.cssText = "height: 100%; width: 150px; background: red;"; 39 40 info("Set tooltip content using width:auto"); 41 tooltip.panel.appendChild(tooltipContent); 42 tooltip.setContentSize({ width: "auto", height: 50 }); 43 44 info("Show the tooltip and check the tooltip panel width."); 45 await showTooltip(tooltip, doc.getElementById("box1")); 46 47 const containerRect = tooltip.container.getBoundingClientRect(); 48 is(containerRect.width, 150, "Tooltip container has the expected width."); 49 50 await hideTooltip(tooltip); 51 52 tooltip.destroy(); 53 }