summaryrefslogtreecommitdiffstats
path: root/comm/calendar/test/browser/eventDialog/browser_alarmDialog.js
blob: 0d6a07a3c47789d1588045adc0fd66460b092f85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* 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/. */

var { saveAndCloseItemDialog, setData } = ChromeUtils.import(
  "resource://testing-common/calendar/ItemEditingHelpers.jsm"
);

var { dayView } = CalendarTestUtils;

add_task(async function testAlarmDialog() {
  let now = new Date();

  const TITLE = "Event";

  let calendar = CalendarTestUtils.createCalendar();
  registerCleanupFunction(() => {
    CalendarTestUtils.removeCalendar(calendar);
  });

  await CalendarTestUtils.setCalendarView(window, "day");
  await CalendarTestUtils.goToDate(
    window,
    now.getUTCFullYear(),
    now.getUTCMonth() + 1,
    now.getUTCDate()
  );
  await CalendarTestUtils.calendarViewForward(window, 1);

  let allDayHeader = dayView.getAllDayHeader(window);
  Assert.ok(allDayHeader);
  EventUtils.synthesizeMouseAtCenter(allDayHeader, {}, window);

  // Create a new all-day event tomorrow.

  // Prepare to dismiss the alarm.
  let alarmPromise = BrowserTestUtils.promiseAlertDialog(
    null,
    "chrome://calendar/content/calendar-alarm-dialog.xhtml",
    {
      async callback(alarmWindow) {
        await new Promise(resolve => alarmWindow.setTimeout(resolve, 500));

        let dismissButton = alarmWindow.document.getElementById("alarm-dismiss-all-button");
        EventUtils.synthesizeMouseAtCenter(dismissButton, {}, alarmWindow);
      },
    }
  );
  let { dialogWindow, iframeWindow } = await CalendarTestUtils.editNewEvent(window);
  await setData(dialogWindow, iframeWindow, {
    allday: true,
    reminder: "1day",
    title: TITLE,
  });

  await saveAndCloseItemDialog(dialogWindow);
  await alarmPromise;

  // Change the reminder duration, this resets the alarm.
  let eventBox = await dayView.waitForAllDayItemAt(window, 1);

  // Prepare to snooze the alarm.
  alarmPromise = BrowserTestUtils.promiseAlertDialog(
    null,
    "chrome://calendar/content/calendar-alarm-dialog.xhtml",
    {
      async callback(alarmWindow) {
        await new Promise(resolve => alarmWindow.setTimeout(resolve, 500));

        let snoozeAllButton = alarmWindow.document.getElementById("alarm-snooze-all-button");
        let popup = alarmWindow.document.querySelector("#alarm-snooze-all-popup");
        let menuitems = alarmWindow.document.querySelectorAll("#alarm-snooze-all-popup > menuitem");

        let shownPromise = BrowserTestUtils.waitForEvent(snoozeAllButton, "popupshown");
        EventUtils.synthesizeMouseAtCenter(snoozeAllButton, {}, alarmWindow);
        await shownPromise;
        popup.activateItem(menuitems[5]);
      },
    }
  );

  ({ dialogWindow, iframeWindow } = await CalendarTestUtils.editItem(window, eventBox));
  await setData(dialogWindow, iframeWindow, { reminder: "2days", title: TITLE });
  await saveAndCloseItemDialog(dialogWindow);
  await alarmPromise;

  Assert.ok(true, "Test ran to completion");
});