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/imap/test/unit/test_downloadOffline.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.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 '')
-rw-r--r-- | comm/mailnews/imap/test/unit/test_downloadOffline.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/comm/mailnews/imap/test/unit/test_downloadOffline.js b/comm/mailnews/imap/test/unit/test_downloadOffline.js new file mode 100644 index 0000000000..931995ee01 --- /dev/null +++ b/comm/mailnews/imap/test/unit/test_downloadOffline.js @@ -0,0 +1,75 @@ +/* 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 to ensure that downloadAllForOffline works correctly with imap folders + * and returns success. + */ + +/* import-globals-from ../../../test/resources/logHelper.js */ +/* import-globals-from ../../../test/resources/MessageGenerator.jsm */ +load("../../../resources/logHelper.js"); +load("../../../resources/MessageGenerator.jsm"); + +var gFileName = "bug460636"; +var gMsgFile = do_get_file("../../../data/" + gFileName); + +var tests = [setup, downloadAllForOffline, verifyDownloaded, teardownIMAPPump]; + +async function setup() { + setupIMAPPump(); + + /* + * Ok, prelude done. Read the original message from disk + * (through a file URI), and add it to the Inbox. + */ + let msgfileuri = Services.io + .newFileURI(gMsgFile) + .QueryInterface(Ci.nsIFileURL); + + IMAPPump.mailbox.addMessage( + new ImapMessage(msgfileuri.spec, IMAPPump.mailbox.uidnext++, []) + ); + + let messages = []; + let gMessageGenerator = new MessageGenerator(); + messages = messages.concat(gMessageGenerator.makeMessage()); + let dataUri = Services.io.newURI( + "data:text/plain;base64," + btoa(messages[0].toMessageString()) + ); + let imapMsg = new ImapMessage(dataUri.spec, IMAPPump.mailbox.uidnext++, []); + imapMsg.setSize(5000); + IMAPPump.mailbox.addMessage(imapMsg); + + // ...and download for offline use. + let promiseUrlListener = new PromiseTestUtils.PromiseUrlListener(); + IMAPPump.inbox.downloadAllForOffline(promiseUrlListener, null); + await promiseUrlListener.promise; +} + +async function downloadAllForOffline() { + let promiseUrlListener = new PromiseTestUtils.PromiseUrlListener(); + IMAPPump.inbox.downloadAllForOffline(promiseUrlListener, null); + await promiseUrlListener.promise; +} + +function verifyDownloaded() { + // verify that the message headers have the offline flag set. + for (let header of IMAPPump.inbox.msgDatabase.enumerateMessages()) { + // Verify that each message has been downloaded and looks OK. + if ( + header instanceof Ci.nsIMsgDBHdr && + header.flags & Ci.nsMsgMessageFlags.Offline + ) { + IMAPPump.inbox.getLocalMsgStream(header).close(); + } else { + do_throw("Message not downloaded for offline use"); + } + } +} + +function run_test() { + tests.forEach(x => add_task(x)); + run_next_test(); +} |