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_autosync_date_constraints.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/imap/test/unit/test_autosync_date_constraints.js')
-rw-r--r-- | comm/mailnews/imap/test/unit/test_autosync_date_constraints.js | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/comm/mailnews/imap/test/unit/test_autosync_date_constraints.js b/comm/mailnews/imap/test/unit/test_autosync_date_constraints.js new file mode 100644 index 0000000000..101413d491 --- /dev/null +++ b/comm/mailnews/imap/test/unit/test_autosync_date_constraints.js @@ -0,0 +1,88 @@ +/* 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 autosync date constraints + */ + +var { MessageGenerator } = ChromeUtils.import( + "resource://testing-common/mailnews/MessageGenerator.jsm" +); +var { PromiseTestUtils } = ChromeUtils.import( + "resource://testing-common/mailnews/PromiseTestUtils.jsm" +); + +var gMsgImapInboxFolder; + +// Adds some messages directly to a mailbox (eg new mail) +function addMessagesToServer(messages, mailbox) { + // Create the ImapMessages and store them on the mailbox + messages.forEach(function (message) { + let dataUri = "data:text/plain," + message.toMessageString(); + mailbox.addMessage(new ImapMessage(dataUri, mailbox.uidnext++, [])); + }); +} + +add_setup(function () { + Services.prefs.setIntPref("mail.server.server1.autosync_max_age_days", 4); + + setupIMAPPump(); + + gMsgImapInboxFolder = IMAPPump.inbox.QueryInterface(Ci.nsIMsgImapMailFolder); + // these hacks are required because we've created the inbox before + // running initial folder discovery, and adding the folder bails + // out before we set it as verified online, so we bail out, and + // then remove the INBOX folder since it's not verified. + gMsgImapInboxFolder.hierarchyDelimiter = "/"; + gMsgImapInboxFolder.verifiedAsOnlineFolder = true; + + // Add a couple of messages to the INBOX + // this is synchronous, afaik + let messageGenerator = new MessageGenerator(); + + // build up a diverse list of messages + let messages = []; + messages = messages.concat( + messageGenerator.makeMessage({ age: { days: 2, hours: 1 } }) + ); + messages = messages.concat( + messageGenerator.makeMessage({ age: { days: 8, hours: 1 } }) + ); + messages = messages.concat( + messageGenerator.makeMessage({ age: { days: 10, hours: 1 } }) + ); + + addMessagesToServer(messages, IMAPPump.daemon.getMailbox("INBOX")); +}); + +add_task(async function downloadForOffline() { + // ...and download for offline use. + // This downloads all messages, ignoring the autosync age constraints. + let listener = new PromiseTestUtils.PromiseUrlListener(); + IMAPPump.inbox.downloadAllForOffline(listener, null); + await listener.promise; +}); + +add_task(function test_applyRetentionSettings() { + IMAPPump.inbox.applyRetentionSettings(); + let enumerator = IMAPPump.inbox.msgDatabase.enumerateMessages(); + if (enumerator) { + let now = new Date(); + let dateInSeconds = now.getSeconds(); + let cutOffDateInSeconds = dateInSeconds - 5 * 60 * 24; + for (let header of enumerator) { + if (header instanceof Ci.nsIMsgDBHdr) { + if (header.dateInSeconds < cutOffDateInSeconds) { + Assert.equal(header.getStringProperty("pendingRemoval"), "1"); + } else { + Assert.equal(header.getStringProperty("pendingRemoval"), ""); + } + } + } + } +}); + +add_task(function endTest() { + teardownIMAPPump(); +}); |