Files
tubestation/toolkit/components/osfile/tests/xpcshell/head.js
Andrew McCreight 272cee1e65 Bug 1432992, part 1 - Remove definitions of Ci, Cr, Cc, and Cu. r=florian
This patch was autogenerated by my decomponents.py

It covers almost every file with the extension js, jsm, html, py,
xhtml, or xul.

It removes blank lines after removed lines, when the removed lines are
preceded by either blank lines or the start of a new block. The "start
of a new block" is defined fairly hackily: either the line starts with
//, ends with */, ends with {, <![CDATA[, """ or '''. The first two
cover comments, the third one covers JS, the fourth covers JS embedded
in XUL, and the final two cover JS embedded in Python. This also
applies if the removed line was the first line of the file.

It covers the pattern matching cases like "var {classes: Cc,
interfaces: Ci, utils: Cu, results: Cr} = Components;". It'll remove
the entire thing if they are all either Ci, Cr, Cc or Cu, or it will
remove the appropriate ones and leave the residue behind. If there's
only one behind, then it will turn it into a normal, non-pattern
matching variable definition. (For instance, "const { classes: Cc,
Constructor: CC, interfaces: Ci, utils: Cu } = Components" becomes
"const CC = Components.Constructor".)

MozReview-Commit-ID: DeSHcClQ7cG
2018-02-06 09:36:57 -08:00

106 lines
3.0 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", {});
// Bug 1014484 can only be reproduced by loading OS.File first from the
// CommonJS loader, so we do not want OS.File to be loaded eagerly for
// all the tests in this directory.
ChromeUtils.defineModuleGetter(this, "OS",
"resource://gre/modules/osfile.jsm");
ChromeUtils.defineModuleGetter(this, "FileUtils",
"resource://gre/modules/FileUtils.jsm");
ChromeUtils.defineModuleGetter(this, "NetUtil",
"resource://gre/modules/NetUtil.jsm");
ChromeUtils.defineModuleGetter(this, "Services",
"resource://gre/modules/Services.jsm");
Services.prefs.setBoolPref("toolkit.osfile.log", true);
/**
* As add_task, but execute the test both with native operations and
* without.
*/
function add_test_pair(generator) {
add_task(async function() {
info("Executing test " + generator.name + " with native operations");
Services.prefs.setBoolPref("toolkit.osfile.native", true);
return generator();
});
add_task(async function() {
info("Executing test " + generator.name + " without native operations");
Services.prefs.setBoolPref("toolkit.osfile.native", false);
return generator();
});
}
/**
* Fetch asynchronously the contents of a file using xpcom.
*
* Used for comparing xpcom-based results to os.file-based results.
*
* @param {string} path The _absolute_ path to the file.
* @return {promise}
* @resolves {string} The contents of the file.
*/
function reference_fetch_file(path, test) {
info("Fetching file " + path);
return new Promise((resolve, reject) => {
let file = new FileUtils.File(path);
NetUtil.asyncFetch({
uri: NetUtil.newURI(file),
loadUsingSystemPrincipal: true
}, function(stream, status) {
if (!Components.isSuccessCode(status)) {
reject(status);
return;
}
let result, reject;
try {
result = NetUtil.readInputStreamToString(stream, stream.available());
} catch (x) {
reject = x;
}
stream.close();
if (reject) {
reject(reject);
} else {
resolve(result);
}
});
});
}
/**
* Compare asynchronously the contents two files using xpcom.
*
* Used for comparing xpcom-based results to os.file-based results.
*
* @param {string} a The _absolute_ path to the first file.
* @param {string} b The _absolute_ path to the second file.
*
* @resolves {null}
*/
function reference_compare_files(a, b, test) {
return (async function() {
info("Comparing files " + a + " and " + b);
let a_contents = await reference_fetch_file(a, test);
let b_contents = await reference_fetch_file(b, test);
Assert.equal(a_contents, b_contents);
})();
}
async function removeTestFile(filePath, ignoreNoSuchFile = true) {
try {
await OS.File.remove(filePath);
} catch (ex) {
if (!ignoreNoSuchFile || !ex.becauseNoSuchFile) {
do_throw(ex);
}
}
}