diff --git a/devtools/client/shared/test/browser_html_tooltip-02.js b/devtools/client/shared/test/browser_html_tooltip-02.js index ae5daf6e393a..f6e2b2d1350b 100644 --- a/devtools/client/shared/test/browser_html_tooltip-02.js +++ b/devtools/client/shared/test/browser_html_tooltip-02.js @@ -12,13 +12,16 @@ const HTML_NS = "http://www.w3.org/1999/xhtml"; const TEST_URI = `data:text/xml;charset=UTF-8, - + test1 test2 test3 test4 + `; @@ -32,6 +35,7 @@ add_task(function* () { yield testTooltipNotClosingOnInsideClick(doc); yield testConsumeOutsideClicksFalse(doc); yield testConsumeOutsideClicksTrue(doc); + yield testClickInsideIframe(doc); }); function* testTooltipNotClosingOnInsideClick(doc) { @@ -90,6 +94,22 @@ function* testConsumeOutsideClicksTrue(doc) { tooltip.destroy(); } +function* testClickInsideIframe(doc) { + info("Test closing a tooltip via click inside an iframe"); + let frame = doc.getElementById("frame"); + + let tooltip = new HTMLTooltip({doc}); + yield tooltip.setContent(getTooltipContent(doc), 100, 50); + yield showTooltip(tooltip, doc.getElementById("box1")); + + let onHidden = once(tooltip, "hidden"); + EventUtils.synthesizeMouseAtCenter(frame, {}, doc.defaultView); + yield onHidden; + + is(tooltip.isVisible(), false, "Tooltip is hidden"); + tooltip.destroy(); +} + function getTooltipContent(doc) { let div = doc.createElementNS(HTML_NS, "div"); div.style.height = "50px"; diff --git a/devtools/client/shared/widgets/HTMLTooltip.js b/devtools/client/shared/widgets/HTMLTooltip.js index 1de2a91dc4fb..1096f30de04b 100644 --- a/devtools/client/shared/widgets/HTMLTooltip.js +++ b/devtools/client/shared/widgets/HTMLTooltip.js @@ -229,22 +229,27 @@ HTMLTooltip.prototype = { }, _isInTooltipContainer: function (node) { - let contentWindow = this.panel.ownerDocument.defaultView; + let tooltipWindow = this.panel.ownerDocument.defaultView; let win = node.ownerDocument.defaultView; - if (win === contentWindow) { - // If node is in the same window as the tooltip, check if the tooltip - // parent contains node. + if (this.arrow && this.arrow === node) { + return true; + } + + if (win === tooltipWindow) { + // If node is in the same window as the tooltip, check if the tooltip panel + // contains node. return this.panel.contains(node); } - // Otherwise check if the node window is in the tooltip window. + // Otherwise check if the node window is in the tooltip container. while (win.parent && win.parent != win) { win = win.parent; - if (win === contentWindow) { - return true; + if (win === tooltipWindow) { + return this.panel.contains(win.frameElement); } } + return false; },