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 --- comm/mailnews/imap/test/unit/test_mailboxes.js | 80 ++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 comm/mailnews/imap/test/unit/test_mailboxes.js (limited to 'comm/mailnews/imap/test/unit/test_mailboxes.js') diff --git a/comm/mailnews/imap/test/unit/test_mailboxes.js b/comm/mailnews/imap/test/unit/test_mailboxes.js new file mode 100644 index 0000000000..0f13f6b328 --- /dev/null +++ b/comm/mailnews/imap/test/unit/test_mailboxes.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/. */ + +/** + * Tests basic mailbox handling of IMAP, like discovery, rename and empty folder. + */ + +var { MessageGenerator } = ChromeUtils.import( + "resource://testing-common/mailnews/MessageGenerator.jsm" +); +var { PromiseTestUtils } = ChromeUtils.import( + "resource://testing-common/mailnews/PromiseTestUtils.jsm" +); + +// The following folder names are not pure ASCII and will be MUTF-7 encoded. +const folderName1 = "I18N box\u00E1"; // I18N boxá +const folderName2 = "test \u00E4"; // test ä + +add_setup(async function () { + setupIMAPPump(); + + IMAPPump.daemon.createMailbox(folderName1, { subscribed: true }); + IMAPPump.daemon.createMailbox("Unsubscribed box"); + // Create an all upper case trash folder name to make sure + // we handle special folder names case-insensitively. + IMAPPump.daemon.createMailbox("TRASH", { subscribed: true }); + + // Get the server list... + IMAPPump.server.performTest("LIST"); + + let listener = new PromiseTestUtils.PromiseUrlListener(); + IMAPPump.inbox.updateFolderWithListener(null, listener); + await listener.promise; +}); + +add_task(async function checkDiscovery() { + let rootFolder = IMAPPump.incomingServer.rootFolder; + // Check that we've subscribed to the boxes returned by LSUB. We also get + // checking of proper i18n in mailboxes for free here. + Assert.ok(rootFolder.containsChildNamed("Inbox")); + Assert.ok(rootFolder.containsChildNamed("TRASH")); + // Make sure we haven't created an extra "Trash" folder. + let trashes = rootFolder.getFoldersWithFlags(Ci.nsMsgFolderFlags.Trash); + Assert.equal(trashes.length, 1); + Assert.equal(rootFolder.numSubFolders, 3); + Assert.ok(rootFolder.containsChildNamed(folderName1)); + // This is not a subscribed box, so we shouldn't be subscribing to it. + Assert.ok(!rootFolder.containsChildNamed("Unsubscribed box")); + + let i18nChild = rootFolder.getChildNamed(folderName1); + + let listener = new PromiseTestUtils.PromiseUrlListener(); + MailServices.imap.renameLeaf(i18nChild, folderName2, listener, null); + await listener.promise; +}); + +add_task(async function checkRename() { + let rootFolder = IMAPPump.incomingServer.rootFolder; + Assert.ok(rootFolder.containsChildNamed(folderName2)); + let newChild = rootFolder + .getChildNamed(folderName2) + .QueryInterface(Ci.nsIMsgImapMailFolder); + let listener = new PromiseTestUtils.PromiseUrlListener(); + newChild.updateFolderWithListener(null, listener); + await listener.promise; +}); + +add_task(function checkEmptyFolder() { + try { + let serverSink = IMAPPump.server.QueryInterface(Ci.nsIImapServerSink); + serverSink.possibleImapMailbox("/", "/", 0); + } catch (ex) { + // We expect this to fail, but not crash or assert. + } +}); + +add_task(function endTest() { + teardownIMAPPump(); +}); -- cgit v1.2.3