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 --- .../imap/test/unit/test_downloadOffline.js | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 comm/mailnews/imap/test/unit/test_downloadOffline.js (limited to 'comm/mailnews/imap/test/unit/test_downloadOffline.js') 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(); +} -- cgit v1.2.3