summaryrefslogtreecommitdiffstats
path: root/addon-sdk/source/test/fixtures/child-process-scripts.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /addon-sdk/source/test/fixtures/child-process-scripts.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'addon-sdk/source/test/fixtures/child-process-scripts.js')
-rw-r--r--addon-sdk/source/test/fixtures/child-process-scripts.js81
1 files changed, 81 insertions, 0 deletions
diff --git a/addon-sdk/source/test/fixtures/child-process-scripts.js b/addon-sdk/source/test/fixtures/child-process-scripts.js
new file mode 100644
index 000000000..d808e56cb
--- /dev/null
+++ b/addon-sdk/source/test/fixtures/child-process-scripts.js
@@ -0,0 +1,81 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+const { platform, pathFor } = require('sdk/system');
+const { defer } = require('sdk/core/promise');
+const { emit } = require('sdk/event/core');
+const { join } = require('sdk/fs/path');
+const { writeFile, unlinkSync, existsSync } = require('sdk/io/fs');
+const PROFILE_DIR= pathFor('ProfD');
+const isWindows = platform.toLowerCase().indexOf('win') === 0;
+const isOSX = platform.toLowerCase().indexOf('darwin') === 0;
+
+var scripts = {
+ 'args.sh': 'echo $1 $2 $3 $4',
+ 'args.bat': 'echo %1 %2 %3 %4',
+ 'check-env.sh': 'echo $CHILD_PROCESS_ENV_TEST',
+ 'check-env.bat': 'echo %CHILD_PROCESS_ENV_TEST%',
+ 'check-pwd.sh': 'echo $PWD',
+ 'check-pwd.bat': 'cd',
+ 'large-err.sh': 'for n in `seq 0 $1` ; do echo "E" 1>&2; done',
+ 'large-err-mac.sh': 'for ((i=0; i<$1; i=i+1)); do echo "E" 1>&2; done',
+ 'large-err.bat': 'FOR /l %%i in (0,1,%1) DO echo "E" 1>&2',
+ 'large-out.sh': 'for n in `seq 0 $1` ; do echo "O"; done',
+ 'large-out-mac.sh': 'for ((i=0; i<$1; i=i+1)); do echo "O"; done',
+ 'large-out.bat': 'FOR /l %%i in (0,1,%1) DO echo "O"',
+ 'wait.sh': 'sleep 2',
+ // Use `ping` to an invalid IP address because `timeout` isn't
+ // on all environments? http://stackoverflow.com/a/1672349/1785755
+ 'wait.bat': 'ping 1.1.1.1 -n 1 -w 2000 > nul'
+};
+
+Object.keys(scripts).forEach(filename => {
+ if (/\.sh$/.test(filename))
+ scripts[filename] = '#!/bin/sh\n' + scripts[filename];
+ else if (/\.bat$/.test(filename))
+ scripts[filename] = '@echo off\n' + scripts[filename];
+});
+
+function getScript (name) {
+ // Use specific OSX script if exists
+ if (isOSX && scripts[name + '-mac.sh'])
+ name = name + '-mac';
+ let fileName = name + (isWindows ? '.bat' : '.sh');
+ return createFile(fileName, scripts[fileName]);
+}
+exports.getScript = getScript;
+
+function createFile (name, data) {
+ let { promise, resolve, reject } = defer();
+ let fileName = join(PROFILE_DIR, name);
+ writeFile(fileName, data, function (err) {
+ if (err) reject();
+ else {
+ makeExecutable(fileName);
+ resolve(fileName);
+ }
+ });
+ return promise;
+}
+
+// TODO Use fs.chmod once implemented, bug 914606
+function makeExecutable (name) {
+ let { CC } = require('chrome');
+ let nsILocalFile = CC('@mozilla.org/file/local;1', 'nsILocalFile', 'initWithPath');
+ let file = nsILocalFile(name);
+ file.permissions = 0o777;
+}
+
+function deleteFile (name) {
+ let file = join(PROFILE_DIR, name);
+ if (existsSync(file))
+ unlinkSync(file);
+}
+
+function cleanUp () {
+ Object.keys(scripts).forEach(deleteFile);
+}
+exports.cleanUp = cleanUp;