2010-02-01 07:11:08 -08:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
|
|
|
<!--
|
|
|
|
XUL Widget Test for the titlebar element and window dragging
|
|
|
|
-->
|
|
|
|
<window title="Titlebar" width="200" height="200"
|
|
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
|
|
|
|
|
|
|
<script type="application/javascript"
|
|
|
|
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
|
|
|
|
|
|
|
|
<titlebar id="titlebar">
|
|
|
|
<label id="label" value="Titlebar"/>
|
|
|
|
</titlebar>
|
|
|
|
|
2010-07-27 06:38:04 -07:00
|
|
|
<!-- a non-noautohide panel is treated as anchored -->
|
|
|
|
<panel id="panel" onpopupshown="popupshown(this, false)" onpopuphidden="popuphidden('panelnoautohide')">
|
2010-02-01 07:11:08 -08:00
|
|
|
<titlebar>
|
|
|
|
<label id="panellabel" value="Titlebar"/>
|
|
|
|
</titlebar>
|
|
|
|
</panel>
|
|
|
|
|
2010-07-27 06:38:04 -07:00
|
|
|
<panel id="panelnoautohide" noautohide="true"
|
|
|
|
onpopupshown="popupshown(this, false)" onpopuphidden="popuphidden('panelanchored')">
|
|
|
|
<titlebar>
|
|
|
|
<label id="panellabelnoautohide" value="Titlebar"/>
|
|
|
|
</titlebar>
|
|
|
|
</panel>
|
|
|
|
|
|
|
|
<panel id="panelanchored" noautohide="true"
|
|
|
|
onpopupshown="popupshown(this, true)" onpopuphidden="popuphidden('paneltop')">
|
|
|
|
<titlebar>
|
|
|
|
<label id="panellabelanchored" value="Titlebar"/>
|
|
|
|
</titlebar>
|
|
|
|
</panel>
|
|
|
|
|
|
|
|
<panel id="paneltop" noautohide="true" level="top"
|
|
|
|
onpopupshown="popupshown(this, false)" onpopuphidden="popuphidden('panelfloating')">
|
|
|
|
<titlebar>
|
|
|
|
<label id="panellabeltop" value="Titlebar"/>
|
|
|
|
</titlebar>
|
|
|
|
</panel>
|
|
|
|
|
|
|
|
<panel id="panelfloating" noautohide="true" level="floating"
|
|
|
|
onpopupshown="popupshown(this, false)" onpopuphidden="popuphidden('')">
|
|
|
|
<titlebar>
|
|
|
|
<label id="panellabelfloating" value="Titlebar"/>
|
|
|
|
</titlebar>
|
|
|
|
</panel>
|
|
|
|
|
2010-02-01 07:11:08 -08:00
|
|
|
<button id="button" label="OK"/>
|
|
|
|
<statusbar id="statusbar">
|
|
|
|
<statusbarpanel>
|
|
|
|
<label id="statuslabel" value="Status"/>
|
|
|
|
</statusbarpanel>
|
|
|
|
</statusbar>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
<![CDATA[
|
|
|
|
|
|
|
|
var SimpleTest = window.opener.wrappedJSObject.SimpleTest;
|
|
|
|
|
|
|
|
SimpleTest.waitForFocus(test_titlebar, window);
|
|
|
|
|
2010-03-12 09:58:50 -08:00
|
|
|
var mouseDownTarget;
|
|
|
|
var origoldx, origoldy, oldx, oldy, waitSteps = 0;
|
2010-07-27 06:38:04 -07:00
|
|
|
function waitForWindowMove(element, x, y, callback, arg, panel, anchored)
|
2010-03-12 09:58:50 -08:00
|
|
|
{
|
2010-07-27 06:38:04 -07:00
|
|
|
var isPanelMove = (element.id != "label");
|
|
|
|
|
2010-03-12 09:58:50 -08:00
|
|
|
if (!waitSteps) {
|
2010-07-27 06:38:04 -07:00
|
|
|
oldx = isPanelMove ? panel.getBoundingClientRect().left : window.screenX;
|
|
|
|
oldy = isPanelMove ? panel.getBoundingClientRect().top : window.screenY;
|
2010-03-12 09:58:50 -08:00
|
|
|
synthesizeMouse(element, x, y, { type: "mousemove" });
|
|
|
|
}
|
|
|
|
|
2010-07-27 06:38:04 -07:00
|
|
|
var newx = isPanelMove ? panel.getBoundingClientRect().left : window.screenX;
|
|
|
|
var newy = isPanelMove ? panel.getBoundingClientRect().top : window.screenY;
|
2010-03-12 09:58:50 -08:00
|
|
|
if (newx == oldx && newy == oldy) {
|
|
|
|
if (waitSteps++ > 10) {
|
|
|
|
SimpleTest.is(window.screenX + "," + window.screenY, oldx + "," + oldy + " ",
|
2010-07-27 06:38:04 -07:00
|
|
|
"Window never moved properly to " + x + "," + y + (panel ? " " + panel.id : ""));
|
2010-03-12 09:58:50 -08:00
|
|
|
window.opener.wrappedJSObject.SimpleTest.finish();
|
|
|
|
window.close();
|
2010-07-27 06:38:04 -07:00
|
|
|
return;
|
2010-03-12 09:58:50 -08:00
|
|
|
}
|
|
|
|
|
2010-07-27 06:38:04 -07:00
|
|
|
setTimeout(waitForWindowMove, 100, element, x, y, callback, arg, panel, anchored);
|
2010-03-12 09:58:50 -08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
waitSteps = 0;
|
2010-07-27 06:38:04 -07:00
|
|
|
|
|
|
|
// on Linux, we need to wait a bit for the popup to be moved as well
|
|
|
|
if (navigator.platform.indexOf("Linux") >= 0) {
|
|
|
|
setTimeout(callback, 0, arg, panel, anchored);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
callback(arg, panel, anchored);
|
|
|
|
}
|
2010-03-12 09:58:50 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-01 07:11:08 -08:00
|
|
|
function test_titlebar()
|
|
|
|
{
|
|
|
|
var titlebar = document.getElementById("titlebar");
|
|
|
|
var label = document.getElementById("label");
|
|
|
|
|
2013-02-05 13:40:34 -08:00
|
|
|
// On Mac, the window can also be moved with the statusbar, but this works
|
|
|
|
// via the MozMouseHittest event, not via mouse events.
|
2010-02-01 07:11:08 -08:00
|
|
|
if (navigator.platform.indexOf("Mac") >= 0) {
|
2013-02-05 13:40:34 -08:00
|
|
|
var preventDefaulted;
|
|
|
|
|
2010-02-01 07:11:08 -08:00
|
|
|
var statuslabel = document.getElementById("statuslabel");
|
2013-02-05 13:40:34 -08:00
|
|
|
preventDefaulted = synthesizeMouse(statuslabel, 2, 2, { type: "MozMouseHittest" });
|
|
|
|
SimpleTest.ok(preventDefaulted, "MozMouseHittest should have been defaultPrevented over statusbar");
|
|
|
|
|
|
|
|
var button = document.getElementById("button");
|
|
|
|
preventDefaulted = synthesizeMouse(button, 2, 2, { type: "MozMouseHittest" });
|
|
|
|
SimpleTest.ok(!preventDefaulted, "MozMouseHittest should NOT have been defaultPrevented over button");
|
2010-02-01 07:11:08 -08:00
|
|
|
}
|
|
|
|
|
2010-03-12 09:58:50 -08:00
|
|
|
origoldx = window.screenX;
|
|
|
|
origoldy = window.screenY;
|
2010-02-01 07:11:08 -08:00
|
|
|
|
2010-03-12 09:58:50 -08:00
|
|
|
var mousedownListener = function (event) mouseDownTarget = event.originalTarget;
|
2010-02-01 07:11:08 -08:00
|
|
|
window.addEventListener("mousedown", mousedownListener, false);
|
|
|
|
synthesizeMouse(label, 2, 2, { type: "mousedown" });
|
2010-03-12 09:58:50 -08:00
|
|
|
SimpleTest.is(mouseDownTarget, titlebar, "movedown on titlebar");
|
|
|
|
waitForWindowMove(label, 22, 22, test_titlebar_step2, mousedownListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_titlebar_step2(mousedownListener)
|
|
|
|
{
|
|
|
|
var titlebar = document.getElementById("titlebar");
|
|
|
|
var label = document.getElementById("label");
|
|
|
|
|
|
|
|
SimpleTest.is(window.screenX, origoldx + 20, "move window horizontal");
|
|
|
|
SimpleTest.is(window.screenY, origoldy + 20, "move window vertical");
|
2010-02-01 07:11:08 -08:00
|
|
|
synthesizeMouse(label, 22, 22, { type: "mouseup" });
|
|
|
|
|
|
|
|
// with allowEvents set to true, the mouse should target the label instead
|
|
|
|
// and not move the window
|
|
|
|
titlebar.allowEvents = true;
|
|
|
|
|
|
|
|
synthesizeMouse(label, 2, 2, { type: "mousedown" });
|
2010-03-12 09:58:50 -08:00
|
|
|
SimpleTest.is(mouseDownTarget, label, "movedown on titlebar with allowevents");
|
2010-02-01 07:11:08 -08:00
|
|
|
synthesizeMouse(label, 22, 22, { type: "mousemove" });
|
2010-03-12 09:58:50 -08:00
|
|
|
SimpleTest.is(window.screenX, origoldx + 20, "mouse on label move window horizontal");
|
|
|
|
SimpleTest.is(window.screenY, origoldy + 20, "mouse on label move window vertical");
|
2010-02-01 07:11:08 -08:00
|
|
|
synthesizeMouse(label, 22, 22, { type: "mouseup" });
|
|
|
|
|
|
|
|
window.removeEventListener("mousedown", mousedownListener, false);
|
|
|
|
|
|
|
|
document.getElementById("panel").openPopupAtScreen(window.screenX + 50, window.screenY + 60, false);
|
|
|
|
}
|
|
|
|
|
2010-07-27 06:38:04 -07:00
|
|
|
function popupshown(panel, anchored)
|
2010-02-01 07:11:08 -08:00
|
|
|
{
|
2010-07-27 06:38:04 -07:00
|
|
|
var rect = panel.getBoundingClientRect();
|
|
|
|
|
|
|
|
// skip this check for non-noautohide panels
|
|
|
|
if (panel.id == "panel") {
|
|
|
|
var panellabel = panel.firstChild.firstChild;
|
|
|
|
synthesizeMouse(panellabel, 2, 2, { type: "mousedown" });
|
|
|
|
waitForWindowMove(panellabel, 22, 22, popupshown_step3, rect, panel, anchored);
|
|
|
|
return;
|
|
|
|
}
|
2010-02-01 07:11:08 -08:00
|
|
|
|
2010-07-27 06:38:04 -07:00
|
|
|
// now, try moving the window. If anchored, the popup should move with the
|
|
|
|
// window. If not anchored, the popup should remain at its current screen location.
|
|
|
|
window.moveBy(10, 10);
|
|
|
|
waitSteps = 1;
|
|
|
|
waitForWindowMove(document.getElementById("label"), 1, 1, popupshown_step2, rect, panel, anchored);
|
2010-03-12 09:58:50 -08:00
|
|
|
}
|
|
|
|
|
2010-07-27 06:38:04 -07:00
|
|
|
function popupshown_step2(oldrect, panel, anchored)
|
2010-03-12 09:58:50 -08:00
|
|
|
{
|
2010-02-01 07:11:08 -08:00
|
|
|
var newrect = panel.getBoundingClientRect();
|
|
|
|
|
2010-07-27 06:38:04 -07:00
|
|
|
// The window movement that occured long ago at the beginning of the test
|
|
|
|
// on Linux is delayed and there isn't any way to tell when the move
|
|
|
|
// actually happened. This causes the checks here to fail. Instead, just
|
|
|
|
// wait a bit for the test to be ready.
|
|
|
|
if (navigator.platform.indexOf("Linux") >= 0 &&
|
|
|
|
newrect.left != oldrect.left - (anchored ? 0 : 10)) {
|
|
|
|
setTimeout(popupshown_step2, 10, oldrect, panel, anchored);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// anchored popups should still be at the same offset. Non-anchored popups will
|
|
|
|
// now be offset by 10 pixels less.
|
|
|
|
SimpleTest.is(newrect.left, oldrect.left - (anchored ? 0 : 10),
|
|
|
|
panel.id + " horizontal after window move");
|
|
|
|
SimpleTest.is(newrect.top, oldrect.top - (anchored ? 0 : 10),
|
|
|
|
panel.id + " vertical after window move");
|
|
|
|
|
|
|
|
var panellabel = panel.firstChild.firstChild;
|
|
|
|
synthesizeMouse(panellabel, 2, 2, { type: "mousedown" });
|
|
|
|
waitForWindowMove(panellabel, 22, 22, popupshown_step3, newrect, panel, anchored);
|
|
|
|
}
|
|
|
|
|
|
|
|
function popupshown_step3(oldrect, panel, anchored)
|
|
|
|
{
|
|
|
|
// skip this check on Linux for the same window positioning reasons as above
|
2013-09-06 06:47:39 -07:00
|
|
|
if (navigator.platform.indexOf("Linux") == -1 || (panel.id != "panelanchored" && panel.id != "paneltop")) {
|
2010-07-27 06:38:04 -07:00
|
|
|
// next, drag the titlebar in the panel
|
|
|
|
var newrect = panel.getBoundingClientRect();
|
|
|
|
SimpleTest.is(newrect.left, oldrect.left + 20, panel.id + " move popup horizontal");
|
|
|
|
SimpleTest.is(newrect.top, oldrect.top + 20, panel.id + " move popup vertical");
|
|
|
|
synthesizeMouse(document.getElementById("panellabel"), 22, 22, { type: "mouseup" });
|
|
|
|
|
|
|
|
synthesizeMouse(document.getElementById("button"), 5, 5, { type: "mousemove" });
|
|
|
|
newrect = panel.getBoundingClientRect();
|
|
|
|
SimpleTest.is(newrect.left, oldrect.left + 20, panel.id + " horizontal after mouse on button");
|
|
|
|
SimpleTest.is(newrect.top, oldrect.top + 20, panel.id + " vertical after mouse on button");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
synthesizeMouse(document.getElementById("panellabel"), 22, 22, { type: "mouseup" });
|
|
|
|
}
|
2010-02-01 07:11:08 -08:00
|
|
|
|
|
|
|
panel.hidePopup();
|
|
|
|
}
|
|
|
|
|
2010-07-27 06:38:04 -07:00
|
|
|
function popuphidden(nextPopup)
|
2010-02-01 07:11:08 -08:00
|
|
|
{
|
2010-07-27 06:38:04 -07:00
|
|
|
if (nextPopup) {
|
|
|
|
var panel = document.getElementById(nextPopup);
|
|
|
|
if (panel.id == "panelnoautohide") {
|
|
|
|
panel.openPopupAtScreen(window.screenX + 50, window.screenY + 60, false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
panel.openPopup(document.getElementById("button"), "after_start");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
window.opener.wrappedJSObject.done(window);
|
2010-02-01 07:11:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
]]>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</window>
|