michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: michael@0: SpecialPowers.setIntPref("ui.tooltipDelay", 0); michael@0: michael@0: let target; michael@0: let doc; michael@0: let win; michael@0: let callbackOnPopupShown; michael@0: let callbackOnPopupHidden; michael@0: let dragService = Components.classes["@mozilla.org/widget/dragservice;1"]. michael@0: getService(Components.interfaces.nsIDragService); michael@0: michael@0: let onPopupHidden = function (aEvent) michael@0: { michael@0: if (aEvent.originalTarget.localName != "tooltip") { michael@0: return; michael@0: } michael@0: if (callbackOnPopupHidden) { michael@0: setTimeout(callbackOnPopupHidden, 0); michael@0: } michael@0: } michael@0: michael@0: let onPopupShown = function (aEvent) michael@0: { michael@0: if (aEvent.originalTarget.localName != "tooltip") { michael@0: return; michael@0: } michael@0: if (callbackOnPopupShown) { michael@0: setTimeout(callbackOnPopupShown, 0); michael@0: } michael@0: } michael@0: michael@0: let finishTest = function () michael@0: { michael@0: document.removeEventListener("popupshown", onPopupShown, true); michael@0: document.removeEventListener("popuphidden", onPopupHidden, true); michael@0: michael@0: SpecialPowers.clearUserPref("ui.tooltipDelay"); michael@0: michael@0: gBrowser.removeCurrentTab(); michael@0: finish(); michael@0: } michael@0: michael@0: let testHideTooltipByMouseDown = function () michael@0: { michael@0: callbackOnPopupShown = function () { michael@0: callbackOnPopupShown = null; michael@0: ok(true, "tooltip is shown before testing mousedown"); michael@0: michael@0: // hide tooltip by mousemove to outside. michael@0: callbackOnPopupHidden = function () { michael@0: callbackOnPopupHidden = null; michael@0: ok(true, "The tooltip is hidden by mousedown"); michael@0: michael@0: EventUtils.synthesizeMouse(target, 5, 15, { type: "mouseup" }, win); michael@0: EventUtils.synthesizeMouse(target, -5, 15, { type: "mousemove" }, win); michael@0: michael@0: setTimeout(finishTest, 0); michael@0: } michael@0: EventUtils.synthesizeMouse(target, 5, 15, { type: "mousedown" }, win); michael@0: } michael@0: EventUtils.synthesizeMouse(target, 5, 15, { type: "mousemove" }, win); michael@0: } michael@0: michael@0: let testShowTooltipAgain = function () michael@0: { michael@0: // If tooltip listener used a flag for managing D&D state, we would need michael@0: // to test if the tooltip is shown after drag. michael@0: callbackOnPopupShown = function () { michael@0: callbackOnPopupShown = null; michael@0: ok(true, "tooltip is shown after drag"); michael@0: michael@0: // hide tooltip by mousemove to outside. michael@0: callbackOnPopupHidden = function () { michael@0: callbackOnPopupHidden = null; michael@0: ok(true, "The tooltip is hidden again"); michael@0: michael@0: setTimeout(testHideTooltipByMouseDown, 0); michael@0: } michael@0: EventUtils.synthesizeMouse(target, -5, 15, { type: "mousemove" }, win); michael@0: } michael@0: EventUtils.synthesizeMouse(target, 5, 15, { type: "mousemove" }, win); michael@0: } michael@0: michael@0: let testDuringDnD = function () michael@0: { michael@0: // mousemove into the target and start drag by emulation via nsIDragService. michael@0: // Note that on some platforms, we cannot actually start the drag by michael@0: // synthesized events. E.g., Windows waits an actual mousemove event after michael@0: // dragstart. michael@0: callbackOnPopupShown = function () { michael@0: callbackOnPopupShown = null; michael@0: ok(false, "tooltip is shown during drag"); michael@0: } michael@0: dragService.startDragSession(); michael@0: // Emulate a buggy mousemove event. widget might dispatch mousemove event michael@0: // during drag. michael@0: EventUtils.synthesizeMouse(target, 5, 15, { type: "mousemove" }, win); michael@0: setTimeout(function () { michael@0: callbackOnPopupShown = null; michael@0: ok(true, "tooltip isn't shown during drag"); michael@0: dragService.endDragSession(true); michael@0: EventUtils.synthesizeMouse(target, -5, -5, { type: "mousemove" }, win); michael@0: michael@0: setTimeout(testShowTooltipAgain, 0); michael@0: }, 100); michael@0: } michael@0: michael@0: let onLoad = function (aEvent) michael@0: { michael@0: doc = gBrowser.contentDocument; michael@0: win = gBrowser.contentWindow; michael@0: target = doc.getElementById("target"); michael@0: michael@0: document.addEventListener("popupshown", onPopupShown, true); michael@0: document.addEventListener("popuphidden", onPopupHidden, true); michael@0: michael@0: EventUtils.synthesizeMouse(target, -5, -5, { type: "mousemove" }, win); michael@0: michael@0: // show tooltip by mousemove into target. michael@0: callbackOnPopupShown = function () michael@0: { michael@0: callbackOnPopupShown = null; michael@0: ok(true, "The tooltip is shown"); michael@0: michael@0: // hide tooltip by mousemove to outside. michael@0: callbackOnPopupHidden = function () { michael@0: callbackOnPopupHidden = null; michael@0: ok(true, "The tooltip is hidden"); michael@0: michael@0: setTimeout(testDuringDnD, 0); michael@0: } michael@0: EventUtils.synthesizeMouse(target, -5, 15, { type: "mousemove" }, win); michael@0: } michael@0: EventUtils.synthesizeMouse(target, 5, 15, { type: "mousemove" }, win); michael@0: } michael@0: michael@0: gBrowser.selectedBrowser.addEventListener("load", michael@0: function () { michael@0: gBrowser.selectedBrowser. michael@0: removeEventListener("load", arguments.callee, true); michael@0: setTimeout(onLoad, 0); michael@0: }, true); michael@0: michael@0: content.location = "data:text/html," + michael@0: "here is an anchor element"; michael@0: } michael@0: michael@0: michael@0: