2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
6 function getTestingFiles() {
7 const filenameBase = "3128029391StpsleeTn+ddi";
8 let baseDir = getRelativeFile("storage/permanent/chrome/idb");
10 let dbFile = baseDir.clone();
11 dbFile.append(filenameBase + ".sqlite");
13 let dir = baseDir.clone();
14 dir.append(filenameBase + ".files");
16 let markerFile = baseDir.clone();
17 markerFile.append("idb-deleting-" + filenameBase);
19 return { dbFile, dir, markerFile };
22 function createTestingEnvironment(markerFileOnly = false) {
23 let testingFiles = getTestingFiles();
25 if (!markerFileOnly) {
26 testingFiles.dbFile.create(
27 Ci.nsIFile.NORMAL_FILE_TYPE,
31 testingFiles.dir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755", 8));
34 testingFiles.markerFile.create(
35 Ci.nsIFile.NORMAL_FILE_TYPE,
41 * This test verifies the initialization, indexedDB.open(), and
42 * indexedDB.deleteDatabase() aren't blocked when there are unexpected files
43 * which haven't been deleted due to some reasons. Normally, we expect every
44 * delete operation works fine. Hoever, it's reported that there is only a
45 * directory without a corresponding database. It's probably because the delete
46 * operation fails for some reasons. P1 introduces the mark-file to let the
47 * future operation understand whether there might be unexpected files in idb
48 * directory. And, this test verifies these three things work fine if a
49 * marker-file, a databse file, and a directory exist in current idb directory.
52 /* exported testSteps */
53 async function testSteps() {
54 SpecialPowers.setBoolPref("dom.quotaManager.testing", true);
56 const name = this.window ? window.location.pathname : "Splendid Test";
58 info("Verifying initialization");
60 let request = initStorage();
61 await requestFinished(request);
63 createTestingEnvironment();
65 request = initPersistentOrigin(getSystemPrincipal());
66 await requestFinished(request);
68 let testingFiles = getTestingFiles();
69 ok(!testingFiles.dbFile.exists(), "The obsolete database file doesn't exist");
70 ok(!testingFiles.dir.exists(), "The obsolete directory doesn't exist");
71 ok(!testingFiles.markerFile.exists(), "The marker file doesn't exist");
73 info("Verifying open shouldn't be blocked by unexpected files");
75 createTestingEnvironment();
77 request = indexedDB.open(name);
78 await expectingUpgrade(request);
79 let event = await expectingSuccess(request);
80 ok(true, "The database was opened successfully");
81 let db = event.target.result;
84 info("Verifying deleteDatabase isn't blocked by unexpected files");
86 createTestingEnvironment(true);
88 request = indexedDB.deleteDatabase(name);
89 await expectingSuccess(request);
90 ok(true, "The database was deleted successfully");