1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 const utils = require("sdk/keyboard/utils");
8 const runtime = require("sdk/system/runtime");
10 const isMac = runtime.OS === "Darwin";
12 exports["test toString"] = function(assert) {
13 assert.equal(utils.toString({
15 modifiers: [ "Shift", "Ctrl" ]
16 }), "Shift-Ctrl-B", "toString does not normalizes JSON");
18 assert.equal(utils.toString({
21 }), "C", "Works with objects with empty array of modifiers");
23 assert.equal(utils.toString(Object.create((function Type() {}).prototype, {
25 modifiers: { value: [ "alt" ] },
26 method: { value: function() {} }
27 })), "alt-d", "Works with non-json objects");
29 assert.equal(utils.toString({
30 modifiers: [ "shift", "alt" ]
31 }), "shift-alt-", "works with only modifiers");
34 exports["test toJSON"] = function(assert) {
35 assert.deepEqual(utils.toJSON("Shift-Ctrl-B"), {
37 modifiers: [ "control", "shift" ]
38 }, "toJSON normalizes input");
40 assert.deepEqual(utils.toJSON("Meta-Alt-option-C"), {
42 modifiers: [ "alt", "meta" ]
43 }, "removes dublicates");
45 assert.deepEqual(utils.toJSON("AccEl+sHiFt+Z", "+"), {
47 modifiers: isMac ? [ "meta", "shift" ] : [ "control", "shift" ]
48 }, "normalizes OS specific keys and adjustes seperator");
51 exports["test normalize"] = function assert(assert) {
52 assert.equal(utils.normalize("Shift Ctrl A control ctrl", " "),
53 "control shift a", "removes reapeted modifiers");
54 assert.equal(utils.normalize("shift-ctrl-left"), "control-shift-left",
55 "normilizes non printed characters");
57 assert.throws(function() {
58 utils.normalize("shift-alt-b-z");
59 }, "throws if contains more then on non-modifier key");
62 require("test").run(exports);