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