summaryrefslogtreecommitdiffstats
path: root/services/fxaccounts/tests/xpcshell/test_telemetry.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /services/fxaccounts/tests/xpcshell/test_telemetry.js
parentInitial commit. (diff)
downloadfirefox-upstream/124.0.1.tar.xz
firefox-upstream/124.0.1.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'services/fxaccounts/tests/xpcshell/test_telemetry.js')
-rw-r--r--services/fxaccounts/tests/xpcshell/test_telemetry.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/services/fxaccounts/tests/xpcshell/test_telemetry.js b/services/fxaccounts/tests/xpcshell/test_telemetry.js
new file mode 100644
index 0000000000..3b9d318404
--- /dev/null
+++ b/services/fxaccounts/tests/xpcshell/test_telemetry.js
@@ -0,0 +1,52 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const { getFxAccountsSingleton } = ChromeUtils.importESModule(
+ "resource://gre/modules/FxAccounts.sys.mjs"
+);
+const fxAccounts = getFxAccountsSingleton();
+
+_("Misc tests for FxAccounts.telemetry");
+
+const MOCK_HASHED_UID = "00112233445566778899aabbccddeeff";
+const MOCK_DEVICE_ID = "ffeeddccbbaa99887766554433221100";
+
+add_task(function test_sanitized_uid() {
+ Services.prefs.deleteBranch(
+ "identity.fxaccounts.account.telemetry.sanitized_uid"
+ );
+
+ // Returns `null` by default.
+ Assert.equal(fxAccounts.telemetry.getSanitizedUID(), null);
+
+ // Returns provided value if set.
+ fxAccounts.telemetry._setHashedUID(MOCK_HASHED_UID);
+ Assert.equal(fxAccounts.telemetry.getSanitizedUID(), MOCK_HASHED_UID);
+
+ // Reverts to unset for falsey values.
+ fxAccounts.telemetry._setHashedUID("");
+ Assert.equal(fxAccounts.telemetry.getSanitizedUID(), null);
+});
+
+add_task(function test_sanitize_device_id() {
+ Services.prefs.deleteBranch(
+ "identity.fxaccounts.account.telemetry.sanitized_uid"
+ );
+
+ // Returns `null` by default.
+ Assert.equal(fxAccounts.telemetry.sanitizeDeviceId(MOCK_DEVICE_ID), null);
+
+ // Hashes with the sanitized UID if set.
+ // (test value here is SHA256(MOCK_DEVICE_ID + MOCK_HASHED_UID))
+ fxAccounts.telemetry._setHashedUID(MOCK_HASHED_UID);
+ Assert.equal(
+ fxAccounts.telemetry.sanitizeDeviceId(MOCK_DEVICE_ID),
+ "dd7c845006df9baa1c6d756926519c8ce12f91230e11b6057bf8ec65f9b55c1a"
+ );
+
+ // Reverts to unset for falsey values.
+ fxAccounts.telemetry._setHashedUID("");
+ Assert.equal(fxAccounts.telemetry.sanitizeDeviceId(MOCK_DEVICE_ID), null);
+});