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

@ -59,6 +59,5 @@ function run_test() {
try {
properties2.load(inp);
do_throw("load() didn't fail");
} catch (e) {
}
} catch (e) {}
}

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,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

@ -19,8 +19,9 @@ function create_file(fileName) {
outFile.append(fileName);
outFile.createUnique(outFile.NORMAL_FILE_TYPE, 0o600);
var stream = Cc["@mozilla.org/network/file-output-stream;1"]
.createInstance(Ci.nsIFileOutputStream);
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();

View file

@ -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

@ -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

@ -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

@ -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

@ -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

@ -3,8 +3,7 @@ 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

@ -32,13 +32,15 @@ function checkParserOutput(parser, expected) {
Assert.equal(output[section][key], expected[section][key]);
delete output[section][key];
}
for (let key in output[section])
for (let key in output[section]) {
Assert.equal(key, "wasn't expecting this key!");
}
delete output[section];
}
for (let section in output)
for (let section in output) {
Assert.equal(section, "wasn't expecting this section!");
}
}
function getParserOutput(parser) {
let output = {};
@ -66,99 +68,193 @@ var testdata = [
{ 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/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);
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
@ -169,8 +265,9 @@ while (testnum < testdata.length) {
dump(", filename " + filename + "\n");
let parser = parserForFile(filename);
checkParserOutput(parser, testdata[testnum - 1].reference);
if (!parser)
if (!parser) {
continue;
}
Assert.ok(parser instanceof Ci.nsIINIParserWriter);
// write contents out to a new file
let newfilename = filename + ".new";
@ -189,15 +286,20 @@ 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())
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");
Assert.equal(
e.result,
Cr.NS_ERROR_FILE_NOT_FOUND,
"Caught a file not found exception"
);
}
parser = factory.createINIParser();
Assert.ok(!!parser);
@ -236,67 +338,127 @@ caughtError = null;
checkParserOutput(parser, { section1: { name1: "value2" } });
// Bad characters in section name
try { parser.setString("bad\0", "ok", "ok"); } catch (e) { caughtError = e; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
try {
parser.setString("ok", "ok", "good=");
} catch (e) {
caughtError = e;
}
Assert.ok(!caughtError);
caughtError = null;
} catch (e) {

View file

@ -20,8 +20,9 @@ function run_test() {
Assert.equal(e.result, Cr.NS_ERROR_INVALID_POINTER);
}
var s = Cc["@mozilla.org/io/string-input-stream;1"]
.createInstance(Ci.nsIStringInputStream);
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

@ -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",
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"];
"\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);
@ -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",
rename_and_test(
"TestArguments",
// "Unicode" in Tamil
"\u0BAF\u0BC1\u0BA9\u0BBF\u0B95\u0BCB\u0B9F\u0BCD",
TEST_ARGS, true);
TEST_ARGS,
true
);
rename_and_test("TestUnicodeArguments",
rename_and_test(
"TestUnicodeArguments",
// "Unicode" in Thai
"\u0E22\u0E39\u0E19\u0E34\u0E42\u0E04\u0E14",
TEST_UNICODE_ARGS, false);
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,12 +2,12 @@ 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);

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");
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",
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",
"setOutputStream"
);
var BinaryInput = CC(
"@mozilla.org/binaryinputstream;1",
"nsIBinaryInputStream",
"setInputStream");
"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);
@ -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.
@ -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,14 +4,16 @@
* 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 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);
var sis = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
Ci.nsIScriptableInputStream
);
sis.init(s);
Assert.equal(sis.read(body.length), body);

View file

@ -16,12 +16,10 @@ 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);
}
@ -92,15 +90,17 @@ 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) {
@ -120,8 +120,13 @@ function testSymLinks(testDir, relative) {
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

@ -4,7 +4,7 @@ const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
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

@ -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

@ -40,7 +40,11 @@ function run_test() {
function setup_test_run(testKey, keyName) {
info("Setup test run");
try {
testKey.open(nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, keyName, nsIWindowsRegKey.ACCESS_READ);
testKey.open(
nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
keyName,
nsIWindowsRegKey.ACCESS_READ
);
info("Test key exists. Needs cleanup.");
cleanup_test_run(testKey, keyName);
} catch (e) {
@ -49,7 +53,11 @@ function setup_test_run(testKey, keyName) {
}
}
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) {
@ -78,17 +86,32 @@ function test_value_functions(testKey) {
}
function test_reading_functions(testKey) {
strictEqual(testKey.getValueType(TESTDATA_STRNAME), nsIWindowsRegKey.TYPE_STRING);
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.getValueType(TESTDATA_INTNAME),
nsIWindowsRegKey.TYPE_INT
);
strictEqual(testKey.readIntValue(TESTDATA_INTNAME), TESTDATA_INTVALUE);
strictEqual(testKey.getValueType(TESTDATA_INT64NAME), nsIWindowsRegKey.TYPE_INT64);
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) {
@ -103,7 +126,9 @@ function test_invalidread_functions(testKey) {
try {
let val = testKey.readStringValue(TESTDATA_INTNAME);
do_throw("Reading an string from an Int registry value should throw." + val);
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;
@ -133,7 +158,10 @@ function test_childkey_functions(testKey) {
strictEqual(testKey.childCount, 0);
strictEqual(testKey.hasChild(TESTDATA_CHILD_KEY), false);
let childKey = testKey.createChild(TESTDATA_CHILD_KEY, nsIWindowsRegKey.ACCESS_ALL);
let childKey = testKey.createChild(
TESTDATA_CHILD_KEY,
nsIWindowsRegKey.ACCESS_ALL
);
childKey.close();
strictEqual(testKey.childCount, 1);
@ -157,7 +185,10 @@ function test_watching_functions(testKey) {
strictEqual(testKey.isWatching(), false);
// Create a child key, and update a value
let childKey = testKey.createChild(TESTDATA_CHILD_KEY, nsIWindowsRegKey.ACCESS_ALL);
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
@ -183,7 +214,11 @@ function cleanup_test_run(testKey, keyName) {
testKey.close();
let baseKey = regKeyComponent.createInstance(nsIWindowsRegKey);
baseKey.open(nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, BASE_PATH, nsIWindowsRegKey.ACCESS_ALL);
baseKey.open(
nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
BASE_PATH,
nsIWindowsRegKey.ACCESS_ALL
);
baseKey.removeChild(TESTDATA_KEYNAME);
baseKey.close();
}