Bug 1500122 - Fix xpcshell tests relying on en-US datetime formatter results to pass locally irrespective of locale. r=philipp
authorMakeMyDay <makemyday@gmx-topmail.de>
Thu, 18 Oct 2018 16:51:05 +0200
changeset 33661 e327b83756cc7bc509b3bf5ad559de58aff31457
parent 33660 25adff603af0c4b0817fb34baa80185a76081704
child 33662 d3c5b1d085805fd54890be3cf65a16d0c704541d
push id388
push userclokep@gmail.com
push dateMon, 28 Jan 2019 20:54:56 +0000
reviewersphilipp
bugs1500122
Bug 1500122 - Fix xpcshell tests relying on en-US datetime formatter results to pass locally irrespective of locale. r=philipp
calendar/test/unit/test_datetimeformatter.js
calendar/test/unit/test_ltninvitationutils.js
--- a/calendar/test/unit/test_datetimeformatter.js
+++ b/calendar/test/unit/test_datetimeformatter.js
@@ -29,19 +29,22 @@ add_task(async function formatDate_test(
             timezone: "Pacific/Fakaofo",
             dateformat: 1 // short
         },
         expected: ["4/1/2017", "4/1/17"]
     }];
 
     let dateformat = Preferences.get("calendar.date.format", 0);
     let tzlocal = Preferences.get("calendar.timezone.local", "Pacific/Fakaofo");
+    let useOsLocale = Preferences.get("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
+    Preferences.set("intl.regional_prefs.use_os_locales", false);
     Preferences.set("calendar.timezone.local", "Pacific/Fakaofo");
 
-
     let tzs = cal.getTimezoneService();
 
     let i = 0;
     for (let test of data) {
         i++;
         Preferences.set("calendar.date.format", test.input.dateformat);
         let zone = (test.input.timezone == "floating") ? cal.dtz.floating : tzs.getTimezone(test.input.timezone);
         let date = cal.createDateTime(test.input.datetime).getInTimezone(zone);
@@ -52,16 +55,17 @@ add_task(async function formatDate_test(
         ok(
             test.expected.includes(formatted),
             "(test #" + i + ": result '" + formatted + "', expected '" + test.expected + "')"
         );
     }
     // let's reset the preferences
     Preferences.set("calendar.timezone.local", tzlocal);
     Preferences.set("calendar.date.format", dateformat);
+    Preferences.set("intl.regional_prefs.use_os_locales", useOsLocale);
 });
 
 add_task(async function formatDateShort_test() {
     let data = [{
         input: {
             datetime: "20170401T180000",
             timezone: "Pacific/Fakaofo"
         },
@@ -107,16 +111,20 @@ add_task(async function formatDateShort_
             datetime: "20170401",
             timezone: "floating"
         },
         expected: ["4/1/2017", "4/1/17"]
     }];
 
     let dateformat = Preferences.get("calendar.date.format", 0);
     let tzlocal = Preferences.get("calendar.timezone.local", "Pacific/Fakaofo");
+    let useOsLocale = Preferences.get("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
+    Preferences.set("intl.regional_prefs.use_os_locales", false);
     Preferences.set("calendar.timezone.local", "Pacific/Fakaofo");
     // we make sure to have set long format
     Preferences.set("calendar.date.format", 0);
 
     let tzs = cal.getTimezoneService();
 
     let i = 0;
     for (let test of data) {
@@ -132,16 +140,17 @@ add_task(async function formatDateShort_
         ok(
             test.expected.includes(formatted),
             "(test #" + i + ": result '" + formatted + "', expected '" + test.expected + "')"
         );
     }
     // let's reset the preferences
     Preferences.set("calendar.timezone.local", tzlocal);
     Preferences.set("calendar.date.format", dateformat);
+    Preferences.set("intl.regional_prefs.use_os_locales", useOsLocale);
 });
 
 add_task(async function formatDateLong_test() {
     let data = [{
         input: {
             datetime: "20170401T180000",
             timezone: "Pacific/Fakaofo"
         },
@@ -187,16 +196,20 @@ add_task(async function formatDateLong_t
             datetime: "20170401",
             timezone: "floating"
         },
         expected: ["Saturday, April 01, 2017", "Saturday, April 1, 2017"]
     }];
 
     let dateformat = Preferences.get("calendar.date.format", 0);
     let tzlocal = Preferences.get("calendar.timezone.local", "Pacific/Fakaofo");
+    let useOsLocale = Preferences.get("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
+    Preferences.set("intl.regional_prefs.use_os_locales", false);
     Preferences.set("calendar.timezone.local", "Pacific/Fakaofo");
     // we make sure to have set short format
     Preferences.set("calendar.date.format", 1);
 
     let tzs = cal.getTimezoneService();
 
     let i = 0;
     for (let test of data) {
@@ -212,16 +225,17 @@ add_task(async function formatDateLong_t
         ok(
             test.expected.includes(formatted),
             "(test #" + i + ": result '" + formatted + "', expected '" + test.expected + "')"
         );
     }
     // let's reset the preferences
     Preferences.set("calendar.timezone.local", tzlocal);
     Preferences.set("calendar.date.format", dateformat);
+    Preferences.set("intl.regional_prefs.use_os_locales", useOsLocale);
 });
 
 add_task(async function formatDateWithoutYear_test() {
     let data = [{
         input: {
             datetime: "20170401T180000",
             timezone: "Pacific/Fakaofo"
         },
@@ -267,16 +281,20 @@ add_task(async function formatDateWithou
             datetime: "20170401",
             timezone: "floating"
         },
         expected: "Apr 1"
     }];
 
     let dateformat = Preferences.get("calendar.date.format", 0);
     let tzlocal = Preferences.get("calendar.timezone.local", "Pacific/Fakaofo");
+    let useOsLocale = Preferences.get("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
+    Preferences.set("intl.regional_prefs.use_os_locales", false);
     Preferences.set("calendar.timezone.local", "Pacific/Fakaofo");
     // we make sure to have set short format
     Preferences.set("calendar.date.format", 1);
 
     let tzs = cal.getTimezoneService();
 
     let i = 0;
     for (let test of data) {
@@ -288,16 +306,17 @@ add_task(async function formatDateWithou
         let dtFormatter = Components.classes["@mozilla.org/calendar/datetime-formatter;1"]
                                     .getService(Components.interfaces.calIDateTimeFormatter);
 
         equal(dtFormatter.formatDateWithoutYear(date), test.expected, "(test #" + i + ")");
     }
     // let's reset the preferences
     Preferences.set("calendar.timezone.local", tzlocal);
     Preferences.set("calendar.date.format", dateformat);
+    Preferences.set("intl.regional_prefs.use_os_locales", useOsLocale);
 });
 
 add_task(async function formatTime_test() {
     let data = [{
         input: {
             datetime: "20170401T090000",
             timezone: "Pacific/Fakaofo"
         },
@@ -324,16 +343,20 @@ add_task(async function formatTime_test(
         input: {
             datetime: "20170401",
             timezone: "Pacific/Fakaofo"
         },
         expected: "All Day"
     }];
 
     let tzlocal = Preferences.get("calendar.timezone.local", "Pacific/Fakaofo");
+    let useOsLocale = Preferences.get("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
+    Preferences.set("intl.regional_prefs.use_os_locales", false);
     Preferences.set("calendar.timezone.local", "Pacific/Fakaofo");
 
     let tzs = cal.getTimezoneService();
 
     let i = 0;
     for (let test of data) {
         i++;
 
@@ -346,9 +369,10 @@ add_task(async function formatTime_test(
         let formatted = dtFormatter.formatTime(date);
         ok(
             test.expected.includes(formatted),
             "(test #" + i + ": result '" + formatted + "', expected '" + test.expected + "')"
         );
     }
     // let's reset the preferences
     Preferences.set("calendar.timezone.local", tzlocal);
+    Preferences.set("intl.regional_prefs.use_os_locales", useOsLocale);
 });
--- a/calendar/test/unit/test_ltninvitationutils.js
+++ b/calendar/test/unit/test_ltninvitationutils.js
@@ -505,19 +505,23 @@ add_task(async function compareInvitatio
             each: [
                 "<span xmlns=\"\" class=\"modified\">attendee2@example.net</span>",
                 "attendee3@example.net",
                 "<span xmlns=\"\" class=\"added\">attendee4@example.net</span>",
                 "<span xmlns=\"\" class=\"removed\">attendee1@example.net</span>"
             ]
         }
     }];
-    // we make sure that the Europe/Berlin timezone and long datetime format is set
+    // 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
     let dateformat = Preferences.get("calendar.date.format", 0);
     let tzlocal = Preferences.get("calendar.timezone.local", "Europe/Berlin");
+    let useOsLocale = Preferences.get("intl.regional_prefs.use_os_locales", false);
+    Preferences.set("intl.regional_prefs.use_os_locales", false);
     Preferences.set("calendar.date.format", 0);
     Preferences.set("calendar.timezone.local", "Europe/Berlin");
     let i = 0;
     for (let test of data) {
         i++;
         let dom1 = getDom(test.input.previous);
         let dom2 = getDom(test.input.current);
         let result = ltn.invitation.compareInvitationOverlay(dom1, dom2, test.input.ignore);
@@ -544,16 +548,17 @@ add_task(async function compareInvitatio
             }
             equal(test.expected.each.length, j,
                   "(test #" + i + "): completeness check " + test.expected.node);
         }
     }
     // let's reset setting
     Preferences.set("calendar.date.format", dateformat);
     Preferences.set("calendar.timezone.local", tzlocal);
+    Preferences.set("intl.regional_prefs.use_os_locales", useOsLocale);
 });
 
 add_task(async function getHeaderSection_test() {
     let data = [{
         input: {
             toList: "recipient@example.net",
             subject: "Invitation: test subject",
             identity: {
@@ -1025,16 +1030,21 @@ add_task(async function parseCounter_tes
                 descr: "No difference in counterproposal detected.",
                 type: "NODIFF"
             },
             differences: []
         }
     }];
     /* eslint-enable object-curly-newline */
 
+    // 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
+    let useOsLocale = Preferences.get("intl.regional_prefs.use_os_locales", false);
+    Preferences.set("intl.regional_prefs.use_os_locales", false);
+
     let getItem = function(aProperties) {
         let item = getIcs(true);
 
         let modifyProperty = function(aRegex, aReplacement, aInVevent) {
             let inVevent = false;
             let i = 0;
             item.forEach(aProp => {
                 if (aProp == "BEGIN:VEVENT" && !inVevent) {
@@ -1132,9 +1142,11 @@ add_task(async function parseCounter_tes
                 missingProps.push(aDiff.property);
             }
         });
         ok(additionalProps.length == 0, "(test #" + i + ": differences: check for unexpectedly "+
                                         "occurring additional properties " + additionalProps + ")");
         ok(missingProps.length == 0, "(test #" + i + ": differences: check for unexpectedly " +
                                      "missing properties " + missingProps + ")");
     }
+
+    Preferences.set("intl.regional_prefs.use_os_locales", useOsLocale);
 });