Revision control

Copy as Markdown

Other Tools

/* 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) {
const ChromeRegistry = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(
Ci.nsIChromeRegistry
);
const url = Services.io.newURI(getRootDirectory(gTestPath) + leafName);
info(url.spec);
const 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() {
const file = getFileFromChromeURL("data/teams-meeting-invite.eml");
const msgWindow = await openMessageFromFile(file);
const 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).
const 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,
"link0 href"
);
Assert.equal(
links[0].textContent,
"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,
"link2 href"
);
Assert.equal(
links[2].textContent,
"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() {
const file = getFileFromChromeURL("data/meet-meeting-invite.eml");
const msgWindow = await openMessageFromFile(file);
const 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).
const 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,
"link2 href"
);
Assert.equal(
links[3].textContent,
"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() {
const file = getFileFromChromeURL("data/outlook-test-invite.eml");
const msgWindow = await openMessageFromFile(file);
const aboutMessage = msgWindow.document.getElementById("messageBrowser").contentWindow;
await TestUtils.waitForCondition(
() => !aboutMessage.document.getElementById("imip-bar").collapsed
);
info("Ok, iMIP bar is showing");
const 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() {
const file = getFileFromChromeURL("data/message-containing-event.eml");
const msgWindow = await openMessageFromFile(file);
const 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");
});