diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mailnews/mime/test/unit/test_mimeStreaming.js | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/mailnews/mime/test/unit/test_mimeStreaming.js')
-rw-r--r-- | comm/mailnews/mime/test/unit/test_mimeStreaming.js | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/comm/mailnews/mime/test/unit/test_mimeStreaming.js b/comm/mailnews/mime/test/unit/test_mimeStreaming.js new file mode 100644 index 0000000000..3e82fe51db --- /dev/null +++ b/comm/mailnews/mime/test/unit/test_mimeStreaming.js @@ -0,0 +1,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/. */ + +/** + * This test iterates over the test files in gTestFiles, and streams + * each as a message and makes sure the streaming doesn't assert or crash. + */ +const { localAccountUtils } = ChromeUtils.import( + "resource://testing-common/mailnews/LocalAccountUtils.jsm" +); + +var gTestFiles = ["../../../data/bug505221", "../../../data/bug513543"]; + +var gMessages; + +var gMessenger = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger); + +var gUrlListener = { + OnStartRunningUrl(aUrl) {}, + OnStopRunningUrl(aUrl, aExitCode) { + do_test_finished(); + }, +}; + +localAccountUtils.loadLocalMailAccount(); + +add_task(async function run_the_test() { + do_test_pending(); + localAccountUtils.inboxFolder.QueryInterface(Ci.nsIMsgLocalMailFolder); + for (let fileName of gTestFiles) { + localAccountUtils.inboxFolder.addMessage( + await IOUtils.readUTF8(do_get_file(fileName).path) + ); + } + gMessages = [ + ...localAccountUtils.inboxFolder.msgDatabase.enumerateMessages(), + ]; + doNextTest(); +}); + +function streamMsg(msgHdr) { + let msgURI = localAccountUtils.inboxFolder.getUriForMsg(msgHdr); + let msgService = MailServices.messageServiceFromURI(msgURI); + msgService.streamMessage( + msgURI, + gStreamListener, + null, + gUrlListener, + true, // have them create the converter + // additional uri payload, note that "header=" is prepended automatically + "filter", + true + ); +} + +var gStreamListener = { + QueryInterface: ChromeUtils.generateQI(["nsIStreamListener"]), + _stream: null, + // nsIRequestObserver part + onStartRequest(aRequest) {}, + onStopRequest(aRequest, aStatusCode) { + doNextTest(); + }, + + /* okay, our onDataAvailable should actually never be called. the stream + converter is actually eating everything except the start and stop + notification. */ + // nsIStreamListener part + onDataAvailable(aRequest, aInputStream, aOffset, aCount) { + if (this._stream === null) { + this._stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance( + Ci.nsIScriptableInputStream + ); + this._stream.init(aInputStream); + } + this._stream.read(aCount); + }, +}; + +function doNextTest() { + if (gMessages.length > 0) { + let msgHdr = gMessages.shift(); + streamMsg(msgHdr); + } else { + do_test_finished(); + } +} |