test_windowminmaxsize.xhtml (5114B)
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 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"> 8 9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 10 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> 11 12 <html:style> 13 <![CDATA[ 14 panel::part(content) { 15 border: 0; 16 padding: 0; 17 margin: 0; 18 } 19 ]]> 20 </html:style> 21 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> 28 29 <script> 30 <![CDATA[ 31 32 SimpleTest.waitForExplicitFinish(); 33 34 var gTestId = -1; 35 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 } 70 ]; 71 72 var popupTests = [ 73 { testname: "popup unconstrained", 74 width: 60, height: 60 75 }, 76 { testname: "popup with minimum size", 77 minWidth: 150, minHeight: 180, 78 width: 150, height: 180 79 }, 80 { testname: "popup with maximum size", 81 maxWidth: 50, maxHeight: 45, 82 width: 50, height: 45, 83 } 84 ]; 85 86 function nextTest() 87 { 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")) } ); 96 } 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); 101 } 102 } 103 104 function windowOpened(otherWindow) 105 { 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"); 111 112 otherWindow.close(); 113 nextTest(); 114 } 115 116 function doPanelTest(panel) 117 { 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"); 121 122 panel.hidePopup(); 123 } 124 125 function nextPopupTest(panel) 126 { 127 if (++gTestId >= popupTests.length) { 128 SimpleTest.finish(); 129 return; 130 } 131 132 function setStyle(attr) { 133 if (attr in popupTests[gTestId]) 134 panel.style[attr] = popupTests[gTestId][attr] + "px"; 135 else 136 panel.style[attr] = ""; 137 } 138 setStyle("minWidth"); 139 setStyle("minHeight"); 140 setStyle("maxWidth"); 141 setStyle("maxHeight"); 142 143 // Prevent event loop starvation as a result of popup events being 144 // synchronous. See bug 1131576. 145 SimpleTest.executeSoon(() => { 146 // Non-chrome shells require focus to open a popup. 147 SimpleTest.waitForFocus(() => { panel.openPopup() }); 148 }); 149 } 150 151 ]]> 152 </script> 153 154 <body xmlns="http://www.w3.org/1999/xhtml"> 155 <p id="display"> 156 </p> 157 <div id="content" style="display: none"> 158 </div> 159 <pre id="test"> 160 </pre> 161 </body> 162 163 </window>