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: michael@0: "use strict"; michael@0: michael@0: // TODO Fennec support in Bug #894525 michael@0: module.metadata = { michael@0: "engines": { michael@0: "Firefox": "*" michael@0: } michael@0: } michael@0: michael@0: const { openTab, closeTab } = require("sdk/tabs/utils"); michael@0: const { Loader } = require("sdk/test/loader"); michael@0: const { setTimeout } = require("sdk/timers"); michael@0: michael@0: exports["test unload tab observer"] = function(assert, done) { michael@0: let loader = Loader(module); michael@0: michael@0: let window = loader.require("sdk/deprecated/window-utils").activeBrowserWindow; michael@0: let observer = loader.require("sdk/tabs/observer").observer; michael@0: let opened = 0; michael@0: let closed = 0; michael@0: michael@0: observer.on("open", function onOpen(window) { opened++; }); michael@0: observer.on("close", function onClose(window) { closed++; }); michael@0: michael@0: // Open and close tab to trigger observers. michael@0: closeTab(openTab(window, "data:text/html;charset=utf-8,tab-1")); michael@0: michael@0: // Unload the module so that all listeners set by observer are removed. michael@0: loader.unload(); michael@0: michael@0: // Open and close tab once again. michael@0: closeTab(openTab(window, "data:text/html;charset=utf-8,tab-2")); michael@0: michael@0: // Enqueuing asserts to make sure that assertion is not performed early. michael@0: setTimeout(function () { michael@0: assert.equal(1, opened, "observer open was called before unload only"); michael@0: assert.equal(1, closed, "observer close was called before unload only"); michael@0: done(); michael@0: }, 0); michael@0: }; michael@0: michael@0: require("test").run(exports); michael@0: