diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /dom/quota/test/common/xpcshell.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-37a0381f8351b370577b65028ba1f6563ae23fdf.tar.xz firefox-esr-37a0381f8351b370577b65028ba1f6563ae23fdf.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/quota/test/common/xpcshell.js')
-rw-r--r-- | dom/quota/test/common/xpcshell.js | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/dom/quota/test/common/xpcshell.js b/dom/quota/test/common/xpcshell.js new file mode 100644 index 0000000000..ed3afaa467 --- /dev/null +++ b/dom/quota/test/common/xpcshell.js @@ -0,0 +1,91 @@ +/** + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +loadScript("dom/quota/test/common/system.js"); + +function enableStorageTesting() { + Services.prefs.setBoolPref("dom.quotaManager.testing", true); + Services.prefs.setBoolPref("dom.storageManager.enabled", true); + Services.prefs.setBoolPref("dom.simpleDB.enabled", true); + if (Services.appinfo.OS === "WINNT") { + Services.prefs.setBoolPref("dom.quotaManager.useDOSDevicePathSyntax", true); + } +} + +function resetStorageTesting() { + Services.prefs.clearUserPref("dom.quotaManager.testing"); + Services.prefs.clearUserPref("dom.storageManager.enabled"); + Services.prefs.clearUserPref("dom.simpleDB.enabled"); + if (Services.appinfo.OS === "WINNT") { + Services.prefs.clearUserPref("dom.quotaManager.useDOSDevicePathSyntax"); + } +} + +function clear(callback) { + let request = Services.qms.clear(); + request.callback = callback; + + return request; +} + +function reset(callback) { + let request = Services.qms.reset(); + request.callback = callback; + + return request; +} + +function installPackage(packageRelativePath, allowFileOverwrites) { + let currentDir = Services.dirsvc.get("CurWorkD", Ci.nsIFile); + + let packageFile = getRelativeFile(packageRelativePath + ".zip", currentDir); + + let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance( + Ci.nsIZipReader + ); + zipReader.open(packageFile); + + let entryNames = Array.from(zipReader.findEntries(null)); + entryNames.sort(); + + for (let entryName of entryNames) { + if (entryName.match(/^create_db\.(html|js)/)) { + continue; + } + + let zipentry = zipReader.getEntry(entryName); + + let file = getRelativeFile(entryName); + + if (zipentry.isDirectory) { + if (!file.exists()) { + file.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755", 8)); + } + } else { + if (!allowFileOverwrites && file.exists()) { + throw new Error("File already exists!"); + } + + let 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); + + let bostream = Cc[ + "@mozilla.org/network/buffered-output-stream;1" + ].createInstance(Ci.nsIBufferedOutputStream); + bostream.init(ostream, 32768); + + bostream.writeFrom(istream, istream.available()); + + istream.close(); + bostream.close(); + } + } + + zipReader.close(); +} |