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_syncChanges.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_syncChanges.js | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/comm/mailnews/imap/test/unit/test_syncChanges.js b/comm/mailnews/imap/test/unit/test_syncChanges.js new file mode 100644 index 0000000000..e4b46f35a8 --- /dev/null +++ b/comm/mailnews/imap/test/unit/test_syncChanges.js @@ -0,0 +1,80 @@ +/* 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 changes made from a different profile/machine + * are synced correctly. In particular, we're checking that emptying out + * an imap folder on the server makes us delete all the headers from our db. + */ + +var { MessageGenerator } = ChromeUtils.import( + "resource://testing-common/mailnews/MessageGenerator.jsm" +); +var { PromiseTestUtils } = ChromeUtils.import( + "resource://testing-common/mailnews/PromiseTestUtils.jsm" +); + +var gMessage; +var gSecondFolder; +var gSynthMessage; + +add_setup(async function () { + /* + * Set up an IMAP server. + */ + setupIMAPPump(); + + IMAPPump.daemon.createMailbox("secondFolder", { subscribed: true }); + + let messages = []; + let gMessageGenerator = new MessageGenerator(); + messages = messages.concat(gMessageGenerator.makeMessage()); + gSynthMessage = messages[0]; + + let msgURI = Services.io.newURI( + "data:text/plain;base64," + btoa(gSynthMessage.toMessageString()) + ); + gMessage = new ImapMessage(msgURI.spec, IMAPPump.mailbox.uidnext++, []); + IMAPPump.mailbox.addMessage(gMessage); + + // update folder to download header. + let listener = new PromiseTestUtils.PromiseUrlListener(); + IMAPPump.inbox.updateFolderWithListener(null, listener); + await listener.promise; +}); + +add_task(async function switchAwayFromInbox() { + let rootFolder = IMAPPump.incomingServer.rootFolder; + gSecondFolder = rootFolder + .getChildNamed("secondFolder") + .QueryInterface(Ci.nsIMsgImapMailFolder); + + // Selecting the second folder will close the cached connection + // on the inbox because fake server only supports one connection at a time. + // Then, we can poke at the message on the imap server directly, which + // simulates the user changing the message from a different machine, + // and Thunderbird discovering the change when it does a flag sync + // upon reselecting the Inbox. + let listener = new PromiseTestUtils.PromiseUrlListener(); + gSecondFolder.updateFolderWithListener(null, listener); + await listener.promise; +}); + +add_task(async function simulateMailboxEmptied() { + gMessage.setFlag("\\Deleted"); + let expungeListener = new PromiseTestUtils.PromiseUrlListener(); + IMAPPump.inbox.expunge(expungeListener, null); + await expungeListener.promise; + let updateListener = new PromiseTestUtils.PromiseUrlListener(); + IMAPPump.inbox.updateFolderWithListener(null, updateListener); + await updateListener.promise; +}); + +add_task(function checkMailboxEmpty() { + Assert.equal(IMAPPump.inbox.getTotalMessages(false), 0); +}); + +add_task(function endTest() { + teardownIMAPPump(); +}); |