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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     5 'use strict';
     7 const { env } = require('sdk/system/environment');
     8 const { Cc, Ci } = require('chrome');
     9 const { get, set, exists } = Cc['@mozilla.org/process/environment;1'].
    10                              getService(Ci.nsIEnvironment);
    12 exports['test exists'] = function(assert) {
    13   assert.equal('PATH' in env, exists('PATH'),
    14                'PATH environment variable is defined');
    15   assert.equal('FOO1' in env, exists('FOO1'),
    16                'FOO1 environment variable is not defined');
    17   set('FOO1', 'foo');
    18   assert.equal('FOO1' in env, true,
    19                'FOO1 environment variable was set');
    20   set('FOO1', null);
    21   assert.equal('FOO1' in env, false,
    22                'FOO1 environment variable was unset');
    23 };
    25 exports['test get'] = function(assert) {
    26   assert.equal(env.PATH, get('PATH'), 'PATH env variable matches');
    27   assert.equal(env.BAR2, undefined, 'BAR2 env variable is not defined');
    28   set('BAR2', 'bar');
    29   assert.equal(env.BAR2, 'bar', 'BAR2 env variable was set');
    30   set('BAR2', null);
    31   assert.equal(env.BAR2, undefined, 'BAR2 env variable was unset');
    32 };
    34 exports['test set'] = function(assert) {
    35   assert.equal(get('BAZ3'), '', 'BAZ3 env variable is not set');
    36   assert.equal(env.BAZ3, undefined, 'BAZ3 is not set');
    37   env.BAZ3 = 'baz';
    38   assert.equal(env.BAZ3, get('BAZ3'), 'BAZ3 env variable is set');
    39   assert.equal(get('BAZ3'), 'baz', 'BAZ3 env variable was set to "baz"');
    40 };
    42 exports['test unset'] = function(assert) {
    43   env.BLA4 = 'bla';
    44   assert.equal(env.BLA4, 'bla', 'BLA4 env variable is set');
    45   assert.equal(delete env.BLA4, true, 'BLA4 env variable is removed');
    46   assert.equal(env.BLA4, undefined, 'BLA4 env variable is unset');
    47   assert.equal('BLA4' in env, false, 'BLA4 env variable no longer exists' );
    48 };
    50 require('test').run(exports);

mercurial