commit cd9bb28c070b2873ad77a3d96456ce686b052e68
parent 3c3f7ac9ec21d9c0a0c941ae709f000bacefae3e
Author: Tom Ritter <tom@mozilla.com>
Date: Mon, 29 Dec 2025 20:28:59 +0000
Bug 2005864: Add a test for the timezone metrics r=timhuang
Differential Revision: https://phabricator.services.mozilla.com/D276929
Diffstat:
2 files changed, 56 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_timezone.js"]
+
["browser_worker_granular_overrides.js"]
["browser_worker_overrides.js"]
diff --git a/toolkit/components/resistfingerprinting/tests/browser/browser_usercharacteristics_timezone.js b/toolkit/components/resistfingerprinting/tests/browser/browser_usercharacteristics_timezone.js
@@ -0,0 +1,54 @@
+/* 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_timezone_metrics() {
+ info("Testing timezone metrics collection");
+
+ await BrowserTestUtils.withNewTab({ gBrowser, url: emptyPage }, () =>
+ GleanPings.userCharacteristics.testSubmission(
+ () => {
+ // Test timezone_web metric
+ const timezoneWeb = Glean.characteristics.timezoneWeb.testGetValue();
+ Assert.ok(timezoneWeb, "timezone_web should have a value");
+ Assert.notEqual(timezoneWeb, "", "timezone_web should not be empty");
+ info(`timezone_web: ${timezoneWeb}`);
+
+ // Test timezone_offset_web metric
+ const timezoneOffsetWeb =
+ Glean.characteristics.timezoneOffsetWeb.testGetValue();
+ Assert.strictEqual(
+ typeof timezoneOffsetWeb,
+ "number",
+ "timezone_offset_web should be a number"
+ );
+ info(`timezone_offset_web: ${timezoneOffsetWeb} minutes`);
+
+ // Timezone offset is typically in the range of -720 to +840 minutes
+ // (UTC-12 to UTC+14, though most are -12 to +12)
+ Assert.ok(
+ timezoneOffsetWeb >= -720 && timezoneOffsetWeb <= 840,
+ `timezone_offset_web (${timezoneOffsetWeb}) should be in valid range`
+ );
+ },
+ 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();
+ }
+ )
+ );
+});