addon-sdk/source/test/addons/child_process/index.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/test/addons/child_process/index.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,39 @@
     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 +/**
    1.11 + * Ensures using child_process and underlying subprocess.jsm
    1.12 + * works within an addon
    1.13 + */
    1.14 +
    1.15 +const { exec } = require("sdk/system/child_process");
    1.16 +const { platform, pathFor } = require("sdk/system");
    1.17 +const PROFILE_DIR = pathFor("ProfD");
    1.18 +const isWindows = platform.toLowerCase().indexOf("win") === 0;
    1.19 +const app = require("sdk/system/xul-app");
    1.20 +
    1.21 +// Once Bug 903018 is resolved, just move the application testing to
    1.22 +// module.metadata.engines
    1.23 +if (app.is("Firefox")) {
    1.24 +  exports["test child_process in an addon"] = (assert, done) => {
    1.25 +    exec(isWindows ? "DIR /A-D" : "ls -al", {
    1.26 +      cwd: PROFILE_DIR
    1.27 +    }, (err, stdout, stderr) => {
    1.28 +      assert.ok(!err, "no errors");
    1.29 +      assert.equal(stderr, "", "stderr is empty");
    1.30 +      assert.ok(/extensions\.ini/.test(stdout), "stdout output of `ls -al` finds files");
    1.31 +
    1.32 +      if (isWindows)
    1.33 +        assert.ok(!/<DIR>/.test(stdout), "passing args works");
    1.34 +      else
    1.35 +        assert.ok(/d(r[-|w][-|x]){3}/.test(stdout), "passing args works");
    1.36 +      done();
    1.37 +    });
    1.38 +  };
    1.39 +} else {
    1.40 +  exports["test unsupported"] = (assert) => assert.pass("This application is unsupported.");
    1.41 +}
    1.42 +require("sdk/test/runner").runTestsFromModule(module);

mercurial