|
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/. */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 /** |
|
8 * Ensures using child_process and underlying subprocess.jsm |
|
9 * works within an addon |
|
10 */ |
|
11 |
|
12 const { exec } = require("sdk/system/child_process"); |
|
13 const { platform, pathFor } = require("sdk/system"); |
|
14 const PROFILE_DIR = pathFor("ProfD"); |
|
15 const isWindows = platform.toLowerCase().indexOf("win") === 0; |
|
16 const app = require("sdk/system/xul-app"); |
|
17 |
|
18 // Once Bug 903018 is resolved, just move the application testing to |
|
19 // module.metadata.engines |
|
20 if (app.is("Firefox")) { |
|
21 exports["test child_process in an addon"] = (assert, done) => { |
|
22 exec(isWindows ? "DIR /A-D" : "ls -al", { |
|
23 cwd: PROFILE_DIR |
|
24 }, (err, stdout, stderr) => { |
|
25 assert.ok(!err, "no errors"); |
|
26 assert.equal(stderr, "", "stderr is empty"); |
|
27 assert.ok(/extensions\.ini/.test(stdout), "stdout output of `ls -al` finds files"); |
|
28 |
|
29 if (isWindows) |
|
30 assert.ok(!/<DIR>/.test(stdout), "passing args works"); |
|
31 else |
|
32 assert.ok(/d(r[-|w][-|x]){3}/.test(stdout), "passing args works"); |
|
33 done(); |
|
34 }); |
|
35 }; |
|
36 } else { |
|
37 exports["test unsupported"] = (assert) => assert.pass("This application is unsupported."); |
|
38 } |
|
39 require("sdk/test/runner").runTestsFromModule(module); |