browser_html_tooltip-04.js (3721B)
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 positioning for a small tooltip element (should aways 9 * find a way to fit). 10 */ 11 12 const HTML_NS = "http://www.w3.org/1999/xhtml"; 13 const TEST_URI = CHROME_URL_ROOT + "doc_html_tooltip-04.xhtml"; 14 15 const { 16 HTMLTooltip, 17 } = require("resource://devtools/client/shared/widgets/tooltip/HTMLTooltip.js"); 18 loadHelperScript("helper_html_tooltip.js"); 19 20 const TOOLTIP_HEIGHT = 30; 21 const TOOLTIP_WIDTH = 100; 22 23 add_task(async function () { 24 // Force the toolbox to be 400px high; 25 await pushPref("devtools.toolbox.footer.height", 400); 26 27 await addTab("about:blank"); 28 const { doc } = await createHost("bottom", TEST_URI); 29 30 info("Create HTML tooltip"); 31 const tooltip = new HTMLTooltip(doc, { useXulWrapper: false }); 32 const div = doc.createElementNS(HTML_NS, "div"); 33 div.style.height = "100%"; 34 tooltip.panel.appendChild(div); 35 tooltip.setContentSize({ width: TOOLTIP_WIDTH, height: TOOLTIP_HEIGHT }); 36 37 const box1 = doc.getElementById("box1"); 38 const box2 = doc.getElementById("box2"); 39 const box3 = doc.getElementById("box3"); 40 const box4 = doc.getElementById("box4"); 41 const height = TOOLTIP_HEIGHT, 42 width = TOOLTIP_WIDTH; 43 44 // box1: Can only fit below box1 45 info("Display the tooltip on box1."); 46 await showTooltip(tooltip, box1); 47 let expectedTooltipGeometry = { position: "bottom", height, width }; 48 checkTooltipGeometry(tooltip, box1, expectedTooltipGeometry); 49 await hideTooltip(tooltip); 50 51 info("Try to display the tooltip on top of box1."); 52 await showTooltip(tooltip, box1, { position: "top" }); 53 expectedTooltipGeometry = { position: "bottom", height, width }; 54 checkTooltipGeometry(tooltip, box1, expectedTooltipGeometry); 55 await hideTooltip(tooltip); 56 57 // box2: Can fit above or below, will default to bottom, more height 58 // available. 59 info("Try to display the tooltip on box2."); 60 await showTooltip(tooltip, box2); 61 expectedTooltipGeometry = { position: "bottom", height, width }; 62 checkTooltipGeometry(tooltip, box2, expectedTooltipGeometry); 63 await hideTooltip(tooltip); 64 65 info("Try to display the tooltip on top of box2."); 66 await showTooltip(tooltip, box2, { position: "top" }); 67 expectedTooltipGeometry = { position: "top", height, width }; 68 checkTooltipGeometry(tooltip, box2, expectedTooltipGeometry); 69 await hideTooltip(tooltip); 70 71 // box3: Can fit above or below, will default to top, more height available. 72 info("Try to display the tooltip on box3."); 73 await showTooltip(tooltip, box3); 74 expectedTooltipGeometry = { position: "top", height, width }; 75 checkTooltipGeometry(tooltip, box3, expectedTooltipGeometry); 76 await hideTooltip(tooltip); 77 78 info("Try to display the tooltip on bottom of box3."); 79 await showTooltip(tooltip, box3, { position: "bottom" }); 80 expectedTooltipGeometry = { position: "bottom", height, width }; 81 checkTooltipGeometry(tooltip, box3, expectedTooltipGeometry); 82 await hideTooltip(tooltip); 83 84 // box4: Can only fit above box4 85 info("Display the tooltip on box4."); 86 await showTooltip(tooltip, box4); 87 expectedTooltipGeometry = { position: "top", height, width }; 88 checkTooltipGeometry(tooltip, box4, expectedTooltipGeometry); 89 await hideTooltip(tooltip); 90 91 info("Try to display the tooltip on bottom of box4."); 92 await showTooltip(tooltip, box4, { position: "bottom" }); 93 expectedTooltipGeometry = { position: "top", height, width }; 94 checkTooltipGeometry(tooltip, box4, expectedTooltipGeometry); 95 await hideTooltip(tooltip); 96 97 is(tooltip.isVisible(), false, "Tooltip is not visible"); 98 99 tooltip.destroy(); 100 });