commit 092c54471a99f4494ab705618bbe7091469ed562
parent a42f6c233c879dee36aae58067d0bda7e08eb9d5
Author: Tom Ritter <tom@mozilla.com>
Date: Mon, 29 Dec 2025 20:29:01 +0000
Bug 2005866: Add a test for the new math metrics r=timhuang
Differential Revision: https://phabricator.services.mozilla.com/D276930
Diffstat:
2 files changed, 78 insertions(+), 0 deletions(-)
diff --git a/toolkit/components/resistfingerprinting/tests/browser/browser.toml b/toolkit/components/resistfingerprinting/tests/browser/browser.toml
@@ -85,6 +85,8 @@ support-files = ["file_pdf.pdf"]
["browser_usercharacteristics_linux_distro.js"]
skip-if = ["os != 'linux'"]
+["browser_usercharacteristics_math.js"]
+
["browser_usercharacteristics_timezone.js"]
["browser_worker_granular_overrides.js"]
diff --git a/toolkit/components/resistfingerprinting/tests/browser/browser_usercharacteristics_math.js b/toolkit/components/resistfingerprinting/tests/browser/browser_usercharacteristics_math.js
@@ -0,0 +1,76 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+const emptyPage =
+ getRootDirectory(gTestPath).replace(
+ "chrome://mochitests/content",
+ "https://example.com"
+ ) + "empty.html";
+
+add_task(async function test_math_and_binary_arch() {
+ info("Testing firefox_binary_arch and math_ops_fdlibm_2 metrics");
+
+ await BrowserTestUtils.withNewTab({ gBrowser, url: emptyPage }, () =>
+ GleanPings.userCharacteristics.testSubmission(
+ () => {
+ // Test firefox_binary_arch metric
+ const firefoxBinaryArch =
+ Glean.characteristics.firefoxBinaryArch.testGetValue();
+ Assert.ok(firefoxBinaryArch, "firefox_binary_arch should have a value");
+ Assert.notEqual(
+ firefoxBinaryArch,
+ "",
+ "firefox_binary_arch should not be empty"
+ );
+ info(`firefox_binary_arch: ${firefoxBinaryArch}`);
+
+ // Test math_ops_fdlibm_2 metric
+ const mathOpsFdlibm2 =
+ Glean.characteristics.mathOpsFdlibm2.testGetValue();
+ Assert.ok(mathOpsFdlibm2, "math_ops_fdlibm_2 should have a value");
+ Assert.notEqual(
+ mathOpsFdlibm2,
+ "",
+ "math_ops_fdlibm_2 should not be empty"
+ );
+
+ // Parse the JSON array and check the count
+ let mathValues;
+ try {
+ mathValues = JSON.parse(mathOpsFdlibm2);
+ } catch (e) {
+ Assert.ok(false, `math_ops_fdlibm_2 should be valid JSON: ${e}`);
+ return;
+ }
+
+ Assert.ok(
+ Array.isArray(mathValues),
+ "math_ops_fdlibm_2 should be an array"
+ );
+
+ // The function collects 36 values
+ const expectedCount = 36;
+ Assert.equal(
+ mathValues.length,
+ expectedCount,
+ `math_ops_fdlibm_2 should have ${expectedCount} values`
+ );
+
+ info(`math_ops_fdlibm_2 has ${mathValues.length} values as expected`);
+ },
+ async () => {
+ const populated = TestUtils.topicObserved(
+ "user-characteristics-populating-data-done",
+ () => true
+ );
+ Services.obs.notifyObservers(
+ null,
+ "user-characteristics-testing-please-populate-data"
+ );
+ await populated;
+ GleanPings.userCharacteristics.submit();
+ }
+ )
+ );
+});