Bug 1943761 - Add class alignment to the mozsearch analysis file. r=asuth
[gecko.git] / dom / quota / test / xpcshell / make_unknownFiles.js
blobb48cbd8acede194228f581e785dc7f825d85f768
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/file.js");
8 async function testSteps() {
9 const principal = getPrincipal("http://example.com");
11 const repoRelativePath = "storage/default";
12 const originRelativePath = `${repoRelativePath}/http+++example.com`;
14 let unknownFileCounter = 1;
15 let unknownDirCounter = 1;
17 function createUnknownFileIn(dirRelativePath, recursive) {
18 const dir = getRelativeFile(dirRelativePath);
20 let file = dir.clone();
21 file.append("foo" + unknownFileCounter + ".bar");
23 const ostream = Cc[
24 "@mozilla.org/network/file-output-stream;1"
25 ].createInstance(Ci.nsIFileOutputStream);
27 ostream.init(file, -1, parseInt("0644", 8), 0);
29 ostream.write("x".repeat(unknownFileCounter), unknownFileCounter);
31 ostream.close();
33 unknownFileCounter++;
35 if (recursive) {
36 const entries = dir.directoryEntries;
37 while ((file = entries.nextFile)) {
38 if (file.isDirectory()) {
39 createUnknownFileIn(dirRelativePath + "/" + file.leafName);
45 function createUnknownDirectoryIn(dirRelativePath) {
46 createUnknownFileIn(dirRelativePath + "/foo" + unknownDirCounter++);
49 // storage.sqlite and storage/ls-archive.sqlite
51 const request = init();
52 await requestFinished(request);
55 // Unknown file in the repository
57 createUnknownFileIn(repoRelativePath);
60 // Unknown file and unknown directory in the origin directory
62 let request = init();
63 await requestFinished(request);
65 request = initTemporaryStorage();
66 await requestFinished(request);
68 request = initTemporaryOrigin("default", principal);
69 await requestFinished(request);
71 Assert.strictEqual(
72 request.result,
73 true,
74 "The origin directory was created"
77 createUnknownFileIn(originRelativePath);
78 createUnknownDirectoryIn(originRelativePath);
81 // Unknown files in idb client directory and its subdirectories and unknown
82 // directory in .files directory
84 const request = indexedDB.openForPrincipal(principal, "myIndexedDB");
85 await openDBRequestUpgradeNeeded(request);
87 const database = request.result;
89 const objectStore = database.createObjectStore("Blobs", {});
91 objectStore.add(getNullBlob(200), 42);
93 await openDBRequestSucceeded(request);
95 database.close();
97 createUnknownFileIn(`${originRelativePath}/idb`);
98 createUnknownFileIn(
99 `${originRelativePath}/idb/2320029346mByDIdnedxe.files`
101 createUnknownDirectoryIn(
102 `${originRelativePath}/idb/2320029346mByDIdnedxe.files`
104 createUnknownFileIn(
105 `${originRelativePath}/idb/2320029346mByDIdnedxe.files/journals`
109 // Unknown files in cache client directory and its subdirectories
111 async function sandboxScript() {
112 const cache = await caches.open("myCache");
113 const request = new Request("http://example.com/index.html");
114 const response = new Response("hello world");
115 await cache.put(request, response);
118 const sandbox = new Cu.Sandbox(principal, {
119 wantGlobalProperties: ["caches", "fetch"],
122 const promise = new Promise(function (resolve, reject) {
123 sandbox.resolve = resolve;
124 sandbox.reject = reject;
127 Cu.evalInSandbox(
128 sandboxScript.toSource() + " sandboxScript().then(resolve, reject);",
129 sandbox
131 await promise;
133 createUnknownFileIn(`${originRelativePath}/cache`);
134 createUnknownFileIn(
135 `${originRelativePath}/cache/morgue`,
136 /* recursive */ true
140 // Unknown file and unknown directory in sdb client directory
142 const database = getSimpleDatabase(principal);
144 let request = database.open("mySimpleDB");
145 await requestFinished(request);
147 request = database.write(getBuffer(100));
148 await requestFinished(request);
150 request = database.close();
151 await requestFinished(request);
153 createUnknownFileIn(`${originRelativePath}/sdb`);
154 createUnknownDirectoryIn(`${originRelativePath}/sdb`);
157 // Unknown file and unknown directory in ls client directory
159 Services.prefs.setBoolPref("dom.storage.testing", true);
160 Services.prefs.setBoolPref("dom.storage.client_validation", false);
162 const storage = Services.domStorageManager.createStorage(
163 null,
164 principal,
165 principal,
169 storage.setItem("foo", "bar");
171 storage.close();
173 createUnknownFileIn(`${originRelativePath}/ls`);
174 createUnknownDirectoryIn(`${originRelativePath}/ls`);