layout/xul/test/test_windowminmaxsize.xul

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
michael@0 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
michael@0 4
michael@0 5 <window title="Window Minimum and Maximum Size Tests" onload="nextTest()"
michael@0 6 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
michael@0 7
michael@0 8 <script type="application/javascript"
michael@0 9 src="chrome://mochikit/content/MochiKit/packed.js"/>
michael@0 10 <script type="application/javascript"
michael@0 11 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 12 <script type="application/javascript"
michael@0 13 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
michael@0 14
michael@0 15 <panel id="panel" onpopupshown="doPanelTest(this)" onpopuphidden="nextPopupTest(this)"
michael@0 16 align="start" pack="start" style="-moz-appearance: none; margin: 0; border: 0; padding: 0;">
michael@0 17 <resizer id="popupresizer" dir="bottomright" flex="1" width="60" height="60"
michael@0 18 style="-moz-appearance: none; margin: 0; border: 0; padding: 0;"/>
michael@0 19 </panel>
michael@0 20
michael@0 21 <script>
michael@0 22 <![CDATA[
michael@0 23
michael@0 24 SimpleTest.waitForExplicitFinish();
michael@0 25
michael@0 26 var gTestId = -1;
michael@0 27
michael@0 28 var prefix = "data:application/vnd.mozilla.xul+xml,<?xml-stylesheet href='chrome://global/skin' type='text/css'?><window " +
michael@0 29 "xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul' " +
michael@0 30 "align='start' pack='start' style='-moz-appearance: none; margin: 0; padding: 0; border: 0; ";
michael@0 31 var suffix = "><resizer dir='bottomright' flex='1' width='150' height='150' style='-moz-appearance: none; margin: 0; border: 0; padding: 0;'/></window>";
michael@0 32 var titledpanel = "<panel noautohide='true' titlebar='normal' minwidth='120' minheight='140'/><label value='Test'/>";
michael@0 33
michael@0 34 // width and height in the tests below specify the expected size of the window.
michael@0 35 // note, win8 has a minimum inner window size of around 122 pixels. Don't go below this on min-width tests.
michael@0 36 var tests = [
michael@0 37 { testname: "unconstrained",
michael@0 38 style: "", attrs: "",
michael@0 39 width: 150, height: 150 },
michael@0 40 { testname: "constraint min style",
michael@0 41 style: "min-width: 180px; min-height: 210px;", attrs: "",
michael@0 42 width: 180, height: 210 },
michael@0 43 { testname: "constraint max style",
michael@0 44 style: "max-width: 125px; max-height: 140px;", attrs: "",
michael@0 45 width: 125, height: 140 },
michael@0 46 { testname: "constraint min attributes",
michael@0 47 style: "", attrs: "minwidth='240' minheight='220'",
michael@0 48 width: 240, height: 220 },
michael@0 49 { testname: "constraint min attributes with width and height set",
michael@0 50 style: "", attrs: "width='190' height='220' minwidth='215' minheight='235'",
michael@0 51 width: 215, height: 235 },
michael@0 52 { testname: "constraint max attributes",
michael@0 53 style: "", attrs: "maxwidth='125' maxheight='95'",
michael@0 54 width: 125, height: 95 },
michael@0 55 // this gets the inner width as <window minwidth='210'> makes the box 210 pixels wide
michael@0 56 { testname: "constraint min width attribute only",
michael@0 57 style: "", attrs: "minwidth='210'",
michael@0 58 width: 210, height: 150 },
michael@0 59 { testname: "constraint max width attribute only",
michael@0 60 style: "", attrs: "maxwidth='128'",
michael@0 61 width: 128, height: 150 },
michael@0 62 { testname: "constraint max width attribute with minheight",
michael@0 63 style: "", attrs: "maxwidth='195' width='230' height='120' minheight='180'",
michael@0 64 width: 195, height: 180 },
michael@0 65 { testname: "constraint minwidth, minheight, maxwidth and maxheight set",
michael@0 66 style: "", attrs: "minwidth='120' maxwidth='480' minheight='110' maxheight='470'",
michael@0 67 width: 150, height: 150, last: true }
michael@0 68 ];
michael@0 69
michael@0 70 var popupTests = [
michael@0 71 { testname: "popup unconstrained",
michael@0 72 width: 60, height: 60
michael@0 73 },
michael@0 74 { testname: "popup with minimum size",
michael@0 75 minwidth: 150, minheight: 180,
michael@0 76 width: 150, height: 180
michael@0 77 },
michael@0 78 { testname: "popup with maximum size",
michael@0 79 maxwidth: 50, maxheight: 45,
michael@0 80 width: 50, height: 45,
michael@0 81 },
michael@0 82 { testname: "popup with minimum and size",
michael@0 83 minwidth: 80, minheight: 70, maxwidth: 250, maxheight: 220,
michael@0 84 width: 80, height: 70, last: true
michael@0 85 }
michael@0 86 ];
michael@0 87
michael@0 88 function nextTest()
michael@0 89 {
michael@0 90 // Run through each of the tests above by opening a simple window with
michael@0 91 // the attributes or style defined for that test. The comparisons will be
michael@0 92 // done by windowOpened. gTestId holds the index into the tests array.
michael@0 93 if (++gTestId >= tests.length) {
michael@0 94 // Now do the popup tests
michael@0 95 gTestId = -1;
michael@0 96 SimpleTest.waitForFocus(function () { nextPopupTest(document.getElementById("panel")) } );
michael@0 97 }
michael@0 98 else {
michael@0 99 tests[gTestId].window = window.open(prefix + tests[gTestId].style + "' " + tests[gTestId].attrs + suffix, "_blank", "chrome,resizable=yes");
michael@0 100 SimpleTest.waitForFocus(windowOpened, tests[gTestId].window);
michael@0 101 }
michael@0 102 }
michael@0 103
michael@0 104 function windowOpened(otherWindow)
michael@0 105 {
michael@0 106 // Check the width and the width plus one due to bug 696746.
michael@0 107 ok(otherWindow.innerWidth == tests[gTestId].width ||
michael@0 108 otherWindow.innerWidth == tests[gTestId].width + 1,
michael@0 109 tests[gTestId].testname + " width of " + otherWindow.innerWidth + " matches " + tests[gTestId].width);
michael@0 110 is(otherWindow.innerHeight, tests[gTestId].height, tests[gTestId].testname + " height");
michael@0 111
michael@0 112 // On the last test, try moving the resizer to a size larger than the maximum
michael@0 113 // and smaller than the minimum. This test is only done on Mac as the other
michael@0 114 // platforms use native resizing.
michael@0 115 if ('last' in tests[gTestId] && (navigator.platform.indexOf("Mac") == 0)) {
michael@0 116 var resizer = otherWindow.document.documentElement.firstChild;
michael@0 117 synthesizeMouse(resizer, 4, 4, { type:"mousedown" }, otherWindow);
michael@0 118 synthesizeMouse(resizer, 800, 800, { type:"mousemove" }, otherWindow);
michael@0 119 is(otherWindow.innerWidth, 480, "Width after maximum resize");
michael@0 120 is(otherWindow.innerHeight, 470, "Height after maximum resize");
michael@0 121
michael@0 122 synthesizeMouse(resizer, -100, -100, { type:"mousemove" }, otherWindow);
michael@0 123 is(otherWindow.innerWidth, 120, "Width after minimum resize");
michael@0 124 is(otherWindow.innerHeight, 110, "Height after minimum resize");
michael@0 125
michael@0 126 synthesizeMouse(resizer, 4, 4, { type:"mouseup" }, otherWindow);
michael@0 127
michael@0 128 // Change the minimum and maximum size and try resizing the window again.
michael@0 129 otherWindow.document.documentElement.minWidth = 140;
michael@0 130 otherWindow.document.documentElement.minHeight = 130;
michael@0 131 otherWindow.document.documentElement.maxWidth = 380;
michael@0 132 otherWindow.document.documentElement.maxHeight = 360;
michael@0 133
michael@0 134 synthesizeMouse(resizer, 4, 4, { type:"mousedown" }, otherWindow);
michael@0 135 synthesizeMouse(resizer, 800, 800, { type:"mousemove" }, otherWindow);
michael@0 136 is(otherWindow.innerWidth, 380, "Width after changed maximum resize");
michael@0 137 is(otherWindow.innerHeight, 360, "Height after changed maximum resize");
michael@0 138
michael@0 139 synthesizeMouse(resizer, -100, -100, { type:"mousemove" }, otherWindow);
michael@0 140 is(otherWindow.innerWidth, 140, "Width after changed minimum resize");
michael@0 141 is(otherWindow.innerHeight, 130, "Height after changed minimum resize");
michael@0 142
michael@0 143 synthesizeMouse(resizer, 4, 4, { type:"mouseup" }, otherWindow);
michael@0 144 }
michael@0 145
michael@0 146 otherWindow.close();
michael@0 147 nextTest();
michael@0 148 }
michael@0 149
michael@0 150 function doPanelTest(panel)
michael@0 151 {
michael@0 152 var rect = panel.getBoundingClientRect();
michael@0 153 is(rect.width, popupTests[gTestId].width, popupTests[gTestId].testname + " width");
michael@0 154 is(rect.height, popupTests[gTestId].height, popupTests[gTestId].testname + " height");
michael@0 155
michael@0 156 if ('last' in popupTests[gTestId]) {
michael@0 157 var resizer = document.getElementById("popupresizer");
michael@0 158 synthesizeMouse(resizer, 4, 4, { type:"mousedown" });
michael@0 159 synthesizeMouse(resizer, 800, 800, { type:"mousemove" });
michael@0 160
michael@0 161 rect = panel.getBoundingClientRect();
michael@0 162 is(rect.width, 250, "Popup width after maximum resize");
michael@0 163 is(rect.height, 220, "Popup height after maximum resize");
michael@0 164
michael@0 165 synthesizeMouse(resizer, -100, -100, { type:"mousemove" });
michael@0 166
michael@0 167 rect = panel.getBoundingClientRect();
michael@0 168 is(rect.width, 80, "Popup width after minimum resize");
michael@0 169 is(rect.height, 70, "Popup height after minimum resize");
michael@0 170
michael@0 171 synthesizeMouse(resizer, 4, 4, { type:"mouseup" });
michael@0 172 }
michael@0 173
michael@0 174 panel.hidePopup();
michael@0 175 }
michael@0 176
michael@0 177 function nextPopupTest(panel)
michael@0 178 {
michael@0 179 if (++gTestId >= popupTests.length) {
michael@0 180 // Next, check a panel that has a titlebar to ensure that it is accounted for
michael@0 181 // properly in the size.
michael@0 182 var titledPanelWindow = window.open(prefix + "'>" + titledpanel + "</window>", "_blank", "chrome,resizable=yes");
michael@0 183 SimpleTest.waitForFocus(titledPanelWindowOpened, titledPanelWindow);
michael@0 184 }
michael@0 185 else {
michael@0 186 function setattr(attr) {
michael@0 187 if (attr in popupTests[gTestId])
michael@0 188 panel.setAttribute(attr, popupTests[gTestId][attr]);
michael@0 189 else
michael@0 190 panel.removeAttribute(attr);
michael@0 191 }
michael@0 192 setattr("minwidth");
michael@0 193 setattr("minheight");
michael@0 194 setattr("maxwidth");
michael@0 195 setattr("maxheight");
michael@0 196
michael@0 197 // Remove the flexibility as it causes the resizer to not shrink down
michael@0 198 // when resizing.
michael@0 199 if ("last" in popupTests[gTestId])
michael@0 200 document.getElementById("popupresizer").removeAttribute("flex");
michael@0 201
michael@0 202 panel.openPopup();
michael@0 203 }
michael@0 204 }
michael@0 205
michael@0 206 function titledPanelWindowOpened(panelwindow)
michael@0 207 {
michael@0 208 var panel = panelwindow.document.documentElement.firstChild;
michael@0 209 panel.openPopup();
michael@0 210 panel.addEventListener("popupshown", function() doTitledPanelTest(panel), false);
michael@0 211 panel.addEventListener("popuphidden", function() done(panelwindow), false);
michael@0 212 }
michael@0 213
michael@0 214 function doTitledPanelTest(panel)
michael@0 215 {
michael@0 216 var rect = panel.getBoundingClientRect();
michael@0 217 is(rect.width, 120, "panel with titlebar width");
michael@0 218 is(rect.height, 140, "panel with titlebar height");
michael@0 219 panel.hidePopup();
michael@0 220 }
michael@0 221
michael@0 222 function done(panelwindow)
michael@0 223 {
michael@0 224 panelwindow.close();
michael@0 225 SimpleTest.finish();
michael@0 226 }
michael@0 227
michael@0 228 ]]>
michael@0 229 </script>
michael@0 230
michael@0 231 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 232 <p id="display">
michael@0 233 </p>
michael@0 234 <div id="content" style="display: none">
michael@0 235 </div>
michael@0 236 <pre id="test">
michael@0 237 </pre>
michael@0 238 </body>
michael@0 239
michael@0 240 </window>

mercurial