Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Bug 866464 test window-observer doesn't throw on Fennec
Browse files Browse the repository at this point in the history
  • Loading branch information
jsantell committed Aug 13, 2013
1 parent 52b1103 commit 7762f96
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions test/test-window-observer.js
Expand Up @@ -3,17 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";

// Opening new windows in Fennec causes issues
module.metadata = {
engines: {
'Firefox': '*'
}
};

const { Loader } = require("sdk/test/loader");
const { open, close } = require("sdk/window/helpers");
const { browserWindows: windows } = require("sdk/windows");
const { isBrowser } = require('sdk/window/utils');
const app = require("sdk/system/xul-app");

exports["test unload window observer"] = function(assert, done) {
// Hacky way to be able to create unloadable modules via makeSandboxedLoader.
Expand All @@ -23,17 +17,14 @@ exports["test unload window observer"] = function(assert, done) {
let closed = 0;
let windowsOpen = windows.length;

observer.on("open", function onOpen(window) {
// Ignoring non-browser windows
if (isBrowser(window))
opened++;
});
observer.on("close", function onClose(window) {
// Ignore non-browser windows & already opened `activeWindow` (unload will
// emit close on it even though it is not actually closed).
if (isBrowser(window))
closed++;
});
observer.on("open", onOpen);
observer.on("close", onClose);

// On Fennec, only test that the module does not throw an error
if (app.is("Fennec")) {
assert.pass("Windows observer did not throw on Fennec");
return cleanUp();
}

// Open window and close it to trigger observers.
open().
Expand All @@ -46,7 +37,25 @@ exports["test unload window observer"] = function(assert, done) {
assert.equal(1, opened, "observer open was called before unload only");
assert.equal(windowsOpen + 1, closed, "observer close was called before unload only");
}).
then(done, assert.fail);
then(cleanUp, assert.fail);

function cleanUp () {
observer.removeListener("open", onOpen);
observer.removeListener("close", onClose);
done();
}

function onOpen(window) {
// Ignoring non-browser windows
if (isBrowser(window))
opened++;
}
function onClose(window) {
// Ignore non-browser windows & already opened `activeWindow` (unload will
// emit close on it even though it is not actually closed).
if (isBrowser(window))
closed++;
}
};

require("test").run(exports);

0 comments on commit 7762f96

Please sign in to comment.