Bug 1561435 - Format xpcom/, a=automatic-formatting

# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D35945

--HG--
extra : source : c64ace0e98b196a9a392d54800159e327921bf99
This commit is contained in:
Victor Porof 2019-07-05 11:19:37 +02:00
parent c03a3e486b
commit 1fcaa7d445
40 changed files with 978 additions and 647 deletions

View file

@ -45,7 +45,6 @@ module.exports = {
"overrides": [{
"files": [
"devtools/**",
"xpcom/**",
"xpfe/**",
],
"rules": {

View file

@ -40,7 +40,6 @@ toolkit/components/telemetry/datareporting-prefs.js
toolkit/components/telemetry/healthreport-prefs.js
# Ignore all top-level directories for now.
xpcom/**
xpfe/**
# Ignore all devtools directories for now, except the debugger.

View file

@ -10,8 +10,9 @@ const nsIWindowsRegKey = Ci.nsIWindowsRegKey;
const BASE_PATH = "SOFTWARE\\Mozilla\\Firefox";
function idump(indent, str) {
for (var j = 0; j < indent; ++j)
for (var j = 0; j < indent; ++j) {
dump(" ");
}
dump(str);
}
@ -24,10 +25,11 @@ function list_values(indent, key) {
if (key.getValueType(vn) == nsIWindowsRegKey.TYPE_STRING) {
val = key.readStringValue(vn);
}
if (vn == "")
idump(indent + 1, "(Default): \"" + val + "\"\n");
else
idump(indent + 1, vn + ": \"" + val + "\"\n");
if (vn == "") {
idump(indent + 1, '(Default): "' + val + '"\n');
} else {
idump(indent + 1, vn + ': "' + val + '"\n');
}
}
idump(indent, "}\n");
}
@ -44,13 +46,20 @@ function list_children(indent, key) {
}
// enumerate everything under BASE_PATH
var key = Cc["@mozilla.org/windows-registry-key;1"].
createInstance(nsIWindowsRegKey);
key.open(nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE, BASE_PATH,
nsIWindowsRegKey.ACCESS_READ);
var key = Cc["@mozilla.org/windows-registry-key;1"].createInstance(
nsIWindowsRegKey
);
key.open(
nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
BASE_PATH,
nsIWindowsRegKey.ACCESS_READ
);
list_children(1, key);
key.close();
key.open(nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, BASE_PATH,
nsIWindowsRegKey.ACCESS_READ);
key.open(
nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
BASE_PATH,
nsIWindowsRegKey.ACCESS_READ
);
list_children(1, key);

View file

@ -1,11 +1,12 @@
/* 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/. */
const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
function TestProcessDirective() {}
TestProcessDirective.prototype = {
/* Boilerplate */
QueryInterface: ChromeUtils.generateQI([Ci.nsIProperty]),
contractID: "@mozilla.org/xpcom/tests/ChildProcessDirectiveTest;1",

View file

@ -1,11 +1,12 @@
/* 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/. */
const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
function TestProcessDirective() {}
TestProcessDirective.prototype = {
/* Boilerplate */
QueryInterface: ChromeUtils.generateQI([Ci.nsIProperty]),
contractID: "@mozilla.org/xpcom/tests/MainProcessDirectiveTest;1",

View file

@ -8,12 +8,14 @@ function get_test_program(prog) {
}
function set_process_running_environment() {
var envSvc = Cc["@mozilla.org/process/environment;1"].
getService(Ci.nsIEnvironment);
var envSvc = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
// Importing Services here messes up appInfo for some of the tests.
// eslint-disable-next-line mozilla/use-services
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(
Ci.nsIProperties
);
var greBinDir = dirSvc.get("GreBinD", Ci.nsIFile);
envSvc.set("DYLD_LIBRARY_PATH", greBinDir.path);
// For Linux

View file

@ -1,5 +1,5 @@
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
function run_test() {
var dataFile = do_get_file("data/bug121341.properties");
@ -59,6 +59,5 @@ function run_test() {
try {
properties2.load(inp);
do_throw("load() didn't fail");
} catch (e) {
}
} catch (e) {}
}

View file

@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/ */
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
function run_test() {
let complete = false;

View file

@ -14,12 +14,16 @@ var observer1 = {
timer.cancel();
// Actual delay may not be exact, so convert to seconds and round.
Assert.equal(Math.round((Date.now() - gStartTime1) / 1000),
kExpectedDelay1);
Assert.equal(
Math.round((Date.now() - gStartTime1) / 1000),
kExpectedDelay1
);
timer = null;
info("1st timer triggered (before being cancelled). Should not have happened!");
info(
"1st timer triggered (before being cancelled). Should not have happened!"
);
Assert.ok(false);
}
},
@ -32,8 +36,10 @@ var observer2 = {
timer.cancel();
// Actual delay may not be exact, so convert to seconds and round.
Assert.equal(Math.round((Date.now() - gStartTime2) / 1000),
kExpectedDelay2);
Assert.equal(
Math.round((Date.now() - gStartTime2) / 1000),
kExpectedDelay2
);
timer = null;
@ -49,12 +55,18 @@ function run_test() {
// Initialize the timer (with some delay), then cancel it.
gStartTime1 = Date.now();
timer.init(observer1, kExpectedDelay1 * 1000,
timer.TYPE_REPEATING_PRECISE_CAN_SKIP);
timer.init(
observer1,
kExpectedDelay1 * 1000,
timer.TYPE_REPEATING_PRECISE_CAN_SKIP
);
timer.cancel();
// Re-initialize the timer (with a different delay).
gStartTime2 = Date.now();
timer.init(observer2, kExpectedDelay2 * 1000,
timer.TYPE_REPEATING_PRECISE_CAN_SKIP);
timer.init(
observer2,
kExpectedDelay2 * 1000,
timer.TYPE_REPEATING_PRECISE_CAN_SKIP
);
}

View file

@ -1,4 +1,4 @@
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
function run_test() {
var f = Services.dirsvc.get("CurProcD", Ci.nsIFile);

View file

@ -1,8 +1,9 @@
function run_test() {
var dirEntries = do_get_cwd().directoryEntries;
while (dirEntries.hasMoreElements())
while (dirEntries.hasMoreElements()) {
dirEntries.getNext();
}
// We ensure there is no crash
dirEntries.hasMoreElements();

View file

@ -1,44 +1,45 @@
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
var nameArray = [
"ascii", // ASCII
"fran\u00E7ais", // Latin-1
"\u0420\u0443\u0441\u0441\u043A\u0438\u0439", // Cyrillic
"\u65E5\u672C\u8A9E", // Japanese
"\u4E2D\u6587", // Chinese
"\uD55C\uAD6D\uC5B4", // Korean
"\uD801\uDC0F\uD801\uDC2D\uD801\uDC3B\uD801\uDC2B", // Deseret
"ascii", // ASCII
"fran\u00E7ais", // Latin-1
"\u0420\u0443\u0441\u0441\u043A\u0438\u0439", // Cyrillic
"\u65E5\u672C\u8A9E", // Japanese
"\u4E2D\u6587", // Chinese
"\uD55C\uAD6D\uC5B4", // Korean
"\uD801\uDC0F\uD801\uDC2D\uD801\uDC3B\uD801\uDC2B", // Deseret
];
function getTempDir() {
return Services.dirsvc.get("TmpD", Ci.nsIFile);
return Services.dirsvc.get("TmpD", Ci.nsIFile);
}
function create_file(fileName) {
var outFile = getTempDir();
outFile.append(fileName);
outFile.createUnique(outFile.NORMAL_FILE_TYPE, 0o600);
var outFile = getTempDir();
outFile.append(fileName);
outFile.createUnique(outFile.NORMAL_FILE_TYPE, 0o600);
var stream = Cc["@mozilla.org/network/file-output-stream;1"]
.createInstance(Ci.nsIFileOutputStream);
stream.init(outFile, 0x02 | 0x08 | 0x20, 0o600, 0);
stream.write("foo", 3);
stream.close();
var stream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(
Ci.nsIFileOutputStream
);
stream.init(outFile, 0x02 | 0x08 | 0x20, 0o600, 0);
stream.write("foo", 3);
stream.close();
Assert.equal(outFile.leafName.substr(0, fileName.length), fileName);
Assert.equal(outFile.leafName.substr(0, fileName.length), fileName);
return outFile;
return outFile;
}
function test_create(fileName) {
var file1 = create_file(fileName);
var file2 = create_file(fileName);
file1.remove(false);
file2.remove(false);
var file1 = create_file(fileName);
var file2 = create_file(fileName);
file1.remove(false);
file2.remove(false);
}
function run_test() {
for (var i = 0; i < nameArray.length; ++i) {
test_create(nameArray[i]);
}
for (var i = 0; i < nameArray.length; ++i) {
test_create(nameArray[i]);
}
}

View file

@ -1,4 +1,4 @@
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
var addedTopic = "xpcom-category-entry-added";
var removedTopic = "xpcom-category-entry-removed";
@ -25,13 +25,18 @@ var observer = {
timer = null;
}
if (subject.QueryInterface(Ci.nsISupportsCString).data != testEntry || data != testCategory)
if (
subject.QueryInterface(Ci.nsISupportsCString).data != testEntry ||
data != testCategory
) {
return;
}
if (topic == addedTopic)
if (topic == addedTopic) {
result += "add ";
else if (topic == removedTopic)
} else if (topic == removedTopic) {
result += "remove ";
}
},
};
@ -41,8 +46,20 @@ function run_test() {
Services.obs.addObserver(observer, addedTopic);
Services.obs.addObserver(observer, removedTopic);
Services.catMan.addCategoryEntry(testCategory, testEntry, testValue, false, true);
Services.catMan.addCategoryEntry(testCategory, testEntry, testValue, false, true);
Services.catMan.addCategoryEntry(
testCategory,
testEntry,
testValue,
false,
true
);
Services.catMan.addCategoryEntry(
testCategory,
testEntry,
testValue,
false,
true
);
Services.catMan.deleteCategoryEntry(testCategory, testEntry, false);
timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);

View file

@ -7,17 +7,21 @@ function run_test() {
// create a test file, then symlink it, then check that we think it's a symlink
var targetFile = testDir.clone();
targetFile.append("target.txt");
if (!targetFile.exists())
if (!targetFile.exists()) {
targetFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o644);
}
var link = testDir.clone();
link.append("link");
if (link.exists())
if (link.exists()) {
link.remove(false);
}
var ln = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
ln.initWithPath("/bin/ln");
var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
var process = Cc["@mozilla.org/process/util;1"].createInstance(
Ci.nsIProcess
);
process.init(ln);
var args = ["-s", targetFile.path, link.path];
process.run(true, args, args.length);

View file

@ -3,8 +3,7 @@
function run_test() {
var nsIFile = Ci.nsIFile;
var root = Cc["@mozilla.org/file/local;1"].
createInstance(nsIFile);
var root = Cc["@mozilla.org/file/local;1"].createInstance(nsIFile);
// copied from http://mxr.mozilla.org/mozilla-central/source/image/test/unit/test_imgtools.js#135
// nsIXULRuntime.OS doesn't seem to be available in xpcshell, so we'll use

View file

@ -2,7 +2,7 @@
* 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/. */
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const manifest = do_get_file("bug725015.manifest");
const contract = "@bug725015.test.contract";
@ -14,8 +14,9 @@ const cid = Components.ID("{05070380-6e6e-42ba-aaa5-3289fc55ca5a}");
function observe_category(subj, topic, data) {
try {
Assert.equal(topic, observerTopic);
if (data != category)
if (data != category) {
return;
}
var thisentry = subj.QueryInterface(Ci.nsISupportsCString).data;
Assert.equal(thisentry, entry);
@ -31,5 +32,7 @@ function observe_category(subj, topic, data) {
function run_test() {
do_test_pending();
Services.obs.addObserver(observe_category, observerTopic);
Components.manager.QueryInterface(Ci.nsIComponentRegistrar).autoRegister(manifest);
Components.manager
.QueryInterface(Ci.nsIComponentRegistrar)
.autoRegister(manifest);
}

View file

@ -1,4 +1,6 @@
const {FileUtils} = ChromeUtils.import("resource://gre/modules/FileUtils.jsm");
const { FileUtils } = ChromeUtils.import(
"resource://gre/modules/FileUtils.jsm"
);
function run_test() {
Assert.ok(FileUtils.File("~").equals(FileUtils.getDir("Home", [])));

View file

@ -3,7 +3,7 @@
* 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/. */
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
function run_test() {
// Generate a leaf name that is 255 characters long.
@ -18,8 +18,12 @@ function run_test() {
tempFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);
do_throw("Creating an item in a folder with a very long name should throw");
} catch (e) {
if (!(e instanceof Ci.nsIException &&
e.result == Cr.NS_ERROR_FILE_UNRECOGNIZED_PATH)) {
if (
!(
e instanceof Ci.nsIException &&
e.result == Cr.NS_ERROR_FILE_UNRECOGNIZED_PATH
)
) {
throw e;
}
// We expect the function not to crash but to raise this exception.

View file

@ -6,7 +6,7 @@
var LocalFile = CC("@mozilla.org/file/local;1", "nsIFile", "initWithPath");
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
function run_test() {
test_normalized_vs_non_normalized();
@ -17,8 +17,9 @@ function test_normalized_vs_non_normalized() {
var tmp1 = Services.dirsvc.get("TmpD", Ci.nsIFile);
var exists = tmp1.exists();
Assert.ok(exists);
if (!exists)
if (!exists) {
return;
}
// the test logic below assumes we're starting with a normalized path, but the
// default location on macos is a symbolic link, so resolve it before starting

View file

@ -3,7 +3,7 @@
* 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/. */
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
function run_test() {
// Create the base directory.

View file

@ -2,7 +2,7 @@ const NS_OS_TEMP_DIR = "TmpD";
const CWD = do_get_cwd();
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
var hiddenUnixFile;
function createUNIXHiddenFile() {
@ -11,15 +11,17 @@ function createUNIXHiddenFile() {
hiddenUnixFile.append(".foo");
// we don't care if this already exists because we don't care
// about the file's contents (just the name)
if (!hiddenUnixFile.exists())
if (!hiddenUnixFile.exists()) {
hiddenUnixFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o666);
}
return hiddenUnixFile.exists();
}
function run_test() {
// Skip this test on Windows
if (mozinfo.os == "win")
if (mozinfo.os == "win") {
return;
}
Assert.ok(createUNIXHiddenFile());
Assert.ok(hiddenUnixFile.isHidden());

View file

@ -1,10 +1,9 @@
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const CWD = do_get_cwd();
function checkOS(os) {
const nsILocalFile_ = "nsILocalFile" + os;
return nsILocalFile_ in Ci &&
CWD instanceof Ci[nsILocalFile_];
return nsILocalFile_ in Ci && CWD instanceof Ci[nsILocalFile_];
}
const isWin = checkOS("Win");
@ -14,7 +13,9 @@ function run_test() {
var homeDir = Services.dirsvc.get("Home", Ci.nsIFile);
var env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
var env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
var expected = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
expected.initWithPath(env.get(envVar));

View file

@ -2,304 +2,466 @@ var testnum = 0;
var factory;
function parserForFile(filename) {
let parser = null;
try {
let file = do_get_file(filename);
Assert.ok(!!file);
parser = factory.createINIParser(file);
Assert.ok(!!parser);
} catch (e) {
dump("INFO | caught error: " + e);
// checkParserOutput will handle a null parser when it's expected.
}
return parser;
let parser = null;
try {
let file = do_get_file(filename);
Assert.ok(!!file);
parser = factory.createINIParser(file);
Assert.ok(!!parser);
} catch (e) {
dump("INFO | caught error: " + e);
// checkParserOutput will handle a null parser when it's expected.
}
return parser;
}
function checkParserOutput(parser, expected) {
// If the expected output is null, we expect the parser to have
// failed (and vice-versa).
if (!parser || !expected) {
Assert.equal(parser, null);
Assert.equal(expected, null);
return;
}
// If the expected output is null, we expect the parser to have
// failed (and vice-versa).
if (!parser || !expected) {
Assert.equal(parser, null);
Assert.equal(expected, null);
return;
}
let output = getParserOutput(parser);
for (let section in expected) {
Assert.ok(section in output);
for (let key in expected[section]) {
Assert.ok(key in output[section]);
Assert.equal(output[section][key], expected[section][key]);
delete output[section][key];
}
for (let key in output[section])
Assert.equal(key, "wasn't expecting this key!");
delete output[section];
let output = getParserOutput(parser);
for (let section in expected) {
Assert.ok(section in output);
for (let key in expected[section]) {
Assert.ok(key in output[section]);
Assert.equal(output[section][key], expected[section][key]);
delete output[section][key];
}
for (let section in output)
Assert.equal(section, "wasn't expecting this section!");
for (let key in output[section]) {
Assert.equal(key, "wasn't expecting this key!");
}
delete output[section];
}
for (let section in output) {
Assert.equal(section, "wasn't expecting this section!");
}
}
function getParserOutput(parser) {
let output = {};
let output = {};
for (let section of parser.getSections()) {
Assert.equal(false, section in output); // catch dupes
output[section] = {};
for (let section of parser.getSections()) {
Assert.equal(false, section in output); // catch dupes
output[section] = {};
for (let key of parser.getKeys(section)) {
Assert.equal(false, key in output[section]); // catch dupes
let value = parser.getString(section, key);
output[section][key] = value;
}
for (let key of parser.getKeys(section)) {
Assert.equal(false, key in output[section]); // catch dupes
let value = parser.getString(section, key);
output[section][key] = value;
}
return output;
}
return output;
}
function run_test() {
try {
var testdata = [
{ filename: "data/iniparser01.ini", reference: {} },
{ filename: "data/iniparser02.ini", reference: {} },
{ filename: "data/iniparser03.ini", reference: {} },
{ filename: "data/iniparser04.ini", reference: {} },
{ filename: "data/iniparser05.ini", reference: {} },
{ filename: "data/iniparser06.ini", reference: {} },
{ filename: "data/iniparser07.ini", reference: {} },
{ filename: "data/iniparser08.ini", reference: { section1: { name1: "" }} },
{ filename: "data/iniparser09.ini", reference: { section1: { name1: "value1" } } },
{ filename: "data/iniparser10.ini", reference: { section1: { name1: "value1" } } },
{ filename: "data/iniparser11.ini", reference: { section1: { name1: "value1" } } },
{ filename: "data/iniparser12.ini", reference: { section1: { name1: "value1" } } },
{ filename: "data/iniparser13.ini", reference: { section1: { name1: "value1" } } },
{ filename: "data/iniparser14.ini", reference:
{ section1: { name1: "value1", name2: "value2" },
section2: { name1: "value1", name2: "foopy" }} },
{ filename: "data/iniparser15.ini", reference:
{ section1: { name1: "newValue1" },
section2: { name1: "foopy" }} },
{ filename: "data/iniparser16.ini", reference:
{ "☺♫": { "♫": "☻", "♪": "♥" },
"☼": { "♣": "♠", "♦": "♥" }} },
{ filename: "data/iniparser17.ini", reference: { section: { key: "" } } },
try {
var testdata = [
{ filename: "data/iniparser01.ini", reference: {} },
{ filename: "data/iniparser02.ini", reference: {} },
{ filename: "data/iniparser03.ini", reference: {} },
{ filename: "data/iniparser04.ini", reference: {} },
{ filename: "data/iniparser05.ini", reference: {} },
{ filename: "data/iniparser06.ini", reference: {} },
{ filename: "data/iniparser07.ini", reference: {} },
{
filename: "data/iniparser08.ini",
reference: { section1: { name1: "" } },
},
{
filename: "data/iniparser09.ini",
reference: { section1: { name1: "value1" } },
},
{
filename: "data/iniparser10.ini",
reference: { section1: { name1: "value1" } },
},
{
filename: "data/iniparser11.ini",
reference: { section1: { name1: "value1" } },
},
{
filename: "data/iniparser12.ini",
reference: { section1: { name1: "value1" } },
},
{
filename: "data/iniparser13.ini",
reference: { section1: { name1: "value1" } },
},
{
filename: "data/iniparser14.ini",
reference: {
section1: { name1: "value1", name2: "value2" },
section2: { name1: "value1", name2: "foopy" },
},
},
{
filename: "data/iniparser15.ini",
reference: {
section1: { name1: "newValue1" },
section2: { name1: "foopy" },
},
},
{
filename: "data/iniparser16.ini",
reference: {
"☺♫": { "♫": "☻", "♪": "♥" },
"☼": { "♣": "♠", "♦": "♥" },
},
},
{ filename: "data/iniparser17.ini", reference: { section: { key: "" } } },
];
testdata.push( { filename: "data/iniparser01-utf8BOM.ini",
reference: testdata[0].reference } );
testdata.push( { filename: "data/iniparser02-utf8BOM.ini",
reference: testdata[1].reference } );
testdata.push( { filename: "data/iniparser03-utf8BOM.ini",
reference: testdata[2].reference } );
testdata.push( { filename: "data/iniparser04-utf8BOM.ini",
reference: testdata[3].reference } );
testdata.push( { filename: "data/iniparser05-utf8BOM.ini",
reference: testdata[4].reference } );
testdata.push( { filename: "data/iniparser06-utf8BOM.ini",
reference: testdata[5].reference } );
testdata.push( { filename: "data/iniparser07-utf8BOM.ini",
reference: testdata[6].reference } );
testdata.push( { filename: "data/iniparser08-utf8BOM.ini",
reference: testdata[7].reference } );
testdata.push( { filename: "data/iniparser09-utf8BOM.ini",
reference: testdata[8].reference } );
testdata.push( { filename: "data/iniparser10-utf8BOM.ini",
reference: testdata[9].reference } );
testdata.push( { filename: "data/iniparser11-utf8BOM.ini",
reference: testdata[10].reference } );
testdata.push( { filename: "data/iniparser12-utf8BOM.ini",
reference: testdata[11].reference } );
testdata.push( { filename: "data/iniparser13-utf8BOM.ini",
reference: testdata[12].reference } );
testdata.push( { filename: "data/iniparser14-utf8BOM.ini",
reference: testdata[13].reference } );
testdata.push( { filename: "data/iniparser15-utf8BOM.ini",
reference: testdata[14].reference } );
testdata.push( { filename: "data/iniparser16-utf8BOM.ini",
reference: testdata[15].reference } );
testdata.push({
filename: "data/iniparser01-utf8BOM.ini",
reference: testdata[0].reference,
});
testdata.push({
filename: "data/iniparser02-utf8BOM.ini",
reference: testdata[1].reference,
});
testdata.push({
filename: "data/iniparser03-utf8BOM.ini",
reference: testdata[2].reference,
});
testdata.push({
filename: "data/iniparser04-utf8BOM.ini",
reference: testdata[3].reference,
});
testdata.push({
filename: "data/iniparser05-utf8BOM.ini",
reference: testdata[4].reference,
});
testdata.push({
filename: "data/iniparser06-utf8BOM.ini",
reference: testdata[5].reference,
});
testdata.push({
filename: "data/iniparser07-utf8BOM.ini",
reference: testdata[6].reference,
});
testdata.push({
filename: "data/iniparser08-utf8BOM.ini",
reference: testdata[7].reference,
});
testdata.push({
filename: "data/iniparser09-utf8BOM.ini",
reference: testdata[8].reference,
});
testdata.push({
filename: "data/iniparser10-utf8BOM.ini",
reference: testdata[9].reference,
});
testdata.push({
filename: "data/iniparser11-utf8BOM.ini",
reference: testdata[10].reference,
});
testdata.push({
filename: "data/iniparser12-utf8BOM.ini",
reference: testdata[11].reference,
});
testdata.push({
filename: "data/iniparser13-utf8BOM.ini",
reference: testdata[12].reference,
});
testdata.push({
filename: "data/iniparser14-utf8BOM.ini",
reference: testdata[13].reference,
});
testdata.push({
filename: "data/iniparser15-utf8BOM.ini",
reference: testdata[14].reference,
});
testdata.push({
filename: "data/iniparser16-utf8BOM.ini",
reference: testdata[15].reference,
});
// Intentional test for appInfo that can't be preloaded.
// eslint-disable-next-line mozilla/use-services
let os = Cc["@mozilla.org/xre/app-info;1"]
.getService(Ci.nsIXULRuntime).OS;
let os = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS;
if ("WINNT" === os) {
testdata.push( { filename: "data/iniparser01-utf16leBOM.ini",
reference: testdata[0].reference } );
testdata.push( { filename: "data/iniparser02-utf16leBOM.ini",
reference: testdata[1].reference } );
testdata.push( { filename: "data/iniparser03-utf16leBOM.ini",
reference: testdata[2].reference } );
testdata.push( { filename: "data/iniparser04-utf16leBOM.ini",
reference: testdata[3].reference } );
testdata.push( { filename: "data/iniparser05-utf16leBOM.ini",
reference: testdata[4].reference } );
testdata.push( { filename: "data/iniparser06-utf16leBOM.ini",
reference: testdata[5].reference } );
testdata.push( { filename: "data/iniparser07-utf16leBOM.ini",
reference: testdata[6].reference } );
testdata.push( { filename: "data/iniparser08-utf16leBOM.ini",
reference: testdata[7].reference } );
testdata.push( { filename: "data/iniparser09-utf16leBOM.ini",
reference: testdata[8].reference } );
testdata.push( { filename: "data/iniparser10-utf16leBOM.ini",
reference: testdata[9].reference } );
testdata.push( { filename: "data/iniparser11-utf16leBOM.ini",
reference: testdata[10].reference } );
testdata.push( { filename: "data/iniparser12-utf16leBOM.ini",
reference: testdata[11].reference } );
testdata.push( { filename: "data/iniparser13-utf16leBOM.ini",
reference: testdata[12].reference } );
testdata.push( { filename: "data/iniparser14-utf16leBOM.ini",
reference: testdata[13].reference } );
testdata.push( { filename: "data/iniparser15-utf16leBOM.ini",
reference: testdata[14].reference } );
testdata.push( { filename: "data/iniparser16-utf16leBOM.ini",
reference: testdata[15].reference } );
testdata.push({
filename: "data/iniparser01-utf16leBOM.ini",
reference: testdata[0].reference,
});
testdata.push({
filename: "data/iniparser02-utf16leBOM.ini",
reference: testdata[1].reference,
});
testdata.push({
filename: "data/iniparser03-utf16leBOM.ini",
reference: testdata[2].reference,
});
testdata.push({
filename: "data/iniparser04-utf16leBOM.ini",
reference: testdata[3].reference,
});
testdata.push({
filename: "data/iniparser05-utf16leBOM.ini",
reference: testdata[4].reference,
});
testdata.push({
filename: "data/iniparser06-utf16leBOM.ini",
reference: testdata[5].reference,
});
testdata.push({
filename: "data/iniparser07-utf16leBOM.ini",
reference: testdata[6].reference,
});
testdata.push({
filename: "data/iniparser08-utf16leBOM.ini",
reference: testdata[7].reference,
});
testdata.push({
filename: "data/iniparser09-utf16leBOM.ini",
reference: testdata[8].reference,
});
testdata.push({
filename: "data/iniparser10-utf16leBOM.ini",
reference: testdata[9].reference,
});
testdata.push({
filename: "data/iniparser11-utf16leBOM.ini",
reference: testdata[10].reference,
});
testdata.push({
filename: "data/iniparser12-utf16leBOM.ini",
reference: testdata[11].reference,
});
testdata.push({
filename: "data/iniparser13-utf16leBOM.ini",
reference: testdata[12].reference,
});
testdata.push({
filename: "data/iniparser14-utf16leBOM.ini",
reference: testdata[13].reference,
});
testdata.push({
filename: "data/iniparser15-utf16leBOM.ini",
reference: testdata[14].reference,
});
testdata.push({
filename: "data/iniparser16-utf16leBOM.ini",
reference: testdata[15].reference,
});
}
/* ========== 0 ========== */
factory = Cc["@mozilla.org/xpcom/ini-parser-factory;1"].
getService(Ci.nsIINIParserFactory);
Assert.ok(!!factory);
/* ========== 0 ========== */
factory = Cc["@mozilla.org/xpcom/ini-parser-factory;1"].getService(
Ci.nsIINIParserFactory
);
Assert.ok(!!factory);
// Test reading from a variety of files. While we're at it, write out each one
// and read it back to ensure that nothing changed.
while (testnum < testdata.length) {
dump("\nINFO | test #" + ++testnum);
let filename = testdata[testnum - 1].filename;
dump(", filename " + filename + "\n");
let parser = parserForFile(filename);
checkParserOutput(parser, testdata[testnum - 1].reference);
if (!parser)
// Test reading from a variety of files. While we're at it, write out each one
// and read it back to ensure that nothing changed.
while (testnum < testdata.length) {
dump("\nINFO | test #" + ++testnum);
let filename = testdata[testnum - 1].filename;
dump(", filename " + filename + "\n");
let parser = parserForFile(filename);
checkParserOutput(parser, testdata[testnum - 1].reference);
if (!parser) {
continue;
}
Assert.ok(parser instanceof Ci.nsIINIParserWriter);
// write contents out to a new file
let newfilename = filename + ".new";
let newfile = do_get_file(filename);
newfile.leafName += ".new";
parser.writeFile(newfile);
// read new file and make sure the contents are the same.
parser = parserForFile(newfilename);
checkParserOutput(parser, testdata[testnum - 1].reference);
// cleanup after the test
newfile.remove(false);
}
dump("INFO | test #" + ++testnum + "\n");
// test writing to a new file.
var newfile = do_get_file("data/");
newfile.append("nonexistent-file.ini");
if (newfile.exists()) {
newfile.remove(false);
}
Assert.ok(!newfile.exists());
try {
var parser = factory.createINIParser(newfile);
Assert.ok(false, "Should have thrown an exception");
} catch (e) {
Assert.equal(
e.result,
Cr.NS_ERROR_FILE_NOT_FOUND,
"Caught a file not found exception"
);
}
parser = factory.createINIParser();
Assert.ok(!!parser);
Assert.ok(parser instanceof Ci.nsIINIParserWriter);
// write contents out to a new file
let newfilename = filename + ".new";
let newfile = do_get_file(filename);
newfile.leafName += ".new";
checkParserOutput(parser, {});
parser.writeFile(newfile);
// read new file and make sure the contents are the same.
parser = parserForFile(newfilename);
checkParserOutput(parser, testdata[testnum - 1].reference);
Assert.ok(newfile.exists());
// test adding a new section and new key
parser.setString("section", "key", "value");
parser.setString("section", "key2", "");
parser.writeFile(newfile);
Assert.ok(newfile.exists());
checkParserOutput(parser, { section: { key: "value", key2: "" } });
// read it in again, check for same data.
parser = parserForFile("data/nonexistent-file.ini");
checkParserOutput(parser, { section: { key: "value", key2: "" } });
// cleanup after the test
newfile.remove(false);
}
dump("INFO | test #" + ++testnum + "\n");
dump("INFO | test #" + ++testnum + "\n");
// test writing to a new file.
var newfile = do_get_file("data/");
newfile.append("nonexistent-file.ini");
if (newfile.exists())
newfile.remove(false);
Assert.ok(!newfile.exists());
// test modifying a existing key's value (in an existing section)
parser = parserForFile("data/iniparser09.ini");
checkParserOutput(parser, { section1: { name1: "value1" } });
try {
var parser = factory.createINIParser(newfile);
Assert.ok(false, "Should have thrown an exception");
} catch (e) {
Assert.equal(e.result, Cr.NS_ERROR_FILE_NOT_FOUND, "Caught a file not found exception");
}
parser = factory.createINIParser();
Assert.ok(!!parser);
Assert.ok(parser instanceof Ci.nsIINIParserWriter);
checkParserOutput(parser, {});
parser.writeFile(newfile);
Assert.ok(newfile.exists());
Assert.ok(parser instanceof Ci.nsIINIParserWriter);
parser.setString("section1", "name1", "value2");
checkParserOutput(parser, { section1: { name1: "value2" } });
// test adding a new section and new key
parser.setString("section", "key", "value");
parser.setString("section", "key2", "");
parser.writeFile(newfile);
Assert.ok(newfile.exists());
checkParserOutput(parser, {section: {key: "value", key2: ""} });
// read it in again, check for same data.
parser = parserForFile("data/nonexistent-file.ini");
checkParserOutput(parser, {section: {key: "value", key2: ""} });
// cleanup after the test
newfile.remove(false);
dump("INFO | test #" + ++testnum + "\n");
dump("INFO | test #" + ++testnum + "\n");
// test trying to set illegal characters
var caughtError;
caughtError = null;
checkParserOutput(parser, { section1: { name1: "value2" } });
// test modifying a existing key's value (in an existing section)
parser = parserForFile("data/iniparser09.ini");
checkParserOutput(parser, {section1: {name1: "value1"} });
// Bad characters in section name
try {
parser.setString("bad\0", "ok", "ok");
} catch (e) {
caughtError = e;
}
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try {
parser.setString("bad\r", "ok", "ok");
} catch (e) {
caughtError = e;
}
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try {
parser.setString("bad\n", "ok", "ok");
} catch (e) {
caughtError = e;
}
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try {
parser.setString("bad[", "ok", "ok");
} catch (e) {
caughtError = e;
}
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try {
parser.setString("bad]", "ok", "ok");
} catch (e) {
caughtError = e;
}
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try {
parser.setString("", "ok", "ok");
} catch (e) {
caughtError = e;
}
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
Assert.ok(parser instanceof Ci.nsIINIParserWriter);
parser.setString("section1", "name1", "value2");
checkParserOutput(parser, {section1: {name1: "value2"} });
// Bad characters in key name
caughtError = null;
try {
parser.setString("ok", "bad\0", "ok");
} catch (e) {
caughtError = e;
}
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try {
parser.setString("ok", "bad\r", "ok");
} catch (e) {
caughtError = e;
}
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try {
parser.setString("ok", "bad\n", "ok");
} catch (e) {
caughtError = e;
}
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try {
parser.setString("ok", "bad=", "ok");
} catch (e) {
caughtError = e;
}
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try {
parser.setString("ok", "", "ok");
} catch (e) {
caughtError = e;
}
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
dump("INFO | test #" + ++testnum + "\n");
// test trying to set illegal characters
var caughtError;
caughtError = null;
checkParserOutput(parser, {section1: {name1: "value2"} });
// Bad characters in section name
try { parser.setString("bad\0", "ok", "ok"); } catch (e) { caughtError = e; }
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try { parser.setString("bad\r", "ok", "ok"); } catch (e) { caughtError = e; }
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try { parser.setString("bad\n", "ok", "ok"); } catch (e) { caughtError = e; }
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try { parser.setString("bad[", "ok", "ok"); } catch (e) { caughtError = e; }
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try { parser.setString("bad]", "ok", "ok"); } catch (e) { caughtError = e; }
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try { parser.setString("", "ok", "ok"); } catch (e) { caughtError = e; }
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
// Bad characters in key name
caughtError = null;
try { parser.setString("ok", "bad\0", "ok"); } catch (e) { caughtError = e; }
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try { parser.setString("ok", "bad\r", "ok"); } catch (e) { caughtError = e; }
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try { parser.setString("ok", "bad\n", "ok"); } catch (e) { caughtError = e; }
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try { parser.setString("ok", "bad=", "ok"); } catch (e) { caughtError = e; }
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try { parser.setString("ok", "", "ok"); } catch (e) { caughtError = e; }
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
// Bad characters in value
caughtError = null;
try { parser.setString("ok", "ok", "bad\0"); } catch (e) { caughtError = e; }
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try { parser.setString("ok", "ok", "bad\r"); } catch (e) { caughtError = e; }
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try { parser.setString("ok", "ok", "bad\n"); } catch (e) { caughtError = e; }
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try { parser.setString("ok", "ok", "good="); } catch (e) { caughtError = e; }
Assert.ok(!caughtError);
caughtError = null;
} catch (e) {
// Bad characters in value
caughtError = null;
try {
parser.setString("ok", "ok", "bad\0");
} catch (e) {
caughtError = e;
}
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try {
parser.setString("ok", "ok", "bad\r");
} catch (e) {
caughtError = e;
}
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try {
parser.setString("ok", "ok", "bad\n");
} catch (e) {
caughtError = e;
}
Assert.ok(caughtError);
Assert.equal(caughtError.result, Cr.NS_ERROR_INVALID_ARG);
caughtError = null;
try {
parser.setString("ok", "ok", "good=");
} catch (e) {
caughtError = e;
}
Assert.ok(!caughtError);
caughtError = null;
} catch (e) {
throw new Error(`FAILED in test #${testnum} -- ${e}`);
}
}
}

View file

@ -6,23 +6,24 @@
const util = Cc["@mozilla.org/io-util;1"].getService(Ci.nsIIOUtil);
function run_test() {
try {
util.inputStreamIsBuffered(null);
do_throw("inputStreamIsBuffered should have thrown");
} catch (e) {
Assert.equal(e.result, Cr.NS_ERROR_INVALID_POINTER);
}
try {
util.inputStreamIsBuffered(null);
do_throw("inputStreamIsBuffered should have thrown");
} catch (e) {
Assert.equal(e.result, Cr.NS_ERROR_INVALID_POINTER);
}
try {
util.outputStreamIsBuffered(null);
do_throw("outputStreamIsBuffered should have thrown");
} catch (e) {
Assert.equal(e.result, Cr.NS_ERROR_INVALID_POINTER);
}
try {
util.outputStreamIsBuffered(null);
do_throw("outputStreamIsBuffered should have thrown");
} catch (e) {
Assert.equal(e.result, Cr.NS_ERROR_INVALID_POINTER);
}
var s = Cc["@mozilla.org/io/string-input-stream;1"]
.createInstance(Ci.nsIStringInputStream);
var body = "This is a test";
s.setData(body, body.length);
Assert.equal(util.inputStreamIsBuffered(s), true);
var s = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(
Ci.nsIStringInputStream
);
var body = "This is a test";
s.setData(body, body.length);
Assert.equal(util.inputStreamIsBuffered(s), true);
}

View file

@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const MAX_TIME_DIFFERENCE = 2500;
const MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
const MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
var LocalFile = CC("@mozilla.org/file/local;1", "nsIFile", "initWithPath");
@ -38,8 +38,7 @@ function test_normalize_crash_if_media_missing() {
for (var i = a; i <= z; ++i) {
try {
LocalFile(String.fromCharCode(i) + ":.\\test").normalize();
} catch (e) {
}
} catch (e) {}
}
}
@ -49,8 +48,9 @@ function test_file_modification_time() {
file.append("testfile");
// Should never happen but get rid of it anyway
if (file.exists())
if (file.exists()) {
file.remove(true);
}
var now = Date.now();
file.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o644);
@ -88,8 +88,9 @@ function test_directory_modification_time() {
dir.append("testdir");
// Should never happen but get rid of it anyway
if (dir.exists())
if (dir.exists()) {
dir.remove(true);
}
var now = Date.now();
dir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
@ -123,8 +124,9 @@ function test_diskSpaceAvailable() {
Assert.ok(bytes > 0);
file.append("testfile");
if (file.exists())
if (file.exists()) {
file.remove(true);
}
file.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o644);
bytes = file.diskSpaceAvailable;

View file

@ -14,8 +14,10 @@ function run_test() {
let method1Called = false;
let testObject = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIScriptableOK,
Ci.nsIScriptableWithNotXPCOM]),
QueryInterface: ChromeUtils.generateQI([
Ci.nsIScriptableOK,
Ci.nsIScriptableWithNotXPCOM,
]),
method1() {
method1Called = true;
@ -58,7 +60,11 @@ function run_test() {
xpcomObject.QueryInterface(Ci.nsIScriptableWithNotXPCOM);
ok(false, "Should not have implemented nsIScriptableWithNotXPCOM");
} catch (e) {
ok(true, "Should not have implemented nsIScriptableWithNotXPCOM. Correctly threw error: " + e);
ok(
true,
"Should not have implemented nsIScriptableWithNotXPCOM. Correctly threw error: " +
e
);
}
strictEqual(xpcomObject.method2, undefined);
}

View file

@ -125,6 +125,7 @@ var tests = [
];
function run_test() {
for (var i = 0; i < tests.length; i++)
for (var i = 0; i < tests.length; i++) {
tests[i]();
}
}

View file

@ -2,21 +2,30 @@
* 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\""];
const TEST_ARGS = [
"mozilla",
"firefox",
"thunderbird",
"seamonkey",
"foo",
"bar",
"argument with spaces",
'"argument with quotes"',
];
const TEST_UNICODE_ARGS = ["M\u00F8z\u00EEll\u00E5",
"\u041C\u043E\u0437\u0438\u043B\u043B\u0430",
"\u09AE\u09CB\u099C\u09BF\u09B2\u09BE",
"\uD808\uDE2C\uD808\uDF63\uD808\uDDB7"];
const TEST_UNICODE_ARGS = [
"M\u00F8z\u00EEll\u00E5",
"\u041C\u043E\u0437\u0438\u043B\u043B\u0430",
"\u09AE\u09CB\u099C\u09BF\u09B2\u09BE",
"\uD808\uDE2C\uD808\uDF63\uD808\uDDB7",
];
// 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);
var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
process.init(file);
Assert.ok(!process.isRunning);
@ -24,7 +33,7 @@ function test_kill() {
try {
process.kill();
do_throw("Attempting to kill a not-running process should throw");
} catch (e) { }
} catch (e) {}
process.run(false, [], 0);
@ -37,7 +46,7 @@ function test_kill() {
try {
process.kill();
do_throw("Attempting to kill a not-running process should throw");
} catch (e) { }
} catch (e) {}
}
// test if we can get an exit value from an application that is
@ -45,8 +54,7 @@ function test_kill() {
function test_quick() {
var file = get_test_program("TestQuickReturn");
var process = Cc["@mozilla.org/process/util;1"]
.createInstance(Ci.nsIProcess);
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
@ -56,14 +64,14 @@ function test_quick() {
}
function test_args(file, args, argsAreASCII) {
var process = Cc["@mozilla.org/process/util;1"]
.createInstance(Ci.nsIProcess);
var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
process.init(file);
if (argsAreASCII)
if (argsAreASCII) {
process.run(true, args, args.length);
else
} else {
process.runw(true, args, args.length);
}
Assert.equal(process.exitValue, 0);
}
@ -95,23 +103,28 @@ function rename_and_test(asciiName, unicodeName, args, argsAreASCII) {
// 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);
rename_and_test(
"TestArguments",
// "Unicode" in Tamil
"\u0BAF\u0BC1\u0BA9\u0BBF\u0B95\u0BCB\u0B9F\u0BCD",
TEST_ARGS,
true
);
rename_and_test("TestUnicodeArguments",
// "Unicode" in Thai
"\u0E22\u0E39\u0E19\u0E34\u0E42\u0E04\u0E14",
TEST_UNICODE_ARGS, false);
rename_and_test(
"TestUnicodeArguments",
// "Unicode" in Thai
"\u0E22\u0E39\u0E19\u0E34\u0E42\u0E04\u0E14",
TEST_UNICODE_ARGS,
false
);
}
// test if we get notified about a blocking process
function test_notify_blocking() {
var file = get_test_program("TestQuickReturn");
var process = Cc["@mozilla.org/process/util;1"]
.createInstance(Ci.nsIProcess);
var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
process.init(file);
process.runAsync([], 0, {
@ -128,8 +141,7 @@ function test_notify_blocking() {
function test_notify_nonblocking() {
var file = get_test_program("TestArguments");
var process = Cc["@mozilla.org/process/util;1"]
.createInstance(Ci.nsIProcess);
var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
process.init(file);
process.runAsync(TEST_ARGS, TEST_ARGS.length, {
@ -146,8 +158,7 @@ function test_notify_nonblocking() {
function test_notify_killed() {
var file = get_test_program("TestBlockingProcess");
var process = Cc["@mozilla.org/process/util;1"]
.createInstance(Ci.nsIProcess);
var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
process.init(file);
process.runAsync([], 0, {

View file

@ -2,19 +2,19 @@ function run_test() {
set_process_running_environment();
var file = get_test_program("TestQuickReturn");
var tm = Cc["@mozilla.org/thread-manager;1"]
.getService();
var tm = Cc["@mozilla.org/thread-manager;1"].getService();
for (var i = 0; i < 1000; i++) {
var process = Cc["@mozilla.org/process/util;1"]
.createInstance(Ci.nsIProcess);
var process = Cc["@mozilla.org/process/util;1"].createInstance(
Ci.nsIProcess
);
process.init(file);
process.run(false, [], 0);
try {
process.kill();
} catch (e) { }
} catch (e) {}
// We need to ensure that we process any events on the main thread -
// this allow threads to clean up properly and avoid out of memory

View file

@ -12,15 +12,17 @@ function run_test() {
}
function test_not_initialized() {
var p = Cc["@mozilla.org/pipe;1"]
.createInstance(Ci.nsIPipe);
var p = Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe);
try {
var dummy = p.outputStream;
dump("dummy: " + dummy + "\n");
throw Cr.NS_ERROR_FAILURE;
} catch (e) {
if (e.result != Cr.NS_ERROR_NOT_INITIALIZED)
do_throw("using a pipe before initializing it should throw NS_ERROR_NOT_INITIALIZED");
if (e.result != Cr.NS_ERROR_NOT_INITIALIZED) {
do_throw(
"using a pipe before initializing it should throw NS_ERROR_NOT_INITIALIZED"
);
}
}
}

View file

@ -1,21 +1,34 @@
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
function run_test() {
Components.manager.autoRegister(do_get_file("data/process_directive.manifest"));
Components.manager.autoRegister(
do_get_file("data/process_directive.manifest")
);
let isChild = Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT;
let isChild =
Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT;
if (isChild) {
Assert.equal(false, "@mozilla.org/xpcom/tests/MainProcessDirectiveTest;1" in Cc);
Assert.equal(
false,
"@mozilla.org/xpcom/tests/MainProcessDirectiveTest;1" in Cc
);
} else {
let svc = Cc["@mozilla.org/xpcom/tests/MainProcessDirectiveTest;1"].createInstance(Ci.nsIProperty);
let svc = Cc[
"@mozilla.org/xpcom/tests/MainProcessDirectiveTest;1"
].createInstance(Ci.nsIProperty);
Assert.equal(svc.name, "main process");
}
if (!isChild) {
Assert.equal(false, "@mozilla.org/xpcom/tests/ChildProcessDirectiveTest;1" in Cc);
Assert.equal(
false,
"@mozilla.org/xpcom/tests/ChildProcessDirectiveTest;1" in Cc
);
} else {
let svc = Cc["@mozilla.org/xpcom/tests/ChildProcessDirectiveTest;1"].createInstance(Ci.nsIProperty);
let svc = Cc[
"@mozilla.org/xpcom/tests/ChildProcessDirectiveTest;1"
].createInstance(Ci.nsIProperty);
Assert.equal(svc.name, "child process");
}
}

View file

@ -8,21 +8,25 @@ const data = "0123456789";
const count = 10;
function test_multiplex_streams() {
var MultiplexStream = CC("@mozilla.org/io/multiplex-input-stream;1",
"nsIMultiplexInputStream");
var MultiplexStream = CC(
"@mozilla.org/io/multiplex-input-stream;1",
"nsIMultiplexInputStream"
);
Assert.equal(1, 1);
var multiplex = new MultiplexStream();
for (var i = 0; i < count; ++i) {
let s = Cc["@mozilla.org/io/string-input-stream;1"]
.createInstance(Ci.nsIStringInputStream);
let s = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(
Ci.nsIStringInputStream
);
s.setData(data, data.length);
multiplex.appendStream(s);
}
var seekable = multiplex.QueryInterface(Ci.nsISeekableStream);
var sis = Cc["@mozilla.org/scriptableinputstream;1"]
.createInstance(Ci.nsIScriptableInputStream);
var sis = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
Ci.nsIScriptableInputStream
);
sis.init(seekable);
// Read some data.
var readData = sis.read(20);
@ -125,20 +129,24 @@ function test_multiplex_streams() {
function test_multiplex_bug797871() {
var data2 = "1234567890123456789012345678901234567890";
var MultiplexStream = CC("@mozilla.org/io/multiplex-input-stream;1",
"nsIMultiplexInputStream");
var MultiplexStream = CC(
"@mozilla.org/io/multiplex-input-stream;1",
"nsIMultiplexInputStream"
);
Assert.equal(1, 1);
var multiplex = new MultiplexStream();
let s = Cc["@mozilla.org/io/string-input-stream;1"]
.createInstance(Ci.nsIStringInputStream);
let s = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(
Ci.nsIStringInputStream
);
s.setData(data2, data2.length);
multiplex.appendStream(s);
var seekable = multiplex.QueryInterface(Ci.nsISeekableStream);
var sis = Cc["@mozilla.org/scriptableinputstream;1"]
.createInstance(Ci.nsIScriptableInputStream);
var sis = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
Ci.nsIScriptableInputStream
);
sis.init(seekable);
seekable.seek(Ci.nsISeekableStream.NS_SEEK_SET, 8);

View file

@ -18,8 +18,9 @@ function run_test() {
* anything written to it throws a not-initialized exception.
*/
function test1() {
var ss = Cc["@mozilla.org/storagestream;1"]
.createInstance(Ci.nsIStorageStream);
var ss = Cc["@mozilla.org/storagestream;1"].createInstance(
Ci.nsIStorageStream
);
ss.init(1024, 1024, null);
var unusedVariable = ss.getOutputStream(0);
@ -27,9 +28,9 @@ function test1() {
Assert.equal(inp2.available(), 0);
Assert.ok(inp2.isNonBlocking());
var sis =
Cc["@mozilla.org/scriptableinputstream;1"]
.createInstance(Ci.nsIScriptableInputStream);
var sis = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
Ci.nsIScriptableInputStream
);
sis.init(inp2);
var threw = false;
@ -50,8 +51,9 @@ function test1() {
* data have been explicitly written doesn't throw an exception.
*/
function test2() {
var ss = Cc["@mozilla.org/storagestream;1"]
.createInstance(Ci.nsIStorageStream);
var ss = Cc["@mozilla.org/storagestream;1"].createInstance(
Ci.nsIStorageStream
);
ss.init(1024, 1024, null);
var out = ss.getOutputStream(0);
@ -68,8 +70,9 @@ function test2() {
* which has had 0 bytes written to it explicitly works correctly.
*/
function test3() {
var ss = Cc["@mozilla.org/storagestream;1"]
.createInstance(Ci.nsIStorageStream);
var ss = Cc["@mozilla.org/storagestream;1"].createInstance(
Ci.nsIStorageStream
);
ss.init(1024, 1024, null);
var out = ss.getOutputStream(0);
@ -87,12 +90,12 @@ function test3() {
var bis = BIS(inp);
bis.readByteArray(5);
} catch (e) {
if (e.result != Cr.NS_BASE_STREAM_WOULD_BLOCK)
if (e.result != Cr.NS_BASE_STREAM_WOULD_BLOCK) {
do_throw("wrong error thrown: " + e);
}
threw = true;
}
Assert.ok(threw,
"should have thrown (nsStorageInputStream is nonblocking)");
Assert.ok(threw, "should have thrown (nsStorageInputStream is nonblocking)");
}
/**
@ -102,14 +105,16 @@ function test3() {
function test4() {
var bytes = [65, 66, 67, 68, 69, 70, 71, 72, 73, 74];
var ss = Cc["@mozilla.org/storagestream;1"]
.createInstance(Ci.nsIStorageStream);
var ss = Cc["@mozilla.org/storagestream;1"].createInstance(
Ci.nsIStorageStream
);
ss.init(1024, 1024, null);
var outStream = ss.getOutputStream(0);
var bos = Cc["@mozilla.org/binaryoutputstream;1"]
.createInstance(Ci.nsIBinaryOutputStream);
var bos = Cc["@mozilla.org/binaryoutputstream;1"].createInstance(
Ci.nsIBinaryOutputStream
);
bos.setOutputStream(outStream);
bos.writeByteArray(bytes, bytes.length);
@ -128,18 +133,20 @@ function test4() {
try {
data = bis.read8(1);
} catch (e) {
if (e.result != Cr.NS_ERROR_FAILURE)
if (e.result != Cr.NS_ERROR_FAILURE) {
do_throw("wrong error thrown: " + e);
}
threw = true;
}
if (!threw)
if (!threw) {
do_throw("should have thrown but instead returned: '" + data + "'");
}
}
function BIS(input) {
var bis = Cc["@mozilla.org/binaryinputstream;1"]
.createInstance(Ci.nsIBinaryInputStream);
var bis = Cc["@mozilla.org/binaryinputstream;1"].createInstance(
Ci.nsIBinaryInputStream
);
bis.setInputStream(input);
return bis;
}

View file

@ -2,15 +2,17 @@
* 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/. */
var Pipe = CC("@mozilla.org/pipe;1",
"nsIPipe",
"init");
var BinaryOutput = CC("@mozilla.org/binaryoutputstream;1",
"nsIBinaryOutputStream",
"setOutputStream");
var BinaryInput = CC("@mozilla.org/binaryinputstream;1",
"nsIBinaryInputStream",
"setInputStream");
var Pipe = CC("@mozilla.org/pipe;1", "nsIPipe", "init");
var BinaryOutput = CC(
"@mozilla.org/binaryoutputstream;1",
"nsIBinaryOutputStream",
"setOutputStream"
);
var BinaryInput = CC(
"@mozilla.org/binaryinputstream;1",
"nsIBinaryInputStream",
"setInputStream"
);
/**
* Binary stream tests.
@ -25,7 +27,9 @@ function test_binary_streams() {
const LargeNum = Math.pow(2, 18) + Math.pow(2, 12) + 1;
const HugeNum = Math.pow(2, 62);
const HelloStr = "Hello World";
const HelloArray = Array.from(HelloStr, function(c) { return c.charCodeAt(0); });
const HelloArray = Array.from(HelloStr, function(c) {
return c.charCodeAt(0);
});
var countObj = {};
var msg = {};
var buffer = new ArrayBuffer(HelloArray.length);
@ -51,8 +55,8 @@ function test_binary_streams() {
Assert.equal(is.read64(), HugeNum);
os.writeFloat(2.5);
Assert.equal(is.readFloat(), 2.5);
// os.writeDouble(Math.SQRT2);
// do_check_eq(is.readDouble(), Math.SQRT2);
// os.writeDouble(Math.SQRT2);
// do_check_eq(is.readDouble(), Math.SQRT2);
os.writeStringZ("Mozilla");
Assert.equal(is.readCString(), "Mozilla");
os.writeWStringZ("Gecko");
@ -70,8 +74,11 @@ function test_binary_streams() {
Assert.equal(msg.toSource(), HelloArray.toSource());
Assert.equal(is.available(), 0);
os.writeByteArray(HelloArray, HelloArray.length);
Assert.equal(is.readArrayBuffer(buffer.byteLength, buffer), HelloArray.length);
Assert.equal([...(new Uint8Array(buffer))].toSource(), HelloArray.toSource());
Assert.equal(
is.readArrayBuffer(buffer.byteLength, buffer),
HelloArray.length
);
Assert.equal([...new Uint8Array(buffer)].toSource(), HelloArray.toSource());
Assert.equal(is.available(), 0);
// Test writing in one big chunk.
@ -85,7 +92,7 @@ function test_binary_streams() {
os.write64(1024);
os.write64(HugeNum);
os.writeFloat(2.5);
// os.writeDouble(Math.SQRT2);
// os.writeDouble(Math.SQRT2);
os.writeStringZ("Mozilla");
os.writeWStringZ("Gecko");
os.writeBytes(HelloStr, HelloStr.length);
@ -104,7 +111,7 @@ function test_binary_streams() {
Assert.equal(is.read64(), 1024);
Assert.equal(is.read64(), HugeNum);
Assert.equal(is.readFloat(), 2.5);
// do_check_eq(is.readDouble(), Math.SQRT2);
// do_check_eq(is.readDouble(), Math.SQRT2);
Assert.equal(is.readCString(), "Mozilla");
Assert.equal(is.readString(), "Gecko");
// Remember, we wrote HelloStr twice - once as a string, and then as an array.
@ -127,8 +134,9 @@ function test_binary_streams() {
os.writeBoolean(false);
do_throw("Not reached!");
} catch (e) {
if (!(e instanceof Ci.nsIException &&
e.result == Cr.NS_BASE_STREAM_CLOSED)) {
if (
!(e instanceof Ci.nsIException && e.result == Cr.NS_BASE_STREAM_CLOSED)
) {
throw e;
}
// do nothing
@ -138,8 +146,9 @@ function test_binary_streams() {
is.available();
do_throw("Not reached!");
} catch (e) {
if (!(e instanceof Ci.nsIException &&
e.result == Cr.NS_BASE_STREAM_CLOSED)) {
if (
!(e instanceof Ci.nsIException && e.result == Cr.NS_BASE_STREAM_CLOSED)
) {
throw e;
}
// do nothing
@ -149,8 +158,7 @@ function test_binary_streams() {
is.readBoolean();
do_throw("Not reached!");
} catch (e) {
if (!(e instanceof Ci.nsIException &&
e.result == Cr.NS_ERROR_FAILURE)) {
if (!(e instanceof Ci.nsIException && e.result == Cr.NS_ERROR_FAILURE)) {
throw e;
}
// do nothing

View file

@ -4,15 +4,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function run_test() {
var s = Cc["@mozilla.org/io/string-input-stream;1"]
.createInstance(Ci.nsIStringInputStream);
var body = "This is a test";
s.setData(body, body.length);
Assert.equal(s.available(), body.length);
var s = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(
Ci.nsIStringInputStream
);
var body = "This is a test";
s.setData(body, body.length);
Assert.equal(s.available(), body.length);
var sis = Cc["@mozilla.org/scriptableinputstream;1"]
.createInstance(Ci.nsIScriptableInputStream);
sis.init(s);
var sis = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
Ci.nsIScriptableInputStream
);
sis.init(s);
Assert.equal(sis.read(body.length), body);
Assert.equal(sis.read(body.length), body);
}

View file

@ -1,27 +1,25 @@
const CWD = do_get_cwd();
const DIR_TARGET = "target";
const DIR_LINK = "link";
const DIR_LINK_LINK = "link_link";
const FILE_TARGET = "target.txt";
const FILE_LINK = "link.txt";
const DIR_TARGET = "target";
const DIR_LINK = "link";
const DIR_LINK_LINK = "link_link";
const FILE_TARGET = "target.txt";
const FILE_LINK = "link.txt";
const FILE_LINK_LINK = "link_link.txt";
const DOES_NOT_EXIST = "doesnotexist";
const DANGLING_LINK = "dangling_link";
const LOOP_LINK = "loop_link";
const DANGLING_LINK = "dangling_link";
const LOOP_LINK = "loop_link";
const nsIFile = Ci.nsIFile;
var process;
function createSymLink(from, to) {
if (!process) {
var ln = Cc["@mozilla.org/file/local;1"]
.createInstance(Ci.nsIFile);
var ln = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
ln.initWithPath("/bin/ln");
process = Cc["@mozilla.org/process/util;1"]
.createInstance(Ci.nsIProcess);
process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
process.init(ln);
}
@ -81,7 +79,7 @@ function setupTestDir(testDir, relative) {
var loop = testDir.clone();
loop.append(LOOP_LINK);
var dirLink = makeSymLink(targetDir, DIR_LINK, relative);
var dirLink = makeSymLink(targetDir, DIR_LINK, relative);
var fileLink = makeSymLink(targetFile, FILE_LINK, relative);
makeSymLink(dirLink, DIR_LINK_LINK, relative);
@ -92,36 +90,43 @@ function setupTestDir(testDir, relative) {
try {
makeSymLink(loop, LOOP_LINK, relative);
Assert.ok(false);
} catch (e) {
}
} catch (e) {}
}
function createSpaces(dirs, files, links) {
function longest(a, b) {
return a.length > b.length ? a : b;
}
return dirs.concat(files, links).reduce(longest, "").replace(/./g, " ");
return dirs
.concat(files, links)
.reduce(longest, "")
.replace(/./g, " ");
}
function testSymLinks(testDir, relative) {
setupTestDir(testDir, relative);
const dirLinks = [DIR_LINK, DIR_LINK_LINK];
const fileLinks = [FILE_LINK, FILE_LINK_LINK];
const dirLinks = [DIR_LINK, DIR_LINK_LINK];
const fileLinks = [FILE_LINK, FILE_LINK_LINK];
const otherLinks = [DANGLING_LINK, LOOP_LINK];
const dirs = [DIR_TARGET].concat(dirLinks);
const dirs = [DIR_TARGET].concat(dirLinks);
const files = [FILE_TARGET].concat(fileLinks);
const links = otherLinks.concat(dirLinks, fileLinks);
const spaces = createSpaces(dirs, files, links);
const bools = {false: " false", true: " true "};
const bools = { false: " false", true: " true " };
print(spaces + " dir file symlink");
var dirEntries = testDir.directoryEntries;
while (dirEntries.hasMoreElements()) {
const file = dirEntries.nextFile;
const name = file.leafName;
print(name + spaces.substring(name.length) + bools[file.isDirectory()] +
bools[file.isFile()] + bools[file.isSymlink()]);
print(
name +
spaces.substring(name.length) +
bools[file.isDirectory()] +
bools[file.isFile()] +
bools[file.isSymlink()]
);
Assert.equal(file.isDirectory(), dirs.includes(name));
Assert.equal(file.isFile(), files.includes(name));
Assert.equal(file.isSymlink(), links.includes(name));
@ -130,8 +135,9 @@ function testSymLinks(testDir, relative) {
function run_test() {
// Skip this test on Windows
if (mozinfo.os == "win")
if (mozinfo.os == "win") {
return;
}
var testDir = CWD;
testDir.append("test_symlinks");

View file

@ -3,10 +3,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function run_test() {
const PROPERTIES = ["name", "arch", "version", "pagesize",
"pageshift", "memmapalign", "cpucount", "memsize"];
let sysInfo = Cc["@mozilla.org/system-info;1"].
getService(Ci.nsIPropertyBag2);
const PROPERTIES = [
"name",
"arch",
"version",
"pagesize",
"pageshift",
"memmapalign",
"cpucount",
"memsize",
];
let sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2);
PROPERTIES.forEach(function(aPropertyName) {
print("Testing property: " + aPropertyName);

View file

@ -1,10 +1,10 @@
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
// Versions to test listed in ascending order, none can be equal
var comparisons = [
"pre",
// A number that is too large to be supported should be normalized to 0.
String(0x1F0000000),
String(0x1f0000000),
"0.9",
"0.9.1",
"1.0pre1",
@ -27,22 +27,20 @@ var comparisons = [
];
// Every version in this list means the same version number
var equality = [
"1.1pre",
"1.1pre0",
"1.0+",
];
var equality = ["1.1pre", "1.1pre0", "1.0+"];
function run_test() {
for (var i = 0; i < comparisons.length; i++) {
for (var j = 0; j < comparisons.length; j++) {
var result = Services.vc.compare(comparisons[i], comparisons[j]);
if (i == j) {
if (result != 0)
if (result != 0) {
do_throw(comparisons[i] + " should be the same as itself");
}
} else if (i < j) {
if (!(result < 0))
if (!(result < 0)) {
do_throw(comparisons[i] + " should be less than " + comparisons[j]);
}
} else if (!(result > 0)) {
do_throw(comparisons[i] + " should be greater than " + comparisons[j]);
}
@ -51,8 +49,9 @@ function run_test() {
for (i = 0; i < equality.length; i++) {
for (j = 0; j < equality.length; j++) {
if (Services.vc.compare(equality[i], equality[j]) != 0)
if (Services.vc.compare(equality[i], equality[j]) != 0) {
do_throw(equality[i] + " should equal " + equality[j]);
}
}
}
}

View file

@ -1,4 +1,4 @@
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
let executableFile = Services.dirsvc.get("CurProcD", Ci.nsIFile);
executableFile.append("xpcshell.exe");
@ -9,7 +9,11 @@ function run_test() {
info(`Testing with ${cmdline}`);
let f = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFileWin);
f.initWithCommandLine(cmdline);
Assert.equal(f.path, executableFile.path, "Should be able to recover executable path");
Assert.equal(
f.path,
executableFile.path,
"Should be able to recover executable path"
);
}
let f = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFileWin);

View file

@ -9,183 +9,218 @@ const nsIWindowsRegKey = Ci.nsIWindowsRegKey;
let regKeyComponent = Cc["@mozilla.org/windows-registry-key;1"];
function run_test() {
//* create a key structure in a spot that's normally writable (somewhere under HKCU).
let testKey = regKeyComponent.createInstance(nsIWindowsRegKey);
//* create a key structure in a spot that's normally writable (somewhere under HKCU).
let testKey = regKeyComponent.createInstance(nsIWindowsRegKey);
// If it's already present because a previous test crashed or didn't clean up properly, clean it up first.
let keyName = BASE_PATH + "\\" + TESTDATA_KEYNAME;
setup_test_run(testKey, keyName);
// If it's already present because a previous test crashed or didn't clean up properly, clean it up first.
let keyName = BASE_PATH + "\\" + TESTDATA_KEYNAME;
setup_test_run(testKey, keyName);
//* test that the write* functions write stuff
test_writing_functions(testKey);
//* test that the write* functions write stuff
test_writing_functions(testKey);
//* check that the valueCount/getValueName functions work for the values we just wrote
test_value_functions(testKey);
//* check that the valueCount/getValueName functions work for the values we just wrote
test_value_functions(testKey);
//* check that the get* functions work for the values we just wrote.
test_reading_functions(testKey);
//* check that the get* functions work for the values we just wrote.
test_reading_functions(testKey);
//* check that the get* functions fail with the right exception codes if we ask for the wrong type or if the value name doesn't exist at all
test_invalidread_functions(testKey);
//* check that the get* functions fail with the right exception codes if we ask for the wrong type or if the value name doesn't exist at all
test_invalidread_functions(testKey);
//* check that creating/enumerating/deleting child keys works
test_childkey_functions(testKey);
//* check that creating/enumerating/deleting child keys works
test_childkey_functions(testKey);
test_watching_functions(testKey);
test_watching_functions(testKey);
//* clean up
cleanup_test_run(testKey, keyName);
//* clean up
cleanup_test_run(testKey, keyName);
}
function setup_test_run(testKey, keyName) {
info("Setup test run");
try {
testKey.open(nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, keyName, nsIWindowsRegKey.ACCESS_READ);
info("Test key exists. Needs cleanup.");
cleanup_test_run(testKey, keyName);
} catch (e) {
if (!(e instanceof Ci.nsIException && e.result == Cr.NS_ERROR_FAILURE)) {
throw e;
}
info("Setup test run");
try {
testKey.open(
nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
keyName,
nsIWindowsRegKey.ACCESS_READ
);
info("Test key exists. Needs cleanup.");
cleanup_test_run(testKey, keyName);
} catch (e) {
if (!(e instanceof Ci.nsIException && e.result == Cr.NS_ERROR_FAILURE)) {
throw e;
}
}
testKey.create(nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, keyName, nsIWindowsRegKey.ACCESS_ALL);
testKey.create(
nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
keyName,
nsIWindowsRegKey.ACCESS_ALL
);
}
function test_writing_functions(testKey) {
strictEqual(testKey.valueCount, 0);
strictEqual(testKey.valueCount, 0);
strictEqual(testKey.hasValue(TESTDATA_STRNAME), false);
testKey.writeStringValue(TESTDATA_STRNAME, TESTDATA_STRVALUE);
strictEqual(testKey.hasValue(TESTDATA_STRNAME), true);
strictEqual(testKey.hasValue(TESTDATA_STRNAME), false);
testKey.writeStringValue(TESTDATA_STRNAME, TESTDATA_STRVALUE);
strictEqual(testKey.hasValue(TESTDATA_STRNAME), true);
strictEqual(testKey.hasValue(TESTDATA_INTNAME), false);
testKey.writeIntValue(TESTDATA_INTNAME, TESTDATA_INTVALUE);
strictEqual(testKey.hasValue(TESTDATA_INTNAME), false);
testKey.writeIntValue(TESTDATA_INTNAME, TESTDATA_INTVALUE);
strictEqual(testKey.hasValue(TESTDATA_INT64NAME), false);
testKey.writeInt64Value(TESTDATA_INT64NAME, TESTDATA_INT64VALUE);
strictEqual(testKey.hasValue(TESTDATA_INT64NAME), false);
testKey.writeInt64Value(TESTDATA_INT64NAME, TESTDATA_INT64VALUE);
strictEqual(testKey.hasValue(TESTDATA_BINARYNAME), false);
testKey.writeBinaryValue(TESTDATA_BINARYNAME, TESTDATA_BINARYVALUE);
strictEqual(testKey.hasValue(TESTDATA_BINARYNAME), false);
testKey.writeBinaryValue(TESTDATA_BINARYNAME, TESTDATA_BINARYVALUE);
}
function test_value_functions(testKey) {
strictEqual(testKey.valueCount, 4);
strictEqual(testKey.getValueName(0), TESTDATA_STRNAME);
strictEqual(testKey.getValueName(1), TESTDATA_INTNAME);
strictEqual(testKey.getValueName(2), TESTDATA_INT64NAME);
strictEqual(testKey.getValueName(3), TESTDATA_BINARYNAME);
strictEqual(testKey.valueCount, 4);
strictEqual(testKey.getValueName(0), TESTDATA_STRNAME);
strictEqual(testKey.getValueName(1), TESTDATA_INTNAME);
strictEqual(testKey.getValueName(2), TESTDATA_INT64NAME);
strictEqual(testKey.getValueName(3), TESTDATA_BINARYNAME);
}
function test_reading_functions(testKey) {
strictEqual(testKey.getValueType(TESTDATA_STRNAME), nsIWindowsRegKey.TYPE_STRING);
strictEqual(testKey.readStringValue(TESTDATA_STRNAME), TESTDATA_STRVALUE);
strictEqual(
testKey.getValueType(TESTDATA_STRNAME),
nsIWindowsRegKey.TYPE_STRING
);
strictEqual(testKey.readStringValue(TESTDATA_STRNAME), TESTDATA_STRVALUE);
strictEqual(testKey.getValueType(TESTDATA_INTNAME), nsIWindowsRegKey.TYPE_INT);
strictEqual(testKey.readIntValue(TESTDATA_INTNAME), TESTDATA_INTVALUE);
strictEqual(
testKey.getValueType(TESTDATA_INTNAME),
nsIWindowsRegKey.TYPE_INT
);
strictEqual(testKey.readIntValue(TESTDATA_INTNAME), TESTDATA_INTVALUE);
strictEqual(testKey.getValueType(TESTDATA_INT64NAME), nsIWindowsRegKey.TYPE_INT64);
strictEqual( testKey.readInt64Value(TESTDATA_INT64NAME), TESTDATA_INT64VALUE);
strictEqual(
testKey.getValueType(TESTDATA_INT64NAME),
nsIWindowsRegKey.TYPE_INT64
);
strictEqual(testKey.readInt64Value(TESTDATA_INT64NAME), TESTDATA_INT64VALUE);
strictEqual(testKey.getValueType(TESTDATA_BINARYNAME), nsIWindowsRegKey.TYPE_BINARY);
strictEqual( testKey.readBinaryValue(TESTDATA_BINARYNAME), TESTDATA_BINARYVALUE);
strictEqual(
testKey.getValueType(TESTDATA_BINARYNAME),
nsIWindowsRegKey.TYPE_BINARY
);
strictEqual(
testKey.readBinaryValue(TESTDATA_BINARYNAME),
TESTDATA_BINARYVALUE
);
}
function test_invalidread_functions(testKey) {
try {
testKey.readIntValue(TESTDATA_STRNAME);
do_throw("Reading an integer from a string registry value should throw.");
} catch (e) {
if (!(e instanceof Ci.nsIException && e.result == Cr.NS_ERROR_FAILURE)) {
throw e;
}
try {
testKey.readIntValue(TESTDATA_STRNAME);
do_throw("Reading an integer from a string registry value should throw.");
} catch (e) {
if (!(e instanceof Ci.nsIException && e.result == Cr.NS_ERROR_FAILURE)) {
throw e;
}
}
try {
let val = testKey.readStringValue(TESTDATA_INTNAME);
do_throw("Reading an string from an Int registry value should throw." + val);
} catch (e) {
if (!(e instanceof Ci.nsIException && e.result == Cr.NS_ERROR_FAILURE)) {
throw e;
}
try {
let val = testKey.readStringValue(TESTDATA_INTNAME);
do_throw(
"Reading an string from an Int registry value should throw." + val
);
} catch (e) {
if (!(e instanceof Ci.nsIException && e.result == Cr.NS_ERROR_FAILURE)) {
throw e;
}
}
try {
testKey.readStringValue(TESTDATA_INT64NAME);
do_throw("Reading an string from an Int64 registry value should throw.");
} catch (e) {
if (!(e instanceof Ci.nsIException && e.result == Cr.NS_ERROR_FAILURE)) {
throw e;
}
try {
testKey.readStringValue(TESTDATA_INT64NAME);
do_throw("Reading an string from an Int64 registry value should throw.");
} catch (e) {
if (!(e instanceof Ci.nsIException && e.result == Cr.NS_ERROR_FAILURE)) {
throw e;
}
}
try {
testKey.readStringValue(TESTDATA_BINARYNAME);
do_throw("Reading a string from an Binary registry value should throw.");
} catch (e) {
if (!(e instanceof Ci.nsIException && e.result == Cr.NS_ERROR_FAILURE)) {
throw e;
}
try {
testKey.readStringValue(TESTDATA_BINARYNAME);
do_throw("Reading a string from an Binary registry value should throw.");
} catch (e) {
if (!(e instanceof Ci.nsIException && e.result == Cr.NS_ERROR_FAILURE)) {
throw e;
}
}
}
function test_childkey_functions(testKey) {
strictEqual(testKey.childCount, 0);
strictEqual(testKey.hasChild(TESTDATA_CHILD_KEY), false);
strictEqual(testKey.childCount, 0);
strictEqual(testKey.hasChild(TESTDATA_CHILD_KEY), false);
let childKey = testKey.createChild(TESTDATA_CHILD_KEY, nsIWindowsRegKey.ACCESS_ALL);
childKey.close();
let childKey = testKey.createChild(
TESTDATA_CHILD_KEY,
nsIWindowsRegKey.ACCESS_ALL
);
childKey.close();
strictEqual(testKey.childCount, 1);
strictEqual(testKey.hasChild(TESTDATA_CHILD_KEY), true);
strictEqual(testKey.getChildName(0), TESTDATA_CHILD_KEY);
strictEqual(testKey.childCount, 1);
strictEqual(testKey.hasChild(TESTDATA_CHILD_KEY), true);
strictEqual(testKey.getChildName(0), TESTDATA_CHILD_KEY);
childKey = testKey.openChild(TESTDATA_CHILD_KEY, nsIWindowsRegKey.ACCESS_ALL);
testKey.removeChild(TESTDATA_CHILD_KEY);
strictEqual(testKey.childCount, 0);
strictEqual(testKey.hasChild(TESTDATA_CHILD_KEY), false);
childKey = testKey.openChild(TESTDATA_CHILD_KEY, nsIWindowsRegKey.ACCESS_ALL);
testKey.removeChild(TESTDATA_CHILD_KEY);
strictEqual(testKey.childCount, 0);
strictEqual(testKey.hasChild(TESTDATA_CHILD_KEY), false);
}
function test_watching_functions(testKey) {
strictEqual(testKey.isWatching(), false);
strictEqual(testKey.hasChanged(), false);
strictEqual(testKey.isWatching(), false);
strictEqual(testKey.hasChanged(), false);
testKey.startWatching(true);
strictEqual(testKey.isWatching(), true);
testKey.startWatching(true);
strictEqual(testKey.isWatching(), true);
testKey.stopWatching();
strictEqual(testKey.isWatching(), false);
testKey.stopWatching();
strictEqual(testKey.isWatching(), false);
// Create a child key, and update a value
let childKey = testKey.createChild(TESTDATA_CHILD_KEY, nsIWindowsRegKey.ACCESS_ALL);
childKey.writeIntValue(TESTDATA_INTNAME, TESTDATA_INTVALUE);
// Create a child key, and update a value
let childKey = testKey.createChild(
TESTDATA_CHILD_KEY,
nsIWindowsRegKey.ACCESS_ALL
);
childKey.writeIntValue(TESTDATA_INTNAME, TESTDATA_INTVALUE);
// Start a recursive watch, and update the child's value
testKey.startWatching(true);
strictEqual(testKey.isWatching(), true);
// Start a recursive watch, and update the child's value
testKey.startWatching(true);
strictEqual(testKey.isWatching(), true);
childKey.writeIntValue(TESTDATA_INTNAME, 0);
strictEqual(testKey.hasChanged(), true);
testKey.stopWatching();
strictEqual(testKey.isWatching(), false);
childKey.writeIntValue(TESTDATA_INTNAME, 0);
strictEqual(testKey.hasChanged(), true);
testKey.stopWatching();
strictEqual(testKey.isWatching(), false);
childKey.removeValue(TESTDATA_INTNAME);
childKey.close();
testKey.removeChild(TESTDATA_CHILD_KEY);
childKey.removeValue(TESTDATA_INTNAME);
childKey.close();
testKey.removeChild(TESTDATA_CHILD_KEY);
}
function cleanup_test_run(testKey, keyName) {
info("Cleaning up test.");
info("Cleaning up test.");
for (var i = 0; i < testKey.childCount; i++) {
testKey.removeChild(testKey.getChildName(i));
}
testKey.close();
for (var i = 0; i < testKey.childCount; i++) {
testKey.removeChild(testKey.getChildName(i));
}
testKey.close();
let baseKey = regKeyComponent.createInstance(nsIWindowsRegKey);
baseKey.open(nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, BASE_PATH, nsIWindowsRegKey.ACCESS_ALL);
baseKey.removeChild(TESTDATA_KEYNAME);
baseKey.close();
let baseKey = regKeyComponent.createInstance(nsIWindowsRegKey);
baseKey.open(
nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
BASE_PATH,
nsIWindowsRegKey.ACCESS_ALL
);
baseKey.removeChild(TESTDATA_KEYNAME);
baseKey.close();
}
// Test data used above.