michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: "use strict"; michael@0: michael@0: // Opening new windows in Fennec causes issues michael@0: module.metadata = { michael@0: engines: { michael@0: 'Firefox': '*' michael@0: } michael@0: }; michael@0: michael@0: const { Loader } = require("sdk/test/loader"); michael@0: const { open, getMostRecentBrowserWindow, getOuterId } = require("sdk/window/utils"); michael@0: michael@0: exports["test browser events"] = function(assert, done) { michael@0: let loader = Loader(module); michael@0: let { events } = loader.require("sdk/window/events"); michael@0: let { on, off } = loader.require("sdk/event/core"); michael@0: let actual = []; michael@0: michael@0: on(events, "data", function handler(e) { michael@0: actual.push(e); michael@0: michael@0: if (e.type === "open") { michael@0: assert.pass("window open has occured"); michael@0: } michael@0: else if (e.type === "DOMContentLoaded") { michael@0: assert.pass("window DOMContentLoaded has occured"); michael@0: } michael@0: else if (e.type === "load") { michael@0: assert.pass("window load has occured"); michael@0: window.close(); michael@0: } michael@0: else if (e.type === "close") { michael@0: // confirm the ordering of events michael@0: let [ open, ready, load, close ] = actual; michael@0: assert.equal(open.type, "open") michael@0: assert.equal(open.target, window, "window is open") michael@0: michael@0: assert.equal(ready.type, "DOMContentLoaded") michael@0: assert.equal(ready.target, window, "window ready") michael@0: michael@0: assert.equal(load.type, "load") michael@0: assert.equal(load.target, window, "window load") michael@0: michael@0: assert.equal(close.type, "close") michael@0: assert.equal(close.target, window, "window load") michael@0: michael@0: // Note: If window is closed right after this GC won't have time michael@0: // to claim loader and there for this listener. It's better to remove michael@0: // remove listener here to avoid race conditions. michael@0: off(events, "data", handler); michael@0: loader.unload(); michael@0: done(); michael@0: } michael@0: }); michael@0: michael@0: // Open window and close it to trigger observers. michael@0: let window = open(); michael@0: }; michael@0: michael@0: require("sdk/test").run(exports);