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