browser_html_tooltip_arrow-01.js (2604B)
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 "arrow" type on small anchors. The arrow should remain 9 * aligned with the anchors as much as possible 10 */ 11 12 const HTML_NS = "http://www.w3.org/1999/xhtml"; 13 const TEST_URI = CHROME_URL_ROOT + "doc_html_tooltip_arrow-01.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 // Force the toolbox to be 200px high; 24 await pushPref("devtools.toolbox.footer.height", 200); 25 26 await addTab("about:blank"); 27 const { doc } = await createHost("bottom", TEST_URI); 28 29 info("Run tests for a Tooltip without using a XUL panel"); 30 useXulWrapper = false; 31 await runTests(doc); 32 33 info("Run tests for a Tooltip with a XUL panel"); 34 useXulWrapper = true; 35 await runTests(doc); 36 }); 37 38 async function runTests(doc) { 39 info("Create HTML tooltip"); 40 const tooltip = new HTMLTooltip(doc, { type: "arrow", useXulWrapper }); 41 const div = doc.createElementNS(HTML_NS, "div"); 42 div.style.height = "35px"; 43 tooltip.panel.appendChild(div); 44 tooltip.setContentSize({ width: 200, height: 35 }); 45 46 const { right: docRight } = doc.documentElement.getBoundingClientRect(); 47 48 const elements = [...doc.querySelectorAll(".anchor")]; 49 for (const el of elements) { 50 info("Display the tooltip on an anchor."); 51 await showTooltip(tooltip, el); 52 53 const arrow = tooltip.arrow; 54 ok(arrow, "Tooltip has an arrow"); 55 56 // Get the geometry of the anchor, the tooltip panel & arrow. 57 const arrowBounds = arrow.getBoxQuads({ relativeTo: doc })[0].getBounds(); 58 const panelBounds = tooltip.panel 59 .getBoxQuads({ relativeTo: doc })[0] 60 .getBounds(); 61 const anchorBounds = el.getBoxQuads({ relativeTo: doc })[0].getBounds(); 62 63 const intersects = 64 arrowBounds.left <= anchorBounds.right && 65 arrowBounds.right >= anchorBounds.left; 66 const isBlockedByViewport = 67 arrowBounds.left == 0 || arrowBounds.right == docRight; 68 ok( 69 intersects || isBlockedByViewport, 70 "Tooltip arrow is aligned with the anchor, or stuck on viewport's edge." 71 ); 72 73 const isInPanel = 74 arrowBounds.left >= panelBounds.left && 75 arrowBounds.right <= panelBounds.right; 76 77 ok( 78 isInPanel, 79 "The tooltip arrow remains inside the tooltip panel horizontally" 80 ); 81 82 await hideTooltip(tooltip); 83 } 84 85 tooltip.destroy(); 86 }