toolkit/content/tests/chrome/window_titlebar.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/chrome/window_titlebar.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,242 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<!--
     1.7 +  XUL Widget Test for the titlebar element and window dragging
     1.8 +  -->
     1.9 +<window title="Titlebar" width="200" height="200"
    1.10 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.11 +
    1.12 +  <script type="application/javascript"
    1.13 +          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    1.14 +
    1.15 +  <titlebar id="titlebar">
    1.16 +    <label id="label" value="Titlebar"/>
    1.17 +  </titlebar>
    1.18 +
    1.19 +  <!-- a non-noautohide panel is treated as anchored -->
    1.20 +  <panel id="panel" onpopupshown="popupshown(this, false)" onpopuphidden="popuphidden('panelnoautohide')">
    1.21 +    <titlebar>
    1.22 +      <label id="panellabel" value="Titlebar"/>
    1.23 +    </titlebar>
    1.24 +  </panel>
    1.25 +
    1.26 +  <panel id="panelnoautohide" noautohide="true"
    1.27 +         onpopupshown="popupshown(this, false)" onpopuphidden="popuphidden('panelanchored')">
    1.28 +    <titlebar>
    1.29 +      <label id="panellabelnoautohide" value="Titlebar"/>
    1.30 +    </titlebar>
    1.31 +  </panel>
    1.32 +
    1.33 +  <panel id="panelanchored" noautohide="true"
    1.34 +          onpopupshown="popupshown(this, true)" onpopuphidden="popuphidden('paneltop')">
    1.35 +    <titlebar>
    1.36 +      <label id="panellabelanchored" value="Titlebar"/>
    1.37 +    </titlebar>
    1.38 +  </panel>
    1.39 +
    1.40 +  <panel id="paneltop" noautohide="true" level="top"
    1.41 +         onpopupshown="popupshown(this, false)" onpopuphidden="popuphidden('panelfloating')">
    1.42 +    <titlebar>
    1.43 +      <label id="panellabeltop" value="Titlebar"/>
    1.44 +    </titlebar>
    1.45 +  </panel>
    1.46 +
    1.47 +  <panel id="panelfloating" noautohide="true" level="floating"
    1.48 +         onpopupshown="popupshown(this, false)" onpopuphidden="popuphidden('')">
    1.49 +    <titlebar>
    1.50 +      <label id="panellabelfloating" value="Titlebar"/>
    1.51 +    </titlebar>
    1.52 +  </panel>
    1.53 +
    1.54 +  <button id="button" label="OK"/>
    1.55 +  <statusbar id="statusbar">
    1.56 +    <statusbarpanel>
    1.57 +      <label id="statuslabel" value="Status"/>
    1.58 +    </statusbarpanel>
    1.59 +  </statusbar>
    1.60 +
    1.61 +<script>
    1.62 +<![CDATA[
    1.63 +
    1.64 +var SimpleTest = window.opener.wrappedJSObject.SimpleTest;
    1.65 +
    1.66 +SimpleTest.waitForFocus(test_titlebar, window);
    1.67 +
    1.68 +var mouseDownTarget;
    1.69 +var origoldx, origoldy, oldx, oldy, waitSteps = 0;
    1.70 +function waitForWindowMove(element, x, y, callback, arg, panel, anchored)
    1.71 +{
    1.72 +  var isPanelMove = (element.id != "label");
    1.73 +
    1.74 +  if (!waitSteps) {
    1.75 +    oldx = isPanelMove ? panel.getBoundingClientRect().left : window.screenX;
    1.76 +    oldy = isPanelMove ? panel.getBoundingClientRect().top : window.screenY;
    1.77 +    synthesizeMouse(element, x, y, { type: "mousemove" });
    1.78 +  }
    1.79 +
    1.80 +  var newx = isPanelMove ? panel.getBoundingClientRect().left : window.screenX; 
    1.81 +  var newy = isPanelMove ? panel.getBoundingClientRect().top : window.screenY; 
    1.82 +  if (newx == oldx && newy == oldy) {
    1.83 +    if (waitSteps++ > 10) {
    1.84 +      SimpleTest.is(window.screenX + "," + window.screenY, oldx + "," + oldy + " ",
    1.85 +                    "Window never moved properly to " + x + "," + y + (panel ? " " + panel.id : ""));
    1.86 +      window.opener.wrappedJSObject.SimpleTest.finish();
    1.87 +      window.close();
    1.88 +      return;
    1.89 +    }
    1.90 +
    1.91 +    setTimeout(waitForWindowMove, 100, element, x, y, callback, arg, panel, anchored);
    1.92 +  }
    1.93 +  else {
    1.94 +    waitSteps = 0;
    1.95 +
    1.96 +    // on Linux, we need to wait a bit for the popup to be moved as well
    1.97 +    if (navigator.platform.indexOf("Linux") >= 0) {
    1.98 +      setTimeout(callback, 0, arg, panel, anchored);
    1.99 +    }
   1.100 +    else {
   1.101 +      callback(arg, panel, anchored);
   1.102 +    }
   1.103 +  }
   1.104 +}
   1.105 +
   1.106 +function test_titlebar()
   1.107 +{
   1.108 +  var titlebar = document.getElementById("titlebar");
   1.109 +  var label = document.getElementById("label");
   1.110 +
   1.111 +  // On Mac, the window can also be moved with the statusbar, but this works
   1.112 +  // via the MozMouseHittest event, not via mouse events.
   1.113 +  if (navigator.platform.indexOf("Mac") >= 0) {
   1.114 +    var preventDefaulted;
   1.115 +
   1.116 +    var statuslabel = document.getElementById("statuslabel");
   1.117 +    preventDefaulted = synthesizeMouse(statuslabel, 2, 2, { type: "MozMouseHittest" });
   1.118 +    SimpleTest.ok(preventDefaulted, "MozMouseHittest should have been defaultPrevented over statusbar");
   1.119 +
   1.120 +    var button = document.getElementById("button");
   1.121 +    preventDefaulted = synthesizeMouse(button, 2, 2, { type: "MozMouseHittest" });
   1.122 +    SimpleTest.ok(!preventDefaulted, "MozMouseHittest should NOT have been defaultPrevented over button");
   1.123 +  }
   1.124 +
   1.125 +  origoldx = window.screenX;
   1.126 +  origoldy = window.screenY;
   1.127 +
   1.128 +  var mousedownListener = function (event) mouseDownTarget = event.originalTarget;
   1.129 +  window.addEventListener("mousedown", mousedownListener, false);
   1.130 +  synthesizeMouse(label, 2, 2, { type: "mousedown" });
   1.131 +  SimpleTest.is(mouseDownTarget, titlebar, "movedown on titlebar");
   1.132 +  waitForWindowMove(label, 22, 22, test_titlebar_step2, mousedownListener);
   1.133 +}
   1.134 +
   1.135 +function test_titlebar_step2(mousedownListener)
   1.136 +{
   1.137 +  var titlebar = document.getElementById("titlebar");
   1.138 +  var label = document.getElementById("label");
   1.139 +
   1.140 +  SimpleTest.is(window.screenX, origoldx + 20, "move window horizontal");
   1.141 +  SimpleTest.is(window.screenY, origoldy + 20, "move window vertical");
   1.142 +  synthesizeMouse(label, 22, 22, { type: "mouseup" });
   1.143 +
   1.144 +  // with allowEvents set to true, the mouse should target the label instead
   1.145 +  // and not move the window
   1.146 +  titlebar.allowEvents = true;
   1.147 +
   1.148 +  synthesizeMouse(label, 2, 2, { type: "mousedown" });
   1.149 +  SimpleTest.is(mouseDownTarget, label, "movedown on titlebar with allowevents");
   1.150 +  synthesizeMouse(label, 22, 22, { type: "mousemove" });
   1.151 +  SimpleTest.is(window.screenX, origoldx + 20, "mouse on label move window horizontal");
   1.152 +  SimpleTest.is(window.screenY, origoldy + 20, "mouse on label move window vertical");
   1.153 +  synthesizeMouse(label, 22, 22, { type: "mouseup" });
   1.154 +
   1.155 +  window.removeEventListener("mousedown", mousedownListener, false);
   1.156 +
   1.157 +  document.getElementById("panel").openPopupAtScreen(window.screenX + 50, window.screenY + 60, false);
   1.158 +}
   1.159 +
   1.160 +function popupshown(panel, anchored)
   1.161 +{
   1.162 +  var rect = panel.getBoundingClientRect();
   1.163 +
   1.164 +  // skip this check for non-noautohide panels
   1.165 +  if (panel.id == "panel") {
   1.166 +    var panellabel = panel.firstChild.firstChild;
   1.167 +    synthesizeMouse(panellabel, 2, 2, { type: "mousedown" });
   1.168 +    waitForWindowMove(panellabel, 22, 22, popupshown_step3, rect, panel, anchored);
   1.169 +    return;
   1.170 +  }
   1.171 +
   1.172 +  // now, try moving the window. If anchored, the popup should move with the
   1.173 +  // window. If not anchored, the popup should remain at its current screen location.
   1.174 +  window.moveBy(10, 10);
   1.175 +  waitSteps = 1;
   1.176 +  waitForWindowMove(document.getElementById("label"), 1, 1, popupshown_step2, rect, panel, anchored);
   1.177 +}
   1.178 +
   1.179 +function popupshown_step2(oldrect, panel, anchored)
   1.180 +{
   1.181 +  var newrect = panel.getBoundingClientRect();
   1.182 +
   1.183 +  // The window movement that occured long ago at the beginning of the test
   1.184 +  // on Linux is delayed and there isn't any way to tell when the move
   1.185 +  // actually happened. This causes the checks here to fail. Instead, just
   1.186 +  // wait a bit for the test to be ready.
   1.187 +  if (navigator.platform.indexOf("Linux") >= 0 &&
   1.188 +      newrect.left != oldrect.left - (anchored ? 0 : 10)) {
   1.189 +    setTimeout(popupshown_step2, 10, oldrect, panel, anchored);
   1.190 +    return;
   1.191 +  }
   1.192 +
   1.193 +  // anchored popups should still be at the same offset. Non-anchored popups will
   1.194 +  // now be offset by 10 pixels less.
   1.195 +  SimpleTest.is(newrect.left, oldrect.left - (anchored ? 0 : 10),
   1.196 +                panel.id + " horizontal after window move");
   1.197 +  SimpleTest.is(newrect.top, oldrect.top - (anchored ? 0 : 10),
   1.198 +                panel.id + " vertical after window move");
   1.199 +
   1.200 +  var panellabel = panel.firstChild.firstChild;
   1.201 +  synthesizeMouse(panellabel, 2, 2, { type: "mousedown" });
   1.202 +  waitForWindowMove(panellabel, 22, 22, popupshown_step3, newrect, panel, anchored);
   1.203 +}
   1.204 +
   1.205 +function popupshown_step3(oldrect, panel, anchored)
   1.206 +{
   1.207 +  // skip this check on Linux for the same window positioning reasons as above
   1.208 +  if (navigator.platform.indexOf("Linux") == -1 || (panel.id != "panelanchored" && panel.id != "paneltop")) {
   1.209 +    // next, drag the titlebar in the panel
   1.210 +    var newrect = panel.getBoundingClientRect();
   1.211 +    SimpleTest.is(newrect.left, oldrect.left + 20, panel.id + " move popup horizontal");
   1.212 +    SimpleTest.is(newrect.top, oldrect.top + 20, panel.id + " move popup vertical");
   1.213 +    synthesizeMouse(document.getElementById("panellabel"), 22, 22, { type: "mouseup" });
   1.214 +
   1.215 +    synthesizeMouse(document.getElementById("button"), 5, 5, { type: "mousemove" });
   1.216 +    newrect = panel.getBoundingClientRect();
   1.217 +    SimpleTest.is(newrect.left, oldrect.left + 20, panel.id + " horizontal after mouse on button");
   1.218 +    SimpleTest.is(newrect.top, oldrect.top + 20, panel.id + " vertical after mouse on button");
   1.219 +  }
   1.220 +  else {
   1.221 +    synthesizeMouse(document.getElementById("panellabel"), 22, 22, { type: "mouseup" });
   1.222 +  }
   1.223 +
   1.224 +  panel.hidePopup();
   1.225 +}
   1.226 +
   1.227 +function popuphidden(nextPopup)
   1.228 +{
   1.229 +  if (nextPopup) {
   1.230 +    var panel = document.getElementById(nextPopup);
   1.231 +    if (panel.id == "panelnoautohide") {
   1.232 +      panel.openPopupAtScreen(window.screenX + 50, window.screenY + 60, false);
   1.233 +    }
   1.234 +    else {
   1.235 +      panel.openPopup(document.getElementById("button"), "after_start");
   1.236 +    }
   1.237 +  }
   1.238 +  else
   1.239 +    window.opener.wrappedJSObject.done(window);
   1.240 +}
   1.241 +
   1.242 +]]>
   1.243 +</script>
   1.244 +
   1.245 +</window>

mercurial