browser_html_tooltip_screen_edge.js (2349B)
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 "doorhanger" when the anchor is near the edge of the 9 * screen and uses a XUL wrapper. The XUL panel cannot be displayed off screen 10 * at all so this verifies that the calculated position of the tooltip always 11 * ensure that the whole tooltip is rendered on the screen 12 * 13 * See Bug 1590408 14 */ 15 16 const HTML_NS = "http://www.w3.org/1999/xhtml"; 17 const TEST_URI = CHROME_URL_ROOT + "doc_html_tooltip_doorhanger-01.xhtml"; 18 19 const { 20 HTMLTooltip, 21 } = require("resource://devtools/client/shared/widgets/tooltip/HTMLTooltip.js"); 22 loadHelperScript("helper_html_tooltip.js"); 23 24 add_task(async function () { 25 // Force the toolbox to be 200px high; 26 await pushPref("devtools.toolbox.footer.height", 200); 27 28 const { win, doc } = await createHost("bottom", TEST_URI); 29 30 const originalTop = win.screenTop; 31 const originalLeft = win.screenLeft; 32 const screenWidth = win.screen.width; 33 await moveWindowTo(win, screenWidth - win.outerWidth, originalTop); 34 35 registerCleanupFunction(async () => { 36 info(`Restore original window position. ${originalLeft}, ${originalTop}`); 37 await moveWindowTo(win, originalLeft, originalTop); 38 }); 39 40 info("Create a doorhanger HTML tooltip with XULPanel"); 41 const tooltip = new HTMLTooltip(doc, { 42 type: "doorhanger", 43 useXulWrapper: true, 44 }); 45 const div = doc.createElementNS(HTML_NS, "div"); 46 div.style.width = "200px"; 47 div.style.height = "35px"; 48 tooltip.panel.appendChild(div); 49 50 const anchor = doc.querySelector("#anchor5"); 51 52 info("Display the tooltip on an anchor."); 53 await showTooltip(tooltip, anchor); 54 55 const arrow = tooltip.arrow; 56 ok(arrow, "Tooltip has an arrow"); 57 58 const panelBounds = tooltip.panel 59 .getBoxQuads({ relativeTo: doc })[0] 60 .getBounds(); 61 62 const anchorBounds = anchor.getBoxQuads({ relativeTo: doc })[0].getBounds(); 63 ok( 64 anchorBounds.left < panelBounds.right && 65 panelBounds.left < anchorBounds.right, 66 `The tooltip panel is over (ie intersects) the anchor horizontally: ` + 67 `${anchorBounds.left} < ${panelBounds.right} and ` + 68 `${panelBounds.left} < ${anchorBounds.right}` 69 ); 70 71 await hideTooltip(tooltip); 72 73 tooltip.destroy(); 74 });