Bug 1943514 - Close the RC sidebar panel when users opt out of/turn off Review Checke...
[gecko.git] / dom / quota / test / common / xpcshell.js
blobd0c5d784919bf97f56a20aac3a0d206609cb7d3f
1 /**
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
4 */
6 loadScript("dom/quota/test/common/system.js");
8 function enableStorageTesting() {
9 Services.prefs.setBoolPref("dom.quotaManager.testing", true);
10 Services.prefs.setBoolPref("dom.simpleDB.enabled", true);
11 if (Services.appinfo.OS === "WINNT") {
12 Services.prefs.setBoolPref("dom.quotaManager.useDOSDevicePathSyntax", true);
16 function resetStorageTesting() {
17 Services.prefs.clearUserPref("dom.quotaManager.testing");
18 Services.prefs.clearUserPref("dom.simpleDB.enabled");
19 if (Services.appinfo.OS === "WINNT") {
20 Services.prefs.clearUserPref("dom.quotaManager.useDOSDevicePathSyntax");
24 function clear(callback) {
25 let request = Services.qms.clear();
26 request.callback = callback;
28 return request;
31 function reset(callback) {
32 let request = Services.qms.reset();
33 request.callback = callback;
35 return request;
38 function installPackage(packageRelativePath, allowFileOverwrites) {
39 let currentDir = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
41 let packageFile = getRelativeFile(packageRelativePath + ".zip", currentDir);
43 let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
44 Ci.nsIZipReader
46 zipReader.open(packageFile);
48 let entryNames = Array.from(zipReader.findEntries(null));
49 entryNames.sort();
51 for (let entryName of entryNames) {
52 if (entryName.match(/^create_db\.(html|js)/)) {
53 continue;
56 let zipentry = zipReader.getEntry(entryName);
58 let file = getRelativeFile(entryName);
60 if (zipentry.isDirectory) {
61 if (!file.exists()) {
62 file.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755", 8));
64 } else {
65 if (!allowFileOverwrites && file.exists()) {
66 throw new Error("File already exists!");
69 let istream = zipReader.getInputStream(entryName);
71 var ostream = Cc[
72 "@mozilla.org/network/file-output-stream;1"
73 ].createInstance(Ci.nsIFileOutputStream);
74 ostream.init(file, -1, parseInt("0644", 8), 0);
76 let bostream = Cc[
77 "@mozilla.org/network/buffered-output-stream;1"
78 ].createInstance(Ci.nsIBufferedOutputStream);
79 bostream.init(ostream, 32768);
81 bostream.writeFrom(istream, istream.available());
83 istream.close();
84 bostream.close();
88 zipReader.close();