Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet type="text/css" href="chrome://global/skin"?> |
michael@0 | 3 | <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?> |
michael@0 | 4 | <!-- |
michael@0 | 5 | https://bugzilla.mozilla.org/show_bug.cgi?id=565541 |
michael@0 | 6 | --> |
michael@0 | 7 | <window title="Mozilla Bug 565541" |
michael@0 | 8 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
michael@0 | 9 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 10 | |
michael@0 | 11 | <!-- test results are displayed in the html:body --> |
michael@0 | 12 | <body xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 13 | <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=565541" |
michael@0 | 14 | target="_blank">Mozilla Bug 565541</a> |
michael@0 | 15 | </body> |
michael@0 | 16 | |
michael@0 | 17 | <!-- test code goes here --> |
michael@0 | 18 | <script type="application/javascript"> |
michael@0 | 19 | <![CDATA[ |
michael@0 | 20 | |
michael@0 | 21 | /** Test for Bug 565541 **/ |
michael@0 | 22 | var previousX, previousY, previousWidth, previousHeight; |
michael@0 | 23 | |
michael@0 | 24 | function backValues() |
michael@0 | 25 | { |
michael@0 | 26 | previousX = window.top.screenX; |
michael@0 | 27 | previousY = window.top.screenY; |
michael@0 | 28 | previousWidth = window.top.innerWidth; |
michael@0 | 29 | previousHeight = window.top.innerHeight; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | function restoreValues() |
michael@0 | 33 | { |
michael@0 | 34 | window.top.screenX = previousX; |
michael@0 | 35 | window.top.screenY = previousY; |
michael@0 | 36 | window.top.innerWidth = previousWidth; |
michael@0 | 37 | window.top.innerHeight = previousHeight; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | function getNewWidth(aWindow) |
michael@0 | 41 | { |
michael@0 | 42 | return (aWindow.innerWidth > (screen.width / 2)) ? 100 : screen.width; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | function getNewHeight(aWindow) |
michael@0 | 46 | { |
michael@0 | 47 | return (aWindow.innerHeight > (screen.height / 2)) ? 100 : screen.height; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | function getNewX(aWindow) |
michael@0 | 51 | { |
michael@0 | 52 | return (aWindow.screenX > ((screen.width - aWindow.outerWidth) / 2)) |
michael@0 | 53 | ? 0 : screen.width - aWindow.outerWidth; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | function getNewY(aWindow) |
michael@0 | 57 | { |
michael@0 | 58 | return (aWindow.screenY > ((screen.height - aWindow.outerHeight) / 2)) |
michael@0 | 59 | ? 0 : screen.height - aWindow.outerHeight; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | /** |
michael@0 | 63 | * hitEventLoop is called when we want to check something but we can't rely on |
michael@0 | 64 | * an event or a specific number of event loop hiting. |
michael@0 | 65 | * This method can be called by specifying a condition, a test (using SimpleTest |
michael@0 | 66 | * API), how many times the event loop has to be hitten and what to call next. |
michael@0 | 67 | * If times < 0, the event loop will be hitten as long as the condition isn't |
michael@0 | 68 | * true or the test doesn't time out. |
michael@0 | 69 | */ |
michael@0 | 70 | function hitEventLoop(condition, test, times, next) { |
michael@0 | 71 | if (condition() || times == 0) { |
michael@0 | 72 | test(); |
michael@0 | 73 | next(); |
michael@0 | 74 | return; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | setTimeout(hitEventLoop, 0, condition, test, times - 1, next); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | function checkChangeIsEnabled(aWindow, aNext) |
michael@0 | 81 | { |
michael@0 | 82 | // Something should happen. We are not going to go to the next test until |
michael@0 | 83 | // it does. |
michael@0 | 84 | var hits = -1; |
michael@0 | 85 | |
michael@0 | 86 | var prevWidth; |
michael@0 | 87 | var prevHeight; |
michael@0 | 88 | |
michael@0 | 89 | var prevX; |
michael@0 | 90 | var prevY; |
michael@0 | 91 | |
michael@0 | 92 | var oWidth; |
michael@0 | 93 | var oHeight; |
michael@0 | 94 | |
michael@0 | 95 | function sizeChangeCondition() { |
michael@0 | 96 | return aWindow.innerWidth != prevWidth && aWindow.innerHeight != prevHeight; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | function sizeChangeTest() { |
michael@0 | 100 | isnot(aWindow.innerWidth, prevWidth, "Window width should have changed"); |
michael@0 | 101 | isnot(aWindow.innerHeight, prevHeight, "Window height should have changed"); |
michael@0 | 102 | |
michael@0 | 103 | prevWidth = aWindow.innerWidth; |
michael@0 | 104 | prevHeight = aWindow.innerHeight; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | function posChangeCondition() { |
michael@0 | 108 | // With GTK, sometimes, only one dimension changes. |
michael@0 | 109 | if (navigator.platform.indexOf('Linux') != -1) { |
michael@0 | 110 | return aWindow.screenX != prevX || aWindow.screenY != prevY; |
michael@0 | 111 | } |
michael@0 | 112 | return aWindow.screenX != prevX && aWindow.screenY != prevY; |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | function posChangeConditionIgnoreLinux() { |
michael@0 | 116 | if (posChangeCondition()) { |
michael@0 | 117 | return true; |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | if (navigator.platform.indexOf('Linux') != -1) { |
michael@0 | 121 | return true; |
michael@0 | 122 | } |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | function posChangeTest() { |
michael@0 | 126 | // With GTK, sometimes, only one dimension changes. |
michael@0 | 127 | if (navigator.platform.indexOf('Linux') != -1) { |
michael@0 | 128 | // With GTK, sometimes, aWindow.screenX changes during two calls. |
michael@0 | 129 | // So we call it once and save the returned value. |
michael@0 | 130 | var x = aWindow.screenX; |
michael@0 | 131 | var y = aWindow.screenY; |
michael@0 | 132 | if (x != prevX) { |
michael@0 | 133 | isnot(x, prevX, "Window x position should have changed"); |
michael@0 | 134 | } |
michael@0 | 135 | if (y != prevY) { |
michael@0 | 136 | isnot(y, prevY, "Window y position should have changed"); |
michael@0 | 137 | } |
michael@0 | 138 | } else { |
michael@0 | 139 | isnot(aWindow.screenX, prevX, "Window x position should have changed"); |
michael@0 | 140 | isnot(aWindow.screenY, prevY, "Window y position should have changed"); |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | prevX = aWindow.screenX; |
michael@0 | 144 | prevY = aWindow.screenY; |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | function outerChangeCondition() { |
michael@0 | 148 | return aWindow.outerWidth != oWidth && aWindow.outerHeight != oHeight; |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | function outerChangeTest() { |
michael@0 | 152 | isnot(aWindow.outerWidth, oWidth, "Window outerWidth should have changed"); |
michael@0 | 153 | isnot(aWindow.outerHeight, oHeight, "Window outerHeight should have changed"); |
michael@0 | 154 | |
michael@0 | 155 | aWindow.outerWidth = oWidth; |
michael@0 | 156 | aWindow.outerHeight = oHeight; |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | /** |
michael@0 | 160 | * Size checks. |
michael@0 | 161 | */ |
michael@0 | 162 | prevWidth = aWindow.innerWidth; |
michael@0 | 163 | prevHeight = aWindow.innerHeight; |
michael@0 | 164 | |
michael@0 | 165 | aWindow.innerWidth = getNewWidth(aWindow); |
michael@0 | 166 | aWindow.innerHeight = getNewHeight(aWindow); |
michael@0 | 167 | |
michael@0 | 168 | hitEventLoop(sizeChangeCondition, sizeChangeTest, hits, function () { |
michael@0 | 169 | aWindow.resizeTo(getNewWidth(aWindow), getNewHeight(aWindow)); |
michael@0 | 170 | |
michael@0 | 171 | hitEventLoop(sizeChangeCondition, sizeChangeTest, hits, function () { |
michael@0 | 172 | aWindow.resizeBy(getNewWidth(aWindow) - aWindow.innerWidth, |
michael@0 | 173 | getNewHeight(aWindow) - aWindow.innerHeight); |
michael@0 | 174 | |
michael@0 | 175 | hitEventLoop(sizeChangeCondition, sizeChangeTest, hits, function () { |
michael@0 | 176 | prevWidth = aWindow.innerWidth = getNewWidth(aWindow); |
michael@0 | 177 | prevHeight = aWindow.innerHeight = getNewHeight(aWindow); |
michael@0 | 178 | aWindow.sizeToContent(); |
michael@0 | 179 | |
michael@0 | 180 | hitEventLoop(sizeChangeCondition, sizeChangeTest, hits, function () { |
michael@0 | 181 | /** |
michael@0 | 182 | * Position checks. |
michael@0 | 183 | */ |
michael@0 | 184 | prevX = aWindow.screenX; |
michael@0 | 185 | prevY = aWindow.screenY; |
michael@0 | 186 | |
michael@0 | 187 | aWindow.screenX = getNewX(aWindow); |
michael@0 | 188 | aWindow.screenY = getNewY(aWindow); |
michael@0 | 189 | |
michael@0 | 190 | hitEventLoop(posChangeCondition, posChangeTest, hits, function () { |
michael@0 | 191 | aWindow.moveTo(getNewX(aWindow), getNewY(aWindow)); |
michael@0 | 192 | |
michael@0 | 193 | hitEventLoop(posChangeCondition, posChangeTest, hits, function () { |
michael@0 | 194 | aWindow.moveBy(getNewX(aWindow) - aWindow.screenX, |
michael@0 | 195 | getNewY(aWindow) - aWindow.screenY); |
michael@0 | 196 | |
michael@0 | 197 | hitEventLoop(posChangeConditionIgnoreLinux, posChangeTest, hits, function () { |
michael@0 | 198 | /** |
michael@0 | 199 | * Outer width/height checks. |
michael@0 | 200 | */ |
michael@0 | 201 | oWidth = aWindow.outerWidth; |
michael@0 | 202 | oHeight = aWindow.outerHeight; |
michael@0 | 203 | |
michael@0 | 204 | aWindow.outerWidth = oWidth * 2; |
michael@0 | 205 | aWindow.outerHeight = oHeight * 2; |
michael@0 | 206 | |
michael@0 | 207 | hitEventLoop(outerChangeCondition, outerChangeTest, hits, aNext); |
michael@0 | 208 | }); |
michael@0 | 209 | }); |
michael@0 | 210 | }); |
michael@0 | 211 | }); |
michael@0 | 212 | }); |
michael@0 | 213 | }); |
michael@0 | 214 | }); |
michael@0 | 215 | } |
michael@0 | 216 | |
michael@0 | 217 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 218 | SimpleTest.waitForFocus(function() { |
michael@0 | 219 | if (screen.width <= 200 || screen.height <= 200) { |
michael@0 | 220 | todo(false, "The screen is too small to run this test."); |
michael@0 | 221 | SimpleTest.finish(); |
michael@0 | 222 | } |
michael@0 | 223 | |
michael@0 | 224 | backValues(); |
michael@0 | 225 | |
michael@0 | 226 | // We are in a chrome context, we can change the size and position. |
michael@0 | 227 | checkChangeIsEnabled(window.top, function() { |
michael@0 | 228 | // We create a window and check that the size and position can be set with |
michael@0 | 229 | // window.open parameters and can be changed by the created window. |
michael@0 | 230 | var w = window.open("data:text/html,<script>" + |
michael@0 | 231 | "function check(next) {" + |
michael@0 | 232 | " var is_range = function(aTest, aValue, aRange, aMsg) {" + |
michael@0 | 233 | " ok(aTest < aValue + aRange && aTest > aValue - aRange, aMsg);" + |
michael@0 | 234 | " };" + |
michael@0 | 235 | " is_range(window.innerWidth, 170, 5, 'parameter width should be taken into account');" + |
michael@0 | 236 | " is_range(window.innerHeight, 170, 5, 'parameter height should be taken into account');" + |
michael@0 | 237 | " is_range(window.screenX, 25, 5, 'parameter screenX should be taken into account');" + |
michael@0 | 238 | " is_range(window.screenY, 25, 5, 'parameter screenY should be taken into account');" + |
michael@0 | 239 | " checkChangeIsEnabled(window, next);" + |
michael@0 | 240 | "} <\/script>", '', |
michael@0 | 241 | 'width=170,height=170,screenX=25,screenY=25'); |
michael@0 | 242 | |
michael@0 | 243 | SimpleTest.waitForFocus(function() { |
michael@0 | 244 | w.wrappedJSObject.ok = SimpleTest.ok; |
michael@0 | 245 | w.wrappedJSObject.checkChangeIsEnabled = window.checkChangeIsEnabled; |
michael@0 | 246 | w.wrappedJSObject.check(function() { |
michael@0 | 247 | // The current window can change the size and position of the created one. |
michael@0 | 248 | checkChangeIsEnabled(w, function() { |
michael@0 | 249 | w.close(); |
michael@0 | 250 | |
michael@0 | 251 | // If we call window.open with an empty string as a third parameter, |
michael@0 | 252 | // by default, it will create a new tab instead of a new window. |
michael@0 | 253 | // In a chrome context, the size and position can change. |
michael@0 | 254 | w = window.open("data:text/html,<script>" + |
michael@0 | 255 | "function check(next) {" + |
michael@0 | 256 | " checkChangeIsEnabled(window, next);" + |
michael@0 | 257 | "} <\/script>", '', ''); |
michael@0 | 258 | |
michael@0 | 259 | SimpleTest.waitForFocus(function() { |
michael@0 | 260 | w.wrappedJSObject.checkChangeIsEnabled = window.checkChangeIsEnabled; |
michael@0 | 261 | w.wrappedJSObject.check(function() { |
michael@0 | 262 | // The current window can change the size and position of the new tab. |
michael@0 | 263 | // Because we are in a chrome context. |
michael@0 | 264 | checkChangeIsEnabled(w, function() { |
michael@0 | 265 | w.close(); |
michael@0 | 266 | |
michael@0 | 267 | restoreValues(); |
michael@0 | 268 | SimpleTest.finish(); |
michael@0 | 269 | }); |
michael@0 | 270 | }); |
michael@0 | 271 | }, w, false); |
michael@0 | 272 | }); |
michael@0 | 273 | }); |
michael@0 | 274 | }, w, false); |
michael@0 | 275 | }); |
michael@0 | 276 | }); |
michael@0 | 277 | ]]> |
michael@0 | 278 | </script> |
michael@0 | 279 | </window> |