Bug 1409973 - Add tests for Date.toLocaleString and Intl.DateTimeFormat.format fingerprinting resistance.
MozReview-Commit-ID: KxJHQ8xPDlp
--- a/browser/components/resistfingerprinting/test/mochitest/mochitest.ini
+++ b/browser/components/resistfingerprinting/test/mochitest/mochitest.ini
@@ -14,8 +14,9 @@ scheme = https
[test_reduce_time_precision.html]
[test_hide_gamepad_info.html]
support-files = test_hide_gamepad_info_iframe.html
[test_speech_synthesis.html]
[test_bug1382499_touch_api.html]
[test_bug863246_resource_uri.html]
[test_bug1354633_media_error.html]
support-files = decode_error.mp4
+[test_bug1409973_date_time_format.html]
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/mochitest/test_bug1409973_date_time_format.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<script src="/tests/SimpleTest/SpawnTask.js"></script>
+<script>
+/* global SimpleTest SpecialPowers add_task */
+
+add_task(async () => {
+ // Create an UTC, en-US string for reference.
+ const date = new Date();
+ const ref = date.toLocaleString("en-US", {timeZone: "UTC", timeZoneName: "long"});
+
+ // Set preferences.
+ await SpecialPowers.pushPrefEnv({
+ set: [
+ ["privacy.resistFingerprinting", true],
+ // In real world, this will be set if the user decides to spoof preferred languages by en-US.
+ ["javascript.use_us_english_locale", true]
+ ]
+ });
+
+ // Check now timezone is UTC and default locale is en-US.
+ SimpleTest.is(date.toLocaleString(undefined, {timeZoneName: "long"}), ref, "Date.toLocaleString");
+ let formatter = new Intl.DateTimeFormat(undefined, {
+ month: "numeric", day: "numeric", year: "numeric", hour: "numeric", minute: "numeric", second: "numeric",
+ timeZoneName: "long"
+ });
+ SimpleTest.is(formatter.format(date), ref, "Intl.DateTimeFormat.format");
+});
+</script>