tor-browser

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

test_orphaned_files.js (1832B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 /**
      7 * The goal of this test is to prove that orphaned files are cleaned up during
      8 * origin initialization. A file is orphaned when there's a file with zero size
      9 * in the $dbName.files/journals directory and the file table in the database
     10 * contains no records for given id. A file can become orphaned when we didn't
     11 * have a chance to remove the file from disk during shutdown or the app just
     12 * crashed.
     13 */
     14 
     15 /* exported testSteps */
     16 async function testSteps() {
     17  const name = "test_orphaned_files.js";
     18 
     19  const objectStoreName = "Blobs";
     20 
     21  const blobData = { key: 1 };
     22 
     23  info("Installing profile");
     24 
     25  let request = clearAllDatabases();
     26  await requestFinished(request);
     27 
     28  // The profile contains one initialized origin directory (with an IndexedDB
     29  // database and an orphaned file), a script for origin initialization and the
     30  // storage database:
     31  // - storage/permanent/chrome
     32  // - create_db.js
     33  // - storage.sqlite
     34  // The file create_db.js in the package was run locally, specifically it was
     35  // temporarily added to xpcshell.toml and then executed:
     36  //   mach xpcshell-test --interactive dom/indexedDB/test/unit/create_db.js
     37  // Note: to make it become the profile in the test, additional manual steps
     38  // are needed.
     39  // 1. Remove the file "storage/ls-archive.sqlite".
     40 
     41  installPackagedProfile("orphaned_files_profile");
     42 
     43  info("Opening database");
     44 
     45  request = indexedDB.open(name);
     46  await expectingSuccess(request);
     47 
     48  info("Getting data");
     49 
     50  request = request.result
     51    .transaction([objectStoreName])
     52    .objectStore(objectStoreName)
     53    .get(blobData.key);
     54  await requestSucceeded(request);
     55 
     56  info("Verifying data");
     57 
     58  ok(request.result === undefined, "Correct result");
     59 }