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_stopMovingToLocalFolder.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 'comm/mailnews/imap/test/unit/test_stopMovingToLocalFolder.js')
-rw-r--r-- | comm/mailnews/imap/test/unit/test_stopMovingToLocalFolder.js | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/comm/mailnews/imap/test/unit/test_stopMovingToLocalFolder.js b/comm/mailnews/imap/test/unit/test_stopMovingToLocalFolder.js new file mode 100644 index 0000000000..9a7718332f --- /dev/null +++ b/comm/mailnews/imap/test/unit/test_stopMovingToLocalFolder.js @@ -0,0 +1,95 @@ +/* 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 that the message failed to move to a local folder remains on IMAP + * server. */ + +var { MailServices } = ChromeUtils.import( + "resource:///modules/MailServices.jsm" +); + +var { MessageGenerator } = ChromeUtils.import( + "resource://testing-common/mailnews/MessageGenerator.jsm" +); +var { PromiseTestUtils } = ChromeUtils.import( + "resource://testing-common/mailnews/PromiseTestUtils.jsm" +); + +function stop_server() { + IMAPPump.incomingServer.closeCachedConnections(); + IMAPPump.server.stop(); + let thread = gThreadManager.currentThread; + while (thread.hasPendingEvents()) { + thread.processNextEvent(true); + } +} + +add_setup(function () { + setupIMAPPump(); + Services.prefs.setBoolPref( + "mail.server.default.autosync_offline_stores", + false + ); +}); + +add_setup(async function () { + let messageGenerator = new MessageGenerator(); + let messageString = messageGenerator.makeMessage().toMessageString(); + let dataUri = Services.io.newURI( + "data:text/plain;base64," + btoa(messageString) + ); + let imapMsg = new ImapMessage(dataUri.spec, IMAPPump.mailbox.uidnext++, []); + IMAPPump.mailbox.addMessage(imapMsg); + + let listener = new PromiseTestUtils.PromiseUrlListener(); + IMAPPump.inbox.updateFolderWithListener(null, listener); + await listener.promise; +}); + +add_task(async function move_messages() { + let msg = IMAPPump.inbox.msgDatabase.getMsgHdrForKey( + IMAPPump.mailbox.uidnext - 1 + ); + let copyListener = new PromiseTestUtils.PromiseCopyListener({ + OnProgress(aProgress, aProgressMax) { + stop_server(); + }, + }); + MailServices.copy.copyMessages( + IMAPPump.inbox, + [msg], + localAccountUtils.inboxFolder, + true, + copyListener, + null, + false + ); + await copyListener.promise; +}); + +add_task(function check_messages() { + Assert.equal(IMAPPump.inbox.getTotalMessages(false), 1); + Assert.equal(localAccountUtils.inboxFolder.getTotalMessages(false), 0); +}); + +add_task(function endTest() { + // IMAPPump.server.performTest() brings this test to a halt, + // so we need teardownIMAPPump() without IMAPPump.server.performTest(). + IMAPPump.inbox = null; + IMAPPump.server.resetTest(); + try { + IMAPPump.incomingServer.closeCachedConnections(); + let serverSink = IMAPPump.incomingServer.QueryInterface( + Ci.nsIImapServerSink + ); + serverSink.abortQueuedUrls(); + } catch (ex) { + dump(ex); + } + IMAPPump.server.stop(); + let thread = gThreadManager.currentThread; + while (thread.hasPendingEvents()) { + thread.processNextEvent(true); + } +}); |