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: const { keyPress } = require("sdk/dom/events/keys"); michael@0: const { Loader } = require("sdk/test/loader"); michael@0: const timer = require("sdk/timers"); michael@0: michael@0: exports["test unload keyboard observer"] = function(assert, done) { michael@0: let loader = Loader(module); michael@0: let element = loader.require("sdk/deprecated/window-utils"). michael@0: activeBrowserWindow.document.documentElement; michael@0: let observer = loader.require("sdk/keyboard/observer"). michael@0: observer; michael@0: let called = 0; michael@0: michael@0: observer.on("keypress", function () { called++; }); michael@0: michael@0: // dispatching "keypress" event to trigger observer listeners. michael@0: keyPress(element, "accel-%"); michael@0: michael@0: // Unload the module. michael@0: loader.unload(); michael@0: michael@0: // dispatching "keypress" even once again. michael@0: keyPress(element, "accel-%"); michael@0: michael@0: // Enqueuing asserts to make sure that assertion is not performed early. michael@0: timer.setTimeout(function () { michael@0: assert.equal(called, 1, "observer was called before unload only."); michael@0: done(); michael@0: }, 0); michael@0: }; michael@0: michael@0: require("test").run(exports);