summaryrefslogtreecommitdiffstats
path: root/services/settings/test/unit/test_remote_settings_dump_lastmodified.js
blob: fd186052431a95d9dbe4237a97ed56bad40bd1c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"use strict";

const { Utils } = ChromeUtils.importESModule(
  "resource://services-settings/Utils.sys.mjs"
);

Cu.importGlobalProperties(["fetch"]);

async function getLocalDumpLastModified(bucket, collection) {
  let res;
  try {
    res = await fetch(
      `resource://app/defaults/settings/${bucket}/${collection}.json`
    );
  } catch (e) {
    return -1;
  }
  const { timestamp } = await res.json();
  ok(timestamp >= 0, `${bucket}/${collection} dump has timestamp`);
  return timestamp;
}

add_task(async function lastModified_of_non_existing_dump() {
  ok(!Utils._dumpStats, "_dumpStats not initialized");
  equal(
    await Utils.getLocalDumpLastModified("did not", "exist"),
    -1,
    "A non-existent dump has value -1"
  );
  ok(Utils._dumpStats, "_dumpStats was initialized");

  ok("did not/exist" in Utils._dumpStats, "cached non-existing dump result");
  delete Utils._dumpStats["did not/exist"];
});

add_task(async function lastModified_summary_is_correct() {
  ok(!!Object.keys(Utils._dumpStats).length, "Contains summary of dumps");

  let checked = 0;
  for (let [identifier, lastModified] of Object.entries(Utils._dumpStats)) {
    let [bucket, collection] = identifier.split("/");
    let actual = await getLocalDumpLastModified(bucket, collection);
    if (actual < 0) {
      info(`${identifier} has no dump, skip.`);
      continue;
    }
    info(`Checking correctness of ${identifier}`);
    equal(
      await Utils.getLocalDumpLastModified(bucket, collection),
      lastModified,
      `Expected last_modified value for ${identifier}`
    );
    equal(lastModified, actual, `last_modified should match collection`);
    checked++;
  }
  ok(checked > 0, "At least one dump was packaged and checked.");
});