tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_marker_file.js (2808B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 function getTestingFiles() {
      7  const filenameBase = "3128029391StpsleeTn+ddi";
      8  let baseDir = getRelativeFile("storage/permanent/chrome/idb");
      9 
     10  let dbFile = baseDir.clone();
     11  dbFile.append(filenameBase + ".sqlite");
     12 
     13  let dir = baseDir.clone();
     14  dir.append(filenameBase + ".files");
     15 
     16  let markerFile = baseDir.clone();
     17  markerFile.append("idb-deleting-" + filenameBase);
     18 
     19  return { dbFile, dir, markerFile };
     20 }
     21 
     22 function createTestingEnvironment(markerFileOnly = false) {
     23  let testingFiles = getTestingFiles();
     24 
     25  if (!markerFileOnly) {
     26    testingFiles.dbFile.create(
     27      Ci.nsIFile.NORMAL_FILE_TYPE,
     28      parseInt("0644", 8)
     29    );
     30 
     31    testingFiles.dir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755", 8));
     32  }
     33 
     34  testingFiles.markerFile.create(
     35    Ci.nsIFile.NORMAL_FILE_TYPE,
     36    parseInt("0644", 8)
     37  );
     38 }
     39 
     40 /**
     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.
     50 */
     51 
     52 /* exported testSteps */
     53 async function testSteps() {
     54  const name = this.window ? window.location.pathname : "Splendid Test";
     55 
     56  info("Verifying initialization");
     57 
     58  let request = initStorage();
     59  await requestFinished(request);
     60 
     61  createTestingEnvironment();
     62 
     63  request = initPersistentOrigin(getSystemPrincipal());
     64  await requestFinished(request);
     65 
     66  let testingFiles = getTestingFiles();
     67  ok(!testingFiles.dbFile.exists(), "The obsolete database file doesn't exist");
     68  ok(!testingFiles.dir.exists(), "The obsolete directory doesn't exist");
     69  ok(!testingFiles.markerFile.exists(), "The marker file doesn't exist");
     70 
     71  info("Verifying open shouldn't be blocked by unexpected files");
     72 
     73  createTestingEnvironment();
     74 
     75  request = indexedDB.open(name);
     76  await expectingUpgrade(request);
     77  let event = await expectingSuccess(request);
     78  ok(true, "The database was opened successfully");
     79  let db = event.target.result;
     80  db.close();
     81 
     82  info("Verifying deleteDatabase isn't blocked by unexpected files");
     83 
     84  createTestingEnvironment(true);
     85 
     86  request = indexedDB.deleteDatabase(name);
     87  await expectingSuccess(request);
     88  ok(true, "The database was deleted successfully");
     89 }