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/news/test/unit/test_nntpContentLength.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/news/test/unit/test_nntpContentLength.js')
-rw-r--r-- | comm/mailnews/news/test/unit/test_nntpContentLength.js | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/comm/mailnews/news/test/unit/test_nntpContentLength.js b/comm/mailnews/news/test/unit/test_nntpContentLength.js new file mode 100644 index 0000000000..f9f780011d --- /dev/null +++ b/comm/mailnews/news/test/unit/test_nntpContentLength.js @@ -0,0 +1,80 @@ +/* -*- 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 news protocol. This focuses on necko URLs + * that are run externally. + */ + +// The basic daemon to use for testing Nntpd.jsm implementations +var daemon = setupNNTPDaemon(); + +var server; +var localserver; + +function run_test() { + server = makeServer(NNTP_RFC977_handler, daemon); + server.start(); + localserver = setupLocalServer(server.port); + + try { + // Get the folder and new mail + let folder = localserver.rootFolder.getChildNamed("test.subscribe.simple"); + folder.clearFlag(Ci.nsMsgFolderFlags.Offline); + folder.getNewMessages(null, { + OnStopRunningUrl() { + localserver.closeCachedConnections(); + }, + }); + server.performTest(); + + Assert.equal(folder.getTotalMessages(false), 1); + Assert.ok(folder.hasNewMessages); + + server.resetTest(); + + // Get the message URI + let msgHdr = folder.firstNewMessage; + let messageUri = folder.getUriForMsg(msgHdr); + // Convert this to a URI that necko can run + let messageService = MailServices.messageServiceFromURI(messageUri); + let neckoURL = messageService.getUrlForUri(messageUri); + // Don't use the necko URL directly. Instead, get the spec and create a new + // URL using the IO service + let urlToRun = Services.io.newURI(neckoURL.spec); + + // Get a channel from this URI, and check its content length + let channel = Services.io.newChannelFromURI( + urlToRun, + null, + Services.scriptSecurityManager.getSystemPrincipal(), + null, + Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL, + Ci.nsIContentPolicy.TYPE_OTHER + ); + Assert.equal(channel.contentLength, kSimpleNewsArticle.length); + + // Now try an attachment. &part=1.2 + // XXX the message doesn't really have an attachment + let attachmentURL = Services.io.newURI(neckoURL.spec + "&part=1.2"); + 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 + Assert.equal(channel.contentLength, kSimpleNewsArticle.length); + } catch (e) { + server.stop(); + do_throw(e); + } +} |