diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /toolkit/components/telemetry/tests/unit/TelemetryArchiveTesting.sys.mjs | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/telemetry/tests/unit/TelemetryArchiveTesting.sys.mjs')
-rw-r--r-- | toolkit/components/telemetry/tests/unit/TelemetryArchiveTesting.sys.mjs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/toolkit/components/telemetry/tests/unit/TelemetryArchiveTesting.sys.mjs b/toolkit/components/telemetry/tests/unit/TelemetryArchiveTesting.sys.mjs new file mode 100644 index 0000000000..0ec25213a4 --- /dev/null +++ b/toolkit/components/telemetry/tests/unit/TelemetryArchiveTesting.sys.mjs @@ -0,0 +1,76 @@ +import { TelemetryArchive } from "resource://gre/modules/TelemetryArchive.sys.mjs"; + +function checkForProperties(ping, expected) { + for (let [props, val] of expected) { + let test = ping; + for (let prop of props) { + test = test[prop]; + if (test === undefined) { + return false; + } + } + if (test !== val) { + return false; + } + } + return true; +} + +/** + * A helper object that allows test code to check whether a telemetry ping + * was properly saved. To use, first initialize to collect the starting pings + * and then check for new ping data. + */ +function Checker() {} +Checker.prototype = { + promiseInit() { + this._pingMap = new Map(); + return TelemetryArchive.promiseArchivedPingList().then(plist => { + for (let ping of plist) { + this._pingMap.set(ping.id, ping); + } + }); + }, + + /** + * Find and return a new ping with certain properties. + * + * @param expected: an array of [['prop'...], 'value'] to check + * For example: + * [ + * [['environment', 'build', 'applicationId'], '20150101010101'], + * [['version'], 1], + * [['metadata', 'OOMAllocationSize'], 123456789], + * ] + * @returns a matching ping if found, or null + */ + async promiseFindPing(type, expected) { + let candidates = []; + let plist = await TelemetryArchive.promiseArchivedPingList(); + for (let ping of plist) { + if (this._pingMap.has(ping.id)) { + continue; + } + if (ping.type == type) { + candidates.push(ping); + } + } + + for (let candidate of candidates) { + let ping = await TelemetryArchive.promiseArchivedPingById(candidate.id); + if (checkForProperties(ping, expected)) { + return ping; + } + } + return null; + }, +}; + +export const TelemetryArchiveTesting = { + setup() { + Services.prefs.setCharPref("toolkit.telemetry.log.level", "Trace"); + Services.prefs.setBoolPref("toolkit.telemetry.archive.enabled", true); + }, + + Checker, +}; |