summaryrefslogtreecommitdiffstats
path: root/services/common/tests/unit/test_uptake_telemetry.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /services/common/tests/unit/test_uptake_telemetry.js
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'services/common/tests/unit/test_uptake_telemetry.js')
-rw-r--r--services/common/tests/unit/test_uptake_telemetry.js121
1 files changed, 121 insertions, 0 deletions
diff --git a/services/common/tests/unit/test_uptake_telemetry.js b/services/common/tests/unit/test_uptake_telemetry.js
new file mode 100644
index 0000000000..24967b641f
--- /dev/null
+++ b/services/common/tests/unit/test_uptake_telemetry.js
@@ -0,0 +1,121 @@
+const { TelemetryTestUtils } = ChromeUtils.importESModule(
+ "resource://testing-common/TelemetryTestUtils.sys.mjs"
+);
+const { UptakeTelemetry } = ChromeUtils.importESModule(
+ "resource://services-common/uptake-telemetry.sys.mjs"
+);
+
+const COMPONENT = "remotesettings";
+
+async function withFakeClientID(uuid, f) {
+ const { Policy } = ChromeUtils.importESModule(
+ "resource://services-common/uptake-telemetry.sys.mjs"
+ );
+ let oldGetClientID = Policy.getClientID;
+ Policy._clientIDHash = null;
+ Policy.getClientID = () => Promise.resolve(uuid);
+ try {
+ return await f();
+ } finally {
+ Policy.getClientID = oldGetClientID;
+ }
+}
+
+add_task(async function test_unknown_status_is_not_reported() {
+ const source = "update-source";
+ const startSnapshot = getUptakeTelemetrySnapshot(COMPONENT, source);
+
+ try {
+ await UptakeTelemetry.report(COMPONENT, "unknown-status", { source });
+ } catch (e) {}
+
+ const endSnapshot = getUptakeTelemetrySnapshot(COMPONENT, source);
+ Assert.deepEqual(startSnapshot, endSnapshot);
+});
+
+add_task(async function test_age_is_converted_to_string_and_reported() {
+ const status = UptakeTelemetry.STATUS.SUCCESS;
+ const age = 42;
+
+ await withFakeChannel("nightly", async () => {
+ await UptakeTelemetry.report(COMPONENT, status, { source: "s", age });
+ });
+
+ TelemetryTestUtils.assertEvents([
+ [
+ "uptake.remotecontent.result",
+ "uptake",
+ COMPONENT,
+ status,
+ { source: "s", age: `${age}` },
+ ],
+ ]);
+});
+
+add_task(async function test_each_status_can_be_caught_in_snapshot() {
+ const source = "some-source";
+ const startSnapshot = getUptakeTelemetrySnapshot(COMPONENT, source);
+
+ const expectedIncrements = {};
+ await withFakeChannel("nightly", async () => {
+ for (const status of Object.values(UptakeTelemetry.STATUS)) {
+ expectedIncrements[status] = 1;
+ await UptakeTelemetry.report(COMPONENT, status, { source });
+ }
+ });
+
+ const endSnapshot = getUptakeTelemetrySnapshot(COMPONENT, source);
+ checkUptakeTelemetry(startSnapshot, endSnapshot, expectedIncrements);
+});
+
+add_task(async function test_events_are_sent_when_hash_is_mod_0() {
+ const source = "some-source";
+ const startSnapshot = getUptakeTelemetrySnapshot(COMPONENT, source);
+ const startSuccess = startSnapshot.success || 0;
+ const uuid = "d81bbfad-d741-41f5-a7e6-29f6bde4972a"; // hash % 100 = 0
+ await withFakeClientID(uuid, async () => {
+ await withFakeChannel("release", async () => {
+ await UptakeTelemetry.report(COMPONENT, UptakeTelemetry.STATUS.SUCCESS, {
+ source,
+ });
+ });
+ });
+ const endSnapshot = getUptakeTelemetrySnapshot(COMPONENT, source);
+ Assert.equal(endSnapshot.success, startSuccess + 1);
+});
+
+add_task(
+ async function test_events_are_not_sent_when_hash_is_greater_than_pref() {
+ const source = "some-source";
+ const startSnapshot = getUptakeTelemetrySnapshot(COMPONENT, source);
+ const startSuccess = startSnapshot.success || 0;
+ const uuid = "d81bbfad-d741-41f5-a7e6-29f6bde49721"; // hash % 100 = 1
+ await withFakeClientID(uuid, async () => {
+ await withFakeChannel("release", async () => {
+ await UptakeTelemetry.report(
+ COMPONENT,
+ UptakeTelemetry.STATUS.SUCCESS,
+ { source }
+ );
+ });
+ });
+ const endSnapshot = getUptakeTelemetrySnapshot(COMPONENT, source);
+ Assert.equal(endSnapshot.success || 0, startSuccess);
+ }
+);
+
+add_task(async function test_events_are_sent_when_nightly() {
+ const source = "some-source";
+ const startSnapshot = getUptakeTelemetrySnapshot(COMPONENT, source);
+ const startSuccess = startSnapshot.success || 0;
+ const uuid = "d81bbfad-d741-41f5-a7e6-29f6bde49721"; // hash % 100 = 1
+ await withFakeClientID(uuid, async () => {
+ await withFakeChannel("nightly", async () => {
+ await UptakeTelemetry.report(COMPONENT, UptakeTelemetry.STATUS.SUCCESS, {
+ source,
+ });
+ });
+ });
+ const endSnapshot = getUptakeTelemetrySnapshot(COMPONENT, source);
+ Assert.equal(endSnapshot.success, startSuccess + 1);
+});