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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | "use strict"; |
michael@0 | 5 | |
michael@0 | 6 | const { Loader } = require("sdk/test/loader"); |
michael@0 | 7 | const { open, close } = require("sdk/window/helpers"); |
michael@0 | 8 | const { browserWindows: windows } = require("sdk/windows"); |
michael@0 | 9 | const { isBrowser } = require('sdk/window/utils'); |
michael@0 | 10 | const app = require("sdk/system/xul-app"); |
michael@0 | 11 | |
michael@0 | 12 | exports["test unload window observer"] = function(assert, done) { |
michael@0 | 13 | // Hacky way to be able to create unloadable modules via makeSandboxedLoader. |
michael@0 | 14 | let loader = Loader(module); |
michael@0 | 15 | let observer = loader.require("sdk/windows/observer").observer; |
michael@0 | 16 | let opened = 0; |
michael@0 | 17 | let closed = 0; |
michael@0 | 18 | let windowsOpen = windows.length; |
michael@0 | 19 | |
michael@0 | 20 | observer.on("open", onOpen); |
michael@0 | 21 | observer.on("close", onClose); |
michael@0 | 22 | |
michael@0 | 23 | // On Fennec, only test that the module does not throw an error |
michael@0 | 24 | if (app.is("Fennec")) { |
michael@0 | 25 | assert.pass("Windows observer did not throw on Fennec"); |
michael@0 | 26 | return cleanUp(); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | // Open window and close it to trigger observers. |
michael@0 | 30 | open(). |
michael@0 | 31 | then(close). |
michael@0 | 32 | then(loader.unload). |
michael@0 | 33 | then(open). |
michael@0 | 34 | then(close). |
michael@0 | 35 | then(function() { |
michael@0 | 36 | // Enqueuing asserts to make sure that assertion is not performed early. |
michael@0 | 37 | assert.equal(1, opened, "observer open was called before unload only"); |
michael@0 | 38 | assert.equal(windowsOpen + 1, closed, "observer close was called before unload only"); |
michael@0 | 39 | }). |
michael@0 | 40 | then(cleanUp, assert.fail); |
michael@0 | 41 | |
michael@0 | 42 | function cleanUp () { |
michael@0 | 43 | observer.removeListener("open", onOpen); |
michael@0 | 44 | observer.removeListener("close", onClose); |
michael@0 | 45 | done(); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | function onOpen(window) { |
michael@0 | 49 | // Ignoring non-browser windows |
michael@0 | 50 | if (isBrowser(window)) |
michael@0 | 51 | opened++; |
michael@0 | 52 | } |
michael@0 | 53 | function onClose(window) { |
michael@0 | 54 | // Ignore non-browser windows & already opened `activeWindow` (unload will |
michael@0 | 55 | // emit close on it even though it is not actually closed). |
michael@0 | 56 | if (isBrowser(window)) |
michael@0 | 57 | closed++; |
michael@0 | 58 | } |
michael@0 | 59 | }; |
michael@0 | 60 | |
michael@0 | 61 | require("sdk/test").run(exports); |