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

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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/. */
     5 "use strict";
     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({
    14     key: "B",
    15     modifiers: [ "Shift", "Ctrl" ]
    16   }), "Shift-Ctrl-B", "toString does not normalizes JSON");
    18   assert.equal(utils.toString({
    19     key: "C",
    20     modifiers: [],
    21   }), "C", "Works with objects with empty array of modifiers");
    23   assert.equal(utils.toString(Object.create((function Type() {}).prototype, {
    24     key: { value: "d" },
    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");
    32 };
    34 exports["test toJSON"] = function(assert) {
    35   assert.deepEqual(utils.toJSON("Shift-Ctrl-B"), {
    36     key: "b",
    37     modifiers: [ "control", "shift" ]
    38   }, "toJSON normalizes input");
    40   assert.deepEqual(utils.toJSON("Meta-Alt-option-C"), {
    41     key: "c",
    42     modifiers: [ "alt", "meta" ]
    43   }, "removes dublicates");
    45   assert.deepEqual(utils.toJSON("AccEl+sHiFt+Z", "+"), {
    46     key: "z",
    47     modifiers: isMac ? [ "meta", "shift" ] : [ "control", "shift" ]
    48   }, "normalizes OS specific keys and adjustes seperator");
    49 };
    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");
    60 };
    62 require("test").run(exports);

mercurial