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">
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"/>
13 <panel id=
"panel" onpopupshown=
"doPanelTest(this)" onpopuphidden=
"nextPopupTest(this)"
14 align=
"start" pack=
"start" style=
"-moz-appearance: none; margin: 0; border: 0; padding: 0;">
15 <resizer id=
"popupresizer" dir=
"bottomright" flex=
"1" width=
"60" height=
"60"
16 style=
"-moz-appearance: none; margin: 0; border: 0; padding: 0;"/>
22 SimpleTest.waitForExplicitFinish();
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.
29 { testname:
"unconstrained",
30 src:
"windowminmaxsize1.xul",
31 width:
150, height:
150 },
32 { testname:
"constraint min style",
33 src:
"windowminmaxsize2.xul",
34 width:
180, height:
210 },
35 { testname:
"constraint max style",
36 src:
"windowminmaxsize3.xul",
37 width:
125, height:
140 },
38 { testname:
"constraint min attributes",
39 src:
"windowminmaxsize4.xul",
40 width:
240, height:
220 },
41 { testname:
"constraint min attributes with width and height set",
42 src:
"windowminmaxsize5.xul",
43 width:
215, height:
235 },
44 { testname:
"constraint max attributes",
45 src:
"windowminmaxsize6.xul",
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 src:
"windowminmaxsize7.xul",
50 width:
210, height:
150 },
51 { testname:
"constraint max width attribute only",
52 src:
"windowminmaxsize8.xul",
53 width:
128, height:
150 },
54 { testname:
"constraint max width attribute with minheight",
55 src:
"windowminmaxsize9.xul",
56 width:
195, height:
180 },
57 { testname:
"constraint minwidth, minheight, maxwidth and maxheight set",
58 src:
"windowminmaxsize10.xul",
59 width:
150, height:
150, last: true }
63 { testname:
"popup unconstrained",
66 { testname:
"popup with minimum size",
67 minwidth:
150, minheight:
180,
68 width:
150, height:
180
70 { testname:
"popup with maximum size",
71 maxwidth:
50, maxheight:
45,
72 width:
50, height:
45,
74 { testname:
"popup with minimum and size",
75 minwidth:
80, minheight:
70, maxwidth:
250, maxheight:
220,
76 width:
80, height:
70, last: true
82 // Run through each of the tests above by opening a simple window with
83 // the attributes or style defined for that test. The comparisons will be
84 // done by windowOpened. gTestId holds the index into the tests array.
85 if (++gTestId
>= tests.length) {
86 // Now do the popup tests
88 SimpleTest.waitForFocus(function () { nextPopupTest(document.getElementById(
"panel")) } );
91 tests[gTestId].window = window.open(tests[gTestId].src,
"_blank",
"chrome,resizable=yes");
92 SimpleTest.waitForFocus(windowOpened, tests[gTestId].window);
96 function windowOpened(otherWindow)
98 // Check the width and the width plus one due to bug
696746.
99 ok(otherWindow.innerWidth == tests[gTestId].width ||
100 otherWindow.innerWidth == tests[gTestId].width +
1,
101 tests[gTestId].testname +
" width of " + otherWindow.innerWidth +
" matches " + tests[gTestId].width);
102 is(otherWindow.innerHeight, tests[gTestId].height, tests[gTestId].testname +
" height");
104 // On the last test, try moving the resizer to a size larger than the maximum
105 // and smaller than the minimum. This test is only done on Mac as the other
106 // platforms use native resizing.
107 if ('last' in tests[gTestId] && (navigator.platform.indexOf(
"Mac") ==
0)) {
108 var resizer = otherWindow.document.documentElement.firstChild;
109 synthesizeMouse(resizer,
4,
4, { type:
"mousedown" }, otherWindow);
110 synthesizeMouse(resizer,
800,
800, { type:
"mousemove" }, otherWindow);
111 is(otherWindow.innerWidth,
480,
"Width after maximum resize");
112 is(otherWindow.innerHeight,
470,
"Height after maximum resize");
114 synthesizeMouse(resizer, -
100, -
100, { type:
"mousemove" }, otherWindow);
115 is(otherWindow.innerWidth,
120,
"Width after minimum resize");
116 is(otherWindow.innerHeight,
110,
"Height after minimum resize");
118 synthesizeMouse(resizer,
4,
4, { type:
"mouseup" }, otherWindow);
120 // Change the minimum and maximum size and try resizing the window again.
121 otherWindow.document.documentElement.minWidth =
140;
122 otherWindow.document.documentElement.minHeight =
130;
123 otherWindow.document.documentElement.maxWidth =
380;
124 otherWindow.document.documentElement.maxHeight =
360;
126 synthesizeMouse(resizer,
4,
4, { type:
"mousedown" }, otherWindow);
127 synthesizeMouse(resizer,
800,
800, { type:
"mousemove" }, otherWindow);
128 is(otherWindow.innerWidth,
380,
"Width after changed maximum resize");
129 is(otherWindow.innerHeight,
360,
"Height after changed maximum resize");
131 synthesizeMouse(resizer, -
100, -
100, { type:
"mousemove" }, otherWindow);
132 is(otherWindow.innerWidth,
140,
"Width after changed minimum resize");
133 is(otherWindow.innerHeight,
130,
"Height after changed minimum resize");
135 synthesizeMouse(resizer,
4,
4, { type:
"mouseup" }, otherWindow);
142 function doPanelTest(panel)
144 var rect = panel.getBoundingClientRect();
145 is(rect.width, popupTests[gTestId].width, popupTests[gTestId].testname +
" width");
146 is(rect.height, popupTests[gTestId].height, popupTests[gTestId].testname +
" height");
148 if ('last' in popupTests[gTestId]) {
149 var resizer = document.getElementById(
"popupresizer");
150 synthesizeMouse(resizer,
4,
4, { type:
"mousedown" });
151 synthesizeMouse(resizer,
800,
800, { type:
"mousemove" });
153 rect = panel.getBoundingClientRect();
154 is(rect.width,
250,
"Popup width after maximum resize");
155 is(rect.height,
220,
"Popup height after maximum resize");
157 synthesizeMouse(resizer, -
100, -
100, { type:
"mousemove" });
159 rect = panel.getBoundingClientRect();
160 is(rect.width,
80,
"Popup width after minimum resize");
161 is(rect.height,
70,
"Popup height after minimum resize");
163 synthesizeMouse(resizer,
4,
4, { type:
"mouseup" });
169 function nextPopupTest(panel)
171 if (++gTestId
>= popupTests.length) {
172 // Next, check a panel that has a titlebar to ensure that it is accounted for
173 // properly in the size.
174 var titledPanelWindow = window.open(
"titledpanelwindow.xul",
"_blank",
"chrome,resizable=yes");
175 SimpleTest.waitForFocus(titledPanelWindowOpened, titledPanelWindow);
178 function setattr(attr) {
179 if (attr in popupTests[gTestId])
180 panel.setAttribute(attr, popupTests[gTestId][attr]);
182 panel.removeAttribute(attr);
185 setattr(
"minheight");
187 setattr(
"maxheight");
189 // Remove the flexibility as it causes the resizer to not shrink down
191 if (
"last" in popupTests[gTestId])
192 document.getElementById(
"popupresizer").removeAttribute(
"flex");
194 // Prevent event loop starvation as a result of popup events being
195 // synchronous. See bug
1131576.
196 SimpleTest.executeSoon(() =
> {
197 // Non-chrome shells require focus to open a popup.
198 SimpleTest.waitForFocus(() =
> { panel.openPopup() });
203 function titledPanelWindowOpened(panelwindow)
205 var panel = panelwindow.document.documentElement.firstChild;
207 panel.addEventListener(
"popupshown", () =
> doTitledPanelTest(panel), false);
208 panel.addEventListener(
"popuphidden", () =
> done(panelwindow), false);
211 function doTitledPanelTest(panel)
213 var rect = panel.getBoundingClientRect();
214 is(rect.width,
120,
"panel with titlebar width");
215 is(rect.height,
140,
"panel with titlebar height");
219 function done(panelwindow)
228 <body xmlns=
"http://www.w3.org/1999/xhtml">
231 <div id=
"content" style=
"display: none">