Bug 1946184 - Fix computing the CSD margin right after calling HideWindowChrome(...
[gecko.git] / dom / quota / test / common / system.js
blobb01bb8d1fa47979c3a37d6dcdcf34afa8db877fe
1 /**
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
4 */
6 const PR_USEC_PER_SEC = 1000000;
8 const NS_ERROR_STORAGE_BUSY = Cr.NS_ERROR_STORAGE_BUSY;
10 loadScript("dom/quota/test/common/global.js");
12 function getProfileDir() {
13 return Services.dirsvc.get("ProfD", Ci.nsIFile);
16 // Given a "/"-delimited path relative to a base file (or the profile
17 // directory if a base file is not provided) return an nsIFile representing the
18 // path. This does not test for the existence of the file or parent
19 // directories. It is safe even on Windows where the directory separator is
20 // not "/", but make sure you're not passing in a "\"-delimited path.
21 function getRelativeFile(relativePath, baseFile) {
22 if (!baseFile) {
23 baseFile = getProfileDir();
26 let file = baseFile.clone();
28 if (Services.appinfo.OS === "WINNT") {
29 let winFile = file.QueryInterface(Ci.nsILocalFileWin);
30 winFile.useDOSDevicePathSyntax = true;
33 relativePath.split("/").forEach(function (component) {
34 if (component == "..") {
35 file = file.parent;
36 } else {
37 file.append(component);
39 });
41 return file;
44 function getCurrentPrincipal() {
45 return Cc["@mozilla.org/systemprincipal;1"].createInstance(Ci.nsIPrincipal);
48 function getSimpleDatabase(principal, persistence) {
49 let connection = Cc["@mozilla.org/dom/sdb-connection;1"].createInstance(
50 Ci.nsISDBConnection
53 if (!principal) {
54 principal = getCurrentPrincipal();
57 connection.init(principal, persistence);
59 return connection;
62 async function requestFinished(request) {
63 await new Promise(function (resolve) {
64 request.callback = function () {
65 resolve();
67 });
69 if (request.resultCode !== Cr.NS_OK) {
70 throw new RequestError(request.resultCode, request.resultName);
73 return request.result;