test_windowminmaxsize.xul 9.4 KB

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