tor-browser

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

test_createLocalStorage.js (3774B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 async function testSteps() {
      7  const webAppsStoreFile = "webappsstore.sqlite";
      8  const lsArchiveFile = "storage/ls-archive.sqlite";
      9  const lsArchiveTmpFile = "storage/ls-archive-tmp.sqlite";
     10 
     11  function checkArchiveFileNotExists() {
     12    info("Checking archive tmp file");
     13 
     14    let archiveTmpFile = getRelativeFile(lsArchiveTmpFile);
     15 
     16    let exists = archiveTmpFile.exists();
     17    ok(!exists, "archive tmp file doesn't exist");
     18 
     19    info("Checking archive file");
     20 
     21    let archiveFile = getRelativeFile(lsArchiveFile);
     22 
     23    exists = archiveFile.exists();
     24    ok(!exists, "archive file doesn't exist");
     25  }
     26 
     27  function checkArchiveFileExists() {
     28    info("Checking archive tmp file");
     29 
     30    let archiveTmpFile = getRelativeFile(lsArchiveTmpFile);
     31 
     32    let exists = archiveTmpFile.exists();
     33    ok(!exists, "archive tmp file doesn't exist");
     34 
     35    info("Checking archive file");
     36 
     37    let archiveFile = getRelativeFile(lsArchiveFile);
     38 
     39    exists = archiveFile.exists();
     40    ok(exists, "archive file does exist");
     41 
     42    info("Checking archive file size");
     43 
     44    let fileSize = archiveFile.fileSize;
     45    Assert.greater(fileSize, 0, "archive file size is greater than zero");
     46  }
     47 
     48  // Profile 1 - Nonexistent apps store file.
     49  info("Clearing");
     50 
     51  let request = clear();
     52  await requestFinished(request);
     53 
     54  let appsStoreFile = getRelativeFile(webAppsStoreFile);
     55 
     56  let exists = appsStoreFile.exists();
     57  ok(!exists, "apps store file doesn't exist");
     58 
     59  checkArchiveFileNotExists();
     60 
     61  try {
     62    request = init();
     63    await requestFinished(request);
     64 
     65    ok(true, "Should not have thrown");
     66  } catch (ex) {
     67    ok(false, "Should not have thrown");
     68  }
     69 
     70  checkArchiveFileExists();
     71 
     72  // Profile 2 - apps store file is a directory.
     73  info("Clearing");
     74 
     75  request = clear();
     76  await requestFinished(request);
     77 
     78  appsStoreFile.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755", 8));
     79 
     80  checkArchiveFileNotExists();
     81 
     82  try {
     83    request = init();
     84    await requestFinished(request);
     85 
     86    ok(true, "Should not have thrown");
     87  } catch (ex) {
     88    ok(false, "Should not have thrown");
     89  }
     90 
     91  checkArchiveFileExists();
     92 
     93  appsStoreFile.remove(true);
     94 
     95  // Profile 3 - Corrupted apps store file.
     96  info("Clearing");
     97 
     98  request = clear();
     99  await requestFinished(request);
    100 
    101  let ostream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(
    102    Ci.nsIFileOutputStream
    103  );
    104  ostream.init(appsStoreFile, -1, parseInt("0644", 8), 0);
    105  ostream.write("foobar", 6);
    106  ostream.close();
    107 
    108  checkArchiveFileNotExists();
    109 
    110  try {
    111    request = init();
    112    await requestFinished(request);
    113 
    114    ok(true, "Should not have thrown");
    115  } catch (ex) {
    116    ok(false, "Should not have thrown");
    117  }
    118 
    119  checkArchiveFileExists();
    120 
    121  appsStoreFile.remove(false);
    122 
    123  // Profile 4 - Nonupdateable apps store file.
    124  info("Clearing");
    125 
    126  request = clear();
    127  await requestFinished(request);
    128 
    129  info("Installing package");
    130 
    131  // The profile contains storage.sqlite and webappsstore.sqlite
    132  // webappstore.sqlite was taken from FF 54 to force an upgrade.
    133  // There's just one record in the webappsstore2 table. The record was
    134  // modified by renaming the origin attribute userContextId to userContextKey.
    135  // This triggers an error during the upgrade.
    136  installPackage("createLocalStorage_profile");
    137 
    138  let fileSize = appsStoreFile.fileSize;
    139  Assert.greater(fileSize, 0, "apps store file size is greater than zero");
    140 
    141  checkArchiveFileNotExists();
    142 
    143  try {
    144    request = init();
    145    await requestFinished(request);
    146 
    147    ok(true, "Should not have thrown");
    148  } catch (ex) {
    149    ok(false, "Should not have thrown");
    150  }
    151 
    152  checkArchiveFileExists();
    153 
    154  appsStoreFile.remove(false);
    155 }