2015-09-01 00:26:30 +03:00
|
|
|
/**
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Enumerate the directory tree and store results in entryList as
|
|
|
|
//
|
|
|
|
// { path: 'a/b/c', file: <nsIFile> }
|
|
|
|
//
|
|
|
|
// The algorithm starts with the first entry already in entryList.
|
|
|
|
function enumerate_tree(entryList) {
|
|
|
|
for (var index = 0; index < entryList.length; ++index) {
|
|
|
|
var path = entryList[index].path;
|
|
|
|
var file = entryList[index].file;
|
|
|
|
|
|
|
|
if (file.isDirectory()) {
|
|
|
|
var dirList = file.directoryEntries;
|
|
|
|
while (dirList.hasMoreElements()) {
|
2018-05-20 06:17:45 +03:00
|
|
|
var dirFile = dirList.nextFile;
|
2019-03-06 11:04:15 +03:00
|
|
|
entryList.push({ path: path + "/" + dirFile.leafName, file: dirFile });
|
2015-09-01 00:26:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function zip_profile(zipFile, profileDir) {
|
2019-03-06 11:04:15 +03:00
|
|
|
var zipWriter = Cc["@mozilla.org/zipwriter;1"]
|
2015-09-01 00:26:30 +03:00
|
|
|
.createInstance(Ci.nsIZipWriter);
|
|
|
|
zipWriter.open(zipFile, 0x04 | 0x08 | 0x20);
|
|
|
|
|
|
|
|
var root = profileDir.clone();
|
2019-03-06 11:04:15 +03:00
|
|
|
root.append("storage");
|
|
|
|
root.append("default");
|
|
|
|
root.append("chrome");
|
2015-09-01 00:26:30 +03:00
|
|
|
|
2019-03-06 11:04:15 +03:00
|
|
|
var entryList = [{path: "storage/default/chrome", file: root}];
|
2015-09-01 00:26:30 +03:00
|
|
|
enumerate_tree(entryList);
|
|
|
|
|
|
|
|
entryList.forEach(function(entry) {
|
|
|
|
if (entry.file.isDirectory()) {
|
|
|
|
zipWriter.addEntryDirectory(entry.path, entry.file.lastModifiedTime,
|
|
|
|
false);
|
|
|
|
} else {
|
2019-03-06 11:04:15 +03:00
|
|
|
var istream = Cc["@mozilla.org/network/file-input-stream;1"]
|
2015-09-01 00:26:30 +03:00
|
|
|
.createInstance(Ci.nsIFileInputStream);
|
|
|
|
istream.init(entry.file, -1, -1, 0);
|
|
|
|
zipWriter.addEntryStream(entry.path, entry.file.lastModifiedTime,
|
|
|
|
Ci.nsIZipWriter.COMPRESSION_DEFAULT, istream,
|
|
|
|
false);
|
|
|
|
istream.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
zipWriter.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
function exactGC() {
|
|
|
|
return new Promise(function(resolve) {
|
|
|
|
var count = 0;
|
|
|
|
function doPreciseGCandCC() {
|
|
|
|
function scheduleGCCallback() {
|
|
|
|
Cu.forceCC();
|
|
|
|
|
|
|
|
if (++count < 2) {
|
|
|
|
doPreciseGCandCC();
|
|
|
|
} else {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Cu.schedulePreciseGC(scheduleGCCallback);
|
|
|
|
}
|
|
|
|
doPreciseGCandCC();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetQuotaManager() {
|
|
|
|
return new Promise(function(resolve) {
|
2019-03-06 11:04:15 +03:00
|
|
|
var qm = Cc["@mozilla.org/dom/quota/manager;1"]
|
2015-09-01 00:26:30 +03:00
|
|
|
.getService(Ci.nsIQuotaManager);
|
|
|
|
|
2019-03-06 11:04:15 +03:00
|
|
|
var prefService = Cc["@mozilla.org/preferences-service;1"]
|
2015-09-01 00:26:30 +03:00
|
|
|
.getService(Ci.nsIPrefService);
|
|
|
|
|
|
|
|
// enable quota manager testing mode
|
2019-03-06 11:04:15 +03:00
|
|
|
var pref = "dom.quotaManager.testing";
|
2015-09-01 00:26:30 +03:00
|
|
|
prefService.getBranch(null).setBoolPref(pref, true);
|
|
|
|
|
2015-11-22 12:44:16 +03:00
|
|
|
var request = qm.reset();
|
|
|
|
request.callback = resolve;
|
2015-09-01 00:26:30 +03:00
|
|
|
|
|
|
|
// disable quota manager testing mode
|
2019-03-06 11:04:15 +03:00
|
|
|
// prefService.getBranch(null).setBoolPref(pref, false);
|
2015-09-01 00:26:30 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_test() {
|
|
|
|
do_test_pending();
|
|
|
|
do_get_profile();
|
|
|
|
|
2019-03-06 11:04:15 +03:00
|
|
|
var directoryService = Cc["@mozilla.org/file/directory_service;1"]
|
2015-09-01 00:26:30 +03:00
|
|
|
.getService(Ci.nsIProperties);
|
2019-03-06 11:04:15 +03:00
|
|
|
var profileDir = directoryService.get("ProfD", Ci.nsIFile);
|
|
|
|
var currentDir = directoryService.get("CurWorkD", Ci.nsIFile);
|
2015-09-01 00:26:30 +03:00
|
|
|
|
|
|
|
var zipFile = currentDir.clone();
|
2019-03-06 11:04:15 +03:00
|
|
|
zipFile.append("new_profile.zip");
|
2015-09-01 00:26:30 +03:00
|
|
|
if (zipFile.exists()) {
|
|
|
|
zipFile.remove(false);
|
|
|
|
}
|
|
|
|
ok(!zipFile.exists());
|
|
|
|
|
2019-03-06 11:04:15 +03:00
|
|
|
caches.open("xpcshell-test").then(function(c) {
|
|
|
|
var request = new Request("http://example.com/index.html");
|
|
|
|
var response = new Response("hello world");
|
2015-09-01 00:26:30 +03:00
|
|
|
return c.put(request, response);
|
|
|
|
}).then(exactGC).then(resetQuotaManager).then(function() {
|
|
|
|
zip_profile(zipFile, profileDir);
|
2019-03-06 11:04:15 +03:00
|
|
|
dump("### ### created zip at: " + zipFile.path + "\n");
|
2015-09-01 00:26:30 +03:00
|
|
|
do_test_finished();
|
|
|
|
}).catch(function(e) {
|
|
|
|
do_test_finished();
|
|
|
|
ok(false, e);
|
|
|
|
});
|
|
|
|
}
|