summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/mime/test/unit/test_mimeStreaming.js
diff options
context:
space:
mode:
Diffstat (limited to 'comm/mailnews/mime/test/unit/test_mimeStreaming.js')
-rw-r--r--comm/mailnews/mime/test/unit/test_mimeStreaming.js88
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();
+ }
+}