|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> |
|
4 <!-- |
|
5 XUL Widget Test for panels |
|
6 --> |
|
7 <window title="Titlebar" width="200" height="200" |
|
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
9 <script type="application/javascript" |
|
10 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
11 <script type="application/javascript" |
|
12 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> |
|
13 |
|
14 <tree id="tree" seltype="single" width="100" height="100"> |
|
15 <treecols> |
|
16 <treecol flex="1"/> |
|
17 <treecol flex="1"/> |
|
18 </treecols> |
|
19 <treechildren id="treechildren"> |
|
20 <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem> |
|
21 <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem> |
|
22 <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem> |
|
23 <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem> |
|
24 <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem> |
|
25 <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem> |
|
26 </treechildren> |
|
27 </tree> |
|
28 |
|
29 |
|
30 <!-- test results are displayed in the html:body --> |
|
31 <body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/> |
|
32 |
|
33 <!-- test code goes here --> |
|
34 <script type="application/javascript"><![CDATA[ |
|
35 |
|
36 SimpleTest.waitForExplicitFinish(); |
|
37 |
|
38 var currentTest = null; |
|
39 |
|
40 function ok(condition, message) { |
|
41 window.opener.wrappedJSObject.SimpleTest.ok(condition, message); |
|
42 } |
|
43 |
|
44 function is(left, right, message) { |
|
45 window.opener.wrappedJSObject.SimpleTest.is(left, right, message); |
|
46 } |
|
47 |
|
48 function test_panels() |
|
49 { |
|
50 checkTreeCoords(); |
|
51 |
|
52 addEventListener("popupshowing", popupShowing, false); |
|
53 addEventListener("popupshown", popupShown, false); |
|
54 addEventListener("popuphidden", nextTest, false); |
|
55 nextTest(); |
|
56 } |
|
57 |
|
58 function nextTest() |
|
59 { |
|
60 if (!tests.length) { |
|
61 window.close(); |
|
62 window.opener.wrappedJSObject.SimpleTest.finish(); |
|
63 return; |
|
64 } |
|
65 |
|
66 currentTest = tests.shift(); |
|
67 var panel = createPanel(currentTest.attrs); |
|
68 currentTest.test(panel); |
|
69 } |
|
70 |
|
71 function popupShowing(event) |
|
72 { |
|
73 var rect = event.target.getOuterScreenRect(); |
|
74 ok(!rect.left && !rect.top && !rect.width && !rect.height, |
|
75 currentTest.testname + " empty rectangle during popupshowing"); |
|
76 } |
|
77 |
|
78 var waitSteps = 0; |
|
79 function popupShown(event) |
|
80 { |
|
81 var panel = event.target; |
|
82 |
|
83 if (waitSteps > 0 && navigator.platform.indexOf("Linux") >= 0 && |
|
84 panel.boxObject.screenY == 210) { |
|
85 waitSteps--; |
|
86 setTimeout(popupShown, 10, event); |
|
87 return; |
|
88 } |
|
89 |
|
90 currentTest.result(currentTest.testname + " ", panel); |
|
91 panel.hidePopup(); |
|
92 } |
|
93 |
|
94 function createPanel(attrs) |
|
95 { |
|
96 var panel = document.createElement("panel"); |
|
97 for (var a in attrs) { |
|
98 panel.setAttribute(a, attrs[a]); |
|
99 } |
|
100 |
|
101 var button = document.createElement("button"); |
|
102 panel.appendChild(button); |
|
103 button.label = "OK"; |
|
104 button.width = 120; |
|
105 button.height = 40; |
|
106 button.setAttribute("style", "-moz-appearance: none; border: 0; margin: 0;"); |
|
107 panel.setAttribute("style", "-moz-appearance: none; border: 0; margin: 0;"); |
|
108 return document.documentElement.appendChild(panel); |
|
109 } |
|
110 |
|
111 function checkTreeCoords() |
|
112 { |
|
113 var tree = $("tree"); |
|
114 var treechildren = $("treechildren"); |
|
115 tree.currentIndex = 0; |
|
116 tree.treeBoxObject.scrollToRow(0); |
|
117 synthesizeMouse(treechildren, 10, tree.treeBoxObject.rowHeight + 2, { }); |
|
118 is(tree.currentIndex, 1, "tree selection"); |
|
119 |
|
120 tree.treeBoxObject.scrollToRow(2); |
|
121 synthesizeMouse(treechildren, 10, tree.treeBoxObject.rowHeight + 2, { }); |
|
122 is(tree.currentIndex, 3, "tree selection after scroll"); |
|
123 } |
|
124 |
|
125 var tests = [ |
|
126 { |
|
127 testname: "normal panel", |
|
128 attrs: { }, |
|
129 test: function(panel) { |
|
130 var screenRect = panel.getOuterScreenRect(); |
|
131 is(screenRect.left, 0, this.testname + " screen left before open"); |
|
132 is(screenRect.top, 0, this.testname + " screen top before open"); |
|
133 is(screenRect.width, 0, this.testname + " screen width before open"); |
|
134 is(screenRect.height, 0, this.testname + " screen height before open"); |
|
135 |
|
136 panel.openPopupAtScreen(200, 210); |
|
137 }, |
|
138 result: function(testname, panel) { |
|
139 var panelrect = panel.getBoundingClientRect(); |
|
140 is(panelrect.left, 200 - mozInnerScreenX, testname + "left"); |
|
141 is(panelrect.top, 210 - mozInnerScreenY, testname + "top"); |
|
142 is(panelrect.width, 120, testname + "width"); |
|
143 is(panelrect.height, 40, testname + "height"); |
|
144 |
|
145 var screenRect = panel.getOuterScreenRect(); |
|
146 is(screenRect.left, 200, testname + " screen left"); |
|
147 is(screenRect.top, 210, testname + " screen top"); |
|
148 is(screenRect.width, 120, testname + " screen width"); |
|
149 is(screenRect.height, 40, testname + " screen height"); |
|
150 } |
|
151 }, |
|
152 { |
|
153 // only noautohide panels support titlebars, so one shouldn't be shown here |
|
154 testname: "autohide panel with titlebar", |
|
155 attrs: { titlebar: "normal" }, |
|
156 test: function(panel) { |
|
157 var screenRect = panel.getOuterScreenRect(); |
|
158 is(screenRect.left, 0, this.testname + " screen left before open"); |
|
159 is(screenRect.top, 0, this.testname + " screen top before open"); |
|
160 is(screenRect.width, 0, this.testname + " screen width before open"); |
|
161 is(screenRect.height, 0, this.testname + " screen height before open"); |
|
162 |
|
163 panel.openPopupAtScreen(200, 210); |
|
164 }, |
|
165 result: function(testname, panel) { |
|
166 var panelrect = panel.getBoundingClientRect(); |
|
167 is(panelrect.left, 200 - mozInnerScreenX, testname + "left"); |
|
168 is(panelrect.top, 210 - mozInnerScreenY, testname + "top"); |
|
169 is(panelrect.width, 120, testname + "width"); |
|
170 is(panelrect.height, 40, testname + "height"); |
|
171 |
|
172 var screenRect = panel.getOuterScreenRect(); |
|
173 is(screenRect.left, 200, testname + " screen left"); |
|
174 is(screenRect.top, 210, testname + " screen top"); |
|
175 is(screenRect.width, 120, testname + " screen width"); |
|
176 is(screenRect.height, 40, testname + " screen height"); |
|
177 } |
|
178 }, |
|
179 { |
|
180 testname: "noautohide panel with titlebar", |
|
181 attrs: { noautohide: true, titlebar: "normal" }, |
|
182 test: function(panel) { |
|
183 waitSteps = 25; |
|
184 |
|
185 var screenRect = panel.getOuterScreenRect(); |
|
186 is(screenRect.left, 0, this.testname + " screen left before open"); |
|
187 is(screenRect.top, 0, this.testname + " screen top before open"); |
|
188 is(screenRect.width, 0, this.testname + " screen width before open"); |
|
189 is(screenRect.height, 0, this.testname + " screen height before open"); |
|
190 |
|
191 panel.openPopupAtScreen(200, 210); |
|
192 }, |
|
193 result: function(testname, panel) { |
|
194 var panelrect = panel.getBoundingClientRect(); |
|
195 ok(panelrect.left >= 200 - mozInnerScreenX, testname + "left"); |
|
196 if (navigator.platform.indexOf("Linux") < 0) { |
|
197 ok(panelrect.top >= 210 - mozInnerScreenY + 10, testname + "top greater"); |
|
198 } |
|
199 ok(panelrect.top <= 210 - mozInnerScreenY + 30, testname + "top less"); |
|
200 is(panelrect.width, 120, testname + "width"); |
|
201 is(panelrect.height, 40, testname + "height"); |
|
202 |
|
203 var screenRect = panel.getOuterScreenRect(); |
|
204 if (navigator.platform.indexOf("Linux") < 0) { |
|
205 is(screenRect.left, 200, testname + " screen left"); |
|
206 is(screenRect.top, 210, testname + " screen top"); |
|
207 } |
|
208 ok(screenRect.width >= 120 && screenRect.width <= 140, testname + " screen width"); |
|
209 ok(screenRect.height >= 40 && screenRect.height <= 80, testname + " screen height"); |
|
210 |
|
211 var gotMouseEvent = false; |
|
212 function mouseMoved(event) |
|
213 { |
|
214 is(event.clientY, panelrect.top + 10, |
|
215 "popup clientY"); |
|
216 is(event.screenY, panel.boxObject.screenY + 10, |
|
217 "popup screenY"); |
|
218 is(event.originalTarget, panel.firstChild, "popup target"); |
|
219 gotMouseEvent = true; |
|
220 } |
|
221 |
|
222 panel.addEventListener("mousemove", mouseMoved, true); |
|
223 synthesizeMouse(panel, 10, 10, { type: "mousemove" }); |
|
224 ok(gotMouseEvent, "mouse event on panel"); |
|
225 panel.removeEventListener("mousemove", mouseMoved, true); |
|
226 |
|
227 var tree = $("tree"); |
|
228 tree.currentIndex = 0; |
|
229 panel.appendChild(tree); |
|
230 checkTreeCoords(); |
|
231 } |
|
232 }, |
|
233 { |
|
234 testname: "noautohide panel with backdrag", |
|
235 attrs: { noautohide: true, backdrag: "true" }, |
|
236 test: function(panel) { |
|
237 var label = document.createElement("label"); |
|
238 label.id = "backdragspot"; |
|
239 label.setAttribute("value", "Hello There"); |
|
240 panel.appendChild(label); |
|
241 panel.openPopupAtScreen(200, 230); |
|
242 }, |
|
243 result: function(testname, panel) { |
|
244 var oldrect = panel.getOuterScreenRect(); |
|
245 |
|
246 // Linux uses native window moving |
|
247 if (navigator.platform.indexOf("Linux") == -1) { |
|
248 var backdragspot = document.getElementById("backdragspot"); |
|
249 synthesizeMouse(backdragspot, 5, 5, { type: "mousedown" }); |
|
250 synthesizeMouse(backdragspot, 15, 20, { type: "mousemove" }); |
|
251 synthesizeMouse(backdragspot, 15, 20, { type: "mouseup" }); |
|
252 |
|
253 is(panel.getOuterScreenRect().left, 210, testname + "left"); |
|
254 is(panel.getOuterScreenRect().top, 245, testname + "top"); |
|
255 } |
|
256 } |
|
257 }, |
|
258 { |
|
259 // The panel should be allowed to appear and remain offscreen |
|
260 testname: "normal panel with flip='none' off-screen", |
|
261 attrs: { "flip": "none" }, |
|
262 test: function(panel) { |
|
263 panel.openPopup(document.documentElement, "", -100 - mozInnerScreenX, -100 - mozInnerScreenY, false, false, null); |
|
264 }, |
|
265 result: function(testname, panel) { |
|
266 var panelrect = panel.getBoundingClientRect(); |
|
267 is(panelrect.left, -100 - mozInnerScreenX, testname + "left"); |
|
268 is(panelrect.top, -100 - mozInnerScreenY, testname + "top"); |
|
269 is(panelrect.width, 120, testname + "width"); |
|
270 is(panelrect.height, 40, testname + "height"); |
|
271 |
|
272 var screenRect = panel.getOuterScreenRect(); |
|
273 is(screenRect.left, -100, testname + " screen left"); |
|
274 is(screenRect.top, -100, testname + " screen top"); |
|
275 is(screenRect.width, 120, testname + " screen width"); |
|
276 is(screenRect.height, 40, testname + " screen height"); |
|
277 } |
|
278 }, |
|
279 { |
|
280 // The panel should be allowed to remain offscreen after moving and it should follow the anchor |
|
281 testname: "normal panel with flip='none' moved off-screen", |
|
282 attrs: { "flip": "none" }, |
|
283 test: function(panel) { |
|
284 panel.openPopup(document.documentElement, "", -100 - mozInnerScreenX, -100 - mozInnerScreenY, false, false, null); |
|
285 window.moveBy(-50, -50); |
|
286 }, |
|
287 result: function(testname, panel) { |
|
288 if (navigator.platform.indexOf("Linux") >= 0) { |
|
289 // The window position doesn't get updated immediately on Linux. |
|
290 return; |
|
291 } |
|
292 var panelrect = panel.getBoundingClientRect(); |
|
293 is(panelrect.left, -150 - mozInnerScreenX, testname + "left"); |
|
294 is(panelrect.top, -150 - mozInnerScreenY, testname + "top"); |
|
295 is(panelrect.width, 120, testname + "width"); |
|
296 is(panelrect.height, 40, testname + "height"); |
|
297 |
|
298 var screenRect = panel.getOuterScreenRect(); |
|
299 is(screenRect.left, -150, testname + " screen left"); |
|
300 is(screenRect.top, -150, testname + " screen top"); |
|
301 is(screenRect.width, 120, testname + " screen width"); |
|
302 is(screenRect.height, 40, testname + " screen height"); |
|
303 } |
|
304 }, |
|
305 ]; |
|
306 |
|
307 window.opener.wrappedJSObject.SimpleTest.waitForFocus(test_panels, window); |
|
308 |
|
309 ]]> |
|
310 </script> |
|
311 |
|
312 </window> |