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
|
<?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"?>
<!--
XUL Widget Test for panels
-->
<window title="Titlebar" width="200" height="200"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml">
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
<html:style>
<![CDATA[
panel, panel::part(content) {
border: 0;
margin: 0;
padding: 0;
}
]]>
</html:style>
<tree id="tree" seltype="single" width="100" height="100">
<treecols>
<treecol flex="1"/>
<treecol flex="1"/>
</treecols>
<treechildren id="treechildren">
<treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem>
<treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem>
<treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem>
<treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem>
<treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem>
<treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem>
</treechildren>
</tree>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
SimpleTest.waitForExplicitFinish();
var currentTest = null;
function ok(condition, message) {
window.arguments[0].SimpleTest.ok(condition, message);
}
function is(left, right, message) {
window.arguments[0].SimpleTest.is(left, right, message);
}
function test_panels()
{
checkTreeCoords();
addEventListener("popupshowing", popupShowing, false);
addEventListener("popupshown", popupShown, false);
addEventListener("popuphidden", nextTest, false);
nextTest();
}
function nextTest()
{
if (!tests.length) {
window.close();
window.arguments[0].SimpleTest.finish();
return;
}
currentTest = tests.shift();
var panel = createPanel(currentTest.attrs);
currentTest.test(panel);
}
function popupShowing(event)
{
var rect = event.target.getOuterScreenRect();
ok(!rect.left && !rect.top && !rect.width && !rect.height,
currentTest.testname + " empty rectangle during popupshowing");
}
var waitSteps = 0;
function popupShown(event)
{
var panel = event.target;
if (waitSteps > 0 && navigator.platform.includes("Linux") &&
panel.screenY == 210) {
waitSteps--;
setTimeout(popupShown, 10, event);
return;
}
currentTest.result(currentTest.testname + " ", panel);
panel.hidePopup();
}
function createPanel(attrs)
{
var panel = document.createXULElement("panel");
for (var a in attrs) {
panel.setAttribute(a, attrs[a]);
}
var button = document.createXULElement("button");
panel.appendChild(button);
button.label = "OK";
button.setAttribute("style", "appearance: none; border: 0; margin: 0; width: 120px; height: 40px;");
panel.setAttribute("style", "appearance: none; border: 0; margin: 0;");
return document.documentElement.appendChild(panel);
}
function checkTreeCoords()
{
var tree = $("tree");
var treechildren = $("treechildren");
tree.currentIndex = 0;
tree.scrollToRow(0);
synthesizeMouse(treechildren, 10, tree.rowHeight + 2, { });
is(tree.currentIndex, 1, "tree selection");
tree.scrollToRow(2);
synthesizeMouse(treechildren, 10, tree.rowHeight + 2, { });
is(tree.currentIndex, 3, "tree selection after scroll");
}
var tests = [
{
testname: "normal panel",
attrs: { },
test(panel) {
var screenRect = panel.getOuterScreenRect();
is(screenRect.left, 0, this.testname + " screen left before open");
is(screenRect.top, 0, this.testname + " screen top before open");
is(screenRect.width, 0, this.testname + " screen width before open");
is(screenRect.height, 0, this.testname + " screen height before open");
panel.openPopupAtScreen(200, 210);
},
result(testname, panel) {
var panelrect = panel.getBoundingClientRect();
is(panelrect.left, 200 - window.mozInnerScreenX, testname + "left");
is(panelrect.top, 210 - window.mozInnerScreenY, testname + "top");
is(panelrect.width, 120, testname + "width");
is(panelrect.height, 40, testname + "height");
var screenRect = panel.getOuterScreenRect();
is(screenRect.left, 200, testname + " screen left");
is(screenRect.top, 210, testname + " screen top");
is(screenRect.width, 120, testname + " screen width");
is(screenRect.height, 40, testname + " screen height");
}
},
{
// only noautohide panels support titlebars, so one shouldn't be shown here
testname: "autohide panel with titlebar",
attrs: { titlebar: "normal" },
test(panel) {
var screenRect = panel.getOuterScreenRect();
is(screenRect.left, 0, this.testname + " screen left before open");
is(screenRect.top, 0, this.testname + " screen top before open");
is(screenRect.width, 0, this.testname + " screen width before open");
is(screenRect.height, 0, this.testname + " screen height before open");
panel.openPopupAtScreen(200, 210);
},
result(testname, panel) {
var panelrect = panel.getBoundingClientRect();
is(panelrect.left, 200 - window.mozInnerScreenX, testname + "left");
is(panelrect.top, 210 - window.mozInnerScreenY, testname + "top");
is(panelrect.width, 120, testname + "width");
is(panelrect.height, 40, testname + "height");
var screenRect = panel.getOuterScreenRect();
is(screenRect.left, 200, testname + " screen left");
is(screenRect.top, 210, testname + " screen top");
is(screenRect.width, 120, testname + " screen width");
is(screenRect.height, 40, testname + " screen height");
}
},
{
testname: "noautohide panel with titlebar",
attrs: { noautohide: true, titlebar: "normal" },
test(panel) {
waitSteps = 25;
var screenRect = panel.getOuterScreenRect();
is(screenRect.left, 0, this.testname + " screen left before open");
is(screenRect.top, 0, this.testname + " screen top before open");
is(screenRect.width, 0, this.testname + " screen width before open");
is(screenRect.height, 0, this.testname + " screen height before open");
panel.openPopupAtScreen(200, 210);
},
result(testname, panel) {
var panelrect = panel.getBoundingClientRect();
ok(panelrect.left >= 200 - window.mozInnerScreenX, testname + "left");
if (!navigator.platform.includes("Linux")) {
ok(panelrect.top >= 210 - window.mozInnerScreenY, testname + "top greater " + panelrect.top + " " + window.mozInnerScreenY);
}
ok(panelrect.top <= 210 - window.mozInnerScreenY + 36, testname + "top less");
is(panelrect.width, 120, testname + "width");
is(panelrect.height, 40, testname + "height");
var screenRect = panel.getOuterScreenRect();
if (!navigator.platform.includes("Linux")) {
is(screenRect.left, 200, testname + " screen left");
is(screenRect.top, 210, testname + " screen top");
}
ok(screenRect.width >= 120 && screenRect.width <= 140, testname + " screen width");
ok(screenRect.height >= 40 && screenRect.height <= 118, testname + " screen height");
var gotMouseEvent = false;
function mouseMoved(event)
{
is(event.clientY, panelrect.top + 10,
"popup clientY");
is(event.screenY, panel.screenY + 10,
"popup screenY");
is(event.originalTarget, panel.firstChild, "popup target");
gotMouseEvent = true;
}
panel.addEventListener("mousemove", mouseMoved, true);
synthesizeMouse(panel, 10, 10, { type: "mousemove" });
ok(gotMouseEvent, "mouse event on panel");
panel.removeEventListener("mousemove", mouseMoved, true);
var tree = $("tree");
tree.currentIndex = 0;
panel.appendChild(tree);
checkTreeCoords();
}
},
{
// The panel should be allowed to appear and remain offscreen
testname: "normal panel with flip='none' off-screen",
attrs: { "flip": "none" },
test(panel) {
panel.openPopup(document.documentElement, "", -100 - window.mozInnerScreenX, -100 - window.mozInnerScreenY, false, false, null);
},
result(testname, panel) {
var panelrect = panel.getBoundingClientRect();
is(panelrect.left, -100 - window.mozInnerScreenX, testname + "left");
is(panelrect.top, -100 - window.mozInnerScreenY, testname + "top");
is(panelrect.width, 120, testname + "width");
is(panelrect.height, 40, testname + "height");
var screenRect = panel.getOuterScreenRect();
is(screenRect.left, -100, testname + " screen left");
is(screenRect.top, -100, testname + " screen top");
is(screenRect.width, 120, testname + " screen width");
is(screenRect.height, 40, testname + " screen height");
}
},
{
// The panel should be allowed to remain offscreen after moving and it should follow the anchor
testname: "normal panel with flip='none' moved off-screen",
attrs: { "flip": "none" },
test(panel) {
panel.openPopup(document.documentElement, "", -100 - window.mozInnerScreenX, -100 - window.mozInnerScreenY, false, false, null);
window.moveBy(-50, -50);
},
result(testname, panel) {
if (navigator.platform.includes("Linux")) {
// The window position doesn't get updated immediately on Linux.
return;
}
var panelrect = panel.getBoundingClientRect();
is(panelrect.left, -150 - window.mozInnerScreenX, testname + "left");
is(panelrect.top, -150 - window.mozInnerScreenY, testname + "top");
is(panelrect.width, 120, testname + "width");
is(panelrect.height, 40, testname + "height");
var screenRect = panel.getOuterScreenRect();
is(screenRect.left, -150, testname + " screen left");
is(screenRect.top, -150, testname + " screen top");
is(screenRect.width, 120, testname + " screen width");
is(screenRect.height, 40, testname + " screen height");
}
},
];
window.arguments[0].SimpleTest.waitForFocus(test_panels, window);
]]>
</script>
</window>
|