addon-sdk/source/test/test-ui-id.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/. */
     4 "use strict";
     6 const { identify } = require('sdk/ui/id');
     7 const { Class } = require('sdk/core/heritage');
     9 const signature = /{[0-9a-f\-]+}/;
    11 exports['test generate id'] = function(assert) {
    12   let first = identify({});
    13   let second = identify({});
    15   assert.ok(signature.test(first), 'first id has a correct signature');
    16   assert.ok(signature.test(second), 'second id has a correct signature');
    18   assert.notEqual(first, identify({}), 'identify generated new uuid [1]');
    19   assert.notEqual(first, second, 'identify generated new uuid [2]');
    20 };
    22 exports['test get id'] = function(assert) {
    23   let thing = {};
    24   let thingID = identify(thing);
    26   assert.equal(thingID, identify(thing), 'ids for things are cached by default');
    27   assert.notEqual(identify(thing), identify({}), 'new ids for new things');
    28 };
    30 exports['test custom id definition for classes'] = function(assert) {
    31   let Thing = Class({});
    32   let thing = Thing();
    33   let counter = 0;
    35   identify.define(Thing, function(thing) {
    36     return ++counter;
    37   });
    39   assert.equal(identify(thing), counter, 'it is possible to define custom identifications');
    40   assert.ok(signature.test(identify({})), 'defining a custom identification does not affect the default behavior');
    41 }
    43 require('sdk/test').run(exports);

mercurial