toolkit/content/tests/chrome/window_panel.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/chrome/window_panel.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,312 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     1.7 +<!--
     1.8 +  XUL Widget Test for panels
     1.9 +  -->
    1.10 +<window title="Titlebar" width="200" height="200"
    1.11 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.12 +  <script type="application/javascript"
    1.13 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.14 +  <script type="application/javascript"
    1.15 +          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    1.16 +
    1.17 +<tree id="tree" seltype="single" width="100" height="100">
    1.18 +  <treecols>
    1.19 +    <treecol flex="1"/>
    1.20 +    <treecol flex="1"/>
    1.21 +  </treecols>
    1.22 +  <treechildren id="treechildren">
    1.23 +    <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem>
    1.24 +    <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem>
    1.25 +    <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem>
    1.26 +    <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem>
    1.27 +    <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem>
    1.28 +    <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem>
    1.29 +  </treechildren>
    1.30 +</tree>
    1.31 +
    1.32 +
    1.33 +  <!-- test results are displayed in the html:body -->
    1.34 +  <body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/>
    1.35 +
    1.36 +  <!-- test code goes here -->
    1.37 +  <script type="application/javascript"><![CDATA[
    1.38 +
    1.39 +SimpleTest.waitForExplicitFinish();
    1.40 +
    1.41 +var currentTest = null;
    1.42 +
    1.43 +function ok(condition, message) {
    1.44 +  window.opener.wrappedJSObject.SimpleTest.ok(condition, message);
    1.45 +}
    1.46 +
    1.47 +function is(left, right, message) {
    1.48 +  window.opener.wrappedJSObject.SimpleTest.is(left, right, message);
    1.49 +}
    1.50 +
    1.51 +function test_panels()
    1.52 +{
    1.53 +  checkTreeCoords();
    1.54 +
    1.55 +  addEventListener("popupshowing", popupShowing, false);
    1.56 +  addEventListener("popupshown", popupShown, false);
    1.57 +  addEventListener("popuphidden", nextTest, false);
    1.58 +  nextTest();
    1.59 +}
    1.60 +
    1.61 +function nextTest()
    1.62 +{
    1.63 +  if (!tests.length) {
    1.64 +    window.close();
    1.65 +    window.opener.wrappedJSObject.SimpleTest.finish();
    1.66 +    return;
    1.67 +  }
    1.68 +
    1.69 +  currentTest = tests.shift();
    1.70 +  var panel = createPanel(currentTest.attrs);
    1.71 +  currentTest.test(panel);
    1.72 +}
    1.73 +
    1.74 +function popupShowing(event)
    1.75 +{
    1.76 +  var rect = event.target.getOuterScreenRect();
    1.77 +  ok(!rect.left && !rect.top && !rect.width && !rect.height,
    1.78 +     currentTest.testname + " empty rectangle during popupshowing");
    1.79 +}
    1.80 +
    1.81 +var waitSteps = 0;
    1.82 +function popupShown(event)
    1.83 +{
    1.84 +  var panel = event.target;
    1.85 +
    1.86 +  if (waitSteps > 0 && navigator.platform.indexOf("Linux") >= 0 &&
    1.87 +      panel.boxObject.screenY == 210) {
    1.88 +    waitSteps--;
    1.89 +    setTimeout(popupShown, 10, event);
    1.90 +    return;
    1.91 +  }
    1.92 +
    1.93 +  currentTest.result(currentTest.testname + " ", panel);
    1.94 +  panel.hidePopup();
    1.95 +}
    1.96 +
    1.97 +function createPanel(attrs)
    1.98 +{
    1.99 +  var panel = document.createElement("panel");
   1.100 +  for (var a in attrs) {
   1.101 +    panel.setAttribute(a, attrs[a]);
   1.102 +  }
   1.103 +
   1.104 +  var button = document.createElement("button");
   1.105 +  panel.appendChild(button);
   1.106 +  button.label = "OK";
   1.107 +  button.width = 120;
   1.108 +  button.height = 40;
   1.109 +  button.setAttribute("style", "-moz-appearance: none; border: 0; margin: 0;");
   1.110 +  panel.setAttribute("style", "-moz-appearance: none; border: 0; margin: 0;");
   1.111 +  return document.documentElement.appendChild(panel);
   1.112 +}
   1.113 +
   1.114 +function checkTreeCoords()
   1.115 +{
   1.116 +  var tree = $("tree");
   1.117 +  var treechildren = $("treechildren");
   1.118 +  tree.currentIndex = 0;
   1.119 +  tree.treeBoxObject.scrollToRow(0);
   1.120 +  synthesizeMouse(treechildren, 10, tree.treeBoxObject.rowHeight + 2, { });
   1.121 +  is(tree.currentIndex, 1, "tree selection");
   1.122 +
   1.123 +  tree.treeBoxObject.scrollToRow(2);
   1.124 +  synthesizeMouse(treechildren, 10, tree.treeBoxObject.rowHeight + 2, { });
   1.125 +  is(tree.currentIndex, 3, "tree selection after scroll");
   1.126 +}
   1.127 +
   1.128 +var tests = [
   1.129 +  {
   1.130 +    testname: "normal panel",
   1.131 +    attrs: { },
   1.132 +    test: function(panel) {
   1.133 +      var screenRect = panel.getOuterScreenRect();
   1.134 +      is(screenRect.left, 0, this.testname + " screen left before open");
   1.135 +      is(screenRect.top, 0, this.testname + " screen top before open");
   1.136 +      is(screenRect.width, 0, this.testname + " screen width before open");
   1.137 +      is(screenRect.height, 0, this.testname + " screen height before open");
   1.138 +
   1.139 +      panel.openPopupAtScreen(200, 210);
   1.140 +    },
   1.141 +    result: function(testname, panel) {
   1.142 +      var panelrect = panel.getBoundingClientRect();
   1.143 +      is(panelrect.left, 200 - mozInnerScreenX, testname + "left");
   1.144 +      is(panelrect.top, 210 - mozInnerScreenY, testname + "top");
   1.145 +      is(panelrect.width, 120, testname + "width");
   1.146 +      is(panelrect.height, 40, testname + "height");
   1.147 +
   1.148 +      var screenRect = panel.getOuterScreenRect();
   1.149 +      is(screenRect.left, 200, testname + " screen left");
   1.150 +      is(screenRect.top, 210, testname + " screen top");
   1.151 +      is(screenRect.width, 120, testname + " screen width");
   1.152 +      is(screenRect.height, 40, testname + " screen height");
   1.153 +    }
   1.154 +  },
   1.155 +  {
   1.156 +    // only noautohide panels support titlebars, so one shouldn't be shown here
   1.157 +    testname: "autohide panel with titlebar",
   1.158 +    attrs: { titlebar: "normal" },
   1.159 +    test: function(panel) {
   1.160 +      var screenRect = panel.getOuterScreenRect();
   1.161 +      is(screenRect.left, 0, this.testname + " screen left before open");
   1.162 +      is(screenRect.top, 0, this.testname + " screen top before open");
   1.163 +      is(screenRect.width, 0, this.testname + " screen width before open");
   1.164 +      is(screenRect.height, 0, this.testname + " screen height before open");
   1.165 +
   1.166 +      panel.openPopupAtScreen(200, 210);
   1.167 +    },
   1.168 +    result: function(testname, panel) {
   1.169 +      var panelrect = panel.getBoundingClientRect();
   1.170 +      is(panelrect.left, 200 - mozInnerScreenX, testname + "left");
   1.171 +      is(panelrect.top, 210 - mozInnerScreenY, testname + "top");
   1.172 +      is(panelrect.width, 120, testname + "width");
   1.173 +      is(panelrect.height, 40, testname + "height");
   1.174 +
   1.175 +      var screenRect = panel.getOuterScreenRect();
   1.176 +      is(screenRect.left, 200, testname + " screen left");
   1.177 +      is(screenRect.top, 210, testname + " screen top");
   1.178 +      is(screenRect.width, 120, testname + " screen width");
   1.179 +      is(screenRect.height, 40, testname + " screen height");
   1.180 +    }
   1.181 +  },
   1.182 +  {
   1.183 +    testname: "noautohide panel with titlebar",
   1.184 +    attrs: { noautohide: true, titlebar: "normal" },
   1.185 +    test: function(panel) {
   1.186 +      waitSteps = 25;
   1.187 +
   1.188 +      var screenRect = panel.getOuterScreenRect();
   1.189 +      is(screenRect.left, 0, this.testname + " screen left before open");
   1.190 +      is(screenRect.top, 0, this.testname + " screen top before open");
   1.191 +      is(screenRect.width, 0, this.testname + " screen width before open");
   1.192 +      is(screenRect.height, 0, this.testname + " screen height before open");
   1.193 +
   1.194 +      panel.openPopupAtScreen(200, 210);
   1.195 +    },
   1.196 +    result: function(testname, panel) {
   1.197 +      var panelrect = panel.getBoundingClientRect();
   1.198 +      ok(panelrect.left >= 200 - mozInnerScreenX, testname + "left");
   1.199 +      if (navigator.platform.indexOf("Linux") < 0) {
   1.200 +        ok(panelrect.top >= 210 - mozInnerScreenY + 10, testname + "top greater");
   1.201 +      }
   1.202 +      ok(panelrect.top <= 210 - mozInnerScreenY + 30, testname + "top less");
   1.203 +      is(panelrect.width, 120, testname + "width");
   1.204 +      is(panelrect.height, 40, testname + "height");
   1.205 +
   1.206 +      var screenRect = panel.getOuterScreenRect();
   1.207 +      if (navigator.platform.indexOf("Linux") < 0) {
   1.208 +        is(screenRect.left, 200, testname + " screen left");
   1.209 +        is(screenRect.top, 210, testname + " screen top");
   1.210 +      }
   1.211 +      ok(screenRect.width >= 120 && screenRect.width <= 140, testname + " screen width");
   1.212 +      ok(screenRect.height >= 40 && screenRect.height <= 80, testname + " screen height");
   1.213 +
   1.214 +      var gotMouseEvent = false;
   1.215 +      function mouseMoved(event)
   1.216 +      {
   1.217 +        is(event.clientY, panelrect.top + 10,
   1.218 +           "popup clientY");
   1.219 +        is(event.screenY, panel.boxObject.screenY + 10,
   1.220 +           "popup screenY");
   1.221 +        is(event.originalTarget, panel.firstChild, "popup target");
   1.222 +        gotMouseEvent = true;
   1.223 +      }
   1.224 +
   1.225 +      panel.addEventListener("mousemove", mouseMoved, true);
   1.226 +      synthesizeMouse(panel, 10, 10, { type: "mousemove" });
   1.227 +      ok(gotMouseEvent, "mouse event on panel");      
   1.228 +      panel.removeEventListener("mousemove", mouseMoved, true);
   1.229 +
   1.230 +      var tree = $("tree");
   1.231 +      tree.currentIndex = 0;
   1.232 +      panel.appendChild(tree);
   1.233 +      checkTreeCoords();
   1.234 +    }
   1.235 +  },
   1.236 +  {
   1.237 +    testname: "noautohide panel with backdrag",
   1.238 +    attrs: { noautohide: true, backdrag: "true" },
   1.239 +    test: function(panel) {
   1.240 +      var label = document.createElement("label");
   1.241 +      label.id = "backdragspot";
   1.242 +      label.setAttribute("value", "Hello There");
   1.243 +      panel.appendChild(label);
   1.244 +      panel.openPopupAtScreen(200, 230);
   1.245 +    },
   1.246 +    result: function(testname, panel) {
   1.247 +      var oldrect = panel.getOuterScreenRect();
   1.248 +
   1.249 +      // Linux uses native window moving
   1.250 +      if (navigator.platform.indexOf("Linux") == -1) {
   1.251 +        var backdragspot = document.getElementById("backdragspot");
   1.252 +        synthesizeMouse(backdragspot, 5, 5, { type: "mousedown" });
   1.253 +        synthesizeMouse(backdragspot, 15, 20, { type: "mousemove" });
   1.254 +        synthesizeMouse(backdragspot, 15, 20, { type: "mouseup" });
   1.255 +
   1.256 +        is(panel.getOuterScreenRect().left, 210, testname + "left");
   1.257 +        is(panel.getOuterScreenRect().top, 245, testname + "top");
   1.258 +      }
   1.259 +    }
   1.260 +  },
   1.261 +  {
   1.262 +    // The panel should be allowed to appear and remain offscreen
   1.263 +    testname: "normal panel with flip='none' off-screen",
   1.264 +    attrs: { "flip": "none" },
   1.265 +    test: function(panel) {
   1.266 +      panel.openPopup(document.documentElement, "", -100 - mozInnerScreenX, -100 - mozInnerScreenY, false, false, null);
   1.267 +    },
   1.268 +    result: function(testname, panel) {
   1.269 +      var panelrect = panel.getBoundingClientRect();
   1.270 +      is(panelrect.left, -100 - mozInnerScreenX, testname + "left");
   1.271 +      is(panelrect.top, -100 - mozInnerScreenY, testname + "top");
   1.272 +      is(panelrect.width, 120, testname + "width");
   1.273 +      is(panelrect.height, 40, testname + "height");
   1.274 +
   1.275 +      var screenRect = panel.getOuterScreenRect();
   1.276 +      is(screenRect.left, -100, testname + " screen left");
   1.277 +      is(screenRect.top, -100, testname + " screen top");
   1.278 +      is(screenRect.width, 120, testname + " screen width");
   1.279 +      is(screenRect.height, 40, testname + " screen height");
   1.280 +    }
   1.281 +  },
   1.282 +  {
   1.283 +    // The panel should be allowed to remain offscreen after moving and it should follow the anchor
   1.284 +    testname: "normal panel with flip='none' moved off-screen",
   1.285 +    attrs: { "flip": "none" },
   1.286 +    test: function(panel) {
   1.287 +      panel.openPopup(document.documentElement, "", -100 - mozInnerScreenX, -100 - mozInnerScreenY, false, false, null);
   1.288 +      window.moveBy(-50, -50);
   1.289 +    },
   1.290 +    result: function(testname, panel) {
   1.291 +      if (navigator.platform.indexOf("Linux") >= 0) {
   1.292 +        // The window position doesn't get updated immediately on Linux.
   1.293 +        return;
   1.294 +      }
   1.295 +      var panelrect = panel.getBoundingClientRect();
   1.296 +      is(panelrect.left, -150 - mozInnerScreenX, testname + "left");
   1.297 +      is(panelrect.top, -150 - mozInnerScreenY, testname + "top");
   1.298 +      is(panelrect.width, 120, testname + "width");
   1.299 +      is(panelrect.height, 40, testname + "height");
   1.300 +
   1.301 +      var screenRect = panel.getOuterScreenRect();
   1.302 +      is(screenRect.left, -150, testname + " screen left");
   1.303 +      is(screenRect.top, -150, testname + " screen top");
   1.304 +      is(screenRect.width, 120, testname + " screen width");
   1.305 +      is(screenRect.height, 40, testname + " screen height");
   1.306 +    }
   1.307 +  },
   1.308 +];
   1.309 +
   1.310 +window.opener.wrappedJSObject.SimpleTest.waitForFocus(test_panels, window);
   1.311 +
   1.312 +]]>
   1.313 +</script>
   1.314 +
   1.315 +</window>

mercurial