From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../compose/test/unit/test_createRFC822Message.js | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 comm/mailnews/compose/test/unit/test_createRFC822Message.js (limited to 'comm/mailnews/compose/test/unit/test_createRFC822Message.js') diff --git a/comm/mailnews/compose/test/unit/test_createRFC822Message.js b/comm/mailnews/compose/test/unit/test_createRFC822Message.js new file mode 100644 index 0000000000..9502031484 --- /dev/null +++ b/comm/mailnews/compose/test/unit/test_createRFC822Message.js @@ -0,0 +1,68 @@ +/* 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 createRFC822Message creates a mail file. + */ + +var { MailUtils } = ChromeUtils.import("resource:///modules/MailUtils.jsm"); + +let customSendListener = { + ...copyListener, + OnStopCopy() {}, + + /** + * Test a mail file is created and has correct content. + */ + async onStopSending(msgId, status, msg, returnFile) { + ok(returnFile.exists(), "createRFC822Message should create a mail file"); + let content = await IOUtils.read(returnFile.path); + content = String.fromCharCode(...content); + ok( + content.includes("Subject: Test createRFC822Message\r\n"), + "Mail file should contain correct subject line" + ); + ok( + content.includes( + "createRFC822Message is used by nsImportService \xe4\xe9" + ), + "Mail file should contain correct body" + ); + do_test_finished(); + }, +}; + +/** + * Call createRFC822Message, expect onStopSending to be called. + */ +add_task(async function testCreateRFC822Message() { + let identity = getSmtpIdentity( + "from@tinderbox.invalid", + getBasicSmtpServer() + ); + + let fields = Cc[ + "@mozilla.org/messengercompose/composefields;1" + ].createInstance(Ci.nsIMsgCompFields); + fields.from = "Somebody "; + fields.to = "Nobody "; + fields.subject = "Test createRFC822Message"; + + let msgSend = Cc["@mozilla.org/messengercompose/send;1"].createInstance( + Ci.nsIMsgSend + ); + msgSend.createRFC822Message( + identity, + fields, + "text/plain", + // The following parameter is the message body that can contain arbitrary + // binary data, let's try some windows-1252 data (äé). + "createRFC822Message is used by nsImportService \xe4\xe9", + true, // isDraft + [], + [], + customSendListener + ); + do_test_pending(); +}); -- cgit v1.2.3