diff options
Diffstat (limited to '')
-rw-r--r-- | comm/mailnews/imap/test/unit/test_subfolderLocation.js | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/comm/mailnews/imap/test/unit/test_subfolderLocation.js b/comm/mailnews/imap/test/unit/test_subfolderLocation.js new file mode 100644 index 0000000000..7cbf1b7bb8 --- /dev/null +++ b/comm/mailnews/imap/test/unit/test_subfolderLocation.js @@ -0,0 +1,83 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test proper location of new imap offline subfolders for maildir. + +// async support +/* import-globals-from ../../../test/resources/logHelper.js */ +/* import-globals-from ../../../test/resources/alertTestUtils.js */ +load("../../../resources/logHelper.js"); +load("../../../resources/alertTestUtils.js"); + +// Globals + +// Messages to load must have CRLF line endings, that is Windows style +var gMessage = "bugmail10"; // message file used as the test message + +add_task(function () { + Services.prefs.setBoolPref( + "mail.server.server1.autosync_offline_stores", + false + ); + setupIMAPPump(); +}); + +// load and update a message in the imap fake server +add_task(async function loadImapMessage() { + IMAPPump.mailbox.addMessage( + new ImapMessage(specForFileName(gMessage), IMAPPump.mailbox.uidnext++, []) + ); + let promiseUrlListener = new PromiseTestUtils.PromiseUrlListener(); + IMAPPump.inbox.updateFolderWithListener(gDummyMsgWindow, promiseUrlListener); + await promiseUrlListener.promise; + + Assert.equal(1, IMAPPump.inbox.getTotalMessages(false)); + let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox); + Assert.ok(msgHdr instanceof Ci.nsIMsgDBHdr); +}); + +add_task(async function downloadOffline() { + // ...and download for offline use. + let promiseUrlListener = new PromiseTestUtils.PromiseUrlListener(); + IMAPPump.inbox.downloadAllForOffline(promiseUrlListener, null); + await promiseUrlListener.promise; +}); + +var folderName1 = "sub1"; +var folderName2 = "sub2"; + +// use a folder method to add a subfolder +add_task(async function addSubfolder() { + let promiseFolder1 = PromiseTestUtils.promiseFolderAdded(folderName1); + IMAPPump.inbox.createSubfolder(folderName1, null); + await promiseFolder1; +}); + +// use a store method to add a subfolder +add_task(function storeAddSubfolder() { + IMAPPump.incomingServer.msgStore.createFolder(IMAPPump.inbox, folderName2); +}); + +// test that folders created with store and folder have the same parent +add_task(function testSubfolder() { + let subfolder1 = IMAPPump.inbox.getChildNamed(folderName1); + let subfolder2 = IMAPPump.inbox.getChildNamed(folderName2); + Assert.equal( + subfolder1.filePath.parent.path, + subfolder2.filePath.parent.path + ); +}); + +// Cleanup at end +add_task(teardownIMAPPump); + +/* + * helper functions + */ + +// given a test file, return the file uri spec +function specForFileName(aFileName) { + let file = do_get_file("../../../data/" + aFileName); + let msgfileuri = Services.io.newFileURI(file).QueryInterface(Ci.nsIFileURL); + return msgfileuri.spec; +} |