michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: /** michael@0: * Ensures using child_process and underlying subprocess.jsm michael@0: * works within an addon michael@0: */ michael@0: michael@0: const { exec } = require("sdk/system/child_process"); michael@0: const { platform, pathFor } = require("sdk/system"); michael@0: const PROFILE_DIR = pathFor("ProfD"); michael@0: const isWindows = platform.toLowerCase().indexOf("win") === 0; michael@0: const app = require("sdk/system/xul-app"); michael@0: michael@0: // Once Bug 903018 is resolved, just move the application testing to michael@0: // module.metadata.engines michael@0: if (app.is("Firefox")) { michael@0: exports["test child_process in an addon"] = (assert, done) => { michael@0: exec(isWindows ? "DIR /A-D" : "ls -al", { michael@0: cwd: PROFILE_DIR michael@0: }, (err, stdout, stderr) => { michael@0: assert.ok(!err, "no errors"); michael@0: assert.equal(stderr, "", "stderr is empty"); michael@0: assert.ok(/extensions\.ini/.test(stdout), "stdout output of `ls -al` finds files"); michael@0: michael@0: if (isWindows) michael@0: assert.ok(!//.test(stdout), "passing args works"); michael@0: else michael@0: assert.ok(/d(r[-|w][-|x]){3}/.test(stdout), "passing args works"); michael@0: done(); michael@0: }); michael@0: }; michael@0: } else { michael@0: exports["test unsupported"] = (assert) => assert.pass("This application is unsupported."); michael@0: } michael@0: require("sdk/test/runner").runTestsFromModule(module);