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/. */
/**
* Tests that a load of the displayed message in a frame of its own content
* isn't handled as the load of the message pane, which would process the
* headers again and clear the displayed message.
*/
"use strict";
const about3Pane = document.getElementById("tabmail").currentAbout3Pane;
let testFolder;
add_setup(async () => {
const account = MailServices.accounts.createLocalMailAccount();
const rootFolder = account.incomingServer.rootFolder.QueryInterface(
Ci.nsIMsgLocalMailFolder
);
testFolder = rootFolder
.createLocalSubfolder("nestedLoad")
.QueryInterface(Ci.nsIMsgLocalMailFolder);
registerCleanupFunction(() => {
MailServices.accounts.removeAccount(account, false);
});
});
add_task(async function test_nestedLoadOfDisplayedMessage() {
// The first message in a new folder gets key 1, so the message can refer to
// its own URL.
const messageURI = testFolder.generateMessageURI(1);
const messageURL = MailServices.messageServiceFromURI(messageURI)
.getUrlForUri(messageURI)
.spec.replaceAll("&", "&");
testFolder.addMessage(
[
"From - Mon Jan 01 00:00:00 2024",
"From: sender@example.invalid",
"To: recipient@example.invalid",
"Subject: Nested load",
"Date: Mon, 01 Jan 2024 00:00:00 +0000",
"Message-ID: <nested-load@example.invalid>",
"MIME-Version: 1.0",
"Content-Type: text/html; charset=UTF-8",
"",
`<html><body><p id="content">Content</p>`,
`<iframe src="${messageURL}"></iframe>`,
`</body></html>`,
"",
].join("\r\n")
);
const message = [...testFolder.messages][0];
Assert.equal(
message.folder.getUriForMsg(message),
messageURI,
"the message should have the URI it refers to"
);
about3Pane.restoreState({
folderURI: testFolder.URI,
messagePaneVisible: true,
});
const aboutMessage = about3Pane.messageBrowser.contentWindow;
const { messageProgressListener } = aboutMessage;
const originalOnStartHeaders = messageProgressListener.onStartHeaders;
let startHeadersCount = 0;
messageProgressListener.onStartHeaders = function () {
startHeadersCount++;
return originalOnStartHeaders.call(this);
};
try {
about3Pane.threadTree.selectedIndex = 0;
await messageLoadedIn(about3Pane.messageBrowser);
const doc = aboutMessage.getMessagePaneBrowser().contentDocument;
await TestUtils.waitForCondition(
() =>
startHeadersCount > 1 ||
doc.querySelector("iframe")?.contentDocument?.getElementById("content"),
"waiting for the nested load of the message"
);
Assert.equal(
startHeadersCount,
1,
"only the load of the message pane should be handled"
);
Assert.ok(
doc.getElementById("content"),
"the displayed message should not have been cleared"
);
} finally {
messageProgressListener.onStartHeaders = originalOnStartHeaders;
}
about3Pane.threadTree.selectedIndex = -1;
});