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 | Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 2 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 3 | |
michael@0 | 4 | let Cc = Components.classes; |
michael@0 | 5 | let Ci = Components.interfaces; |
michael@0 | 6 | |
michael@0 | 7 | const PREF_DISABLE_OPEN_NEW_WINDOW = "browser.link.open_newwindow.disabled_in_fullscreen"; |
michael@0 | 8 | const isOSX = (Services.appinfo.OS === "Darwin"); |
michael@0 | 9 | |
michael@0 | 10 | const TEST_FILE = "file_fullscreen-window-open.html"; |
michael@0 | 11 | const gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", |
michael@0 | 12 | "http://127.0.0.1:8888/"); |
michael@0 | 13 | |
michael@0 | 14 | function test () { |
michael@0 | 15 | waitForExplicitFinish(); |
michael@0 | 16 | |
michael@0 | 17 | Services.prefs.setBoolPref(PREF_DISABLE_OPEN_NEW_WINDOW, true); |
michael@0 | 18 | |
michael@0 | 19 | let newTab = gBrowser.addTab(); |
michael@0 | 20 | gBrowser.selectedTab = newTab; |
michael@0 | 21 | |
michael@0 | 22 | let gTestBrowser = gBrowser.selectedBrowser; |
michael@0 | 23 | gTestBrowser.addEventListener("load", function onLoad(){ |
michael@0 | 24 | gTestBrowser.removeEventListener("load", onLoad, true, true); |
michael@0 | 25 | |
michael@0 | 26 | // Enter browser fullscreen mode. |
michael@0 | 27 | BrowserFullScreen(); |
michael@0 | 28 | |
michael@0 | 29 | runNextTest(); |
michael@0 | 30 | }, true, true); |
michael@0 | 31 | gTestBrowser.contentWindow.location.href = gHttpTestRoot + TEST_FILE; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | registerCleanupFunction(function(){ |
michael@0 | 35 | // Exit browser fullscreen mode. |
michael@0 | 36 | BrowserFullScreen(); |
michael@0 | 37 | |
michael@0 | 38 | gBrowser.removeCurrentTab(); |
michael@0 | 39 | |
michael@0 | 40 | Services.prefs.clearUserPref(PREF_DISABLE_OPEN_NEW_WINDOW); |
michael@0 | 41 | }); |
michael@0 | 42 | |
michael@0 | 43 | let gTests = [ |
michael@0 | 44 | test_open, |
michael@0 | 45 | test_open_with_size, |
michael@0 | 46 | test_open_with_pos, |
michael@0 | 47 | test_open_with_outerSize, |
michael@0 | 48 | test_open_with_innerSize, |
michael@0 | 49 | test_open_with_dialog, |
michael@0 | 50 | test_open_when_open_new_window_by_pref, |
michael@0 | 51 | test_open_with_pref_to_disable_in_fullscreen, |
michael@0 | 52 | test_open_from_chrome, |
michael@0 | 53 | ]; |
michael@0 | 54 | |
michael@0 | 55 | function runNextTest () { |
michael@0 | 56 | let test = gTests.shift(); |
michael@0 | 57 | if (test) { |
michael@0 | 58 | executeSoon(test); |
michael@0 | 59 | } |
michael@0 | 60 | else { |
michael@0 | 61 | finish(); |
michael@0 | 62 | } |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | |
michael@0 | 66 | // Test for window.open() with no feature. |
michael@0 | 67 | function test_open() { |
michael@0 | 68 | waitForTabOpen({ |
michael@0 | 69 | message: { |
michael@0 | 70 | title: "test_open", |
michael@0 | 71 | param: "", |
michael@0 | 72 | }, |
michael@0 | 73 | finalizeFn: function () {}, |
michael@0 | 74 | }); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | // Test for window.open() with width/height. |
michael@0 | 78 | function test_open_with_size() { |
michael@0 | 79 | waitForTabOpen({ |
michael@0 | 80 | message: { |
michael@0 | 81 | title: "test_open_with_size", |
michael@0 | 82 | param: "width=400,height=400", |
michael@0 | 83 | }, |
michael@0 | 84 | finalizeFn: function () {}, |
michael@0 | 85 | }); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | // Test for window.open() with top/left. |
michael@0 | 89 | function test_open_with_pos() { |
michael@0 | 90 | waitForTabOpen({ |
michael@0 | 91 | message: { |
michael@0 | 92 | title: "test_open_with_pos", |
michael@0 | 93 | param: "top=200,left=200", |
michael@0 | 94 | }, |
michael@0 | 95 | finalizeFn: function () {}, |
michael@0 | 96 | }); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | // Test for window.open() with outerWidth/Height. |
michael@0 | 100 | function test_open_with_outerSize() { |
michael@0 | 101 | let [outerWidth, outerHeight] = [window.outerWidth, window.outerHeight]; |
michael@0 | 102 | waitForTabOpen({ |
michael@0 | 103 | message: { |
michael@0 | 104 | title: "test_open_with_outerSize", |
michael@0 | 105 | param: "outerWidth=200,outerHeight=200", |
michael@0 | 106 | }, |
michael@0 | 107 | successFn: function () { |
michael@0 | 108 | is(window.outerWidth, outerWidth, "Don't change window.outerWidth."); |
michael@0 | 109 | is(window.outerHeight, outerHeight, "Don't change window.outerHeight."); |
michael@0 | 110 | }, |
michael@0 | 111 | finalizeFn: function () {}, |
michael@0 | 112 | }); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | // Test for window.open() with innerWidth/Height. |
michael@0 | 116 | function test_open_with_innerSize() { |
michael@0 | 117 | let [innerWidth, innerHeight] = [window.innerWidth, window.innerHeight]; |
michael@0 | 118 | waitForTabOpen({ |
michael@0 | 119 | message: { |
michael@0 | 120 | title: "test_open_with_innerSize", |
michael@0 | 121 | param: "innerWidth=200,innerHeight=200", |
michael@0 | 122 | }, |
michael@0 | 123 | successFn: function () { |
michael@0 | 124 | is(window.innerWidth, innerWidth, "Don't change window.innerWidth."); |
michael@0 | 125 | is(window.innerHeight, innerHeight, "Don't change window.innerHeight."); |
michael@0 | 126 | }, |
michael@0 | 127 | finalizeFn: function () {}, |
michael@0 | 128 | }); |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | // Test for window.open() with dialog. |
michael@0 | 132 | function test_open_with_dialog() { |
michael@0 | 133 | waitForTabOpen({ |
michael@0 | 134 | message: { |
michael@0 | 135 | title: "test_open_with_dialog", |
michael@0 | 136 | param: "dialog=yes", |
michael@0 | 137 | }, |
michael@0 | 138 | finalizeFn: function () {}, |
michael@0 | 139 | }); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | // Test for window.open() |
michael@0 | 143 | // when "browser.link.open_newwindow" is nsIBrowserDOMWindow.OPEN_NEWWINDOW |
michael@0 | 144 | function test_open_when_open_new_window_by_pref() { |
michael@0 | 145 | const PREF_NAME = "browser.link.open_newwindow"; |
michael@0 | 146 | Services.prefs.setIntPref(PREF_NAME, Ci.nsIBrowserDOMWindow.OPEN_NEWWINDOW); |
michael@0 | 147 | is(Services.prefs.getIntPref(PREF_NAME), Ci.nsIBrowserDOMWindow.OPEN_NEWWINDOW, |
michael@0 | 148 | PREF_NAME + " is nsIBrowserDOMWindow.OPEN_NEWWINDOW at this time"); |
michael@0 | 149 | |
michael@0 | 150 | waitForTabOpen({ |
michael@0 | 151 | message: { |
michael@0 | 152 | title: "test_open_when_open_new_window_by_pref", |
michael@0 | 153 | param: "width=400,height=400", |
michael@0 | 154 | }, |
michael@0 | 155 | finalizeFn: function () { |
michael@0 | 156 | Services.prefs.clearUserPref(PREF_NAME); |
michael@0 | 157 | }, |
michael@0 | 158 | }); |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | // Test for the pref, "browser.link.open_newwindow.disabled_in_fullscreen" |
michael@0 | 162 | function test_open_with_pref_to_disable_in_fullscreen() { |
michael@0 | 163 | Services.prefs.setBoolPref(PREF_DISABLE_OPEN_NEW_WINDOW, false); |
michael@0 | 164 | |
michael@0 | 165 | waitForWindowOpen({ |
michael@0 | 166 | message: { |
michael@0 | 167 | title: "test_open_with_pref_disabled_in_fullscreen", |
michael@0 | 168 | param: "width=400,height=400", |
michael@0 | 169 | }, |
michael@0 | 170 | finalizeFn: function () { |
michael@0 | 171 | Services.prefs.setBoolPref(PREF_DISABLE_OPEN_NEW_WINDOW, true); |
michael@0 | 172 | }, |
michael@0 | 173 | }); |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | |
michael@0 | 177 | // Test for window.open() called from chrome context. |
michael@0 | 178 | function test_open_from_chrome() { |
michael@0 | 179 | waitForWindowOpenFromChrome({ |
michael@0 | 180 | message: { |
michael@0 | 181 | title: "test_open_from_chrome", |
michael@0 | 182 | param: "", |
michael@0 | 183 | }, |
michael@0 | 184 | finalizeFn: function () {}, |
michael@0 | 185 | timeout: 10000, |
michael@0 | 186 | }); |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | function waitForTabOpen(aOptions) { |
michael@0 | 190 | let start = Date.now(); |
michael@0 | 191 | let timeout = aOptions.timeout || 5000; |
michael@0 | 192 | let message = aOptions.message; |
michael@0 | 193 | |
michael@0 | 194 | if (!message.title) { |
michael@0 | 195 | ok(false, "Can't get message.title."); |
michael@0 | 196 | aOptions.finalizeFn(); |
michael@0 | 197 | runNextTest(); |
michael@0 | 198 | return; |
michael@0 | 199 | } |
michael@0 | 200 | |
michael@0 | 201 | info("Running test: " + message.title); |
michael@0 | 202 | |
michael@0 | 203 | let onTabOpen = function onTabOpen(aEvent) { |
michael@0 | 204 | gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, true); |
michael@0 | 205 | |
michael@0 | 206 | let tab = aEvent.target; |
michael@0 | 207 | tab.linkedBrowser.addEventListener("load", function onLoad(ev){ |
michael@0 | 208 | let browser = ev.currentTarget; |
michael@0 | 209 | browser.removeEventListener("load", onLoad, true, true); |
michael@0 | 210 | clearTimeout(onTimeout); |
michael@0 | 211 | |
michael@0 | 212 | is(browser.contentWindow.document.title, message.title, |
michael@0 | 213 | "Opened Tab is expected: " + message.title); |
michael@0 | 214 | |
michael@0 | 215 | if (aOptions.successFn) { |
michael@0 | 216 | aOptions.successFn(); |
michael@0 | 217 | } |
michael@0 | 218 | |
michael@0 | 219 | gBrowser.removeTab(tab); |
michael@0 | 220 | finalize(); |
michael@0 | 221 | }, true, true); |
michael@0 | 222 | } |
michael@0 | 223 | gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, true); |
michael@0 | 224 | |
michael@0 | 225 | let finalize = function () { |
michael@0 | 226 | aOptions.finalizeFn(); |
michael@0 | 227 | info("Finished: " + message.title); |
michael@0 | 228 | runNextTest(); |
michael@0 | 229 | }; |
michael@0 | 230 | |
michael@0 | 231 | let onTimeout = setTimeout(function(){ |
michael@0 | 232 | gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, true); |
michael@0 | 233 | |
michael@0 | 234 | ok(false, "Timeout: '"+message.title + "'."); |
michael@0 | 235 | finalize(); |
michael@0 | 236 | }, timeout); |
michael@0 | 237 | |
michael@0 | 238 | |
michael@0 | 239 | const URI = "data:text/html;charset=utf-8,<!DOCTYPE html><html><head><title>"+ |
michael@0 | 240 | message.title + |
michael@0 | 241 | "<%2Ftitle><%2Fhead><body><%2Fbody><%2Fhtml>"; |
michael@0 | 242 | |
michael@0 | 243 | executeWindowOpenInContent({ |
michael@0 | 244 | uri: URI, |
michael@0 | 245 | title: message.title, |
michael@0 | 246 | option: message.param, |
michael@0 | 247 | }); |
michael@0 | 248 | } |
michael@0 | 249 | |
michael@0 | 250 | |
michael@0 | 251 | function waitForWindowOpen(aOptions) { |
michael@0 | 252 | let start = Date.now(); |
michael@0 | 253 | let timeout = aOptions.timeout || 10000; |
michael@0 | 254 | let message = aOptions.message; |
michael@0 | 255 | let url = aOptions.url || getBrowserURL(); |
michael@0 | 256 | |
michael@0 | 257 | if (!message.title) { |
michael@0 | 258 | ok(false, "Can't get message.title"); |
michael@0 | 259 | aOptions.finalizeFn(); |
michael@0 | 260 | runNextTest(); |
michael@0 | 261 | return; |
michael@0 | 262 | } |
michael@0 | 263 | |
michael@0 | 264 | info("Running test: " + message.title); |
michael@0 | 265 | |
michael@0 | 266 | let onFinalize = function () { |
michael@0 | 267 | aOptions.finalizeFn(); |
michael@0 | 268 | |
michael@0 | 269 | info("Finished: " + message.title); |
michael@0 | 270 | runNextTest(); |
michael@0 | 271 | }; |
michael@0 | 272 | |
michael@0 | 273 | let onTimeout = setTimeout(function(){ |
michael@0 | 274 | Services.wm.removeListener(listener); |
michael@0 | 275 | ok(false, "Fail: '"+message.title + "'."); |
michael@0 | 276 | |
michael@0 | 277 | onFinalize(); |
michael@0 | 278 | }, timeout); |
michael@0 | 279 | |
michael@0 | 280 | let listener = new WindowListener(message.title, url, { |
michael@0 | 281 | onSuccess: aOptions.successFn, |
michael@0 | 282 | onTimeout: onTimeout, |
michael@0 | 283 | onFinalize: onFinalize, |
michael@0 | 284 | }); |
michael@0 | 285 | Services.wm.addListener(listener); |
michael@0 | 286 | |
michael@0 | 287 | const URI = aOptions.url || "about:blank"; |
michael@0 | 288 | |
michael@0 | 289 | executeWindowOpenInContent({ |
michael@0 | 290 | uri: URI, |
michael@0 | 291 | title: message.title, |
michael@0 | 292 | option: message.param, |
michael@0 | 293 | }); |
michael@0 | 294 | } |
michael@0 | 295 | |
michael@0 | 296 | function executeWindowOpenInContent(aParam) { |
michael@0 | 297 | var testWindow = gBrowser.selectedBrowser.contentWindow; |
michael@0 | 298 | var testElm = testWindow.document.getElementById("test"); |
michael@0 | 299 | |
michael@0 | 300 | testElm.setAttribute("data-test-param", JSON.stringify(aParam)); |
michael@0 | 301 | EventUtils.synthesizeMouseAtCenter(testElm, {}, testWindow); |
michael@0 | 302 | } |
michael@0 | 303 | |
michael@0 | 304 | function waitForWindowOpenFromChrome(aOptions) { |
michael@0 | 305 | let start = Date.now(); |
michael@0 | 306 | let timeout = aOptions.timeout || 10000; |
michael@0 | 307 | let message = aOptions.message; |
michael@0 | 308 | let url = aOptions.url || getBrowserURL(); |
michael@0 | 309 | |
michael@0 | 310 | if (!message.title) { |
michael@0 | 311 | ok(false, "Can't get message.title"); |
michael@0 | 312 | aOptions.finalizeFn(); |
michael@0 | 313 | runNextTest(); |
michael@0 | 314 | return; |
michael@0 | 315 | } |
michael@0 | 316 | |
michael@0 | 317 | info("Running test: " + message.title); |
michael@0 | 318 | |
michael@0 | 319 | let onFinalize = function () { |
michael@0 | 320 | aOptions.finalizeFn(); |
michael@0 | 321 | |
michael@0 | 322 | info("Finished: " + message.title); |
michael@0 | 323 | runNextTest(); |
michael@0 | 324 | }; |
michael@0 | 325 | |
michael@0 | 326 | let onTimeout = setTimeout(function(){ |
michael@0 | 327 | Services.wm.removeListener(listener); |
michael@0 | 328 | ok(false, "Fail: '"+message.title + "'."); |
michael@0 | 329 | |
michael@0 | 330 | testWindow.close(); |
michael@0 | 331 | onFinalize(); |
michael@0 | 332 | }, timeout); |
michael@0 | 333 | |
michael@0 | 334 | let listener = new WindowListener(message.title, url, { |
michael@0 | 335 | onSuccess: aOptions.successFn, |
michael@0 | 336 | onTimeout: onTimeout, |
michael@0 | 337 | onFinalize: onFinalize, |
michael@0 | 338 | }); |
michael@0 | 339 | Services.wm.addListener(listener); |
michael@0 | 340 | |
michael@0 | 341 | |
michael@0 | 342 | const URI = aOptions.url || "about:blank"; |
michael@0 | 343 | |
michael@0 | 344 | let testWindow = window.open(URI, message.title, message.option); |
michael@0 | 345 | } |
michael@0 | 346 | |
michael@0 | 347 | function WindowListener(aTitle, aUrl, aCallBackObj) { |
michael@0 | 348 | this.test_title = aTitle; |
michael@0 | 349 | this.test_url = aUrl; |
michael@0 | 350 | this.callback_onSuccess = aCallBackObj.onSuccess; |
michael@0 | 351 | this.callBack_onTimeout = aCallBackObj.onTimeout; |
michael@0 | 352 | this.callBack_onFinalize = aCallBackObj.onFinalize; |
michael@0 | 353 | } |
michael@0 | 354 | WindowListener.prototype = { |
michael@0 | 355 | |
michael@0 | 356 | test_title: null, |
michael@0 | 357 | test_url: null, |
michael@0 | 358 | callback_onSuccess: null, |
michael@0 | 359 | callBack_onTimeout: null, |
michael@0 | 360 | callBack_onFinalize: null, |
michael@0 | 361 | |
michael@0 | 362 | onOpenWindow: function(aXULWindow) { |
michael@0 | 363 | Services.wm.removeListener(this); |
michael@0 | 364 | |
michael@0 | 365 | let domwindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 366 | .getInterface(Ci.nsIDOMWindow); |
michael@0 | 367 | domwindow.addEventListener("load", function onLoad(aEvent) { |
michael@0 | 368 | is(domwindow.document.location.href, this.test_url, |
michael@0 | 369 | "Opened Window is expected: "+ this.test_title); |
michael@0 | 370 | if (this.callback_onSuccess) { |
michael@0 | 371 | this.callback_onSuccess(); |
michael@0 | 372 | } |
michael@0 | 373 | |
michael@0 | 374 | domwindow.removeEventListener("load", onLoad, true); |
michael@0 | 375 | clearTimeout(this.callBack_onTimeout); |
michael@0 | 376 | |
michael@0 | 377 | // wait for trasition to fullscreen on OSX Lion later |
michael@0 | 378 | if (isOSX) { |
michael@0 | 379 | setTimeout(function(){ |
michael@0 | 380 | domwindow.close(); |
michael@0 | 381 | executeSoon(this.callBack_onFinalize); |
michael@0 | 382 | }.bind(this), 3000); |
michael@0 | 383 | } |
michael@0 | 384 | else { |
michael@0 | 385 | domwindow.close(); |
michael@0 | 386 | executeSoon(this.callBack_onFinalize); |
michael@0 | 387 | } |
michael@0 | 388 | }.bind(this), true); |
michael@0 | 389 | }, |
michael@0 | 390 | onCloseWindow: function(aXULWindow) {}, |
michael@0 | 391 | onWindowTitleChange: function(aXULWindow, aNewTitle) {}, |
michael@0 | 392 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowMediatorListener, |
michael@0 | 393 | Ci.nsISupports]), |
michael@0 | 394 | }; |