summaryrefslogtreecommitdiffstats
path: root/comm/calendar/test/browser/invitations/browser_imipBarEmail.js
blob: a3816b65dd5c0ea852e07cbc4a5a8c5978f45495 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* 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/. */

/**
 * Test that the IMIP bar behaves properly for eml files with invites.
 */

/* eslint-disable @microsoft/sdl/no-insecure-url */

function getFileFromChromeURL(leafName) {
  let ChromeRegistry = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIChromeRegistry);

  let url = Services.io.newURI(getRootDirectory(gTestPath) + leafName);
  info(url.spec);
  let fileURL = ChromeRegistry.convertChromeURL(url).QueryInterface(Ci.nsIFileURL);
  return fileURL.file;
}

/**
 * Test that when opening a message containing a Teams meeting invite
 * works as it should.
 */
add_task(async function test_event_from_eml() {
  let file = getFileFromChromeURL("data/teams-meeting-invite.eml");

  let msgWindow = await openMessageFromFile(file);
  let aboutMessage = msgWindow.document.getElementById("messageBrowser").contentWindow;

  await TestUtils.waitForCondition(
    () => !aboutMessage.document.getElementById("imip-bar").collapsed
  );
  info("Ok, iMIP bar is showing");

  // The contentDocument has both the imipHTMLDetails HTML part generated by us,
  // and the regular HTML part generated by the sender (the server).
  let links = [
    ...msgWindow.content.document.getElementById("imipHTMLDetails").querySelectorAll("a"),
  ];

  Assert.equal(links.length, 3, "The 3 links should show");

  // Check the links and their text
  Assert.equal(
    links[0].href,
    "https://teams.microsoft.com/l/meetup-join/19%3ameeting_MGU5NmI2ZGYtOWZmOC00Y2ZmLWJlOTItNjUxNjA5YjUyYTYy%40thread.v2/0?context=%7b%22Tid%22%3a%222fd0c1c5-28e1-40c4-9f0d-a0363ca80a3c%22%2c%22Oid%22%3a%2214464d09-ceb8-458c-a61c-717f1e5c66c5%22%7d",
    "link0 href"
  );
  Assert.equal(
    links[0].textContent,
    "<https://teams.microsoft.com/l/meetup-join/19%3ameeting_MGU5NmI2ZGYtOWZmOC00Y2ZmLWJlOTItNjUxNjA5YjUyYTYy%40thread.v2/0?context=%7b%22Tid%22%3a%222fd0c1c5-28e1-40c4-9f0d-a0363ca80a3c%22%2c%22Oid%22%3a%2214464d09-ceb8-458c-a61c-717f1e5c66c5%22%7d>",
    "link0 textContent"
  );

  Assert.equal(links[1].href, "https://aka.ms/JoinTeamsMeeting", "link1 href");
  Assert.equal(links[1].textContent, "<https://aka.ms/JoinTeamsMeeting>", "link1 textContent");

  Assert.equal(
    links[2].href,
    "https://teams.microsoft.com/meetingOptions/?organizerId=14464d09-ceb8-458c-a61c-717f1e5c66c5&tenantId=2fd0c1c5-28e1-40c4-9f0d-a0363ca80a3c&threadId=19_meeting_MGU5NmI2ZGYtOWZmOC00Y2ZmLWJlOTItNjUxNjA5YjUyYTYy@thread.v2&messageId=0&language=fi-FI",
    "link2 href"
  );
  Assert.equal(
    links[2].textContent,
    "<https://teams.microsoft.com/meetingOptions/?organizerId=14464d09-ceb8-458c-a61c-717f1e5c66c5&tenantId=2fd0c1c5-28e1-40c4-9f0d-a0363ca80a3c&threadId=19_meeting_MGU5NmI2ZGYtOWZmOC00Y2ZmLWJlOTItNjUxNjA5YjUyYTYy@thread.v2&messageId=0&language=fi-FI>",
    "link2 textContent"
  );

  await BrowserTestUtils.closeWindow(msgWindow);

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

/**
 * Test that when opening a message containing a Meet meeting invite
 * works as it should.
 */
add_task(async function test_event_from_eml() {
  let file = getFileFromChromeURL("data/meet-meeting-invite.eml");

  let msgWindow = await openMessageFromFile(file);
  let aboutMessage = msgWindow.document.getElementById("messageBrowser").contentWindow;

  await TestUtils.waitForCondition(
    () => !aboutMessage.document.getElementById("imip-bar").collapsed
  );
  info("Ok, iMIP bar is showing");

  // The contentDocument has both the imipHTMLDetails HTML part generated by us,
  // and the regular HTML part generated by the sender (the server).
  let links = [
    ...msgWindow.content.document.getElementById("imipHTMLDetails").querySelectorAll("a"),
  ];

  Assert.equal(links.length, 4, "The 4 links should show");

  // Check the links and their text
  Assert.equal(links[0].href, "mailto:foo@example.com", "link0 href");
  Assert.equal(links[0].textContent, "<foo@example.com>", "link0 textContent");

  Assert.equal(links[1].href, "http://example.com/?foo=bar", "link1 href");
  Assert.equal(links[1].textContent, "http://example.com?foo=bar", "link1 textContent");

  Assert.equal(links[2].href, "https://meet.google.com/pyb-ndcu-hhc", "link1 href");
  Assert.equal(links[2].textContent, "https://meet.google.com/pyb-ndcu-hhc", "link1 textContent");

  Assert.equal(
    links[3].href,
    "https://calendar.google.com/calendar/event?action=VIEW&eid=NjVtMTdoc2RvbG1vdHYza3ZtcnRnNDBvbnQgbWFnbnVzLm1lbGluQGh1dC5maQ&tok=MjEjYmVydGF0aGVib3RAZ21haWwuY29tZTg2NGFjYmNjYWE1MjVlZWJmY2UzYmRmMDAyNWU0MDkzNDAxZjRhZg&ctz=Europe%2FHelsinki&hl=sv&es=1",
    "link2 href"
  );
  Assert.equal(
    links[3].textContent,
    "https://calendar.google.com/calendar/event?action=VIEW&eid=NjVtMTdoc2RvbG1vdHYza3ZtcnRnNDBvbnQgbWFnbnVzLm1lbGluQGh1dC5maQ&tok=MjEjYmVydGF0aGVib3RAZ21haWwuY29tZTg2NGFjYmNjYWE1MjVlZWJmY2UzYmRmMDAyNWU0MDkzNDAxZjRhZg&ctz=Europe%2FHelsinki&hl=sv&es=1",
    "link2 textContent"
  );

  await BrowserTestUtils.closeWindow(msgWindow);

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

/**
 * Test that when opening a message containing an outlook invite with "empty"
 * content works as it should.
 */
add_task(async function test_outlook_event_from_eml() {
  let file = getFileFromChromeURL("data/outlook-test-invite.eml");

  let msgWindow = await openMessageFromFile(file);
  let aboutMessage = msgWindow.document.getElementById("messageBrowser").contentWindow;

  await TestUtils.waitForCondition(
    () => !aboutMessage.document.getElementById("imip-bar").collapsed
  );
  info("Ok, iMIP bar is showing");

  let details = msgWindow.content.document.getElementById("imipHTMLDetails");

  Assert.equal(
    details.getAttribute("open"),
    "open",
    "Details should be expanded when the message doesn't include good details"
  );

  await BrowserTestUtils.closeWindow(msgWindow);

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

/**
 * Test that when opening a message containing an event, the IMIP bar shows.
 */
add_task(async function test_event_from_eml() {
  let file = getFileFromChromeURL("data/message-containing-event.eml");

  let msgWindow = await openMessageFromFile(file);
  let aboutMessage = msgWindow.document.getElementById("messageBrowser").contentWindow;

  await TestUtils.waitForCondition(
    () => !aboutMessage.document.getElementById("imip-bar").collapsed
  );
  info("Ok, iMIP bar is showing");

  await BrowserTestUtils.closeWindow(msgWindow);

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