Bug 1500122 - Use a custom locale for datetime formatting tests. r=darktrojan
Differential Revision: https://phabricator.services.mozilla.com/D123180 --HG-- extra : amend_source : 328f174c5e29e5c44d8a90b781089e46906baa4e
This commit is contained in:
Родитель
ae491a8b50
Коммит
62868bbb82
|
@ -355,7 +355,13 @@ function inTimezone(aDate, aOptions) {
|
|||
formatter = formatCache.get(cacheKey);
|
||||
} else {
|
||||
try {
|
||||
formatter = new Services.intl.DateTimeFormat(undefined, optionsWithTimezone);
|
||||
if (Services.appinfo.name === "xpcshell") {
|
||||
// Use en-US when running in a test to make the result independent of
|
||||
// the locale of the test machine.
|
||||
formatter = new Services.intl.DateTimeFormat("en-US", optionsWithTimezone);
|
||||
} else {
|
||||
formatter = new Services.intl.DateTimeFormat(undefined, optionsWithTimezone);
|
||||
}
|
||||
formatCache.set(cacheKey, formatter);
|
||||
} catch (ex) {
|
||||
// Non-IANA timezones throw a RangeError.
|
||||
|
@ -369,7 +375,13 @@ function inTimezone(aDate, aOptions) {
|
|||
if (formatCache.has(cacheKey)) {
|
||||
formatter = formatCache.get(cacheKey);
|
||||
} else {
|
||||
formatter = new Services.intl.DateTimeFormat(undefined, aOptions);
|
||||
if (Services.appinfo.name === "xpcshell") {
|
||||
// Use en-US when running in a test to make the result independent of
|
||||
// the locale of the test machine.
|
||||
formatter = new Services.intl.DateTimeFormat("en-US", aOptions);
|
||||
} else {
|
||||
formatter = new Services.intl.DateTimeFormat(undefined, aOptions);
|
||||
}
|
||||
formatCache.set(cacheKey, formatter);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,10 +38,6 @@ add_task(async function formatDate_test() {
|
|||
|
||||
let dateformat = Services.prefs.getIntPref("calendar.date.format", 0);
|
||||
let tzlocal = Services.prefs.getStringPref("calendar.timezone.local", "Pacific/Fakaofo");
|
||||
let useOsLocale = Services.prefs.getBoolPref("intl.regional_prefs.use_os_locales", false);
|
||||
// make sure to use the app locale to avoid test failures when running
|
||||
// locally on an OS with a regional setting other than en-US
|
||||
Services.prefs.setBoolPref("intl.regional_prefs.use_os_locales", false);
|
||||
Services.prefs.setStringPref("calendar.timezone.local", "Pacific/Fakaofo");
|
||||
|
||||
let tzs = cal.getTimezoneService();
|
||||
|
@ -63,7 +59,6 @@ add_task(async function formatDate_test() {
|
|||
// let's reset the preferences
|
||||
Services.prefs.setStringPref("calendar.timezone.local", tzlocal);
|
||||
Services.prefs.setIntPref("calendar.date.format", dateformat);
|
||||
Services.prefs.setBoolPref("intl.regional_prefs.use_os_locales", useOsLocale);
|
||||
});
|
||||
|
||||
add_task(async function formatDateShort_test() {
|
||||
|
@ -128,10 +123,6 @@ add_task(async function formatDateShort_test() {
|
|||
|
||||
let dateformat = Services.prefs.getIntPref("calendar.date.format", 0);
|
||||
let tzlocal = Services.prefs.getStringPref("calendar.timezone.local", "Pacific/Fakaofo");
|
||||
let useOsLocale = Services.prefs.getBoolPref("intl.regional_prefs.use_os_locales", false);
|
||||
// make sure to use the app locale to avoid test failures when running
|
||||
// locally on an OS with a regional setting other than en-US
|
||||
Services.prefs.setBoolPref("intl.regional_prefs.use_os_locales", false);
|
||||
Services.prefs.setStringPref("calendar.timezone.local", "Pacific/Fakaofo");
|
||||
// we make sure to have set long format
|
||||
Services.prefs.setIntPref("calendar.date.format", 0);
|
||||
|
@ -155,7 +146,6 @@ add_task(async function formatDateShort_test() {
|
|||
// let's reset the preferences
|
||||
Services.prefs.setStringPref("calendar.timezone.local", tzlocal);
|
||||
Services.prefs.setIntPref("calendar.date.format", dateformat);
|
||||
Services.prefs.setBoolPref("intl.regional_prefs.use_os_locales", useOsLocale);
|
||||
});
|
||||
|
||||
add_task(async function formatDateLong_test() {
|
||||
|
@ -220,10 +210,6 @@ add_task(async function formatDateLong_test() {
|
|||
|
||||
let dateformat = Services.prefs.getIntPref("calendar.date.format", 0);
|
||||
let tzlocal = Services.prefs.getStringPref("calendar.timezone.local", "Pacific/Fakaofo");
|
||||
let useOsLocale = Services.prefs.getBoolPref("intl.regional_prefs.use_os_locales", false);
|
||||
// make sure to use the app locale to avoid test failures when running
|
||||
// locally on an OS with a regional setting other than en-US
|
||||
Services.prefs.setBoolPref("intl.regional_prefs.use_os_locales", false);
|
||||
Services.prefs.setStringPref("calendar.timezone.local", "Pacific/Fakaofo");
|
||||
// we make sure to have set short format
|
||||
Services.prefs.setIntPref("calendar.date.format", 1);
|
||||
|
@ -247,7 +233,6 @@ add_task(async function formatDateLong_test() {
|
|||
// let's reset the preferences
|
||||
Services.prefs.setStringPref("calendar.timezone.local", tzlocal);
|
||||
Services.prefs.setIntPref("calendar.date.format", dateformat);
|
||||
Services.prefs.setBoolPref("intl.regional_prefs.use_os_locales", useOsLocale);
|
||||
});
|
||||
|
||||
add_task(async function formatDateWithoutYear_test() {
|
||||
|
@ -312,10 +297,6 @@ add_task(async function formatDateWithoutYear_test() {
|
|||
|
||||
let dateformat = Services.prefs.getIntPref("calendar.date.format", 0);
|
||||
let tzlocal = Services.prefs.getStringPref("calendar.timezone.local", "Pacific/Fakaofo");
|
||||
let useOsLocale = Services.prefs.getBoolPref("intl.regional_prefs.use_os_locales", false);
|
||||
// make sure to use the app locale to avoid test failures when running
|
||||
// locally on an OS with a regional setting other than en-US
|
||||
Services.prefs.setBoolPref("intl.regional_prefs.use_os_locales", false);
|
||||
Services.prefs.setStringPref("calendar.timezone.local", "Pacific/Fakaofo");
|
||||
// we make sure to have set short format
|
||||
Services.prefs.setIntPref("calendar.date.format", 1);
|
||||
|
@ -335,7 +316,6 @@ add_task(async function formatDateWithoutYear_test() {
|
|||
// let's reset the preferences
|
||||
Services.prefs.setStringPref("calendar.timezone.local", tzlocal);
|
||||
Services.prefs.setIntPref("calendar.date.format", dateformat);
|
||||
Services.prefs.setBoolPref("intl.regional_prefs.use_os_locales", useOsLocale);
|
||||
});
|
||||
|
||||
add_task(async function formatTime_test() {
|
||||
|
@ -378,10 +358,6 @@ add_task(async function formatTime_test() {
|
|||
];
|
||||
|
||||
let tzlocal = Services.prefs.getStringPref("calendar.timezone.local", "Pacific/Fakaofo");
|
||||
let useOsLocale = Services.prefs.getBoolPref("intl.regional_prefs.use_os_locales", false);
|
||||
// make sure to use the app locale to avoid test failures when running
|
||||
// locally on an OS with a regional setting other than en-US
|
||||
Services.prefs.setBoolPref("intl.regional_prefs.use_os_locales", false);
|
||||
Services.prefs.setStringPref("calendar.timezone.local", "Pacific/Fakaofo");
|
||||
|
||||
let tzs = cal.getTimezoneService();
|
||||
|
@ -402,5 +378,4 @@ add_task(async function formatTime_test() {
|
|||
}
|
||||
// let's reset the preferences
|
||||
Services.prefs.setStringPref("calendar.timezone.local", tzlocal);
|
||||
Services.prefs.setBoolPref("intl.regional_prefs.use_os_locales", useOsLocale);
|
||||
});
|
||||
|
|
|
@ -17,16 +17,7 @@ function run_test() {
|
|||
|
||||
// tests for calInvitationUtils.jsm
|
||||
|
||||
// Make sure that the Europe/Berlin timezone and long datetime format is set
|
||||
// and to use the app locale to avoid test failures when running locally on
|
||||
// an OS with a regional setting other than en-US.
|
||||
//
|
||||
// NOTE: If your OS is in English but not US English this will not switch it
|
||||
// to en-US. But the test is still known to work with en-GB.
|
||||
// If it doesn't work, try `export LC_TIME=en_US.UTF-8` before running the
|
||||
// test. Or you can update the test time regular expressions to also include
|
||||
// your English locale.
|
||||
Services.prefs.setBoolPref("intl.regional_prefs.use_os_locales", false);
|
||||
// Make sure that the Europe/Berlin timezone and long datetime format is set.
|
||||
Services.prefs.setIntPref("calendar.date.format", 0);
|
||||
Services.prefs.setStringPref("calendar.timezone.local", "Europe/Berlin");
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче