addon-sdk/source/test/test-ui-id.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/test/test-ui-id.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,43 @@
     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 +"use strict";
     1.8 +
     1.9 +const { identify } = require('sdk/ui/id');
    1.10 +const { Class } = require('sdk/core/heritage');
    1.11 +
    1.12 +const signature = /{[0-9a-f\-]+}/;
    1.13 +
    1.14 +exports['test generate id'] = function(assert) {
    1.15 +  let first = identify({});
    1.16 +  let second = identify({});
    1.17 +
    1.18 +  assert.ok(signature.test(first), 'first id has a correct signature');
    1.19 +  assert.ok(signature.test(second), 'second id has a correct signature');
    1.20 +
    1.21 +  assert.notEqual(first, identify({}), 'identify generated new uuid [1]');
    1.22 +  assert.notEqual(first, second, 'identify generated new uuid [2]');
    1.23 +};
    1.24 +
    1.25 +exports['test get id'] = function(assert) {
    1.26 +  let thing = {};
    1.27 +  let thingID = identify(thing);
    1.28 +
    1.29 +  assert.equal(thingID, identify(thing), 'ids for things are cached by default');
    1.30 +  assert.notEqual(identify(thing), identify({}), 'new ids for new things');
    1.31 +};
    1.32 +
    1.33 +exports['test custom id definition for classes'] = function(assert) {
    1.34 +  let Thing = Class({});
    1.35 +  let thing = Thing();
    1.36 +  let counter = 0;
    1.37 +
    1.38 +  identify.define(Thing, function(thing) {
    1.39 +    return ++counter;
    1.40 +  });
    1.41 +
    1.42 +  assert.equal(identify(thing), counter, 'it is possible to define custom identifications');
    1.43 +  assert.ok(signature.test(identify({})), 'defining a custom identification does not affect the default behavior');
    1.44 +}
    1.45 +
    1.46 +require('sdk/test').run(exports);

mercurial