diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/calendar/test/browser/timezones | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/calendar/test/browser/timezones')
3 files changed, 1099 insertions, 0 deletions
diff --git a/comm/calendar/test/browser/timezones/browser.ini b/comm/calendar/test/browser/timezones/browser.ini new file mode 100644 index 0000000000..2fe2a0b4ea --- /dev/null +++ b/comm/calendar/test/browser/timezones/browser.ini @@ -0,0 +1,17 @@ +[default] +prefs = + calendar.item.promptDelete=false + calendar.timezone.local=UTC + calendar.timezone.useSystemTimezone=false + calendar.week.start=0 + mail.provider.suppress_dialog_on_startup=true + mail.spotlight.firstRunDone=true + mail.winsearch.firstRunDone=true + mailnews.start_page.override_url=about:blank + mailnews.start_page.url=about:blank +subsuite = thunderbird +support-files = data/** + +[browser_minimonth.js] +[browser_timezones.js] +skip-if = debug # Takes way too long, bug 1746973. diff --git a/comm/calendar/test/browser/timezones/browser_minimonth.js b/comm/calendar/test/browser/timezones/browser_minimonth.js new file mode 100644 index 0000000000..eba6bb2485 --- /dev/null +++ b/comm/calendar/test/browser/timezones/browser_minimonth.js @@ -0,0 +1,215 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * Tests the minimonth widget in a range of time zones. It will fail if the + * widget loses time zone awareness. + */ + +/* eslint-disable no-restricted-syntax */ + +var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm"); +var { CalendarTestUtils } = ChromeUtils.import( + "resource://testing-common/calendar/CalendarTestUtils.jsm" +); + +add_setup(async function () { + await CalendarTestUtils.openCalendarTab(window); +}); + +registerCleanupFunction(async function () { + await CalendarTestUtils.closeCalendarTab(window); + Services.prefs.setStringPref("calendar.timezone.local", "UTC"); +}); + +async function subtest() { + let zone = cal.dtz.defaultTimezone; + info(`Running test in ${zone.tzid}`); + + // Set the minimonth to display August 2016. + let minimonth = document.getElementById("calMinimonth"); + minimonth.showMonth(new Date(2016, 7, 15)); + + Assert.deepEqual( + [...minimonth.dayBoxes.keys()], + [ + "2016-07-31", + "2016-08-01", + "2016-08-02", + "2016-08-03", + "2016-08-04", + "2016-08-05", + "2016-08-06", + "2016-08-07", + "2016-08-08", + "2016-08-09", + "2016-08-10", + "2016-08-11", + "2016-08-12", + "2016-08-13", + "2016-08-14", + "2016-08-15", + "2016-08-16", + "2016-08-17", + "2016-08-18", + "2016-08-19", + "2016-08-20", + "2016-08-21", + "2016-08-22", + "2016-08-23", + "2016-08-24", + "2016-08-25", + "2016-08-26", + "2016-08-27", + "2016-08-28", + "2016-08-29", + "2016-08-30", + "2016-08-31", + "2016-09-01", + "2016-09-02", + "2016-09-03", + "2016-09-04", + "2016-09-05", + "2016-09-06", + "2016-09-07", + "2016-09-08", + "2016-09-09", + "2016-09-10", + ], + "day boxes are stored with the correct keys" + ); + + function check(date, row, column) { + if (date instanceof Date) { + info(date); + } else { + info(`${date} ${date.timezone.tzid}`); + } + if (row && column) { + Assert.equal(minimonth.getBoxForDate(date), minimonth.mCalBox.rows[row].cells[column]); + } else { + Assert.equal(minimonth.getBoxForDate(date), null); + } + } + + let dateWithZone = cal.createDateTime(); + + // Dates without timezones or the local timezone. + + // All of these represent the 1st of August. + check(new Date(2016, 7, 1), 1, 2); + check(new Date(2016, 7, 1, 9, 0, 0), 1, 2); + check(new Date(2016, 7, 1, 22, 0, 0), 1, 2); + + check(cal.createDateTime("20160801"), 1, 2); + check(cal.createDateTime("20160801T030000"), 1, 2); + check(cal.createDateTime("20160801T210000"), 1, 2); + + dateWithZone.resetTo(2016, 7, 1, 3, 0, 0, zone); + check(dateWithZone, 1, 2); + dateWithZone.resetTo(2016, 7, 1, 21, 0, 0, zone); + check(dateWithZone, 1, 2); + + // All of these represent the 31st of August. + check(new Date(2016, 7, 31), 5, 4); + check(new Date(2016, 7, 31, 9, 0, 0), 5, 4); + check(new Date(2016, 7, 31, 22, 0, 0), 5, 4); + + check(cal.createDateTime("20160831"), 5, 4); + check(cal.createDateTime("20160831T030000"), 5, 4); + check(cal.createDateTime("20160831T210000"), 5, 4); + + dateWithZone.resetTo(2016, 7, 31, 3, 0, 0, zone); + check(dateWithZone, 5, 4); + dateWithZone.resetTo(2016, 7, 31, 21, 0, 0, zone); + check(dateWithZone, 5, 4); + + // August a year earlier shouldn't be displayed. + check(new Date(2015, 7, 15)); + check(cal.createDateTime("20150815")); + dateWithZone.resetTo(2015, 7, 15, 0, 0, 0, zone); + check(dateWithZone); + + // The Saturday of the previous week shouldn't be displayed. + check(new Date(2016, 6, 30)); + check(cal.createDateTime("20160730")); + dateWithZone.resetTo(2016, 6, 30, 0, 0, 0, zone); + check(dateWithZone); + + // The Sunday of the next week shouldn't be displayed. + check(new Date(2016, 8, 11)); + check(cal.createDateTime("20160911")); + dateWithZone.resetTo(2016, 8, 11, 0, 0, 0, zone); + check(dateWithZone); + + // August a year later shouldn't be displayed. + check(new Date(2017, 7, 15)); + check(cal.createDateTime("20170815")); + dateWithZone.resetTo(2017, 7, 15, 0, 0, 0, zone); + check(dateWithZone); + + // UTC dates. + + check(cal.createDateTime("20160801T030000Z"), 1, zone.tzid == "America/Vancouver" ? 1 : 2); + check(cal.createDateTime("20160801T210000Z"), 1, zone.tzid == "Pacific/Auckland" ? 3 : 2); + + check(cal.createDateTime("20160831T030000Z"), 5, zone.tzid == "America/Vancouver" ? 3 : 4); + check(cal.createDateTime("20160831T210000Z"), 5, zone.tzid == "Pacific/Auckland" ? 5 : 4); + + // Dates in different zones. + + let auckland = cal.timezoneService.getTimezone("Pacific/Auckland"); + let vancouver = cal.timezoneService.getTimezone("America/Vancouver"); + + // Early in Auckland is the previous day everywhere else. + dateWithZone.resetTo(2016, 7, 15, 3, 0, 0, auckland); + check(dateWithZone, 3, zone.tzid == "Pacific/Auckland" ? 2 : 1); + + // Late in Auckland is the same day everywhere. + dateWithZone.resetTo(2016, 7, 15, 21, 0, 0, auckland); + check(dateWithZone, 3, 2); + + // Early in Vancouver is the same day everywhere. + dateWithZone.resetTo(2016, 7, 15, 3, 0, 0, vancouver); + check(dateWithZone, 3, 2); + + // Late in Vancouver is the next day everywhere else. + dateWithZone.resetTo(2016, 7, 15, 21, 0, 0, vancouver); + check(dateWithZone, 3, zone.tzid == "America/Vancouver" ? 2 : 3); + + // Reset the minimonth to a different month. + minimonth.showMonth(new Date(2016, 9, 15)); +} + +/** + * Run the test at UTC+12. + */ +add_task(async function auckland() { + Services.prefs.setStringPref("calendar.timezone.local", "Pacific/Auckland"); + await subtest(); +}); + +/** + * Run the test at UTC+2. + */ +add_task(async function berlin() { + Services.prefs.setStringPref("calendar.timezone.local", "Europe/Berlin"); + await subtest(); +}); + +/** + * Run the test at UTC. + */ +add_task(async function utc() { + Services.prefs.setStringPref("calendar.timezone.local", "UTC"); + await subtest(); +}); + +/** + * Run the test at UTC-7. + */ +add_task(async function vancouver() { + Services.prefs.setStringPref("calendar.timezone.local", "America/Vancouver"); + await subtest(); +}); diff --git a/comm/calendar/test/browser/timezones/browser_timezones.js b/comm/calendar/test/browser/timezones/browser_timezones.js new file mode 100644 index 0000000000..41ce97027a --- /dev/null +++ b/comm/calendar/test/browser/timezones/browser_timezones.js @@ -0,0 +1,867 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +requestLongerTimeout(3); + +var { findEventsInNode } = ChromeUtils.import( + "resource://testing-common/calendar/CalendarUtils.jsm" +); +var { saveAndCloseItemDialog, setData } = ChromeUtils.import( + "resource://testing-common/calendar/ItemEditingHelpers.jsm" +); +var { CalendarTestUtils } = ChromeUtils.import( + "resource://testing-common/calendar/CalendarTestUtils.jsm" +); + +var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm"); + +var DATES = [ + [2009, 1, 1], + [2009, 4, 2], + [2009, 4, 16], + [2009, 4, 30], + [2009, 7, 2], + [2009, 10, 15], + [2009, 10, 29], + [2009, 11, 5], +]; + +var TIMEZONES = [ + "America/St_Johns", + "America/Caracas", // standard time UTC-4:30 from 2007 to 2016 + "America/Phoenix", + "America/Los_Angeles", + "America/Buenos_Aires", // standard time UTC-3, DST UTC-4 from October 2008 to March 2009 + "Europe/Paris", + "Asia/Katmandu", + "Australia/Adelaide", +]; + +const calendarViewsInitialState = CalendarTestUtils.saveCalendarViewsState(window); + +add_setup(async () => { + registerCleanupFunction(async () => { + await CalendarTestUtils.restoreCalendarViewsState(window, calendarViewsInitialState); + Services.prefs.setStringPref("calendar.timezone.local", "UTC"); + }); + + let calendar = CalendarTestUtils.createCalendar(); + registerCleanupFunction(() => { + CalendarTestUtils.removeCalendar(calendar); + }); + + await CalendarTestUtils.setCalendarView(window, "day"); + await CalendarTestUtils.goToDate(window, 2009, 1, 1); + + // Create weekly recurring events in all TIMEZONES. + let times = [ + [4, 30], + [5, 0], + [3, 0], + [3, 0], + [9, 0], + [14, 0], + [19, 45], + [1, 30], + ]; + let time = cal.createDateTime(); + for (let i = 0; i < TIMEZONES.length; i++) { + let eventBox = CalendarTestUtils.dayView.getHourBoxAt(window, i + 11); + let { dialogWindow, iframeWindow } = await CalendarTestUtils.editNewEvent(window, eventBox); + time.hour = times[i][0]; + time.minute = times[i][1]; + + // Set event data. + await setData(dialogWindow, iframeWindow, { + title: TIMEZONES[i], + repeat: "weekly", + repeatuntil: cal.createDateTime("20091231T000000Z"), + starttime: time, + timezone: TIMEZONES[i], + }); + + await saveAndCloseItemDialog(dialogWindow); + } +}); + +add_task(async function testTimezones3_checkStJohns() { + Services.prefs.setStringPref("calendar.timezone.local", "America/St_Johns"); + let times = [ + [ + [4, 30], + [6, 0], + [6, 30], + [7, 30], + [7, 30], + [9, 30], + [10, 30], + [11, 30], + ], + [ + [4, 30], + [7, 0], + [7, 30], + [7, 30], + [9, 30], + [9, 30], + [11, 30], + [12, 30], + ], + [ + [4, 30], + [7, 0], + [7, 30], + [7, 30], + [9, 30], + [9, 30], + [11, 30], + [13, 30], + ], + [ + [4, 30], + [7, 0], + [7, 30], + [7, 30], + [9, 30], + [9, 30], + [11, 30], + [13, 30], + ], + [ + [4, 30], + [7, 0], + [7, 30], + [7, 30], + [9, 30], + [9, 30], + [11, 30], + [13, 30], + ], + [ + [4, 30], + [7, 0], + [7, 30], + [7, 30], + [9, 30], + [9, 30], + [11, 30], + [12, 30], + ], + [ + [4, 30], + [7, 0], + [7, 30], + [7, 30], + [9, 30], + [10, 30], + [11, 30], + [12, 30], + ], + [ + [4, 30], + [6, 0], + [6, 30], + [7, 30], + [8, 30], + [9, 30], + [10, 30], + [11, 30], + ], + ]; + EventUtils.synthesizeMouseAtCenter(document.getElementById("calendarButton"), {}, window); + await CalendarTestUtils.setCalendarView(window, "day"); + await CalendarTestUtils.goToDate(window, 2009, 1, 1); + + await verify(DATES, TIMEZONES, times); +}); + +add_task(async function testTimezones4_checkCaracas() { + Services.prefs.setStringPref("calendar.timezone.local", "America/Caracas"); + let times = [ + [ + [3, 30], + [5, 0], + [5, 30], + [6, 30], + [6, 30], + [8, 30], + [9, 30], + [10, 30], + ], + [ + [2, 30], + [5, 0], + [5, 30], + [5, 30], + [7, 30], + [7, 30], + [9, 30], + [10, 30], + ], + [ + [2, 30], + [5, 0], + [5, 30], + [5, 30], + [7, 30], + [7, 30], + [9, 30], + [11, 30], + ], + [ + [2, 30], + [5, 0], + [5, 30], + [5, 30], + [7, 30], + [7, 30], + [9, 30], + [11, 30], + ], + [ + [2, 30], + [5, 0], + [5, 30], + [5, 30], + [7, 30], + [7, 30], + [9, 30], + [11, 30], + ], + [ + [2, 30], + [5, 0], + [5, 30], + [5, 30], + [7, 30], + [7, 30], + [9, 30], + [10, 30], + ], + [ + [2, 30], + [5, 0], + [5, 30], + [5, 30], + [7, 30], + [8, 30], + [9, 30], + [10, 30], + ], + [ + [3, 30], + [5, 0], + [5, 30], + [6, 30], + [7, 30], + [8, 30], + [9, 30], + [10, 30], + ], + ]; + EventUtils.synthesizeMouseAtCenter(document.getElementById("calendarButton"), {}, window); + await CalendarTestUtils.setCalendarView(window, "day"); + await CalendarTestUtils.goToDate(window, 2009, 1, 1); + + await verify(DATES, TIMEZONES, times); +}); + +add_task(async function testTimezones5_checkPhoenix() { + Services.prefs.setStringPref("calendar.timezone.local", "America/Phoenix"); + let times = [ + [ + [1, 0], + [2, 30], + [3, 0], + [4, 0], + [4, 0], + [6, 0], + [7, 0], + [8, 0], + ], + [ + [0, 0], + [2, 30], + [3, 0], + [3, 0], + [5, 0], + [5, 0], + [7, 0], + [8, 0], + ], + [ + [0, 0], + [2, 30], + [3, 0], + [3, 0], + [5, 0], + [5, 0], + [7, 0], + [9, 0], + ], + [ + [0, 0], + [2, 30], + [3, 0], + [3, 0], + [5, 0], + [5, 0], + [7, 0], + [9, 0], + ], + [ + [0, 0], + [2, 30], + [3, 0], + [3, 0], + [5, 0], + [5, 0], + [7, 0], + [9, 0], + ], + [ + [0, 0], + [2, 30], + [3, 0], + [3, 0], + [5, 0], + [5, 0], + [7, 0], + [8, 0], + ], + [ + [0, 0], + [2, 30], + [3, 0], + [3, 0], + [5, 0], + [6, 0], + [7, 0], + [8, 0], + ], + [ + [1, 0], + [2, 30], + [3, 0], + [4, 0], + [5, 0], + [6, 0], + [7, 0], + [8, 0], + ], + ]; + EventUtils.synthesizeMouseAtCenter(document.getElementById("calendarButton"), {}, window); + await CalendarTestUtils.setCalendarView(window, "day"); + await CalendarTestUtils.goToDate(window, 2009, 1, 1); + + await verify(DATES, TIMEZONES, times); +}); + +add_task(async function testTimezones6_checkLosAngeles() { + Services.prefs.setStringPref("calendar.timezone.local", "America/Los_Angeles"); + let times = [ + [ + [0, 0], + [1, 30], + [2, 0], + [3, 0], + [3, 0], + [5, 0], + [6, 0], + [7, 0], + ], + [ + [0, 0], + [2, 30], + [3, 0], + [3, 0], + [5, 0], + [5, 0], + [7, 0], + [8, 0], + ], + [ + [0, 0], + [2, 30], + [3, 0], + [3, 0], + [5, 0], + [5, 0], + [7, 0], + [9, 0], + ], + [ + [0, 0], + [2, 30], + [3, 0], + [3, 0], + [5, 0], + [5, 0], + [7, 0], + [9, 0], + ], + [ + [0, 0], + [2, 30], + [3, 0], + [3, 0], + [5, 0], + [5, 0], + [7, 0], + [9, 0], + ], + [ + [0, 0], + [2, 30], + [3, 0], + [3, 0], + [5, 0], + [5, 0], + [7, 0], + [8, 0], + ], + [ + [0, 0], + [2, 30], + [3, 0], + [3, 0], + [5, 0], + [6, 0], + [7, 0], + [8, 0], + ], + [ + [0, 0], + [1, 30], + [2, 0], + [3, 0], + [4, 0], + [5, 0], + [6, 0], + [7, 0], + ], + ]; + EventUtils.synthesizeMouseAtCenter(document.getElementById("calendarButton"), {}, window); + await CalendarTestUtils.setCalendarView(window, "day"); + await CalendarTestUtils.goToDate(window, 2009, 1, 1); + + await verify(DATES, TIMEZONES, times); +}); + +add_task(async function testTimezones7_checkBuenosAires() { + Services.prefs.setStringPref("calendar.timezone.local", "America/Argentina/Buenos_Aires"); + let times = [ + [ + [6, 0], + [7, 30], + [8, 0], + [9, 0], + [9, 0], + [11, 0], + [12, 0], + [13, 0], + ], + [ + [4, 0], + [6, 30], + [7, 0], + [7, 0], + [9, 0], + [9, 0], + [11, 0], + [12, 0], + ], + [ + [4, 0], + [6, 30], + [7, 0], + [7, 0], + [9, 0], + [9, 0], + [11, 0], + [13, 0], + ], + [ + [4, 0], + [6, 30], + [7, 0], + [7, 0], + [9, 0], + [9, 0], + [11, 0], + [13, 0], + ], + [ + [4, 0], + [6, 30], + [7, 0], + [7, 0], + [9, 0], + [9, 0], + [11, 0], + [13, 0], + ], + [ + [4, 0], + [6, 30], + [7, 0], + [7, 0], + [9, 0], + [9, 0], + [11, 0], + [12, 0], + ], + [ + [4, 0], + [6, 30], + [7, 0], + [7, 0], + [9, 0], + [10, 0], + [11, 0], + [12, 0], + ], + [ + [5, 0], + [6, 30], + [7, 0], + [8, 0], + [9, 0], + [10, 0], + [11, 0], + [12, 0], + ], + ]; + EventUtils.synthesizeMouseAtCenter(document.getElementById("calendarButton"), {}, window); + await CalendarTestUtils.setCalendarView(window, "day"); + await CalendarTestUtils.goToDate(window, 2009, 1, 1); + + await verify(DATES, TIMEZONES, times); +}); + +add_task(async function testTimezones8_checkParis() { + Services.prefs.setStringPref("calendar.timezone.local", "Europe/Paris"); + let times = [ + [ + [9, 0], + [10, 30], + [11, 0], + [12, 0], + [12, 0], + [14, 0], + [15, 0], + [16, 0], + ], + [ + [9, 0], + [11, 30], + [12, 0], + [12, 0], + [14, 0], + [14, 0], + [16, 0], + [17, 0], + ], + [ + [9, 0], + [11, 30], + [12, 0], + [12, 0], + [14, 0], + [14, 0], + [16, 0], + [18, 0], + ], + [ + [9, 0], + [11, 30], + [12, 0], + [12, 0], + [14, 0], + [14, 0], + [16, 0], + [18, 0], + ], + [ + [9, 0], + [11, 30], + [12, 0], + [12, 0], + [14, 0], + [14, 0], + [16, 0], + [18, 0], + ], + [ + [9, 0], + [11, 30], + [12, 0], + [12, 0], + [14, 0], + [14, 0], + [16, 0], + [17, 0], + ], + [ + [8, 0], + [10, 30], + [11, 0], + [11, 0], + [13, 0], + [14, 0], + [15, 0], + [16, 0], + ], + [ + [9, 0], + [10, 30], + [11, 0], + [12, 0], + [13, 0], + [14, 0], + [15, 0], + [16, 0], + ], + ]; + EventUtils.synthesizeMouseAtCenter(document.getElementById("calendarButton"), {}, window); + await CalendarTestUtils.setCalendarView(window, "day"); + await CalendarTestUtils.goToDate(window, 2009, 1, 1); + + await verify(DATES, TIMEZONES, times); +}); + +add_task(async function testTimezones9_checkKathmandu() { + Services.prefs.setStringPref("calendar.timezone.local", "Asia/Kathmandu"); + let times = [ + [ + [13, 45], + [15, 15], + [15, 45], + [16, 45], + [16, 45], + [18, 45], + [19, 45], + [20, 45], + ], + [ + [12, 45], + [15, 15], + [15, 45], + [15, 45], + [17, 45], + [17, 45], + [19, 45], + [20, 45], + ], + [ + [12, 45], + [15, 15], + [15, 45], + [15, 45], + [17, 45], + [17, 45], + [19, 45], + [21, 45], + ], + [ + [12, 45], + [15, 15], + [15, 45], + [15, 45], + [17, 45], + [17, 45], + [19, 45], + [21, 45], + ], + [ + [12, 45], + [15, 15], + [15, 45], + [15, 45], + [17, 45], + [17, 45], + [19, 45], + [21, 45], + ], + [ + [12, 45], + [15, 15], + [15, 45], + [15, 45], + [17, 45], + [17, 45], + [19, 45], + [20, 45], + ], + [ + [12, 45], + [15, 15], + [15, 45], + [15, 45], + [17, 45], + [18, 45], + [19, 45], + [20, 45], + ], + [ + [13, 45], + [15, 15], + [15, 45], + [16, 45], + [17, 45], + [18, 45], + [19, 45], + [20, 45], + ], + ]; + EventUtils.synthesizeMouseAtCenter(document.getElementById("calendarButton"), {}, window); + await CalendarTestUtils.setCalendarView(window, "day"); + await CalendarTestUtils.goToDate(window, 2009, 1, 1); + + await verify(DATES, TIMEZONES, times); +}); + +add_task(async function testTimezones10_checkAdelaide() { + Services.prefs.setStringPref("calendar.timezone.local", "Australia/Adelaide"); + let times = [ + [ + [18, 30], + [20, 0], + [20, 30], + [21, 30], + [21, 30], + [23, 30], + [0, 30, +1], + [1, 30, +1], + ], + [ + [17, 30], + [20, 0], + [20, 30], + [20, 30], + [22, 30], + [22, 30], + [0, 30, +1], + [1, 30, +1], + ], + [ + [16, 30], + [19, 0], + [19, 30], + [19, 30], + [21, 30], + [21, 30], + [23, 30], + [1, 30, +1], + ], + [ + [16, 30], + [19, 0], + [19, 30], + [19, 30], + [21, 30], + [21, 30], + [23, 30], + [1, 30, +1], + ], + [ + [16, 30], + [19, 0], + [19, 30], + [19, 30], + [21, 30], + [21, 30], + [23, 30], + [1, 30, +1], + ], + [ + [17, 30], + [20, 0], + [20, 30], + [20, 30], + [22, 30], + [22, 30], + [0, 30, +1], + [1, 30, +1], + ], + [ + [17, 30], + [20, 0], + [20, 30], + [20, 30], + [22, 30], + [23, 30], + [0, 30, +1], + [1, 30, +1], + ], + [ + [18, 30], + [20, 0], + [20, 30], + [21, 30], + [22, 30], + [23, 30], + [0, 30, +1], + [1, 30, +1], + ], + ]; + EventUtils.synthesizeMouseAtCenter(document.getElementById("calendarButton"), {}, window); + await CalendarTestUtils.setCalendarView(window, "day"); + await CalendarTestUtils.goToDate(window, 2009, 1, 1); + + await verify(DATES, TIMEZONES, times); +}); + +async function verify(dates, timezones, times) { + function* datetimes() { + for (let idx = 0; idx < dates.length; idx++) { + yield [dates[idx][0], dates[idx][1], dates[idx][2], times[idx]]; + } + } + let allowedDifference = 3; + + for (let [selectedYear, selectedMonth, selectedDay, selectedTime] of datetimes()) { + info(`Verifying on day ${selectedDay}, month ${selectedMonth}, year ${selectedYear}`); + await CalendarTestUtils.goToDate(window, selectedYear, selectedMonth, selectedDay); + + // Find event with timezone tz. + for (let tzIdx = 0; tzIdx < timezones.length; tzIdx++) { + let [hour, minutes, day] = selectedTime[tzIdx]; + info( + `Verifying at ${hour} hours, ${minutes} minutes (offset: ${day || "none"}) ` + + `in timezone "${timezones[tzIdx]}"` + ); + + // following day + if (day == 1) { + await CalendarTestUtils.calendarViewForward(window, 1); + } else if (day == -1) { + await CalendarTestUtils.calendarViewBackward(window, 1); + } + + let hourRect = CalendarTestUtils.dayView.getHourBoxAt(window, hour).getBoundingClientRect(); + let timeY = hourRect.y + hourRect.height * (minutes / 60); + + // Wait for at least one event box to exist. + await CalendarTestUtils.dayView.waitForEventBoxAt(window, 1); + + let eventPositions = Array.from(CalendarTestUtils.dayView.getEventBoxes(window)) + .filter(node => node.mOccurrence.title == timezones[tzIdx]) + .map(node => node.getBoundingClientRect().y); + + dump(`Looking for event at ${timeY}: found ${eventPositions.join(", ")}\n`); + + if (day == 1) { + await CalendarTestUtils.calendarViewBackward(window, 1); + } else if (day == -1) { + await CalendarTestUtils.calendarViewForward(window, 1); + } + + Assert.ok( + eventPositions.some(pos => Math.abs(timeY - pos) < allowedDifference), + `There should be an event box that starts at ${hour} hours, ${minutes} minutes` + ); + } + } +} |