addon-sdk/source/test/test-keyboard-observer.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/test/test-keyboard-observer.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,37 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +const { keyPress } = require("sdk/dom/events/keys");
    1.11 +const { Loader } = require("sdk/test/loader");
    1.12 +const timer = require("sdk/timers");
    1.13 +
    1.14 +exports["test unload keyboard observer"] = function(assert, done) {
    1.15 +  let loader = Loader(module);
    1.16 +  let element = loader.require("sdk/deprecated/window-utils").
    1.17 +                       activeBrowserWindow.document.documentElement;
    1.18 +  let observer = loader.require("sdk/keyboard/observer").
    1.19 +                        observer;
    1.20 +  let called = 0;
    1.21 +
    1.22 +  observer.on("keypress", function () { called++; });
    1.23 +
    1.24 +  // dispatching "keypress" event to trigger observer listeners.
    1.25 +  keyPress(element, "accel-%");
    1.26 +
    1.27 +  // Unload the module.
    1.28 +  loader.unload();
    1.29 +
    1.30 +  // dispatching "keypress" even once again.
    1.31 +  keyPress(element, "accel-%");
    1.32 +
    1.33 +  // Enqueuing asserts to make sure that assertion is not performed early.
    1.34 +  timer.setTimeout(function () {
    1.35 +    assert.equal(called, 1, "observer was called before unload only.");
    1.36 +    done();
    1.37 +  }, 0);
    1.38 +};
    1.39 +
    1.40 +require("test").run(exports);

mercurial