tor-browser

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

test_basics.js (3435B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 function* testSteps() {
      7  const storageFile = "storage.sqlite";
      8 
      9  const metadataFiles = [
     10    {
     11      path: "storage/permanent/chrome/.metadata",
     12      shouldExistAfterInit: false,
     13    },
     14 
     15    {
     16      path: "storage/permanent/chrome/.metadata-tmp",
     17      shouldExistAfterInit: false,
     18    },
     19 
     20    {
     21      path: "storage/permanent/chrome/.metadata-v2",
     22      shouldExistAfterInit: true,
     23    },
     24 
     25    {
     26      path: "storage/permanent/chrome/.metadata-v2-tmp",
     27      shouldExistAfterInit: false,
     28    },
     29  ];
     30 
     31  info("Clearing");
     32 
     33  clear(continueToNextStepSync);
     34  yield undefined;
     35 
     36  info("Verifying initialization status");
     37 
     38  verifyInitializationStatus(false, false, false).then(continueToNextStepSync);
     39  yield undefined;
     40 
     41  info("Getting usage");
     42 
     43  getCurrentUsage(grabUsageAndContinueHandler);
     44  let usage = yield undefined;
     45 
     46  Assert.equal(usage, 0, "Usage is zero");
     47 
     48  info("Verifying initialization status");
     49 
     50  verifyInitializationStatus(true, false, false).then(continueToNextStepSync);
     51  yield undefined;
     52 
     53  info("Clearing");
     54 
     55  clear(continueToNextStepSync);
     56  yield undefined;
     57 
     58  info("Verifying initialization status");
     59 
     60  verifyInitializationStatus(false, false, false).then(continueToNextStepSync);
     61  yield undefined;
     62 
     63  info("Installing package");
     64 
     65  // The profile contains just one empty IndexedDB database. The file
     66  // create_db.js in the package was run locally, specifically it was
     67  // temporarily added to xpcshell.toml and then executed:
     68  // mach xpcshell-test --interactive dom/quota/test/xpcshell/create_db.js
     69  installPackage("basics_profile");
     70 
     71  info("Getting usage");
     72 
     73  getCurrentUsage(grabUsageAndContinueHandler);
     74  usage = yield undefined;
     75 
     76  Assert.greater(usage, 0, "Usage is not zero");
     77 
     78  info("Verifying initialization status");
     79 
     80  verifyInitializationStatus(true, false, false).then(continueToNextStepSync);
     81  yield undefined;
     82 
     83  info("Clearing");
     84 
     85  clear(continueToNextStepSync);
     86  yield undefined;
     87 
     88  info("Checking storage file");
     89 
     90  let file = getRelativeFile(storageFile);
     91 
     92  let exists = file.exists();
     93  ok(!exists, "Storage file doesn't exist");
     94 
     95  info("Verifying initialization status");
     96 
     97  verifyInitializationStatus(false, false, false).then(continueToNextStepSync);
     98  yield undefined;
     99 
    100  info("Initializing");
    101 
    102  request = init(continueToNextStepSync);
    103  yield undefined;
    104 
    105  Assert.equal(request.resultCode, NS_OK, "Initialization succeeded");
    106 
    107  exists = file.exists();
    108  ok(exists, "Storage file does exist");
    109 
    110  info("Verifying initialization status");
    111 
    112  verifyInitializationStatus(true, false, false).then(continueToNextStepSync);
    113  yield undefined;
    114 
    115  info("Initializing origin");
    116 
    117  request = initPersistentOrigin(getCurrentPrincipal(), continueToNextStepSync);
    118  yield undefined;
    119 
    120  Assert.equal(request.resultCode, NS_OK, "Initialization succeeded");
    121 
    122  ok(request.result, "Origin directory was created");
    123 
    124  for (let metadataFile of metadataFiles) {
    125    file = getRelativeFile(metadataFile.path);
    126 
    127    exists = file.exists();
    128 
    129    if (metadataFile.shouldExistAfterInit) {
    130      ok(exists, "Metadata file does exist");
    131    } else {
    132      ok(!exists, "Metadata file doesn't exist");
    133    }
    134  }
    135 
    136  info("Verifying initialization status");
    137 
    138  verifyInitializationStatus(true, false, false).then(continueToNextStepSync);
    139 
    140  yield undefined;
    141 
    142  finishTest();
    143 }