addon-sdk/source/test/test-environment.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/test/test-environment.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,50 @@
     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 +
     1.8 +'use strict';
     1.9 +
    1.10 +const { env } = require('sdk/system/environment');
    1.11 +const { Cc, Ci } = require('chrome');
    1.12 +const { get, set, exists } = Cc['@mozilla.org/process/environment;1'].
    1.13 +                             getService(Ci.nsIEnvironment);
    1.14 +
    1.15 +exports['test exists'] = function(assert) {
    1.16 +  assert.equal('PATH' in env, exists('PATH'),
    1.17 +               'PATH environment variable is defined');
    1.18 +  assert.equal('FOO1' in env, exists('FOO1'),
    1.19 +               'FOO1 environment variable is not defined');
    1.20 +  set('FOO1', 'foo');
    1.21 +  assert.equal('FOO1' in env, true,
    1.22 +               'FOO1 environment variable was set');
    1.23 +  set('FOO1', null);
    1.24 +  assert.equal('FOO1' in env, false,
    1.25 +               'FOO1 environment variable was unset');
    1.26 +};
    1.27 +
    1.28 +exports['test get'] = function(assert) {
    1.29 +  assert.equal(env.PATH, get('PATH'), 'PATH env variable matches');
    1.30 +  assert.equal(env.BAR2, undefined, 'BAR2 env variable is not defined');
    1.31 +  set('BAR2', 'bar');
    1.32 +  assert.equal(env.BAR2, 'bar', 'BAR2 env variable was set');
    1.33 +  set('BAR2', null);
    1.34 +  assert.equal(env.BAR2, undefined, 'BAR2 env variable was unset');
    1.35 +};
    1.36 +
    1.37 +exports['test set'] = function(assert) {
    1.38 +  assert.equal(get('BAZ3'), '', 'BAZ3 env variable is not set');
    1.39 +  assert.equal(env.BAZ3, undefined, 'BAZ3 is not set');
    1.40 +  env.BAZ3 = 'baz';
    1.41 +  assert.equal(env.BAZ3, get('BAZ3'), 'BAZ3 env variable is set');
    1.42 +  assert.equal(get('BAZ3'), 'baz', 'BAZ3 env variable was set to "baz"');
    1.43 +};
    1.44 +
    1.45 +exports['test unset'] = function(assert) {
    1.46 +  env.BLA4 = 'bla';
    1.47 +  assert.equal(env.BLA4, 'bla', 'BLA4 env variable is set');
    1.48 +  assert.equal(delete env.BLA4, true, 'BLA4 env variable is removed');
    1.49 +  assert.equal(env.BLA4, undefined, 'BLA4 env variable is unset');
    1.50 +  assert.equal('BLA4' in env, false, 'BLA4 env variable no longer exists' );
    1.51 +};
    1.52 +
    1.53 +require('test').run(exports);

mercurial