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

branch
TOR_BUG_9701
changeset 10
ac0c01689b40
equal deleted inserted replaced
-1:000000000000 0:0b27fb961d7c
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";
5
6 const { identify } = require('sdk/ui/id');
7 const { Class } = require('sdk/core/heritage');
8
9 const signature = /{[0-9a-f\-]+}/;
10
11 exports['test generate id'] = function(assert) {
12 let first = identify({});
13 let second = identify({});
14
15 assert.ok(signature.test(first), 'first id has a correct signature');
16 assert.ok(signature.test(second), 'second id has a correct signature');
17
18 assert.notEqual(first, identify({}), 'identify generated new uuid [1]');
19 assert.notEqual(first, second, 'identify generated new uuid [2]');
20 };
21
22 exports['test get id'] = function(assert) {
23 let thing = {};
24 let thingID = identify(thing);
25
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 };
29
30 exports['test custom id definition for classes'] = function(assert) {
31 let Thing = Class({});
32 let thing = Thing();
33 let counter = 0;
34
35 identify.define(Thing, function(thing) {
36 return ++counter;
37 });
38
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 }
42
43 require('sdk/test').run(exports);

mercurial