Bug 1682942 - Use JS iterable protocol instead of nsISimpleEnumerator for nsIMsgDatabase.EnumerateMessages() calls. r=mkmelin
This commit is contained in:
Родитель
55fd0faabc
Коммит
d12d30fb7e
|
@ -13,14 +13,14 @@ var { MailServices } = ChromeUtils.import(
|
|||
|
||||
var gCopySource;
|
||||
var gCopyDest;
|
||||
var gMsgEnumerator;
|
||||
var gMessages;
|
||||
var gCurTestNum = 1;
|
||||
|
||||
// main test
|
||||
|
||||
var gTestArray = [
|
||||
function copyMsg1() {
|
||||
gMsgEnumerator = gCopySource.msgDatabase.EnumerateMessages();
|
||||
gMessages = [...gCopySource.msgDatabase.EnumerateMessages()];
|
||||
CopyNextMessage();
|
||||
},
|
||||
function copyMsg2() {
|
||||
|
@ -35,8 +35,8 @@ var gTestArray = [
|
|||
];
|
||||
|
||||
function CopyNextMessage() {
|
||||
if (gMsgEnumerator.hasMoreElements()) {
|
||||
let msgHdr = gMsgEnumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
|
||||
if (gMessages.length > 0) {
|
||||
let msgHdr = gMessages.shift();
|
||||
MailServices.copy.CopyMessages(
|
||||
gCopySource,
|
||||
[msgHdr],
|
||||
|
@ -90,7 +90,7 @@ function doTest() {
|
|||
function endTest() {
|
||||
// Cleanup, null out everything
|
||||
dump(" Exiting mail tests\n");
|
||||
gMsgEnumerator = null;
|
||||
gMessages = null;
|
||||
do_test_finished(); // for the one in run_test()
|
||||
}
|
||||
|
||||
|
|
|
@ -116,8 +116,8 @@ var gTestArray = [
|
|||
// and has no messages.
|
||||
Assert.equal(0, gLocalTrashFolder.filePath.fileSize);
|
||||
Assert.equal(0, gLocalTrashFolder.msgDatabase.dBFolderInfo.numMessages);
|
||||
let enumerator = gLocalTrashFolder.msgDatabase.EnumerateMessages();
|
||||
Assert.equal(false, enumerator.hasMoreElements());
|
||||
let msgs = [...gLocalTrashFolder.msgDatabase.EnumerateMessages()];
|
||||
Assert.equal(0, msgs.length);
|
||||
urlListener.OnStopRunningUrl(null, 0);
|
||||
},
|
||||
];
|
||||
|
|
|
@ -20,10 +20,7 @@ function test_enumerator_cleanup() {
|
|||
localAccountUtils.inboxFolder.msgDatabase = null;
|
||||
db = null;
|
||||
gc();
|
||||
while (enumerator.hasMoreElements()) {
|
||||
enumerator.getNext();
|
||||
}
|
||||
|
||||
[...enumerator];
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
|
|
|
@ -238,12 +238,8 @@ var tests = [
|
|||
},
|
||||
function moveMessagesToSubfolder() {
|
||||
let db = IMAPPump.inbox.msgDatabase;
|
||||
let enumerator = db.EnumerateMessages();
|
||||
Assert.ok(enumerator.hasMoreElements());
|
||||
let messages = [];
|
||||
for (let message of enumerator) {
|
||||
messages.push(message);
|
||||
}
|
||||
let messages = [...db.EnumerateMessages()];
|
||||
Assert.ok(messages.length > 0);
|
||||
// this is sync, I believe?
|
||||
MailServices.copy.CopyMessages(
|
||||
IMAPPump.inbox,
|
||||
|
@ -256,8 +252,7 @@ var tests = [
|
|||
);
|
||||
|
||||
// the inbox should now be empty
|
||||
enumerator = db.EnumerateMessages();
|
||||
Assert.ok(!enumerator.hasMoreElements());
|
||||
Assert.ok([...db.EnumerateMessages()].length == 0);
|
||||
|
||||
// maildir should also delete the files.
|
||||
if (IMAPPump.inbox.msgStore.storeType == "maildir") {
|
||||
|
|
|
@ -20,8 +20,6 @@ load("../../../resources/MessageGenerator.jsm");
|
|||
var mimeMsg = {};
|
||||
ChromeUtils.import("resource:///modules/gloda/MimeMessage.jsm", mimeMsg);
|
||||
|
||||
var gSecondMsg;
|
||||
|
||||
// IMAP pump
|
||||
|
||||
setupIMAPPump();
|
||||
|
@ -97,12 +95,9 @@ function* startMime() {
|
|||
|
||||
// test that we don't mark all inline messages as read.
|
||||
function* testAllInlineMessage() {
|
||||
let enumerator = IMAPPump.inbox.msgDatabase.EnumerateMessages();
|
||||
|
||||
if (enumerator.hasMoreElements()) {
|
||||
gSecondMsg = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
|
||||
for (let msg of IMAPPump.inbox.msgDatabase.EnumerateMessages()) {
|
||||
mimeMsg.MsgHdrToMimeMessage(
|
||||
gSecondMsg,
|
||||
msg,
|
||||
this,
|
||||
function(aMsgHdr, aMimeMessage) {
|
||||
async_driver();
|
||||
|
|
|
@ -56,25 +56,19 @@ var gTestArray = [
|
|||
},
|
||||
function verifyMessages() {
|
||||
// check MoveFolder message
|
||||
let hdrs = [];
|
||||
let keys = [];
|
||||
let enumerator = gMoveFolder.msgDatabase.EnumerateMessages();
|
||||
let hdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
|
||||
keys.push(hdr.messageKey);
|
||||
hdrs.push(hdr);
|
||||
Assert.ok(!gMoveFolder.fetchMsgPreviewText(keys, false, null));
|
||||
Assert.equal(hdrs[0].getStringProperty("preview"), bugmail10_preview);
|
||||
let hdr = [...gMoveFolder.msgDatabase.EnumerateMessages()][0];
|
||||
Assert.ok(!gMoveFolder.fetchMsgPreviewText([hdr.messageKey], false, null));
|
||||
Assert.equal(hdr.getStringProperty("preview"), bugmail10_preview);
|
||||
// check inbox message
|
||||
hdrs = [];
|
||||
keys = [];
|
||||
enumerator = localAccountUtils.inboxFolder.msgDatabase.EnumerateMessages();
|
||||
hdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
|
||||
keys.push(hdr.messageKey);
|
||||
hdrs.push(hdr);
|
||||
hdr = [...localAccountUtils.inboxFolder.msgDatabase.EnumerateMessages()][0];
|
||||
Assert.ok(
|
||||
!localAccountUtils.inboxFolder.fetchMsgPreviewText(keys, false, null)
|
||||
!localAccountUtils.inboxFolder.fetchMsgPreviewText(
|
||||
[hdr.messageKey],
|
||||
false,
|
||||
null
|
||||
)
|
||||
);
|
||||
Assert.equal(hdrs[0].getStringProperty("preview"), basic1_preview);
|
||||
Assert.equal(hdr.getStringProperty("preview"), basic1_preview);
|
||||
},
|
||||
];
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ var { IOUtils } = ChromeUtils.import("resource:///modules/IOUtils.jsm");
|
|||
|
||||
var gTestFiles = ["../../../data/bug505221", "../../../data/bug513543"];
|
||||
|
||||
var gMsgEnumerator;
|
||||
var gMessages;
|
||||
|
||||
var gMessenger = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger);
|
||||
|
||||
|
@ -34,7 +34,9 @@ function run_test() {
|
|||
IOUtils.loadFileToString(do_get_file(fileName))
|
||||
);
|
||||
}
|
||||
gMsgEnumerator = localAccountUtils.inboxFolder.msgDatabase.EnumerateMessages();
|
||||
gMessages = [
|
||||
...localAccountUtils.inboxFolder.msgDatabase.EnumerateMessages(),
|
||||
];
|
||||
doNextTest();
|
||||
}
|
||||
|
||||
|
@ -78,8 +80,9 @@ var gStreamListener = {
|
|||
};
|
||||
|
||||
function doNextTest() {
|
||||
if (gMsgEnumerator.hasMoreElements()) {
|
||||
streamMsg(gMsgEnumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr));
|
||||
if (gMessages.length > 0) {
|
||||
let msgHdr = gMessages.shift();
|
||||
streamMsg(msgHdr);
|
||||
} else {
|
||||
do_test_finished();
|
||||
}
|
||||
|
|
|
@ -55,9 +55,9 @@ var gTestArray = [
|
|||
// operation was a move
|
||||
Assert.equal(folderCount(localAccountUtils.inboxFolder), 0);
|
||||
|
||||
let enumerator = gMoveFolder.msgDatabase.EnumerateMessages();
|
||||
let firstMsgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
|
||||
let secondMsgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
|
||||
let msgs = [...gMoveFolder.msgDatabase.EnumerateMessages()];
|
||||
let firstMsgHdr = msgs[0];
|
||||
let secondMsgHdr = msgs[1];
|
||||
// Check that the messages have content
|
||||
let messageContent = getContentFromMessage(firstMsgHdr);
|
||||
Assert.ok(
|
||||
|
@ -71,9 +71,9 @@ var gTestArray = [
|
|||
);
|
||||
},
|
||||
async function copyMovedMessages() {
|
||||
let enumerator = gMoveFolder.msgDatabase.EnumerateMessages();
|
||||
let firstMsgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
|
||||
let secondMsgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
|
||||
let msgs = [...gMoveFolder.msgDatabase.EnumerateMessages()];
|
||||
let firstMsgHdr = msgs[0];
|
||||
let secondMsgHdr = msgs[1];
|
||||
let promiseCopyListener = new PromiseTestUtils.PromiseCopyListener();
|
||||
MailServices.copy.CopyMessages(
|
||||
gMoveFolder,
|
||||
|
@ -93,9 +93,9 @@ var gTestArray = [
|
|||
function verifyFolders2() {
|
||||
Assert.equal(folderCount(gMoveFolder2), 2);
|
||||
|
||||
let enumerator = gMoveFolder2.msgDatabase.EnumerateMessages();
|
||||
let firstMsgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
|
||||
let secondMsgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
|
||||
let msgs = [...gMoveFolder2.msgDatabase.EnumerateMessages()];
|
||||
let firstMsgHdr = msgs[0];
|
||||
let secondMsgHdr = msgs[1];
|
||||
// Check that the messages have content
|
||||
let messageContent = getContentFromMessage(firstMsgHdr);
|
||||
Assert.ok(
|
||||
|
|
|
@ -121,10 +121,8 @@ var mailTestUtils = {
|
|||
// Gets the first message header in a folder.
|
||||
firstMsgHdr(folder) {
|
||||
let enumerator = folder.msgDatabase.EnumerateMessages();
|
||||
if (enumerator.hasMoreElements()) {
|
||||
return enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
|
||||
}
|
||||
return null;
|
||||
let first = enumerator[Symbol.iterator]().next();
|
||||
return first.done ? null : first.value;
|
||||
},
|
||||
|
||||
// Gets message header number N (0 based index) in a folder.
|
||||
|
|
Загрузка…
Ссылка в новой задаче