Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | function test() { |
michael@0 | 2 | waitForExplicitFinish(); |
michael@0 | 3 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 4 | |
michael@0 | 5 | SpecialPowers.setIntPref("ui.tooltipDelay", 0); |
michael@0 | 6 | |
michael@0 | 7 | let target; |
michael@0 | 8 | let doc; |
michael@0 | 9 | let win; |
michael@0 | 10 | let callbackOnPopupShown; |
michael@0 | 11 | let callbackOnPopupHidden; |
michael@0 | 12 | let dragService = Components.classes["@mozilla.org/widget/dragservice;1"]. |
michael@0 | 13 | getService(Components.interfaces.nsIDragService); |
michael@0 | 14 | |
michael@0 | 15 | let onPopupHidden = function (aEvent) |
michael@0 | 16 | { |
michael@0 | 17 | if (aEvent.originalTarget.localName != "tooltip") { |
michael@0 | 18 | return; |
michael@0 | 19 | } |
michael@0 | 20 | if (callbackOnPopupHidden) { |
michael@0 | 21 | setTimeout(callbackOnPopupHidden, 0); |
michael@0 | 22 | } |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | let onPopupShown = function (aEvent) |
michael@0 | 26 | { |
michael@0 | 27 | if (aEvent.originalTarget.localName != "tooltip") { |
michael@0 | 28 | return; |
michael@0 | 29 | } |
michael@0 | 30 | if (callbackOnPopupShown) { |
michael@0 | 31 | setTimeout(callbackOnPopupShown, 0); |
michael@0 | 32 | } |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | let finishTest = function () |
michael@0 | 36 | { |
michael@0 | 37 | document.removeEventListener("popupshown", onPopupShown, true); |
michael@0 | 38 | document.removeEventListener("popuphidden", onPopupHidden, true); |
michael@0 | 39 | |
michael@0 | 40 | SpecialPowers.clearUserPref("ui.tooltipDelay"); |
michael@0 | 41 | |
michael@0 | 42 | gBrowser.removeCurrentTab(); |
michael@0 | 43 | finish(); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | let testHideTooltipByMouseDown = function () |
michael@0 | 47 | { |
michael@0 | 48 | callbackOnPopupShown = function () { |
michael@0 | 49 | callbackOnPopupShown = null; |
michael@0 | 50 | ok(true, "tooltip is shown before testing mousedown"); |
michael@0 | 51 | |
michael@0 | 52 | // hide tooltip by mousemove to outside. |
michael@0 | 53 | callbackOnPopupHidden = function () { |
michael@0 | 54 | callbackOnPopupHidden = null; |
michael@0 | 55 | ok(true, "The tooltip is hidden by mousedown"); |
michael@0 | 56 | |
michael@0 | 57 | EventUtils.synthesizeMouse(target, 5, 15, { type: "mouseup" }, win); |
michael@0 | 58 | EventUtils.synthesizeMouse(target, -5, 15, { type: "mousemove" }, win); |
michael@0 | 59 | |
michael@0 | 60 | setTimeout(finishTest, 0); |
michael@0 | 61 | } |
michael@0 | 62 | EventUtils.synthesizeMouse(target, 5, 15, { type: "mousedown" }, win); |
michael@0 | 63 | } |
michael@0 | 64 | EventUtils.synthesizeMouse(target, 5, 15, { type: "mousemove" }, win); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | let testShowTooltipAgain = function () |
michael@0 | 68 | { |
michael@0 | 69 | // If tooltip listener used a flag for managing D&D state, we would need |
michael@0 | 70 | // to test if the tooltip is shown after drag. |
michael@0 | 71 | callbackOnPopupShown = function () { |
michael@0 | 72 | callbackOnPopupShown = null; |
michael@0 | 73 | ok(true, "tooltip is shown after drag"); |
michael@0 | 74 | |
michael@0 | 75 | // hide tooltip by mousemove to outside. |
michael@0 | 76 | callbackOnPopupHidden = function () { |
michael@0 | 77 | callbackOnPopupHidden = null; |
michael@0 | 78 | ok(true, "The tooltip is hidden again"); |
michael@0 | 79 | |
michael@0 | 80 | setTimeout(testHideTooltipByMouseDown, 0); |
michael@0 | 81 | } |
michael@0 | 82 | EventUtils.synthesizeMouse(target, -5, 15, { type: "mousemove" }, win); |
michael@0 | 83 | } |
michael@0 | 84 | EventUtils.synthesizeMouse(target, 5, 15, { type: "mousemove" }, win); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | let testDuringDnD = function () |
michael@0 | 88 | { |
michael@0 | 89 | // mousemove into the target and start drag by emulation via nsIDragService. |
michael@0 | 90 | // Note that on some platforms, we cannot actually start the drag by |
michael@0 | 91 | // synthesized events. E.g., Windows waits an actual mousemove event after |
michael@0 | 92 | // dragstart. |
michael@0 | 93 | callbackOnPopupShown = function () { |
michael@0 | 94 | callbackOnPopupShown = null; |
michael@0 | 95 | ok(false, "tooltip is shown during drag"); |
michael@0 | 96 | } |
michael@0 | 97 | dragService.startDragSession(); |
michael@0 | 98 | // Emulate a buggy mousemove event. widget might dispatch mousemove event |
michael@0 | 99 | // during drag. |
michael@0 | 100 | EventUtils.synthesizeMouse(target, 5, 15, { type: "mousemove" }, win); |
michael@0 | 101 | setTimeout(function () { |
michael@0 | 102 | callbackOnPopupShown = null; |
michael@0 | 103 | ok(true, "tooltip isn't shown during drag"); |
michael@0 | 104 | dragService.endDragSession(true); |
michael@0 | 105 | EventUtils.synthesizeMouse(target, -5, -5, { type: "mousemove" }, win); |
michael@0 | 106 | |
michael@0 | 107 | setTimeout(testShowTooltipAgain, 0); |
michael@0 | 108 | }, 100); |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | let onLoad = function (aEvent) |
michael@0 | 112 | { |
michael@0 | 113 | doc = gBrowser.contentDocument; |
michael@0 | 114 | win = gBrowser.contentWindow; |
michael@0 | 115 | target = doc.getElementById("target"); |
michael@0 | 116 | |
michael@0 | 117 | document.addEventListener("popupshown", onPopupShown, true); |
michael@0 | 118 | document.addEventListener("popuphidden", onPopupHidden, true); |
michael@0 | 119 | |
michael@0 | 120 | EventUtils.synthesizeMouse(target, -5, -5, { type: "mousemove" }, win); |
michael@0 | 121 | |
michael@0 | 122 | // show tooltip by mousemove into target. |
michael@0 | 123 | callbackOnPopupShown = function () |
michael@0 | 124 | { |
michael@0 | 125 | callbackOnPopupShown = null; |
michael@0 | 126 | ok(true, "The tooltip is shown"); |
michael@0 | 127 | |
michael@0 | 128 | // hide tooltip by mousemove to outside. |
michael@0 | 129 | callbackOnPopupHidden = function () { |
michael@0 | 130 | callbackOnPopupHidden = null; |
michael@0 | 131 | ok(true, "The tooltip is hidden"); |
michael@0 | 132 | |
michael@0 | 133 | setTimeout(testDuringDnD, 0); |
michael@0 | 134 | } |
michael@0 | 135 | EventUtils.synthesizeMouse(target, -5, 15, { type: "mousemove" }, win); |
michael@0 | 136 | } |
michael@0 | 137 | EventUtils.synthesizeMouse(target, 5, 15, { type: "mousemove" }, win); |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | gBrowser.selectedBrowser.addEventListener("load", |
michael@0 | 141 | function () { |
michael@0 | 142 | gBrowser.selectedBrowser. |
michael@0 | 143 | removeEventListener("load", arguments.callee, true); |
michael@0 | 144 | setTimeout(onLoad, 0); |
michael@0 | 145 | }, true); |
michael@0 | 146 | |
michael@0 | 147 | content.location = "data:text/html,<html><head></head><body>" + |
michael@0 | 148 | "<a id=\"target\" href=\"about:blank\" title=\"This is tooltip text\" " + |
michael@0 | 149 | "style=\"display:block;height:20px;margin:10px;\" " + |
michael@0 | 150 | "onclick=\"return false;\">here is an anchor element</a></body></html>"; |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | |
michael@0 | 154 |