tor-browser

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

test_remote_settings_dump_lastmodified.js (1648B)


      1 "use strict";
      2 
      3 async function getLocalDumpLastModified(bucket, collection) {
      4  let res;
      5  try {
      6    res = await fetch(
      7      `resource://app/defaults/settings/${bucket}/${collection}.json`
      8    );
      9  } catch (e) {
     10    return -1;
     11  }
     12  const { timestamp } = await res.json();
     13  Assert.greaterOrEqual(
     14    timestamp,
     15    0,
     16    `${bucket}/${collection} dump has timestamp`
     17  );
     18  return timestamp;
     19 }
     20 
     21 add_task(async function lastModified_of_non_existing_dump() {
     22  ok(!Utils._dumpStats, "_dumpStats not initialized");
     23  equal(
     24    await Utils.getLocalDumpLastModified("did not", "exist"),
     25    -1,
     26    "A non-existent dump has value -1"
     27  );
     28  ok(Utils._dumpStats, "_dumpStats was initialized");
     29 
     30  ok("did not/exist" in Utils._dumpStats, "cached non-existing dump result");
     31  delete Utils._dumpStats["did not/exist"];
     32 });
     33 
     34 add_task(async function lastModified_summary_is_correct() {
     35  ok(!!Object.keys(Utils._dumpStats).length, "Contains summary of dumps");
     36 
     37  let checked = 0;
     38  for (let [identifier, lastModified] of Object.entries(Utils._dumpStats)) {
     39    let [bucket, collection] = identifier.split("/");
     40    let actual = await getLocalDumpLastModified(bucket, collection);
     41    if (actual < 0) {
     42      info(`${identifier} has no dump, skip.`);
     43      continue;
     44    }
     45    info(`Checking correctness of ${identifier}`);
     46    equal(
     47      await Utils.getLocalDumpLastModified(bucket, collection),
     48      lastModified,
     49      `Expected last_modified value for ${identifier}`
     50    );
     51    equal(lastModified, actual, `last_modified should match collection`);
     52    checked++;
     53  }
     54  Assert.greater(checked, 0, "At least one dump was packaged and checked.");
     55 });