addon-sdk/source/test/addons/curly-id/lib/main.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/test/addons/curly-id/lib/main.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 simple = require('sdk/simple-prefs');
    1.10 +const service = require('sdk/preferences/service');
    1.11 +const { id, preferencesBranch } = require('sdk/self');
    1.12 +const { AddonManager } = require('chrome').Cu.import('resource://gre/modules/AddonManager.jsm');
    1.13 +
    1.14 +exports.testCurlyID = function(assert) {
    1.15 +  assert.equal(id, '{34a1eae1-c20a-464f-9b0e-000000000000}', 'curly ID is curly');
    1.16 +
    1.17 +  assert.equal(simple.prefs.test13, 26, 'test13 is 26');
    1.18 +
    1.19 +  simple.prefs.test14 = '15';
    1.20 +  assert.equal(service.get('extensions.{34a1eae1-c20a-464f-9b0e-000000000000}.test14'), '15', 'test14 is 15');
    1.21 +
    1.22 +  assert.equal(service.get('extensions.{34a1eae1-c20a-464f-9b0e-000000000000}.test14'), simple.prefs.test14, 'simple test14 also 15');
    1.23 +
    1.24 +}
    1.25 +
    1.26 +exports.testInvalidPreferencesBranch = function(assert) {
    1.27 +  assert.notEqual(preferencesBranch, 'invalid^branch*name', 'invalid preferences-branch value ignored');
    1.28 +
    1.29 +  assert.equal(preferencesBranch, '{34a1eae1-c20a-464f-9b0e-000000000000}', 'preferences-branch is {34a1eae1-c20a-464f-9b0e-000000000000}');
    1.30 +
    1.31 +}
    1.32 +
    1.33 +// from `/test/test-self.js`, adapted to `sdk/test/assert` API
    1.34 +exports.testSelfID = function(assert, done) {
    1.35 +
    1.36 +  assert.equal(typeof(id), 'string', 'self.id is a string');
    1.37 +  assert.ok(id.length > 0, 'self.id not empty');
    1.38 +
    1.39 +  AddonManager.getAddonByID(id, function(addon) {
    1.40 +    assert.ok(addon, 'found addon with self.id');
    1.41 +    done();
    1.42 +  });
    1.43 +
    1.44 +}
    1.45 +
    1.46 +require('sdk/test/runner').runTestsFromModule(module);

mercurial