browser_html_tooltip_height-auto.js (3372B)
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 height based on 9 * content. 10 */ 11 12 const HTML_NS = "http://www.w3.org/1999/xhtml"; 13 const TEST_URI = CHROME_URL_ROOT + "doc_html_tooltip.xhtml"; 14 15 const { 16 HTMLTooltip, 17 } = require("resource://devtools/client/shared/widgets/tooltip/HTMLTooltip.js"); 18 loadHelperScript("helper_html_tooltip.js"); 19 20 let useXulWrapper; 21 22 add_task(async function () { 23 await addTab("about:blank"); 24 const { doc } = await createHost("bottom", TEST_URI); 25 26 info("Run tests for a Tooltip without using a XUL panel"); 27 useXulWrapper = false; 28 await runTests(doc); 29 30 info("Run tests for a Tooltip with a XUL panel"); 31 useXulWrapper = true; 32 await runTests(doc); 33 }); 34 35 async function runTests(doc) { 36 const tooltip = new HTMLTooltip(doc, { useXulWrapper }); 37 info("Create tooltip content height to 150px"); 38 const tooltipContent = doc.createElementNS(HTML_NS, "div"); 39 tooltipContent.style.cssText = 40 "width: 300px; height: 150px; background: red;"; 41 42 info("Set tooltip content using width:auto and height:auto"); 43 tooltip.panel.appendChild(tooltipContent); 44 45 info("Show the tooltip and check the tooltip container dimensions."); 46 await showTooltip(tooltip, doc.getElementById("box1")); 47 48 let panelRect = tooltip.container.getBoundingClientRect(); 49 is(panelRect.width, 300, "Tooltip container has the expected width."); 50 is(panelRect.height, 150, "Tooltip container has the expected height."); 51 52 await hideTooltip(tooltip); 53 54 info("Set tooltip content using fixed width and height:auto"); 55 tooltipContent.style.cssText = "width: auto; height: 160px; background: red;"; 56 tooltip.setContentSize({ width: 400 }); 57 58 info("Show the tooltip and check the tooltip container height."); 59 await showTooltip(tooltip, doc.getElementById("box1")); 60 61 panelRect = tooltip.container.getBoundingClientRect(); 62 is(panelRect.height, 160, "Tooltip container has the expected height."); 63 64 await hideTooltip(tooltip); 65 66 info("Update the height and show the tooltip again"); 67 tooltipContent.style.cssText = "width: auto; height: 165px; background: red;"; 68 69 await showTooltip(tooltip, doc.getElementById("box1")); 70 71 panelRect = tooltip.container.getBoundingClientRect(); 72 is( 73 panelRect.height, 74 165, 75 "Tooltip container has the expected updated height." 76 ); 77 78 await hideTooltip(tooltip); 79 80 info( 81 "Check that refreshing the tooltip when it overflows does keep scroll position" 82 ); 83 // Set the tooltip panel to overflow. Some consumers of the HTMLTooltip are doing that 84 // via CSS (e.g. the iframe dropdown, the context selector, …). 85 tooltip.panel.style.overflowY = "auto"; 86 tooltipContent.style.cssText = 87 "width: auto; height: 3000px; background: tomato;"; 88 await showTooltip(tooltip, doc.getElementById("box1")); 89 90 Assert.greater( 91 tooltip.panel.scrollHeight, 92 tooltip.panel.clientHeight, 93 "Tooltip overflows" 94 ); 95 96 const scrollPosition = 500; 97 tooltip.panel.scrollTop = scrollPosition; 98 99 await showTooltip(tooltip, doc.getElementById("box1")); 100 is( 101 tooltip.panel.scrollTop, 102 scrollPosition, 103 "scroll position was kept during the update" 104 ); 105 await hideTooltip(tooltip); 106 107 tooltip.destroy(); 108 }