diff options
Diffstat (limited to 'services/settings/test/unit/test_remote_settings_dump_lastmodified.js')
-rw-r--r-- | services/settings/test/unit/test_remote_settings_dump_lastmodified.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/services/settings/test/unit/test_remote_settings_dump_lastmodified.js b/services/settings/test/unit/test_remote_settings_dump_lastmodified.js new file mode 100644 index 0000000000..1cce089ff7 --- /dev/null +++ b/services/settings/test/unit/test_remote_settings_dump_lastmodified.js @@ -0,0 +1,55 @@ +"use strict"; + +const { Utils } = ChromeUtils.importESModule( + "resource://services-settings/Utils.sys.mjs" +); + +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."); +}); |