Files
tubestation/dom/cache/test/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

90 lines
2.7 KiB
JavaScript

/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*
* All images in schema_15_profile.zip are from https://github.com/mdn/sw-test/
* and are CC licensed by https://www.flickr.com/photos/legofenris/.
*/
// services required be initialized in order to run CacheStorage
var ss = Cc['@mozilla.org/storage/service;1']
.createInstance(Ci.mozIStorageService);
var sts = Cc['@mozilla.org/network/stream-transport-service;1']
.getService(Ci.nsIStreamTransportService);
var hash = Cc['@mozilla.org/security/hash;1']
.createInstance(Ci.nsICryptoHash);
// Expose Cache and Fetch symbols on the global
Cu.importGlobalProperties(['caches', 'File', 'fetch']);
// Extract a zip file into the profile
function create_test_profile(zipFileName) {
do_get_profile();
var directoryService = Cc['@mozilla.org/file/directory_service;1']
.getService(Ci.nsIProperties);
var profileDir = directoryService.get('ProfD', Ci.nsIFile);
var currentDir = directoryService.get('CurWorkD', Ci.nsIFile);
var packageFile = currentDir.clone();
packageFile.append(zipFileName);
var zipReader = Cc['@mozilla.org/libjar/zip-reader;1']
.createInstance(Ci.nsIZipReader);
zipReader.open(packageFile);
var entryNames = [];
var entries = zipReader.findEntries(null);
while (entries.hasMore()) {
var entry = entries.getNext();
entryNames.push(entry);
}
entryNames.sort();
for (var entryName of entryNames) {
var zipentry = zipReader.getEntry(entryName);
var file = profileDir.clone();
entryName.split('/').forEach(function(part) {
file.append(part);
});
if (zipentry.isDirectory) {
file.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt('0755', 8));
} else {
var istream = zipReader.getInputStream(entryName);
var ostream = Cc['@mozilla.org/network/file-output-stream;1']
.createInstance(Ci.nsIFileOutputStream);
ostream.init(file, -1, parseInt('0644', 8), 0);
var bostream = Cc['@mozilla.org/network/buffered-output-stream;1']
.createInstance(Ci.nsIBufferedOutputStream);
bostream.init(ostream, 32 * 1024);
bostream.writeFrom(istream, istream.available());
istream.close();
bostream.close();
}
}
zipReader.close();
}
function getCacheDir()
{
let dirService = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties);
let profileDir = dirService.get("ProfD", Ci.nsIFile);
let cacheDir = profileDir.clone();
cacheDir.append("storage");
cacheDir.append("default");
cacheDir.append("chrome");
cacheDir.append("cache");
return cacheDir;
}