DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (409f3966645a)

VCS Links

Line Code
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
<?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"?>

<window title="Window Minimum and Maximum Size Tests" onload="nextTest()"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>

<panel id="panel" onpopupshown="doPanelTest(this)" onpopuphidden="nextPopupTest(this)"
       align="start" pack="start" style="-moz-appearance: none; margin: 0; border: 0; padding: 0;">
  <resizer id="popupresizer" dir="bottomright" flex="1" width="60" height="60"
           style="-moz-appearance: none; margin: 0; border: 0; padding: 0;"/>
</panel>

<script>
<![CDATA[

SimpleTest.waitForExplicitFinish();

var gTestId = -1;

// width and height in the tests below specify the expected size of the window.
// note, win8 has a minimum inner window size of around 122 pixels. Don't go below this on min-width tests.
var tests = [
  { testname: "unconstrained",
    src: "windowminmaxsize1.xul",
    width: 150, height: 150 },
  { testname: "constraint min style",
    src: "windowminmaxsize2.xul",
    width: 180, height: 210 },
  { testname: "constraint max style",
    src: "windowminmaxsize3.xul",
    width: 125, height: 140 },
  { testname: "constraint min attributes",
    src: "windowminmaxsize4.xul",
    width: 240, height: 220 },
  { testname: "constraint min attributes with width and height set",
    src: "windowminmaxsize5.xul",
    width: 215, height: 235 },
  { testname: "constraint max attributes",
    src: "windowminmaxsize6.xul",
    width: 125, height: 95 },
  // this gets the inner width as <window minwidth='210'> makes the box 210 pixels wide
  { testname: "constraint min width attribute only",
    src: "windowminmaxsize7.xul",
    width: 210, height: 150 },
  { testname: "constraint max width attribute only",
    src: "windowminmaxsize8.xul",
    width: 128, height: 150 },
  { testname: "constraint max width attribute with minheight",
    src: "windowminmaxsize9.xul",
    width: 195, height: 180 },
  { testname: "constraint minwidth, minheight, maxwidth and maxheight set",
    src: "windowminmaxsize10.xul",
    width: 150, height: 150, last: true }
];

var popupTests = [
  { testname: "popup unconstrained",
    width: 60, height: 60
  },
  { testname: "popup with minimum size",
    minwidth: 150, minheight: 180,
    width: 150, height: 180
  },
  { testname: "popup with maximum size",
    maxwidth: 50, maxheight: 45,
    width: 50, height: 45,
  },
  { testname: "popup with minimum and size",
    minwidth: 80, minheight: 70, maxwidth: 250, maxheight: 220,
    width: 80, height: 70, last: true
  }
];

function nextTest()
{
  // Run through each of the tests above by opening a simple window with
  // the attributes or style defined for that test. The comparisons will be
  // done by windowOpened. gTestId holds the index into the tests array.
  if (++gTestId >= tests.length) {
    // Now do the popup tests
    gTestId = -1;
    SimpleTest.waitForFocus(function () { nextPopupTest(document.getElementById("panel")) } );
  }
  else {
    tests[gTestId].window = window.open(tests[gTestId].src, "_blank", "chrome,resizable=yes");
    SimpleTest.waitForFocus(windowOpened, tests[gTestId].window);
  }
}

function windowOpened(otherWindow)
{
  // Check the width and the width plus one due to bug 696746.
  ok(otherWindow.innerWidth == tests[gTestId].width ||
     otherWindow.innerWidth == tests[gTestId].width + 1,
    tests[gTestId].testname + " width of " + otherWindow.innerWidth + " matches " + tests[gTestId].width);
  is(otherWindow.innerHeight, tests[gTestId].height, tests[gTestId].testname + " height");

  // On the last test, try moving the resizer to a size larger than the maximum
  // and smaller than the minimum. This test is only done on Mac as the other
  // platforms use native resizing.
  if ('last' in tests[gTestId] && (navigator.platform.indexOf("Mac") == 0)) {
    var resizer = otherWindow.document.documentElement.firstChild;
    synthesizeMouse(resizer, 4, 4, { type:"mousedown" }, otherWindow);
    synthesizeMouse(resizer, 800, 800, { type:"mousemove" }, otherWindow);
    is(otherWindow.innerWidth, 480, "Width after maximum resize");
    is(otherWindow.innerHeight, 470, "Height after maximum resize");

    synthesizeMouse(resizer, -100, -100, { type:"mousemove" }, otherWindow);
    is(otherWindow.innerWidth, 120, "Width after minimum resize");
    is(otherWindow.innerHeight, 110, "Height after minimum resize");

    synthesizeMouse(resizer, 4, 4, { type:"mouseup" }, otherWindow);

    // Change the minimum and maximum size and try resizing the window again.
    otherWindow.document.documentElement.minWidth = 140;
    otherWindow.document.documentElement.minHeight = 130;
    otherWindow.document.documentElement.maxWidth = 380;
    otherWindow.document.documentElement.maxHeight = 360;

    synthesizeMouse(resizer, 4, 4, { type:"mousedown" }, otherWindow);
    synthesizeMouse(resizer, 800, 800, { type:"mousemove" }, otherWindow);
    is(otherWindow.innerWidth, 380, "Width after changed maximum resize");
    is(otherWindow.innerHeight, 360, "Height after changed maximum resize");

    synthesizeMouse(resizer, -100, -100, { type:"mousemove" }, otherWindow);
    is(otherWindow.innerWidth, 140, "Width after changed minimum resize");
    is(otherWindow.innerHeight, 130, "Height after changed minimum resize");

    synthesizeMouse(resizer, 4, 4, { type:"mouseup" }, otherWindow);
  }

  otherWindow.close();
  nextTest();
}

function doPanelTest(panel)
{
  var rect = panel.getBoundingClientRect();
  is(rect.width, popupTests[gTestId].width, popupTests[gTestId].testname + " width");
  is(rect.height, popupTests[gTestId].height, popupTests[gTestId].testname + " height");

  if ('last' in popupTests[gTestId]) {
    var resizer = document.getElementById("popupresizer");
    synthesizeMouse(resizer, 4, 4, { type:"mousedown" });
    synthesizeMouse(resizer, 800, 800, { type:"mousemove" });

    rect = panel.getBoundingClientRect();
    is(rect.width, 250, "Popup width after maximum resize");
    is(rect.height, 220, "Popup height after maximum resize");

    synthesizeMouse(resizer, -100, -100, { type:"mousemove" });

    rect = panel.getBoundingClientRect();
    is(rect.width, 80, "Popup width after minimum resize");
    is(rect.height, 70, "Popup height after minimum resize");

    synthesizeMouse(resizer, 4, 4, { type:"mouseup" });
  }

  panel.hidePopup();
}

function nextPopupTest(panel)
{
  if (++gTestId >= popupTests.length) {
    // Next, check a panel that has a titlebar to ensure that it is accounted for
    // properly in the size.
    var titledPanelWindow = window.open("titledpanelwindow.xul", "_blank", "chrome,resizable=yes");
    SimpleTest.waitForFocus(titledPanelWindowOpened, titledPanelWindow);
  }
  else {
    function setattr(attr) {
      if (attr in popupTests[gTestId])
        panel.setAttribute(attr, popupTests[gTestId][attr]);
      else
        panel.removeAttribute(attr);
    }
    setattr("minwidth");
    setattr("minheight");
    setattr("maxwidth");
    setattr("maxheight");

    // Remove the flexibility as it causes the resizer to not shrink down
    // when resizing.
    if ("last" in popupTests[gTestId])
      document.getElementById("popupresizer").removeAttribute("flex");

    // Prevent event loop starvation as a result of popup events being
    // synchronous. See bug 1131576.
    SimpleTest.executeSoon(() => {
      // Non-chrome shells require focus to open a popup.
      SimpleTest.waitForFocus(() => { panel.openPopup() });
    });
  }
}

function titledPanelWindowOpened(panelwindow)
{
  var panel = panelwindow.document.documentElement.firstChild;
  panel.openPopup();
  panel.addEventListener("popupshown", () => doTitledPanelTest(panel), false);
  panel.addEventListener("popuphidden", () => done(panelwindow), false);
}

function doTitledPanelTest(panel)
{
  var rect = panel.getBoundingClientRect();
  is(rect.width, 120, "panel with titlebar width");
  is(rect.height, 140, "panel with titlebar height");
  panel.hidePopup();
}

function done(panelwindow)
{
  panelwindow.close();
  SimpleTest.finish();
}

]]>
</script>

<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>

</window>