/* 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/. */ // nsIProcess unit test const TEST_ARGS = [ "mozilla", "firefox", "thunderbird", "seamonkey", "foo", "bar", "argument with spaces", '"argument with quotes"',
];
// test if a process can be started, polled for its running status // and then killed function test_kill() { var file = get_test_program("TestBlockingProcess");
var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
process.init(file);
Assert.ok(!process.isRunning);
try {
process.kill();
do_throw("Attempting to kill a not-running process should throw");
} catch (e) {}
process.run(false, [], 0);
Assert.ok(process.isRunning);
process.kill();
Assert.ok(!process.isRunning);
try {
process.kill();
do_throw("Attempting to kill a not-running process should throw");
} catch (e) {}
}
// test if we can get an exit value from an application that is // guaranteed to return an exit value of 42 function test_quick() { var file = get_test_program("TestQuickReturn");
var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
process.init(file);
// to get an exit value it must be a blocking process
process.run(true, [], 0);
Assert.equal(process.exitValue, 42);
}
function test_args(file, args, argsAreASCII) { var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
process.init(file);
// test if an argument can be successfully passed to an application // that will return 0 if "mozilla" is the only argument function test_arguments() {
test_args(get_test_program("TestArguments"), TEST_ARGS, true);
}
// test if Unicode arguments can be successfully passed to an application function test_unicode_arguments() {
test_args(get_test_program("TestUnicodeArguments"), TEST_UNICODE_ARGS, false);
}
function rename_and_test(asciiName, unicodeName, args, argsAreASCII) { var asciiFile = get_test_program(asciiName); var asciiLeaf = asciiFile.leafName; var unicodeLeaf = asciiLeaf.replace(asciiName, unicodeName);
asciiFile.moveTo(null, unicodeLeaf);
var unicodeFile = get_test_program(unicodeName);
test_args(unicodeFile, args, argsAreASCII);
unicodeFile.moveTo(null, asciiLeaf);
}
// test passing ASCII and Unicode arguments to an application with a Unicode name function test_unicode_app() {
rename_and_test( "TestArguments", // "Unicode" in Tamil "\u0BAF\u0BC1\u0BA9\u0BBF\u0B95\u0BCB\u0B9F\u0BCD",
TEST_ARGS, true
);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.