1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window title="Arrow Panels"
style="padding: 10px;"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
<stack flex="1">
<label id="topleft" value="Top Left Corner" style="justify-self: left; margin-left: 15px; align-self: start; margin-top: 15px;"/>
<label id="topright" value="Top Right" style="justify-self: right; margin-right: 15px; align-self: start; margin-top: 15px;"/>
<label id="bottomleft" value="Bottom Left Corner" style="justify-self: left; margin-left: 15px; align-self: end; margin-bottom: 15px;"/>
<label id="bottomright" value="Bottom Right" style="justify-self: right; margin-right: 15px; align-self: end; margin-bottom: 15px;"/>
<!-- Our SimpleTest/TestRunner.js runs tests inside an iframe which sizes are W=500 H=300.
'left' and 'top' values need to be set so that the panel (popup) has enough room to display on its 4 sides. -->
<label id="middle" value="+/- Centered" style="justify-self: left; margin-left: 225px; align-self: start; margin-top: 135px;"/>
<iframe id="frame" type="content"
src="data:text/html,<input id='input'>" style="width: 100px; height: 100px; justify-self: left; margin-left: 225px; align-self: start; margin-top: 120px;"/>
</stack>
<panel id="panel" type="arrow" animate="false"
onpopupshown="checkPanelPosition(this)" onpopuphidden="runNextTest.next()">
<box width="115" height="65"/>
</panel>
<panel id="bigpanel" type="arrow" animate="false"
onpopupshown="checkBigPanel(this)" onpopuphidden="runNextTest.next()">
<box width="125" height="3000"/>
</panel>
<panel id="animatepanel" type="arrow"
onpopupshown="animatedPopupShown = true;"
onpopuphidden="animatedPopupHidden = true; runNextTest.next();">
<label value="Animate Closed" height="40"/>
</panel>
<script type="application/javascript">
<![CDATA[
SimpleTest.waitForExplicitFinish();
const isOSXYosemite = navigator.userAgent.includes("Mac OS X 10.10");
var expectedAnchor = null;
var expectedSide = "", expectedAnchorEdge = "", expectedPack = "";
var zoomFactor = 1;
var animatedPopupShown = false;
var animatedPopupHidden = false;
var runNextTest;
function startTest()
{
runNextTest = nextTest();
runNextTest.next();
}
function* nextTest()
{
var panel = $("panel");
function openPopup(position, anchor, expected, anchorEdge, pack, alignment)
{
expectedAnchor = anchor instanceof Node ? anchor : $(anchor);
expectedSide = expected;
expectedAnchorEdge = anchorEdge;
expectedPack = pack;
panel.removeAttribute("side");
panel.openPopup(expectedAnchor, position, 0, 0, false, false, null);
}
for (var iter = 0; iter < 2; iter++) {
openPopup("after_start", "topleft", "top", "left", "start");
yield;
openPopup("after_start", "bottomleft", "bottom", "left", "start", "before_start");
yield;
openPopup("before_start", "topleft", "top", "left", "start", "after_start");
yield;
openPopup("before_start", "bottomleft", "bottom", "left", "start");
yield;
openPopup("after_start", "middle", "top", "left", "start");
yield;
openPopup("before_start", "middle", "bottom", "left", "start");
yield;
openPopup("after_start", "topright", "top", "right", "end", "after_end");
yield;
openPopup("after_start", "bottomright", "bottom", "right", "end", "before_end");
yield;
openPopup("before_start", "topright", "top", "right", "end", "after_end");
yield;
openPopup("before_start", "bottomright", "bottom", "right", "end", "before_end");
yield;
openPopup("after_end", "middle", "top", "right", "end");
yield;
openPopup("before_end", "middle", "bottom", "right", "end");
yield;
openPopup("start_before", "topleft", "left", "top", "start", "end_before");
yield;
openPopup("start_before", "topright", "right", "top", "start");
yield;
openPopup("end_before", "topleft", "left", "top", "start");
yield;
openPopup("end_before", "topright", "right", "top", "start", "start_before");
yield;
openPopup("start_before", "middle", "right", "top", "start");
yield;
openPopup("end_before", "middle", "left", "top", "start");
yield;
openPopup("start_before", "bottomleft", "left", "bottom", "end", "end_after");
yield;
openPopup("start_before", "bottomright", "right", "bottom", "end", "start_after");
yield;
openPopup("end_before", "bottomleft", "left", "bottom", "end", "end_after");
yield;
openPopup("end_before", "bottomright", "right", "bottom", "end", "start_after");
yield;
openPopup("start_after", "middle", "right", "bottom", "end");
yield;
openPopup("end_after", "middle", "left", "bottom", "end");
yield;
openPopup("topcenter bottomleft", "bottomleft", "bottom", "center left", "start", "before_start");
yield;
openPopup("bottomcenter topleft", "topleft", "top", "center left", "start", "after_start");
yield;
openPopup("topcenter bottomright", "bottomright", "bottom", "center right", "end", "before_end");
yield;
openPopup("bottomcenter topright", "topright", "top", "center right", "end", "after_end");
yield;
openPopup("topcenter bottomleft", "middle", "bottom", "center left", "start", "before_start");
yield;
openPopup("bottomcenter topleft", "middle", "top", "center left", "start", "after_start");
yield;
openPopup("leftcenter topright", "middle", "right", "center top", "start", "start_before");
yield;
openPopup("rightcenter bottomleft", "middle", "left", "center bottom", "end", "end_after");
yield;
/*
XXXndeakin disable these parts of the test which often cause problems, see bug 626563
openPopup("after_start", frames[0].document.getElementById("input"), "top", "left", "start");
yield;
setScale(frames[0], 1.5);
openPopup("after_start", frames[0].document.getElementById("input"), "top", "left", "start");
yield;
setScale(frames[0], 2.5);
openPopup("before_start", frames[0].document.getElementById("input"), "bottom", "left", "start");
yield;
setScale(frames[0], 1);
*/
$("bigpanel").openPopup($("topleft"), "after_start", 0, 0, false, false, null, "start");
yield;
// switch to rtl mode
document.documentElement.style.direction = "rtl";
$("topleft").style.marginRight = "15px";
$("topleft").style.justifySelf = "right";
$("topright").style.marginLeft = "15px";
$("topright").style.justifySelf = "left";
$("bottomleft").style.marginRight = "15px";
$("bottomleft").style.justifySelf = "right";
$("bottomright").style.marginLeft = "15px";
$("bottomright").style.justifySelf = "left";
$("topleft").style.removeProperty("marginLeft");
$("topright").style.removeProperty("marginRight");
$("bottomleft").style.removeProperty("marginLeft");
$("bottomright").style.removeProperty("marginRight");
}
// Test that a transition occurs when opening or closing the popup.
if (SpecialPowers.getBoolPref("xul.panel-animations.enabled")) {
function transitionEnded(event) {
if ($("animatepanel").state != "open") {
is($("animatepanel").state, "showing", "state is showing during transitionend");
ok(!animatedPopupShown, "popupshown not fired yet")
} else {
is($("animatepanel").state, "open", "state is open after transitionend");
ok(animatedPopupShown, "popupshown now fired")
SimpleTest.executeSoon(() => runNextTest.next());
}
}
// Check that the transition occurs for an arrow panel with animate="true"
$("animatepanel").addEventListener("transitionend", transitionEnded);
$("animatepanel").openPopup($("topleft"), "after_start", 0, 0, false, false, null, "start");
is($("animatepanel").state, "showing", "state is showing");
yield;
$("animatepanel").removeEventListener("transitionend", transitionEnded);
synthesizeKey("KEY_Escape");
ok(!animatedPopupHidden, "animated popup not hidden yet");
yield;
}
SimpleTest.finish()
}
function setScale(win, scale)
{
SpecialPowers.setFullZoom(win, scale);
zoomFactor = scale;
}
function checkPanelPosition(panel)
{
let anchor = panel.anchorNode;
let adj = 0, hwinpos = 0, vwinpos = 0;
if (anchor.ownerDocument != document) {
var framerect = anchor.ownerGlobal.frameElement.getBoundingClientRect();
hwinpos = framerect.left;
vwinpos = framerect.top;
}
// Positions are reversed in rtl yet the coordinates used in the computations
// are not, so flip the expected label side and anchor edge.
var isRTL = (window.getComputedStyle(panel).direction == "rtl");
if (isRTL) {
var flipLeftRight = val => val == "left" ? "right" : "left";
expectedAnchorEdge = expectedAnchorEdge.replace(/(left|right)/, flipLeftRight);
expectedSide = expectedSide.replace(/(left|right)/, flipLeftRight);
}
var panelRect = panel.getBoundingClientRect();
var anchorRect = anchor.getBoundingClientRect();
var contentRect = panel.firstChild.getBoundingClientRect();
switch (expectedSide) {
case "top":
ok(contentRect.top > vwinpos + anchorRect.bottom * zoomFactor + 5, "panel content is below");
break;
case "bottom":
ok(contentRect.bottom < vwinpos + anchorRect.top * zoomFactor - 5, "panel content is above");
break;
case "left":
ok(contentRect.left > hwinpos + anchorRect.right * zoomFactor + 5, "panel content is right");
break;
case "right":
ok(contentRect.right < hwinpos + anchorRect.left * zoomFactor - 5, "panel content is left");
break;
}
let iscentered = false;
if (expectedAnchorEdge.indexOf("center ") == 0) {
expectedAnchorEdge = expectedAnchorEdge.substring(7);
iscentered = true;
}
switch (expectedAnchorEdge) {
case "top":
adj = vwinpos + parseInt(getComputedStyle(panel, "").marginTop);
if (iscentered)
adj += Math.round(anchorRect.height) / 2;
isWithinHalfPixel(panelRect.top, anchorRect.top * zoomFactor + adj, "anchored on top");
break;
case "bottom":
adj = vwinpos + parseInt(getComputedStyle(panel, "").marginBottom);
if (iscentered)
adj += Math.round(anchorRect.height) / 2;
isWithinHalfPixel(panelRect.bottom, anchorRect.bottom * zoomFactor - adj, "anchored on bottom");
break;
case "left":
adj = hwinpos + parseInt(getComputedStyle(panel, "").marginLeft);
if (iscentered)
adj += Math.round(anchorRect.width) / 2;
isWithinHalfPixel(panelRect.left, anchorRect.left * zoomFactor + adj, "anchored on left ");
break;
case "right":
adj = hwinpos + parseInt(getComputedStyle(panel, "").marginRight);
if (iscentered)
adj += Math.round(anchorRect.width) / 2;
if (!isOSXYosemite)
isWithinHalfPixel(panelRect.right, anchorRect.right * zoomFactor - adj, "anchored on right");
break;
}
is(anchor, expectedAnchor, "anchor");
var arrow = panel.shadowRoot.querySelector(".panel-arrow");
is(panel.getAttribute("side"), expectedSide, "panel arrow side");
is(arrow.hidden, false, "panel hidden");
is(arrow.parentNode.getAttribute("pack"), expectedPack, "panel arrow pack");
panel.hidePopup();
}
function isWithinHalfPixel(a, b, desc)
{
ok(Math.abs(a - b) <= 0.5, desc);
}
function checkBigPanel(panel)
{
ok(panel.firstChild.getBoundingClientRect().height < 2800, "big panel height");
panel.hidePopup();
}
SimpleTest.waitForFocus(startTest);
]]>
</script>
<body xmlns="http://www.w3.org/1999/xhtml"/>
</window>
|