Bug 1867190 - Initialise the PHC allocate delay later r=glandium
[gecko.git] / layout / xul / test / test_windowminmaxsize.xhtml
blob187732dd3d6398256b0172079a3138682bd402fa
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"?>
5 <window title="Window Minimum and Maximum Size Tests" onload="nextTest()"
6 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
7 xmlns:html="http://www.w3.org/1999/xhtml">
9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
10 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
12 <html:style>
13 <![CDATA[
14 panel::part(content) {
15 border: 0;
16 padding: 0;
17 margin: 0;
19 ]]>
20 </html:style>
22 <panel id="panel" onpopupshown="doPanelTest(this)" onpopuphidden="nextPopupTest(this)"
23 orient="vertical"
24 align="start" pack="start" style="appearance: none; margin: 0; border: 0; padding: 0;">
25 <hbox id="popupresizer" dir="bottomright"
26 style="width: 60px; height: 60px; appearance: none; margin: 0; border: 0; padding: 0;"/>
27 </panel>
29 <script>
30 <![CDATA[
32 SimpleTest.waitForExplicitFinish();
34 var gTestId = -1;
36 // width and height in the tests below specify the expected size of the window.
37 // note, win8 has a minimum inner window size of around 122 pixels. Don't go below this on min-width tests.
38 var tests = [
39 { testname: "unconstrained",
40 src: "windowminmaxsize1.xhtml",
41 width: 150, height: 150 },
42 { testname: "constraint min style",
43 src: "windowminmaxsize2.xhtml",
44 width: 180, height: 210 },
45 { testname: "constraint max style",
46 src: "windowminmaxsize3.xhtml",
47 width: 125, height: 140 },
48 { testname: "constraint min attributes",
49 src: "windowminmaxsize4.xhtml",
50 width: 240, height: 220 },
51 { testname: "constraint min attributes with width and height set",
52 src: "windowminmaxsize5.xhtml",
53 width: 215, height: 235 },
54 { testname: "constraint max attributes",
55 src: "windowminmaxsize6.xhtml",
56 width: 125, height: 95 },
57 // this gets the inner width as <window minwidth='210'> makes the box 210 pixels wide
58 { testname: "constraint min width attribute only",
59 src: "windowminmaxsize7.xhtml",
60 width: 210, height: 150 },
61 { testname: "constraint max width attribute only",
62 src: "windowminmaxsize8.xhtml",
63 width: 128, height: 150 },
64 { testname: "constraint max width attribute with minheight",
65 src: "windowminmaxsize9.xhtml",
66 width: 195, height: 180 },
67 { testname: "constraint minwidth, minheight, maxwidth and maxheight set",
68 src: "windowminmaxsize10.xhtml",
69 width: 150, height: 150 }
72 var popupTests = [
73 { testname: "popup unconstrained",
74 width: 60, height: 60
76 { testname: "popup with minimum size",
77 minWidth: 150, minHeight: 180,
78 width: 150, height: 180
80 { testname: "popup with maximum size",
81 maxWidth: 50, maxHeight: 45,
82 width: 50, height: 45,
86 function nextTest()
88 info(`Running test ${gTestId}`);
89 // Run through each of the tests above by opening a simple window with
90 // the attributes or style defined for that test. The comparisons will be
91 // done by windowOpened. gTestId holds the index into the tests array.
92 if (++gTestId >= tests.length) {
93 // Now do the popup tests
94 gTestId = -1;
95 SimpleTest.waitForFocus(function () { nextPopupTest(document.getElementById("panel")) } );
97 else {
98 info(`opening ${tests[gTestId].src}`);
99 tests[gTestId].window = window.browsingContext.topChromeWindow.open(tests[gTestId].src, "_blank", "chrome,resizable=yes");
100 SimpleTest.waitForFocus(windowOpened, tests[gTestId].window);
104 function windowOpened(otherWindow)
106 // Check the width and the width plus one due to bug 696746.
107 ok(otherWindow.innerWidth == tests[gTestId].width ||
108 otherWindow.innerWidth == tests[gTestId].width + 1,
109 tests[gTestId].testname + " width of " + otherWindow.innerWidth + " matches " + tests[gTestId].width);
110 is(otherWindow.innerHeight, tests[gTestId].height, tests[gTestId].testname + " height");
112 otherWindow.close();
113 nextTest();
116 function doPanelTest(panel)
118 var rect = panel.getBoundingClientRect();
119 is(rect.width, popupTests[gTestId].width, popupTests[gTestId].testname + " width");
120 is(rect.height, popupTests[gTestId].height, popupTests[gTestId].testname + " height");
122 panel.hidePopup();
125 function nextPopupTest(panel)
127 if (++gTestId >= popupTests.length) {
128 // Next, check a panel that has a titlebar to ensure that it is accounted for
129 // properly in the size.
130 var titledPanelWindow = window.browsingContext.topChromeWindow.open("titledpanelwindow.xhtml", "_blank", "chrome,resizable=yes");
131 SimpleTest.waitForFocus(titledPanelWindowOpened, titledPanelWindow);
133 else {
134 function setStyle(attr) {
135 if (attr in popupTests[gTestId])
136 panel.style[attr] = popupTests[gTestId][attr] + "px";
137 else
138 panel.style[attr] = "";
140 setStyle("minWidth");
141 setStyle("minHeight");
142 setStyle("maxWidth");
143 setStyle("maxHeight");
145 // Prevent event loop starvation as a result of popup events being
146 // synchronous. See bug 1131576.
147 SimpleTest.executeSoon(() => {
148 // Non-chrome shells require focus to open a popup.
149 SimpleTest.waitForFocus(() => { panel.openPopup() });
154 function titledPanelWindowOpened(panelwindow)
156 info("titledPanelWindowOpened");
157 var panel = panelwindow.document.documentElement.firstChild;
158 panel.addEventListener("popupshown", () => doTitledPanelTest(panel));
159 panel.addEventListener("popuphidden", () => done(panelwindow));
160 // See above as for why.
161 SimpleTest.executeSoon(() => {
162 SimpleTest.waitForFocus(() => { panel.openPopup() }, panelwindow);
166 function doTitledPanelTest(panel)
168 info("doTitledPanelTest");
169 var rect = panel.getBoundingClientRect();
170 is(rect.width, 120, "panel with titlebar width");
171 is(rect.height, 140, "panel with titlebar height");
172 panel.hidePopup();
175 function done(panelwindow)
177 panelwindow.close();
178 SimpleTest.finish();
182 </script>
184 <body xmlns="http://www.w3.org/1999/xhtml">
185 <p id="display">
186 </p>
187 <div id="content" style="display: none">
188 </div>
189 <pre id="test">
190 </pre>
191 </body>
193 </window>