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 --- comm/mailnews/imap/test/unit/test_chunkLastLF.js | 108 +++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 comm/mailnews/imap/test/unit/test_chunkLastLF.js (limited to 'comm/mailnews/imap/test/unit/test_chunkLastLF.js') diff --git a/comm/mailnews/imap/test/unit/test_chunkLastLF.js b/comm/mailnews/imap/test/unit/test_chunkLastLF.js new file mode 100644 index 0000000000..003320ad2d --- /dev/null +++ b/comm/mailnews/imap/test/unit/test_chunkLastLF.js @@ -0,0 +1,108 @@ +/* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + * + * ***** END LICENSE BLOCK ***** */ + +/* + * Test content length for the IMAP protocol. This focuses on necko URLs + * that are run externally. + */ + +var { PromiseTestUtils } = ChromeUtils.import( + "resource://testing-common/mailnews/PromiseTestUtils.jsm" +); + +var gFile = do_get_file("../../../data/bug92111b"); +var gIMAPDaemon, gIMAPServer, gIMAPIncomingServer; + +// Adds some messages directly to a mailbox (eg new mail) +function addMessageToServer(file, mailbox) { + let URI = Services.io.newFileURI(file).QueryInterface(Ci.nsIFileURL); + let msg = new ImapMessage(URI.spec, mailbox.uidnext++, []); + // underestimate the actual file size, like some IMAP servers do + msg.setSize(file.fileSize - 55); + mailbox.addMessage(msg); +} + +add_task(async function verifyContentLength() { + // Disable new mail notifications + Services.prefs.setBoolPref("mail.biff.play_sound", false); + Services.prefs.setBoolPref("mail.biff.show_alert", false); + Services.prefs.setBoolPref("mail.biff.show_tray_icon", false); + Services.prefs.setBoolPref("mail.biff.animate_dock_icon", false); + Services.prefs.setBoolPref( + "mail.server.server1.autosync_offline_stores", + false + ); + + // Crank down the message chunk size to make test cases easier + Services.prefs.setBoolPref("mail.server.default.fetch_by_chunks", true); + Services.prefs.setIntPref("mail.imap.chunk_size", 1000); + Services.prefs.setIntPref("mail.imap.min_chunk_size_threshold", 1500); + Services.prefs.setIntPref("mail.imap.chunk_add", 0); + + // set up IMAP fakeserver and incoming server + gIMAPDaemon = new ImapDaemon(); + gIMAPServer = makeServer(gIMAPDaemon, ""); + gIMAPIncomingServer = createLocalIMAPServer(gIMAPServer.port); + + // The server doesn't support more than one connection + Services.prefs.setIntPref("mail.server.server1.max_cached_connections", 1); + // We aren't interested in downloading messages automatically + Services.prefs.setBoolPref("mail.server.server1.download_on_biff", false); + + dump("adding message to server\n"); + // Add a message to the IMAP server + addMessageToServer(gFile, gIMAPDaemon.getMailbox("INBOX")); + + let imapS = Cc[ + "@mozilla.org/messenger/messageservice;1?type=imap" + ].getService(Ci.nsIMsgMessageService); + + let uri = imapS.getUrlForUri("imap-message://user@localhost/INBOX#1"); + + // Get a channel from this URI, and check its content length + let channel = Services.io.newChannelFromURI( + uri, + null, + Services.scriptSecurityManager.getSystemPrincipal(), + null, + Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL, + Ci.nsIContentPolicy.TYPE_OTHER + ); + + let promiseStreamListener = new PromiseTestUtils.PromiseStreamListener(); + + // Read all the contents + channel.asyncOpen(promiseStreamListener, null); + let streamData = (await promiseStreamListener.promise).replace(/\r\n/g, "\n"); + + // Now check whether our stream listener got the right bytes + // First, clean up line endings to avoid CRLF vs. LF differences + let origData = (await IOUtils.readUTF8(gFile.path)).replace(/\r\n/g, "\n"); + Assert.equal(origData.length, streamData.length); + Assert.equal(origData, streamData); + + // Now try an attachment. &part=1.2 + // let attachmentURL = Services.io.newURI(neckoURL.value.spec + "&part=1.2", + // null, null); + // let attachmentChannel = Services.io.newChannelFromURI(attachmentURL, + // null, + // Services.scriptSecurityManager.getSystemPrincipal(), + // null, + // Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL, + // Ci.nsIContentPolicy.TYPE_OTHER); + // Currently attachments have their content length set to the length of the + // entire message + // do_check_eq(attachmentChannel.contentLength, gFile.fileSize); + + gIMAPIncomingServer.closeCachedConnections(); + gIMAPServer.stop(); + let thread = gThreadManager.currentThread; + while (thread.hasPendingEvents()) { + thread.processNextEvent(true); + } +}); -- cgit v1.2.3