browser_html_tooltip-01.js (2044B)
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 show & hide methods. 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 function getTooltipContent(doc) { 22 const div = doc.createElementNS(HTML_NS, "div"); 23 div.style.height = "50px"; 24 div.style.boxSizing = "border-box"; 25 div.textContent = "tooltip"; 26 return div; 27 } 28 29 add_task(async function () { 30 const { doc } = await createHost("bottom", TEST_URI); 31 32 info("Run tests for a Tooltip without using a XUL panel"); 33 useXulWrapper = false; 34 await runTests(doc); 35 36 info("Run tests for a Tooltip with a XUL panel"); 37 useXulWrapper = true; 38 await runTests(doc); 39 }); 40 41 async function runTests(doc) { 42 const tooltip = new HTMLTooltip(doc, { useXulWrapper }); 43 44 info("Set tooltip content"); 45 tooltip.panel.appendChild(getTooltipContent(doc)); 46 tooltip.setContentSize({ width: 100, height: 50 }); 47 48 is(tooltip.isVisible(), false, "Tooltip is not visible"); 49 50 info("Show the tooltip and check the expected events are fired."); 51 52 let shown = 0; 53 tooltip.on("shown", () => shown++); 54 55 const onShown = tooltip.once("shown"); 56 tooltip.show(doc.getElementById("box1")); 57 await onShown; 58 is(shown, 1, "Event shown was fired once"); 59 60 await waitForReflow(tooltip); 61 is(tooltip.isVisible(), true, "Tooltip is visible"); 62 63 info("Hide the tooltip and check the expected events are fired."); 64 65 let hidden = 0; 66 tooltip.on("hidden", () => hidden++); 67 68 const onPopupHidden = tooltip.once("hidden"); 69 tooltip.hide(); 70 71 await onPopupHidden; 72 is(hidden, 1, "Event hidden was fired once"); 73 74 await waitForReflow(tooltip); 75 is(tooltip.isVisible(), false, "Tooltip is not visible"); 76 77 tooltip.destroy(); 78 }