toolkit/content/tests/chrome/window_titlebar.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <?xml version="1.0"?>
     2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     3 <!--
     4   XUL Widget Test for the titlebar element and window dragging
     5   -->
     6 <window title="Titlebar" width="200" height="200"
     7         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     9   <script type="application/javascript"
    10           src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    12   <titlebar id="titlebar">
    13     <label id="label" value="Titlebar"/>
    14   </titlebar>
    16   <!-- a non-noautohide panel is treated as anchored -->
    17   <panel id="panel" onpopupshown="popupshown(this, false)" onpopuphidden="popuphidden('panelnoautohide')">
    18     <titlebar>
    19       <label id="panellabel" value="Titlebar"/>
    20     </titlebar>
    21   </panel>
    23   <panel id="panelnoautohide" noautohide="true"
    24          onpopupshown="popupshown(this, false)" onpopuphidden="popuphidden('panelanchored')">
    25     <titlebar>
    26       <label id="panellabelnoautohide" value="Titlebar"/>
    27     </titlebar>
    28   </panel>
    30   <panel id="panelanchored" noautohide="true"
    31           onpopupshown="popupshown(this, true)" onpopuphidden="popuphidden('paneltop')">
    32     <titlebar>
    33       <label id="panellabelanchored" value="Titlebar"/>
    34     </titlebar>
    35   </panel>
    37   <panel id="paneltop" noautohide="true" level="top"
    38          onpopupshown="popupshown(this, false)" onpopuphidden="popuphidden('panelfloating')">
    39     <titlebar>
    40       <label id="panellabeltop" value="Titlebar"/>
    41     </titlebar>
    42   </panel>
    44   <panel id="panelfloating" noautohide="true" level="floating"
    45          onpopupshown="popupshown(this, false)" onpopuphidden="popuphidden('')">
    46     <titlebar>
    47       <label id="panellabelfloating" value="Titlebar"/>
    48     </titlebar>
    49   </panel>
    51   <button id="button" label="OK"/>
    52   <statusbar id="statusbar">
    53     <statusbarpanel>
    54       <label id="statuslabel" value="Status"/>
    55     </statusbarpanel>
    56   </statusbar>
    58 <script>
    59 <![CDATA[
    61 var SimpleTest = window.opener.wrappedJSObject.SimpleTest;
    63 SimpleTest.waitForFocus(test_titlebar, window);
    65 var mouseDownTarget;
    66 var origoldx, origoldy, oldx, oldy, waitSteps = 0;
    67 function waitForWindowMove(element, x, y, callback, arg, panel, anchored)
    68 {
    69   var isPanelMove = (element.id != "label");
    71   if (!waitSteps) {
    72     oldx = isPanelMove ? panel.getBoundingClientRect().left : window.screenX;
    73     oldy = isPanelMove ? panel.getBoundingClientRect().top : window.screenY;
    74     synthesizeMouse(element, x, y, { type: "mousemove" });
    75   }
    77   var newx = isPanelMove ? panel.getBoundingClientRect().left : window.screenX; 
    78   var newy = isPanelMove ? panel.getBoundingClientRect().top : window.screenY; 
    79   if (newx == oldx && newy == oldy) {
    80     if (waitSteps++ > 10) {
    81       SimpleTest.is(window.screenX + "," + window.screenY, oldx + "," + oldy + " ",
    82                     "Window never moved properly to " + x + "," + y + (panel ? " " + panel.id : ""));
    83       window.opener.wrappedJSObject.SimpleTest.finish();
    84       window.close();
    85       return;
    86     }
    88     setTimeout(waitForWindowMove, 100, element, x, y, callback, arg, panel, anchored);
    89   }
    90   else {
    91     waitSteps = 0;
    93     // on Linux, we need to wait a bit for the popup to be moved as well
    94     if (navigator.platform.indexOf("Linux") >= 0) {
    95       setTimeout(callback, 0, arg, panel, anchored);
    96     }
    97     else {
    98       callback(arg, panel, anchored);
    99     }
   100   }
   101 }
   103 function test_titlebar()
   104 {
   105   var titlebar = document.getElementById("titlebar");
   106   var label = document.getElementById("label");
   108   // On Mac, the window can also be moved with the statusbar, but this works
   109   // via the MozMouseHittest event, not via mouse events.
   110   if (navigator.platform.indexOf("Mac") >= 0) {
   111     var preventDefaulted;
   113     var statuslabel = document.getElementById("statuslabel");
   114     preventDefaulted = synthesizeMouse(statuslabel, 2, 2, { type: "MozMouseHittest" });
   115     SimpleTest.ok(preventDefaulted, "MozMouseHittest should have been defaultPrevented over statusbar");
   117     var button = document.getElementById("button");
   118     preventDefaulted = synthesizeMouse(button, 2, 2, { type: "MozMouseHittest" });
   119     SimpleTest.ok(!preventDefaulted, "MozMouseHittest should NOT have been defaultPrevented over button");
   120   }
   122   origoldx = window.screenX;
   123   origoldy = window.screenY;
   125   var mousedownListener = function (event) mouseDownTarget = event.originalTarget;
   126   window.addEventListener("mousedown", mousedownListener, false);
   127   synthesizeMouse(label, 2, 2, { type: "mousedown" });
   128   SimpleTest.is(mouseDownTarget, titlebar, "movedown on titlebar");
   129   waitForWindowMove(label, 22, 22, test_titlebar_step2, mousedownListener);
   130 }
   132 function test_titlebar_step2(mousedownListener)
   133 {
   134   var titlebar = document.getElementById("titlebar");
   135   var label = document.getElementById("label");
   137   SimpleTest.is(window.screenX, origoldx + 20, "move window horizontal");
   138   SimpleTest.is(window.screenY, origoldy + 20, "move window vertical");
   139   synthesizeMouse(label, 22, 22, { type: "mouseup" });
   141   // with allowEvents set to true, the mouse should target the label instead
   142   // and not move the window
   143   titlebar.allowEvents = true;
   145   synthesizeMouse(label, 2, 2, { type: "mousedown" });
   146   SimpleTest.is(mouseDownTarget, label, "movedown on titlebar with allowevents");
   147   synthesizeMouse(label, 22, 22, { type: "mousemove" });
   148   SimpleTest.is(window.screenX, origoldx + 20, "mouse on label move window horizontal");
   149   SimpleTest.is(window.screenY, origoldy + 20, "mouse on label move window vertical");
   150   synthesizeMouse(label, 22, 22, { type: "mouseup" });
   152   window.removeEventListener("mousedown", mousedownListener, false);
   154   document.getElementById("panel").openPopupAtScreen(window.screenX + 50, window.screenY + 60, false);
   155 }
   157 function popupshown(panel, anchored)
   158 {
   159   var rect = panel.getBoundingClientRect();
   161   // skip this check for non-noautohide panels
   162   if (panel.id == "panel") {
   163     var panellabel = panel.firstChild.firstChild;
   164     synthesizeMouse(panellabel, 2, 2, { type: "mousedown" });
   165     waitForWindowMove(panellabel, 22, 22, popupshown_step3, rect, panel, anchored);
   166     return;
   167   }
   169   // now, try moving the window. If anchored, the popup should move with the
   170   // window. If not anchored, the popup should remain at its current screen location.
   171   window.moveBy(10, 10);
   172   waitSteps = 1;
   173   waitForWindowMove(document.getElementById("label"), 1, 1, popupshown_step2, rect, panel, anchored);
   174 }
   176 function popupshown_step2(oldrect, panel, anchored)
   177 {
   178   var newrect = panel.getBoundingClientRect();
   180   // The window movement that occured long ago at the beginning of the test
   181   // on Linux is delayed and there isn't any way to tell when the move
   182   // actually happened. This causes the checks here to fail. Instead, just
   183   // wait a bit for the test to be ready.
   184   if (navigator.platform.indexOf("Linux") >= 0 &&
   185       newrect.left != oldrect.left - (anchored ? 0 : 10)) {
   186     setTimeout(popupshown_step2, 10, oldrect, panel, anchored);
   187     return;
   188   }
   190   // anchored popups should still be at the same offset. Non-anchored popups will
   191   // now be offset by 10 pixels less.
   192   SimpleTest.is(newrect.left, oldrect.left - (anchored ? 0 : 10),
   193                 panel.id + " horizontal after window move");
   194   SimpleTest.is(newrect.top, oldrect.top - (anchored ? 0 : 10),
   195                 panel.id + " vertical after window move");
   197   var panellabel = panel.firstChild.firstChild;
   198   synthesizeMouse(panellabel, 2, 2, { type: "mousedown" });
   199   waitForWindowMove(panellabel, 22, 22, popupshown_step3, newrect, panel, anchored);
   200 }
   202 function popupshown_step3(oldrect, panel, anchored)
   203 {
   204   // skip this check on Linux for the same window positioning reasons as above
   205   if (navigator.platform.indexOf("Linux") == -1 || (panel.id != "panelanchored" && panel.id != "paneltop")) {
   206     // next, drag the titlebar in the panel
   207     var newrect = panel.getBoundingClientRect();
   208     SimpleTest.is(newrect.left, oldrect.left + 20, panel.id + " move popup horizontal");
   209     SimpleTest.is(newrect.top, oldrect.top + 20, panel.id + " move popup vertical");
   210     synthesizeMouse(document.getElementById("panellabel"), 22, 22, { type: "mouseup" });
   212     synthesizeMouse(document.getElementById("button"), 5, 5, { type: "mousemove" });
   213     newrect = panel.getBoundingClientRect();
   214     SimpleTest.is(newrect.left, oldrect.left + 20, panel.id + " horizontal after mouse on button");
   215     SimpleTest.is(newrect.top, oldrect.top + 20, panel.id + " vertical after mouse on button");
   216   }
   217   else {
   218     synthesizeMouse(document.getElementById("panellabel"), 22, 22, { type: "mouseup" });
   219   }
   221   panel.hidePopup();
   222 }
   224 function popuphidden(nextPopup)
   225 {
   226   if (nextPopup) {
   227     var panel = document.getElementById(nextPopup);
   228     if (panel.id == "panelnoautohide") {
   229       panel.openPopupAtScreen(window.screenX + 50, window.screenY + 60, false);
   230     }
   231     else {
   232       panel.openPopup(document.getElementById("button"), "after_start");
   233     }
   234   }
   235   else
   236     window.opener.wrappedJSObject.done(window);
   237 }
   239 ]]>
   240 </script>
   242 </window>

mercurial