Bug 1571683 - Part 2: Replace asyncTestUtils.js functionality with promises in mailnews/imap/test/unit/**. r=mkmelin
Differential Revision: https://phabricator.services.mozilla.com/D136609
This commit is contained in:
Родитель
6d4243f466
Коммит
8556af48e6
|
@ -1,14 +1,17 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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
|
||||
*/
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
var { MessageGenerator } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/MessageGenerator.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
var gMsgImapInboxFolder;
|
||||
|
||||
|
@ -21,36 +24,7 @@ function addMessagesToServer(messages, mailbox) {
|
|||
});
|
||||
}
|
||||
|
||||
var tests = [
|
||||
setup,
|
||||
function* downloadForOffline() {
|
||||
// ...and download for offline use.
|
||||
// This downloads all messages, ignoring the autosync age constraints.
|
||||
IMAPPump.inbox.downloadAllForOffline(asyncUrlListener, null);
|
||||
yield false;
|
||||
},
|
||||
function 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"), "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
teardown,
|
||||
];
|
||||
|
||||
function setup() {
|
||||
add_task(function setupTest() {
|
||||
Services.prefs.setIntPref("mail.server.server1.autosync_max_age_days", 4);
|
||||
|
||||
setupIMAPPump();
|
||||
|
@ -80,12 +54,35 @@ function setup() {
|
|||
);
|
||||
|
||||
addMessagesToServer(messages, IMAPPump.daemon.getMailbox("INBOX"));
|
||||
}
|
||||
});
|
||||
|
||||
function teardown() {
|
||||
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();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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 BCC gets added to message headers on IMAP download
|
||||
*
|
||||
|
@ -7,17 +10,14 @@
|
|||
* original author Kent James <kent@caspia.com>
|
||||
*/
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
var gFileName = "draft1";
|
||||
var gMsgFile = do_get_file("../../../data/" + gFileName);
|
||||
|
||||
var tests = [setup, downloadAllForOffline, checkBccs, teardown];
|
||||
|
||||
function* setup() {
|
||||
add_task(async function setupTest() {
|
||||
setupIMAPPump();
|
||||
|
||||
/*
|
||||
|
@ -33,28 +33,20 @@ function* setup() {
|
|||
);
|
||||
|
||||
// ...and download for offline use.
|
||||
IMAPPump.inbox.downloadAllForOffline(asyncUrlListener, null);
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.downloadAllForOffline(listener, null);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function* downloadAllForOffline() {
|
||||
IMAPPump.inbox.downloadAllForOffline(asyncUrlListener, null);
|
||||
yield false;
|
||||
}
|
||||
|
||||
function checkBccs() {
|
||||
add_task(function checkBccs() {
|
||||
// locate the new message by enumerating through the database
|
||||
for (let hdr of IMAPPump.inbox.msgDatabase.EnumerateMessages()) {
|
||||
Assert.ok(hdr.bccList.includes("Another Person"));
|
||||
Assert.ok(hdr.bccList.includes("<u1@example.com>"));
|
||||
Assert.ok(!hdr.bccList.includes("IDoNotExist"));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function teardown() {
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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 compacting offline stores works correctly with imap folders
|
||||
* and returns success.
|
||||
*/
|
||||
|
||||
var { MessageGenerator } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/MessageGenerator.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
Services.prefs.setCharPref(
|
||||
"mail.serverDefaultStoreContractID",
|
||||
"@mozilla.org/msgstore/berkeleystore;1"
|
||||
);
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
/* import-globals-from ../../../test/resources/alertTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
load("../../../resources/alertTestUtils.js");
|
||||
|
||||
// Globals
|
||||
var gRootFolder;
|
||||
var gImapInboxOfflineStoreSize;
|
||||
|
@ -35,7 +36,7 @@ var gMsgId2 = "200804111417.m3BEHTk4030129@mrapp51.mozilla.org";
|
|||
var gMsgId4 = "bugmail7.m47LtAEf007542@mrapp51.mozilla.org";
|
||||
var gMsgId5 = "bugmail6.m47LtAEf007542@mrapp51.mozilla.org";
|
||||
|
||||
// Adds some messages directly to a mailbox (eg new mail)
|
||||
// Adds some messages directly to a mailbox (e.g. new mail).
|
||||
function addMessagesToServer(messages, mailbox) {
|
||||
// For every message we have, we need to convert it to a file:/// URI
|
||||
messages.forEach(function(message) {
|
||||
|
@ -58,7 +59,6 @@ function addGeneratedMessagesToServer(messages, mailbox) {
|
|||
}
|
||||
|
||||
function checkOfflineStore(prevOfflineStoreSize) {
|
||||
dump("checking offline store\n");
|
||||
let enumerator = IMAPPump.inbox.msgDatabase.EnumerateMessages();
|
||||
if (enumerator) {
|
||||
for (let header of enumerator) {
|
||||
|
@ -77,88 +77,7 @@ function checkOfflineStore(prevOfflineStoreSize) {
|
|||
Assert.ok(prevOfflineStoreSize > IMAPPump.inbox.filePath.fileSize + 100);
|
||||
}
|
||||
|
||||
var tests = [
|
||||
setup,
|
||||
function* downloadForOffline() {
|
||||
// ...and download for offline use.
|
||||
dump("Downloading for offline use\n");
|
||||
IMAPPump.inbox.downloadAllForOffline(asyncUrlListener, null);
|
||||
yield false;
|
||||
},
|
||||
function* markOneMsgDeleted() {
|
||||
// mark a message deleted, and then do a compact of just
|
||||
// that folder.
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId5);
|
||||
// store the deleted flag
|
||||
IMAPPump.inbox.storeImapFlags(
|
||||
0x0008,
|
||||
true,
|
||||
[msgHdr.messageKey],
|
||||
asyncUrlListener
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function* compactOneFolder() {
|
||||
IMAPPump.incomingServer.deleteModel = Ci.nsMsgImapDeleteModels.IMAPDelete;
|
||||
// asyncUrlListener will get called when both expunge and offline store
|
||||
// compaction are finished. dummyMsgWindow is required to make the backend
|
||||
// compact the offline store.
|
||||
IMAPPump.inbox.compact(asyncUrlListener, gDummyMsgWindow);
|
||||
yield false;
|
||||
},
|
||||
function* deleteOneMessage() {
|
||||
// check that nstmp file has been cleaned up.
|
||||
let tmpFile = gRootFolder.filePath;
|
||||
tmpFile.append("nstmp");
|
||||
Assert.ok(!tmpFile.exists());
|
||||
dump("deleting one message\n");
|
||||
IMAPPump.incomingServer.deleteModel = Ci.nsMsgImapDeleteModels.MoveToTrash;
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId1);
|
||||
IMAPPump.inbox.deleteMessages(
|
||||
[msgHdr],
|
||||
null,
|
||||
false,
|
||||
true,
|
||||
CopyListener,
|
||||
false
|
||||
);
|
||||
let trashFolder = gRootFolder.getChildNamed("Trash");
|
||||
// hack to force uid validity to get initialized for trash.
|
||||
trashFolder.updateFolder(null);
|
||||
yield false;
|
||||
},
|
||||
function* compactOfflineStore() {
|
||||
dump("compacting offline store\n");
|
||||
gImapInboxOfflineStoreSize = IMAPPump.inbox.filePath.fileSize;
|
||||
gRootFolder.compactAll(asyncUrlListener, null, true);
|
||||
yield false;
|
||||
},
|
||||
function* checkCompactionResult() {
|
||||
checkOfflineStore(gImapInboxOfflineStoreSize);
|
||||
asyncUrlListener.OnStopRunningUrl(null, 0);
|
||||
yield false;
|
||||
},
|
||||
function* testPendingRemoval() {
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId2);
|
||||
IMAPPump.inbox.markPendingRemoval(msgHdr, true);
|
||||
gImapInboxOfflineStoreSize = IMAPPump.inbox.filePath.fileSize;
|
||||
gRootFolder.compactAll(asyncUrlListener, null, true);
|
||||
yield false;
|
||||
},
|
||||
function* checkCompactionResult() {
|
||||
let tmpFile = gRootFolder.filePath;
|
||||
tmpFile.append("nstmp");
|
||||
Assert.ok(!tmpFile.exists());
|
||||
checkOfflineStore(gImapInboxOfflineStoreSize);
|
||||
asyncUrlListener.OnStopRunningUrl(null, 0);
|
||||
yield false;
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId2);
|
||||
Assert.equal(msgHdr.flags & Ci.nsMsgMessageFlags.Offline, 0);
|
||||
},
|
||||
teardown,
|
||||
];
|
||||
|
||||
function setup() {
|
||||
add_task(function setupTest() {
|
||||
setupIMAPPump();
|
||||
|
||||
gRootFolder = IMAPPump.incomingServer.rootFolder;
|
||||
|
@ -188,27 +107,85 @@ function setup() {
|
|||
],
|
||||
IMAPPump.daemon.getMailbox("INBOX")
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// nsIMsgCopyServiceListener implementation - runs next test when copy
|
||||
// is completed.
|
||||
var CopyListener = {
|
||||
OnStartCopy() {},
|
||||
OnProgress(aProgress, aProgressMax) {},
|
||||
SetMessageKey(aKey) {},
|
||||
SetMessageId(aMessageId) {},
|
||||
OnStopCopy(aStatus) {
|
||||
// Check: message successfully copied.
|
||||
Assert.equal(aStatus, 0);
|
||||
async_driver();
|
||||
},
|
||||
};
|
||||
add_task(async function downloadForOffline() {
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.downloadAllForOffline(listener, null);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function teardown() {
|
||||
add_task(async function markOneMsgDeleted() {
|
||||
// mark a message deleted, and then do a compact of just
|
||||
// that folder.
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId5);
|
||||
// store the deleted flag
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.storeImapFlags(0x0008, true, [msgHdr.messageKey], listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(async function compactOneFolder() {
|
||||
IMAPPump.incomingServer.deleteModel = Ci.nsMsgImapDeleteModels.IMAPDelete;
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.compact(listener, null);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(async function test_deleteOneMessage() {
|
||||
// check that nstmp file has been cleaned up.
|
||||
let tmpFile = gRootFolder.filePath;
|
||||
tmpFile.append("nstmp");
|
||||
Assert.ok(!tmpFile.exists());
|
||||
// Deleting one message.
|
||||
IMAPPump.incomingServer.deleteModel = Ci.nsMsgImapDeleteModels.MoveToTrash;
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId1);
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener();
|
||||
IMAPPump.inbox.deleteMessages(
|
||||
[msgHdr],
|
||||
null,
|
||||
false,
|
||||
true,
|
||||
copyListener,
|
||||
false
|
||||
);
|
||||
await copyListener.promise;
|
||||
|
||||
let trashFolder = gRootFolder.getChildNamed("Trash");
|
||||
// hack to force uid validity to get initialized for trash.
|
||||
trashFolder.updateFolder(null);
|
||||
});
|
||||
|
||||
add_task(async function compactOfflineStore() {
|
||||
gImapInboxOfflineStoreSize = IMAPPump.inbox.filePath.fileSize;
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
gRootFolder.compactAll(listener, null, true);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(function test_checkCompactionResult() {
|
||||
checkOfflineStore(gImapInboxOfflineStoreSize);
|
||||
});
|
||||
|
||||
add_task(async function pendingRemoval() {
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId2);
|
||||
IMAPPump.inbox.markPendingRemoval(msgHdr, true);
|
||||
gImapInboxOfflineStoreSize = IMAPPump.inbox.filePath.fileSize;
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
gRootFolder.compactAll(listener, null, true);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(function test_checkCompactionResult() {
|
||||
let tmpFile = gRootFolder.filePath;
|
||||
tmpFile.append("nstmp");
|
||||
Assert.ok(!tmpFile.exists());
|
||||
checkOfflineStore(gImapInboxOfflineStoreSize);
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId2);
|
||||
Assert.equal(msgHdr.flags & Ci.nsMsgMessageFlags.Offline, 0);
|
||||
});
|
||||
|
||||
add_task(function endTest() {
|
||||
gRootFolder = null;
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -11,22 +11,13 @@ Services.prefs.setCharPref(
|
|||
"@mozilla.org/msgstore/berkeleystore;1"
|
||||
);
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
/* import-globals-from ../../../test/resources/alertTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
load("../../../resources/alertTestUtils.js");
|
||||
|
||||
var log = console.createInstance({
|
||||
prefix: "mail.mailstoreconverter",
|
||||
maxLogLevel: "Warn",
|
||||
maxLogLevelPref: "mail.mailstoreconverter.loglevel",
|
||||
});
|
||||
|
||||
var { FileUtils } = ChromeUtils.import("resource://gre/modules/FileUtils.jsm");
|
||||
var { MessageGenerator } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/MessageGenerator.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
// Globals
|
||||
var gMsgFile1 = do_get_file("../../../data/bugmail10");
|
||||
|
@ -45,8 +36,8 @@ function checkConversion(aSource, aTarget) {
|
|||
let targetFile = FileUtils.File(
|
||||
PathUtils.join(aTarget.path, sourceContentName)
|
||||
);
|
||||
log.debug("Checking path: " + targetFile.path);
|
||||
|
||||
// Checking path.
|
||||
if (ext == ".msf" || ext == ".dat") {
|
||||
Assert.ok(targetFile.exists());
|
||||
} else if (sourceContent.isDirectory()) {
|
||||
|
@ -69,7 +60,7 @@ function checkConversion(aSource, aTarget) {
|
|||
var EventTarget = function() {
|
||||
this.dispatchEvent = function(aEvent) {
|
||||
if (aEvent.type == "progress") {
|
||||
log.trace("Progress: " + aEvent.detail);
|
||||
console.trace("Progress: " + aEvent.detail);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@ -90,7 +81,7 @@ function addMessagesToServer(aMessages, aMailbox) {
|
|||
});
|
||||
}
|
||||
|
||||
function setup() {
|
||||
add_task(function setupTest() {
|
||||
setupIMAPPump();
|
||||
|
||||
// These hacks are required because we've created the inbox before
|
||||
|
@ -112,29 +103,16 @@ function setup() {
|
|||
IMAPPump.daemon.getMailbox("INBOX"),
|
||||
IMAPPump.inbox
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
async function downloadForOffline() {
|
||||
add_task(async function downloadForOffline() {
|
||||
// Download for offline use.
|
||||
let promiseUrlListener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.downloadAllForOffline(promiseUrlListener, null);
|
||||
await promiseUrlListener.promise;
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
setup();
|
||||
registerCleanupFunction(function() {
|
||||
teardownIMAPPump();
|
||||
});
|
||||
|
||||
run_next_test();
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function convert() {
|
||||
logHelperAllowedErrors.push("DEPRECATION");
|
||||
|
||||
await downloadForOffline();
|
||||
|
||||
let mailstoreContractId = Services.prefs.getCharPref(
|
||||
"mail.server." + IMAPPump.incomingServer.key + ".storeContractID"
|
||||
);
|
||||
|
@ -144,20 +122,22 @@ add_task(async function convert() {
|
|||
IMAPPump.incomingServer,
|
||||
eventTarget
|
||||
);
|
||||
do_test_pending();
|
||||
let originalRootFolder = IMAPPump.incomingServer.rootFolder.filePath;
|
||||
pConverted
|
||||
await pConverted
|
||||
.then(function(val) {
|
||||
log.debug("Conversion done: " + originalRootFolder.path + " => " + val);
|
||||
// Conversion done: originalRootFolder.path => val.
|
||||
let newRootFolder = IMAPPump.incomingServer.rootFolder.filePath;
|
||||
checkConversion(originalRootFolder, newRootFolder);
|
||||
let newRootFolderMsf = FileUtils.File(newRootFolder.path + ".msf");
|
||||
Assert.ok(newRootFolderMsf.exists());
|
||||
do_test_finished();
|
||||
})
|
||||
.catch(function(reason) {
|
||||
log.error("Conversion Failed: " + reason);
|
||||
// Conversion Failed.
|
||||
Assert.ok(false);
|
||||
do_test_finished();
|
||||
throw new Error(reason);
|
||||
});
|
||||
});
|
||||
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
});
|
||||
|
|
|
@ -1,14 +1,20 @@
|
|||
// This file extends test_imapFolderCopy.js to test message
|
||||
// moves from a local folder to an IMAP folder.
|
||||
//
|
||||
// Original Author: Kent James <kent@caspia.com>
|
||||
/* 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/. */
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
/**
|
||||
* This file extends test_imapFolderCopy.js to test message
|
||||
* moves from a local folder to an IMAP folder.
|
||||
*
|
||||
* Original Author: Kent James <kent@caspia.com>
|
||||
*/
|
||||
|
||||
var { MessageGenerator } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/MessageGenerator.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
var { MailServices } = ChromeUtils.import(
|
||||
"resource:///modules/MailServices.jsm"
|
||||
|
@ -19,122 +25,7 @@ var gLastKey;
|
|||
var gMessages = [];
|
||||
var gCopyService = MailServices.copy;
|
||||
|
||||
var tests = [
|
||||
setup,
|
||||
function* copyFolder1() {
|
||||
dump("gEmpty1 " + gEmptyLocal1.URI + "\n");
|
||||
gCopyService.copyFolder(
|
||||
gEmptyLocal1,
|
||||
IMAPPump.inbox,
|
||||
false,
|
||||
CopyListener,
|
||||
null
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function* copyFolder2() {
|
||||
dump("gEmpty2 " + gEmptyLocal2.URI + "\n");
|
||||
gCopyService.copyFolder(
|
||||
gEmptyLocal2,
|
||||
IMAPPump.inbox,
|
||||
false,
|
||||
CopyListener,
|
||||
null
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function* getLocalMessage1() {
|
||||
dump("getLocalMessage\n");
|
||||
var file = do_get_file("../../../data/bugmail1");
|
||||
gCopyService.copyFileMessage(
|
||||
file,
|
||||
localAccountUtils.inboxFolder,
|
||||
null,
|
||||
false,
|
||||
0,
|
||||
"",
|
||||
CopyListener,
|
||||
null
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function* getLocalMessage2() {
|
||||
gMessages.push(localAccountUtils.inboxFolder.GetMessageHeader(gLastKey));
|
||||
dump("getLocalMessage\n");
|
||||
var file = do_get_file("../../../data/draft1");
|
||||
gCopyService.copyFileMessage(
|
||||
file,
|
||||
localAccountUtils.inboxFolder,
|
||||
null,
|
||||
false,
|
||||
0,
|
||||
"",
|
||||
CopyListener,
|
||||
null
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function* copyMessages() {
|
||||
gMessages.push(localAccountUtils.inboxFolder.GetMessageHeader(gLastKey));
|
||||
let folder1 = IMAPPump.inbox.getChildNamed("empty 1");
|
||||
gCopyService.copyMessages(
|
||||
localAccountUtils.inboxFolder,
|
||||
gMessages,
|
||||
folder1,
|
||||
false,
|
||||
CopyListener,
|
||||
null,
|
||||
false
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function* moveMessages() {
|
||||
let folder2 = IMAPPump.inbox.getChildNamed("empty 2");
|
||||
gCopyService.copyMessages(
|
||||
localAccountUtils.inboxFolder,
|
||||
gMessages,
|
||||
folder2,
|
||||
true,
|
||||
CopyListener,
|
||||
null,
|
||||
false
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function* update1() {
|
||||
let folder1 = IMAPPump.inbox
|
||||
.getChildNamed("empty 1")
|
||||
.QueryInterface(Ci.nsIMsgImapMailFolder);
|
||||
folder1.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function* update2() {
|
||||
let folder2 = IMAPPump.inbox
|
||||
.getChildNamed("empty 2")
|
||||
.QueryInterface(Ci.nsIMsgImapMailFolder);
|
||||
folder2.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function verifyFolders() {
|
||||
let folder1 = IMAPPump.inbox.getChildNamed("empty 1");
|
||||
Assert.equal(folderCount(folder1), 2);
|
||||
let folder2 = IMAPPump.inbox.getChildNamed("empty 2");
|
||||
Assert.ok(folder2 !== null);
|
||||
// folder 1 and 2 should each now have two messages in them.
|
||||
Assert.ok(folder1 !== null);
|
||||
Assert.equal(folderCount(folder2), 2);
|
||||
// The local inbox folder should now be empty, since the second
|
||||
// operation was a move.
|
||||
Assert.equal(folderCount(localAccountUtils.inboxFolder), 0);
|
||||
},
|
||||
teardown,
|
||||
];
|
||||
|
||||
function folderCount(folder) {
|
||||
return [...folder.msgDatabase.EnumerateMessages()].length;
|
||||
}
|
||||
|
||||
function setup() {
|
||||
add_task(function setupTest() {
|
||||
// Turn off autosync_offline_stores because
|
||||
// fetching messages is invoked after copying the messages.
|
||||
// (i.e. The fetching process will be invoked after OnStopCopy)
|
||||
|
@ -156,33 +47,155 @@ function setup() {
|
|||
// then remove the INBOX folder since it's not verified.
|
||||
IMAPPump.inbox.hierarchyDelimiter = "/";
|
||||
IMAPPump.inbox.verifiedAsOnlineFolder = true;
|
||||
}
|
||||
});
|
||||
|
||||
// nsIMsgCopyServiceListener implementation - runs next test when copy
|
||||
// is completed.
|
||||
var CopyListener = {
|
||||
OnStartCopy() {},
|
||||
OnProgress(aProgress, aProgressMax) {},
|
||||
SetMessageKey(aKey) {
|
||||
gLastKey = aKey;
|
||||
},
|
||||
SetMessageId(aMessageId) {},
|
||||
OnStopCopy(aStatus) {
|
||||
// Check: message successfully copied.
|
||||
Assert.equal(aStatus, 0);
|
||||
async_driver();
|
||||
},
|
||||
};
|
||||
add_task(async function copyFolder1() {
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener({
|
||||
SetMessageKey(aKey) {
|
||||
gLastKey = aKey;
|
||||
},
|
||||
});
|
||||
gCopyService.copyFolder(
|
||||
gEmptyLocal1,
|
||||
IMAPPump.inbox,
|
||||
false,
|
||||
copyListener,
|
||||
null
|
||||
);
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
asyncUrlListener.callback = function(aUrl, aExitCode) {
|
||||
Assert.equal(aExitCode, 0);
|
||||
};
|
||||
add_task(async function copyFolder2() {
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener({
|
||||
SetMessageKey(aKey) {
|
||||
gLastKey = aKey;
|
||||
},
|
||||
});
|
||||
gCopyService.copyFolder(
|
||||
gEmptyLocal2,
|
||||
IMAPPump.inbox,
|
||||
false,
|
||||
copyListener,
|
||||
null
|
||||
);
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
function teardown() {
|
||||
add_task(async function getLocalMessage1() {
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener({
|
||||
SetMessageKey(aKey) {
|
||||
gLastKey = aKey;
|
||||
},
|
||||
});
|
||||
let file = do_get_file("../../../data/bugmail1");
|
||||
gCopyService.copyFileMessage(
|
||||
file,
|
||||
localAccountUtils.inboxFolder,
|
||||
null,
|
||||
false,
|
||||
0,
|
||||
"",
|
||||
copyListener,
|
||||
null
|
||||
);
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
add_task(async function getLocalMessage2() {
|
||||
gMessages.push(localAccountUtils.inboxFolder.GetMessageHeader(gLastKey));
|
||||
let file = do_get_file("../../../data/draft1");
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener({
|
||||
SetMessageKey(aKey) {
|
||||
gLastKey = aKey;
|
||||
},
|
||||
});
|
||||
gCopyService.copyFileMessage(
|
||||
file,
|
||||
localAccountUtils.inboxFolder,
|
||||
null,
|
||||
false,
|
||||
0,
|
||||
"",
|
||||
copyListener,
|
||||
null
|
||||
);
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
add_task(async function copyMessages() {
|
||||
gMessages.push(localAccountUtils.inboxFolder.GetMessageHeader(gLastKey));
|
||||
let folder1 = IMAPPump.inbox.getChildNamed("empty 1");
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener({
|
||||
SetMessageKey(aKey) {
|
||||
gLastKey = aKey;
|
||||
},
|
||||
});
|
||||
gCopyService.copyMessages(
|
||||
localAccountUtils.inboxFolder,
|
||||
gMessages,
|
||||
folder1,
|
||||
false,
|
||||
copyListener,
|
||||
null,
|
||||
false
|
||||
);
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
add_task(async function moveMessages() {
|
||||
let folder2 = IMAPPump.inbox.getChildNamed("empty 2");
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener({
|
||||
SetMessageKey(aKey) {
|
||||
gLastKey = aKey;
|
||||
},
|
||||
});
|
||||
gCopyService.copyMessages(
|
||||
localAccountUtils.inboxFolder,
|
||||
gMessages,
|
||||
folder2,
|
||||
true,
|
||||
copyListener,
|
||||
null,
|
||||
false
|
||||
);
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
add_task(async function update1() {
|
||||
let folder1 = IMAPPump.inbox
|
||||
.getChildNamed("empty 1")
|
||||
.QueryInterface(Ci.nsIMsgImapMailFolder);
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
folder1.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(async function update2() {
|
||||
let folder2 = IMAPPump.inbox
|
||||
.getChildNamed("empty 2")
|
||||
.QueryInterface(Ci.nsIMsgImapMailFolder);
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
folder2.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(function verifyFolders() {
|
||||
let folder1 = IMAPPump.inbox.getChildNamed("empty 1");
|
||||
Assert.equal(folderCount(folder1), 2);
|
||||
let folder2 = IMAPPump.inbox.getChildNamed("empty 2");
|
||||
Assert.ok(folder2 !== null);
|
||||
// folder 1 and 2 should each now have two messages in them.
|
||||
Assert.ok(folder1 !== null);
|
||||
Assert.equal(folderCount(folder2), 2);
|
||||
// The local inbox folder should now be empty, since the second
|
||||
// operation was a move.
|
||||
Assert.equal(folderCount(localAccountUtils.inboxFolder), 0);
|
||||
});
|
||||
add_task(function endTest() {
|
||||
gMessages = [];
|
||||
teardownIMAPPump();
|
||||
}
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
function folderCount(folder) {
|
||||
return [...folder.msgDatabase.EnumerateMessages()].length;
|
||||
}
|
||||
|
|
|
@ -7,11 +7,9 @@
|
|||
* Bug 778246
|
||||
*/
|
||||
|
||||
// async support
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
// IMAP pump
|
||||
|
||||
|
@ -31,17 +29,13 @@ var gMsgWindow = Cc["@mozilla.org/messenger/msgwindow;1"].createInstance(
|
|||
|
||||
setupIMAPPump("CUSTOM1");
|
||||
|
||||
// Definition of tests
|
||||
var tests = [
|
||||
loadImapMessage,
|
||||
testStoreCustomList,
|
||||
testStoreMinusCustomList,
|
||||
testStorePlusCustomList,
|
||||
endTest,
|
||||
];
|
||||
add_task(async function setupTest() {
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.server1.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
// Load and update a message in the imap fake server.
|
||||
|
||||
// load and update a message in the imap fake server
|
||||
function* loadImapMessage() {
|
||||
gMessage = new imapMessage(
|
||||
specForFileName(gMessageFileName),
|
||||
IMAPPump.mailbox.uidnext++,
|
||||
|
@ -49,11 +43,12 @@ function* loadImapMessage() {
|
|||
);
|
||||
gMessage.xCustomList = [];
|
||||
IMAPPump.mailbox.addMessage(gMessage);
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function* testStoreCustomList() {
|
||||
add_task(async function testStoreCustomList() {
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
gExpectedLength = gCustomList.length;
|
||||
let uri = IMAPPump.inbox.issueCommandOnMsgs(
|
||||
|
@ -62,26 +57,22 @@ function* testStoreCustomList() {
|
|||
gMsgWindow
|
||||
);
|
||||
uri.QueryInterface(Ci.nsIMsgMailNewsUrl);
|
||||
// Listens for response from customCommandResult request for X-CUSTOM-LIST.
|
||||
let storeCustomListSetListener = new PromiseTestUtils.PromiseUrlListener({
|
||||
OnStopRunningUrl(aUrl, aExitCode) {
|
||||
aUrl.QueryInterface(Ci.nsIImapUrl);
|
||||
Assert.equal(
|
||||
aUrl.customCommandResult,
|
||||
"(" + gMessage.xCustomList.join(" ") + ")"
|
||||
);
|
||||
Assert.equal(gMessage.xCustomList.length, gExpectedLength);
|
||||
},
|
||||
});
|
||||
uri.RegisterListener(storeCustomListSetListener);
|
||||
yield false;
|
||||
}
|
||||
await storeCustomListSetListener.promise;
|
||||
});
|
||||
|
||||
// listens for response from customCommandResult request for X-CUSTOM-LIST
|
||||
var storeCustomListSetListener = {
|
||||
OnStartRunningUrl(aUrl) {},
|
||||
|
||||
OnStopRunningUrl(aUrl, aExitCode) {
|
||||
aUrl.QueryInterface(Ci.nsIImapUrl);
|
||||
Assert.equal(
|
||||
aUrl.customCommandResult,
|
||||
"(" + gMessage.xCustomList.join(" ") + ")"
|
||||
);
|
||||
Assert.equal(gMessage.xCustomList.length, gExpectedLength);
|
||||
async_driver();
|
||||
},
|
||||
};
|
||||
|
||||
function* testStoreMinusCustomList() {
|
||||
add_task(async function testStoreMinusCustomList() {
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
gExpectedLength--;
|
||||
let uri = IMAPPump.inbox.issueCommandOnMsgs(
|
||||
|
@ -90,26 +81,22 @@ function* testStoreMinusCustomList() {
|
|||
gMsgWindow
|
||||
);
|
||||
uri.QueryInterface(Ci.nsIMsgMailNewsUrl);
|
||||
// Listens for response from customCommandResult request for X-CUSTOM-LIST.
|
||||
let storeCustomListRemovedListener = new PromiseTestUtils.PromiseUrlListener({
|
||||
OnStopRunningUrl(aUrl, aExitCode) {
|
||||
aUrl.QueryInterface(Ci.nsIImapUrl);
|
||||
Assert.equal(
|
||||
aUrl.customCommandResult,
|
||||
"(" + gMessage.xCustomList.join(" ") + ")"
|
||||
);
|
||||
Assert.equal(gMessage.xCustomList.length, gExpectedLength);
|
||||
},
|
||||
});
|
||||
uri.RegisterListener(storeCustomListRemovedListener);
|
||||
yield false;
|
||||
}
|
||||
await storeCustomListRemovedListener.promise;
|
||||
});
|
||||
|
||||
// listens for response from customCommandResult request for X-CUSTOM-LIST
|
||||
var storeCustomListRemovedListener = {
|
||||
OnStartRunningUrl(aUrl) {},
|
||||
|
||||
OnStopRunningUrl(aUrl, aExitCode) {
|
||||
aUrl.QueryInterface(Ci.nsIImapUrl);
|
||||
Assert.equal(
|
||||
aUrl.customCommandResult,
|
||||
"(" + gMessage.xCustomList.join(" ") + ")"
|
||||
);
|
||||
Assert.equal(gMessage.xCustomList.length, gExpectedLength);
|
||||
async_driver();
|
||||
},
|
||||
};
|
||||
|
||||
function* testStorePlusCustomList() {
|
||||
add_task(async function testStorePlusCustomList() {
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
gExpectedLength++;
|
||||
let uri = IMAPPump.inbox.issueCommandOnMsgs(
|
||||
|
@ -118,37 +105,24 @@ function* testStorePlusCustomList() {
|
|||
gMsgWindow
|
||||
);
|
||||
uri.QueryInterface(Ci.nsIMsgMailNewsUrl);
|
||||
let storeCustomListAddedListener = new PromiseTestUtils.PromiseUrlListener({
|
||||
OnStopRunningUrl(aUrl, aExitCode) {
|
||||
aUrl.QueryInterface(Ci.nsIImapUrl);
|
||||
Assert.equal(
|
||||
aUrl.customCommandResult,
|
||||
"(" + gMessage.xCustomList.join(" ") + ")"
|
||||
);
|
||||
Assert.equal(gMessage.xCustomList.length, gExpectedLength);
|
||||
},
|
||||
});
|
||||
uri.RegisterListener(storeCustomListAddedListener);
|
||||
yield false;
|
||||
}
|
||||
|
||||
// listens for response from customCommandResult request for X-CUSTOM-LIST
|
||||
var storeCustomListAddedListener = {
|
||||
OnStartRunningUrl(aUrl) {},
|
||||
|
||||
OnStopRunningUrl(aUrl, aExitCode) {
|
||||
aUrl.QueryInterface(Ci.nsIImapUrl);
|
||||
Assert.equal(
|
||||
aUrl.customCommandResult,
|
||||
"(" + gMessage.xCustomList.join(" ") + ")"
|
||||
);
|
||||
Assert.equal(gMessage.xCustomList.length, gExpectedLength);
|
||||
async_driver();
|
||||
},
|
||||
};
|
||||
await storeCustomListAddedListener.promise;
|
||||
});
|
||||
|
||||
// Cleanup at end
|
||||
function endTest() {
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.server1.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* helper functions
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/* 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 bodystructure and body fetch by parts. Messages with problem of
|
||||
* 'This part will be downloaded on demand' in message pane content (text) area.
|
||||
|
@ -7,19 +11,15 @@
|
|||
* See current test files for examples.
|
||||
*/
|
||||
|
||||
// async support
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
var gServer, gIMAPIncomingServer, gIMAPDaemon;
|
||||
|
||||
var tests = [streamMessages, endTest];
|
||||
|
||||
function run_test() {
|
||||
add_task(function setupTest() {
|
||||
gIMAPDaemon = new imapDaemon();
|
||||
// pref tuning: one connection only, turn off notifications
|
||||
Services.prefs.setIntPref("mail.server.server1.max_cached_connections", 1);
|
||||
|
@ -44,12 +44,9 @@ function run_test() {
|
|||
|
||||
gServer = makeServer(gIMAPDaemon, "");
|
||||
gIMAPIncomingServer = createLocalIMAPServer(gServer.port);
|
||||
});
|
||||
|
||||
// start first test
|
||||
async_run_tests(tests);
|
||||
}
|
||||
|
||||
function* streamMessages() {
|
||||
add_task(async function streamMessages() {
|
||||
let inbox = gIMAPDaemon.getMailbox("INBOX");
|
||||
let imapS = Cc[
|
||||
"@mozilla.org/messenger/messageservice;1?type=imap"
|
||||
|
@ -87,59 +84,18 @@ function* streamMessages() {
|
|||
Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
|
||||
Ci.nsIContentPolicy.TYPE_OTHER
|
||||
);
|
||||
channel.asyncOpen(gStreamListener, null);
|
||||
yield false;
|
||||
let buf = gStreamListener._data;
|
||||
dump(
|
||||
"##########\nTesting--->" +
|
||||
fileNames[i - 1] +
|
||||
"; 'prefer plain text': " +
|
||||
isPlain +
|
||||
"\n" +
|
||||
buf +
|
||||
"\n" +
|
||||
"##########\nTesting--->" +
|
||||
fileNames[i - 1] +
|
||||
"; 'prefer plain text': " +
|
||||
isPlain +
|
||||
"\n"
|
||||
);
|
||||
let streamListener = new PromiseTestUtils.PromiseStreamListener();
|
||||
channel.asyncOpen(streamListener, null);
|
||||
let buf = await streamListener.promise;
|
||||
|
||||
try {
|
||||
Assert.ok(buf.includes(marker));
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
var gStreamListener = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIStreamListener"]),
|
||||
_stream: null,
|
||||
_data: null,
|
||||
onStartRequest(aRequest) {
|
||||
this._data = "";
|
||||
this._stream = null;
|
||||
},
|
||||
onStopRequest(aRequest, aStatusCode) {
|
||||
async_driver();
|
||||
},
|
||||
onDataAvailable(aRequest, aInputStream, aOff, aCount) {
|
||||
if (this._stream == null) {
|
||||
this._stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
);
|
||||
this._stream.init(aInputStream);
|
||||
}
|
||||
this._data += this._stream.read(aCount);
|
||||
},
|
||||
};
|
||||
|
||||
function* endTest() {
|
||||
add_task(function endTest() {
|
||||
gIMAPIncomingServer.closeCachedConnections();
|
||||
gServer.stop();
|
||||
let thread = Services.tm.currentThread;
|
||||
while (thread.hasPendingEvents()) {
|
||||
thread.processNextEvent(true);
|
||||
}
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/* 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/. */
|
||||
|
||||
// This file tests that checking folders for new mail with STATUS
|
||||
// doesn't try to STAT noselect folders.
|
||||
|
||||
|
@ -6,21 +10,17 @@ var gIMAPInbox;
|
|||
var gFolder2Mailbox;
|
||||
var gFolder1, gFolder2;
|
||||
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
// async support
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
|
||||
var { MailServices } = ChromeUtils.import(
|
||||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
var { MessageGenerator } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/MessageGenerator.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
var tests = [checkStatSelect, checkStatNoSelect, endTest];
|
||||
|
||||
function run_test() {
|
||||
add_task(function setupTest() {
|
||||
var daemon = new imapDaemon();
|
||||
daemon.createMailbox("folder 1", { subscribed: true });
|
||||
let folder1Mailbox = daemon.getMailbox("folder 1");
|
||||
|
@ -68,11 +68,9 @@ function run_test() {
|
|||
gFolder2 = rootFolder.getChildNamed("folder 2");
|
||||
gFolder1.setFlag(Ci.nsMsgFolderFlags.CheckNew);
|
||||
gFolder2.setFlag(Ci.nsMsgFolderFlags.CheckNew);
|
||||
// start first test
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
||||
function* checkStatSelect() {
|
||||
add_task(function checkStatSelect() {
|
||||
// imap fake server's resetTest resets the authentication state - charming.
|
||||
// So poke the _test member directly.
|
||||
gServer._test = true;
|
||||
|
@ -85,27 +83,39 @@ function* checkStatSelect() {
|
|||
gServer._test = true;
|
||||
gIMAPInbox.updateFolder(null);
|
||||
gServer.performTest("NOOP");
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
function* checkStatNoSelect() {
|
||||
add_task(async function checkStatNoSelect() {
|
||||
// folder 2 should have been stat'd, but not folder 1. All we can really check
|
||||
// is that folder 2 was stat'd and that its unread msg count is 1
|
||||
Assert.equal(gFolder2.getNumUnread(false), 1);
|
||||
addMessageToFolder(gFolder2Mailbox);
|
||||
gFolder1.clearFlag(Ci.nsMsgFolderFlags.ImapNoselect);
|
||||
gServer._test = true;
|
||||
|
||||
let folderListener = new FolderListener();
|
||||
|
||||
// we've cleared the ImapNoselect flag, so we will attempt to STAT folder 1,
|
||||
// which will fail. So we verify that we go on and STAT folder 2, and that
|
||||
// it picks up the message we added to it above.
|
||||
MailServices.mailSession.AddFolderListener(
|
||||
gFolderListener,
|
||||
folderListener,
|
||||
Ci.nsIFolderListener.boolPropertyChanged
|
||||
);
|
||||
gIMAPInbox.getNewMessages(null, null);
|
||||
// Wait for the folder listener to get told about new messages.
|
||||
yield false;
|
||||
}
|
||||
await folderListener.promise;
|
||||
});
|
||||
|
||||
add_task(function endTest() {
|
||||
Assert.equal(gFolder2.getNumUnread(false), 2);
|
||||
|
||||
// Clean up the server in preparation
|
||||
gServer.resetTest();
|
||||
gImapServer.closeCachedConnections();
|
||||
gServer.performTest();
|
||||
gServer.stop();
|
||||
});
|
||||
|
||||
function addMessageToFolder(mbox) {
|
||||
// make a couple of messages
|
||||
|
@ -120,21 +130,20 @@ function addMessageToFolder(mbox) {
|
|||
mbox.addMessage(message);
|
||||
}
|
||||
|
||||
function* endTest() {
|
||||
Assert.equal(gFolder2.getNumUnread(false), 2);
|
||||
// Clean up the server in preparation
|
||||
gServer.resetTest();
|
||||
gImapServer.closeCachedConnections();
|
||||
gServer.performTest();
|
||||
gServer.stop();
|
||||
yield true;
|
||||
function FolderListener() {
|
||||
this._promise = new Promise(resolve => {
|
||||
this._resolve = resolve;
|
||||
});
|
||||
}
|
||||
|
||||
var gFolderListener = {
|
||||
FolderListener.prototype = {
|
||||
onFolderBoolPropertyChanged(aItem, aProperty, aOldValue, aNewValue) {
|
||||
// This means that the STAT on "folder 2" has finished.
|
||||
if (aProperty == "NewMessages" && aNewValue) {
|
||||
async_driver();
|
||||
this._resolve();
|
||||
}
|
||||
},
|
||||
get promise() {
|
||||
return this._promise;
|
||||
},
|
||||
};
|
||||
|
|
|
@ -6,11 +6,9 @@
|
|||
* Test to ensure that imap fetchCustomMsgAttribute function works properly
|
||||
*/
|
||||
|
||||
// async support
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
// IMAP pump
|
||||
|
||||
|
@ -28,18 +26,13 @@ var gMsgWindow = Cc["@mozilla.org/messenger/msgwindow;1"].createInstance(
|
|||
Ci.nsIMsgWindow
|
||||
);
|
||||
|
||||
setupIMAPPump("CUSTOM1");
|
||||
|
||||
// Definition of tests
|
||||
var tests = [
|
||||
loadImapMessage,
|
||||
testFetchCustomValue,
|
||||
testFetchCustomList,
|
||||
endTest,
|
||||
];
|
||||
|
||||
// load and update a message in the imap fake server
|
||||
function* loadImapMessage() {
|
||||
add_task(async function setupTest() {
|
||||
setupIMAPPump("CUSTOM1");
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.server1.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
// Load and update a message in the imap fake server.
|
||||
let message = new imapMessage(
|
||||
specForFileName(gMessage),
|
||||
IMAPPump.mailbox.uidnext++,
|
||||
|
@ -48,13 +41,14 @@ function* loadImapMessage() {
|
|||
message.xCustomValue = gCustomValue;
|
||||
message.xCustomList = gCustomList;
|
||||
IMAPPump.mailbox.addMessage(message);
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
// Used to verify that nsIServerResponseParser.msg_fetch() can handle
|
||||
// not in a parenthesis group - Bug 750012
|
||||
function* testFetchCustomValue() {
|
||||
add_task(async function testFetchCustomValue() {
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
let uri = IMAPPump.inbox.fetchCustomMsgAttribute(
|
||||
"X-CUSTOM-VALUE",
|
||||
|
@ -62,23 +56,19 @@ function* testFetchCustomValue() {
|
|||
gMsgWindow
|
||||
);
|
||||
uri.QueryInterface(Ci.nsIMsgMailNewsUrl);
|
||||
// Listens for response from fetchCustomMsgAttribute request for X-CUSTOM-VALUE.
|
||||
let fetchCustomValueListener = new PromiseTestUtils.PromiseUrlListener({
|
||||
OnStopRunningUrl(aUrl, aExitCode) {
|
||||
aUrl.QueryInterface(Ci.nsIImapUrl);
|
||||
Assert.equal(aUrl.customAttributeResult, gCustomValue);
|
||||
},
|
||||
});
|
||||
uri.RegisterListener(fetchCustomValueListener);
|
||||
yield false;
|
||||
}
|
||||
|
||||
// listens for response from fetchCustomMsgAttribute request for X-CUSTOM-VALUE
|
||||
var fetchCustomValueListener = {
|
||||
OnStartRunningUrl(aUrl) {},
|
||||
|
||||
OnStopRunningUrl(aUrl, aExitCode) {
|
||||
aUrl.QueryInterface(Ci.nsIImapUrl);
|
||||
Assert.equal(aUrl.customAttributeResult, gCustomValue);
|
||||
async_driver();
|
||||
},
|
||||
};
|
||||
await fetchCustomValueListener.promise;
|
||||
});
|
||||
|
||||
// Used to verify that nsIServerResponseParser.msg_fetch() can handle a parenthesis group - Bug 735542
|
||||
function* testFetchCustomList() {
|
||||
add_task(async function testFetchCustomList() {
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
let uri = IMAPPump.inbox.fetchCustomMsgAttribute(
|
||||
"X-CUSTOM-LIST",
|
||||
|
@ -86,33 +76,24 @@ function* testFetchCustomList() {
|
|||
gMsgWindow
|
||||
);
|
||||
uri.QueryInterface(Ci.nsIMsgMailNewsUrl);
|
||||
// Listens for response from fetchCustomMsgAttribute request for X-CUSTOM-VALUE.
|
||||
let fetchCustomListListener = new PromiseTestUtils.PromiseUrlListener({
|
||||
OnStopRunningUrl(aUrl, aExitCode) {
|
||||
aUrl.QueryInterface(Ci.nsIImapUrl);
|
||||
Assert.equal(
|
||||
aUrl.customAttributeResult,
|
||||
"(" + gCustomList.join(" ") + ")"
|
||||
);
|
||||
},
|
||||
});
|
||||
uri.RegisterListener(fetchCustomListListener);
|
||||
yield false;
|
||||
}
|
||||
|
||||
// listens for response from fetchCustomMsgAttribute request for X-CUSTOM-LIST
|
||||
var fetchCustomListListener = {
|
||||
OnStartRunningUrl(aUrl) {},
|
||||
|
||||
OnStopRunningUrl(aUrl, aExitCode) {
|
||||
aUrl.QueryInterface(Ci.nsIImapUrl);
|
||||
Assert.equal(aUrl.customAttributeResult, "(" + gCustomList.join(" ") + ")");
|
||||
async_driver();
|
||||
},
|
||||
};
|
||||
await fetchCustomListListener.promise;
|
||||
});
|
||||
|
||||
// Cleanup at end
|
||||
function endTest() {
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.server1.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* helper functions
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/* 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/. */
|
||||
|
||||
/*
|
||||
* This file tests hdr parsing in the filter running context, specifically
|
||||
* filters on custom headers.
|
||||
|
@ -7,11 +11,10 @@
|
|||
* Original author: David Bienvenu <bienvenu@mozilla.com>
|
||||
*/
|
||||
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
|
||||
// IMAP pump
|
||||
|
||||
|
@ -19,13 +22,8 @@ var { IMAPPump, setupIMAPPump, teardownIMAPPump } = ChromeUtils.import(
|
|||
"resource://testing-common/mailnews/IMAPpump.jsm"
|
||||
);
|
||||
|
||||
setupIMAPPump();
|
||||
|
||||
// Definition of tests
|
||||
|
||||
var tests = [setupTest, checkFilterResults, endTest];
|
||||
|
||||
function run_test() {
|
||||
add_task(async function setupTest() {
|
||||
setupIMAPPump();
|
||||
// Create a test filter.
|
||||
let filterList = IMAPPump.incomingServer.getFilterList(null);
|
||||
let filter = filterList.createFilter("test list-id");
|
||||
|
@ -46,11 +44,6 @@ function run_test() {
|
|||
action.type = Ci.nsMsgFilterAction.MarkRead;
|
||||
filter.appendAction(action);
|
||||
filterList.insertFilterAt(0, filter);
|
||||
|
||||
async_run_tests(tests);
|
||||
}
|
||||
|
||||
function* setupTest() {
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.default.autosync_offline_stores",
|
||||
false
|
||||
|
@ -61,18 +54,18 @@ function* setupTest() {
|
|||
IMAPPump.mailbox.addMessage(
|
||||
new imapMessage(msgfileuri.spec, IMAPPump.mailbox.uidnext++, [])
|
||||
);
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function* checkFilterResults() {
|
||||
add_task(function checkFilterResults() {
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
Assert.ok(msgHdr.isRead);
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
// Cleanup
|
||||
function endTest() {
|
||||
add_task(function endTest() {
|
||||
IMAPPump.server.performTest("UID STORE");
|
||||
teardownIMAPPump();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -9,27 +9,14 @@
|
|||
|
||||
// make SOLO_FILE="test_folderOfflineFlags.js" -C mailnews/imap/test check-one
|
||||
|
||||
// async support
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/alertTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/alertTestUtils.js");
|
||||
|
||||
// Definition of tests
|
||||
var tests = [
|
||||
setup,
|
||||
testGeneralFoldersOffline,
|
||||
testTrashNotOffline,
|
||||
testJunkNotOffline,
|
||||
teardown,
|
||||
];
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
/**
|
||||
* Setup the mailboxes that will be used for this test.
|
||||
*/
|
||||
function* setup() {
|
||||
add_task(async function setupTest() {
|
||||
setupIMAPPump("GMail");
|
||||
|
||||
IMAPPump.mailbox.subscribed = true;
|
||||
|
@ -66,15 +53,15 @@ function* setup() {
|
|||
IMAPPump.daemon.createMailbox("folder2", { subscribed: true });
|
||||
|
||||
// select the inbox to force folder discovery, etc.
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
/**
|
||||
* Test that folders generally are marked for offline use by default.
|
||||
*/
|
||||
function* testGeneralFoldersOffline() {
|
||||
add_task(function testGeneralFoldersOffline() {
|
||||
Assert.ok(IMAPPump.inbox.getFlag(Ci.nsMsgFolderFlags.Offline));
|
||||
|
||||
let gmail = IMAPPump.incomingServer.rootFolder.getChildNamed("[Gmail]");
|
||||
|
@ -95,36 +82,27 @@ function* testGeneralFoldersOffline() {
|
|||
|
||||
let folder2 = rootFolder.getChildNamed("folder2");
|
||||
Assert.ok(folder2.getFlag(Ci.nsMsgFolderFlags.Offline));
|
||||
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Test that Trash isn't flagged for offline use by default.
|
||||
*/
|
||||
function* testTrashNotOffline() {
|
||||
add_task(function testTrashNotOffline() {
|
||||
let gmail = IMAPPump.incomingServer.rootFolder.getChildNamed("[Gmail]");
|
||||
let trash = gmail.getFolderWithFlags(Ci.nsMsgFolderFlags.Trash);
|
||||
Assert.ok(!trash.getFlag(Ci.nsMsgFolderFlags.Offline));
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Test that Junk isn't flagged for offline use by default.
|
||||
*/
|
||||
function* testJunkNotOffline() {
|
||||
add_task(function testJunkNotOffline() {
|
||||
let gmail = IMAPPump.incomingServer.rootFolder.getChildNamed("[Gmail]");
|
||||
let spam = gmail.getFolderWithFlags(Ci.nsMsgFolderFlags.Junk);
|
||||
Assert.ok(!spam.getFlag(Ci.nsMsgFolderFlags.Offline));
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
/** Cleanup at the end. */
|
||||
function teardown() {
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
/** Run the tests. */
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -14,13 +14,9 @@
|
|||
* Original Author: Atul Jangra<atuljangra66@gmail.com>
|
||||
*/
|
||||
|
||||
// async support
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
|
||||
// IMAP pump
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
|
@ -31,29 +27,22 @@ var gXGmMsgid = "1278455344230334865";
|
|||
var gXGmThrid = "1266894439832287888";
|
||||
var gXGmLabels = '(\\Inbox \\Sent Important "Muy Importante" foo)';
|
||||
|
||||
setupIMAPPump("GMail");
|
||||
add_task(async function setupTest() {
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.server1.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
setupIMAPPump("GMail");
|
||||
IMAPPump.mailbox.specialUseFlag = "\\Inbox";
|
||||
IMAPPump.mailbox.subscribed = true;
|
||||
|
||||
IMAPPump.mailbox.specialUseFlag = "\\Inbox";
|
||||
IMAPPump.mailbox.subscribed = true;
|
||||
|
||||
// need all mail folder to identify this as gmail server.
|
||||
IMAPPump.daemon.createMailbox("[Gmail]", { flags: ["\\NoSelect"] });
|
||||
IMAPPump.daemon.createMailbox("[Gmail]/All Mail", {
|
||||
subscribed: true,
|
||||
specialUseFlag: "\\AllMail",
|
||||
});
|
||||
|
||||
// Definition of tests
|
||||
var tests = [
|
||||
loadImapMessage,
|
||||
testFetchXGmMsgid,
|
||||
testFetchXGmThrid,
|
||||
testFetchXGmLabels,
|
||||
endTest,
|
||||
];
|
||||
|
||||
// load and update a message in the imap fake server
|
||||
function* loadImapMessage() {
|
||||
// need all mail folder to identify this as gmail server.
|
||||
IMAPPump.daemon.createMailbox("[Gmail]", { flags: ["\\NoSelect"] });
|
||||
IMAPPump.daemon.createMailbox("[Gmail]/All Mail", {
|
||||
subscribed: true,
|
||||
specialUseFlag: "\\AllMail",
|
||||
});
|
||||
// Load and update a message in the imap fake server.
|
||||
let message = new imapMessage(
|
||||
specForFileName(gMessage),
|
||||
IMAPPump.mailbox.uidnext++,
|
||||
|
@ -63,41 +52,34 @@ function* loadImapMessage() {
|
|||
message.xGmThrid = gXGmThrid;
|
||||
message.xGmLabels = gXGmLabels;
|
||||
IMAPPump.mailbox.addMessage(message);
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function testFetchXGmMsgid() {
|
||||
add_task(function testFetchXGmMsgid() {
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
let val = msgHdr.getStringProperty("X-GM-MSGID");
|
||||
Assert.equal(val, gXGmMsgid);
|
||||
}
|
||||
});
|
||||
|
||||
function testFetchXGmThrid() {
|
||||
add_task(function testFetchXGmThrid() {
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
let val = msgHdr.getStringProperty("X-GM-THRID");
|
||||
Assert.equal(val, gXGmThrid);
|
||||
}
|
||||
});
|
||||
|
||||
function testFetchXGmLabels() {
|
||||
add_task(function testFetchXGmLabels() {
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
let val = msgHdr.getStringProperty("X-GM-LABELS");
|
||||
// We need to remove the starting "(" and ending ")" from gXGmLabels while comparing
|
||||
Assert.equal(val, gXGmLabels.substring(1, gXGmLabels.length - 1));
|
||||
}
|
||||
});
|
||||
|
||||
// Cleanup at end
|
||||
function endTest() {
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.server1.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* helper functions
|
||||
|
|
|
@ -18,22 +18,21 @@
|
|||
|
||||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
// Messages to load must have CRLF line endings, that is Windows style
|
||||
// Messages to load must have CRLF line endings, that is Windows style.
|
||||
|
||||
var gMessage1 = "bugmail10"; // message file used as the test message for Inbox and fooFolder
|
||||
var gMessage1 = "bugmail10"; // message file used as the test message for Inbox and fooFolder.
|
||||
var gXGmMsgid1 = "1278455344230334865";
|
||||
var gXGmThrid1 = "1266894439832287888";
|
||||
// We need to have different X-GM-LABELS for different folders. I am doing it here manually, but this issue will be tackled in Bug 781443.
|
||||
var gXGmLabels11 = '( "\\\\Sent" foo bar)'; // for message in Inbox
|
||||
var gXGmLabels12 = '("\\\\Inbox" "\\\\Sent" bar)'; // for message in fooFolder
|
||||
var gXGmLabels11 = '( "\\\\Sent" foo bar)'; // for message in Inbox.
|
||||
var gXGmLabels12 = '("\\\\Inbox" "\\\\Sent" bar)'; // for message in fooFolder.
|
||||
var gMsgId1 = "200806061706.m56H6RWT004933@mrapp54.mozilla.org";
|
||||
|
||||
var gMessage2 = "bugmail11"; // message file used as the test message for fooFolder
|
||||
var gMessage2 = "bugmail11"; // message file used as the test message for fooFolder.
|
||||
var gMsgId2 = "200804111417.m3BEHTk4030129@mrapp51.mozilla.org";
|
||||
var gXGmMsgid2 = "1278455345230334555";
|
||||
var gXGmThrid2 = "1266894639832287111";
|
||||
|
@ -48,22 +47,8 @@ var gImapInboxOfflineStoreSizeFinal;
|
|||
var gFooOfflineStoreSizeInitial;
|
||||
var gFooOfflineStoreSizeFinal;
|
||||
|
||||
var tests = [
|
||||
setup,
|
||||
updateFolder,
|
||||
selectInboxMsg,
|
||||
StreamMessageInbox,
|
||||
createAndUpdate,
|
||||
addFoo,
|
||||
updateFoo,
|
||||
selectFooMsg,
|
||||
StreamMessageFoo,
|
||||
crossStreaming,
|
||||
teardown,
|
||||
];
|
||||
|
||||
function setup() {
|
||||
// We aren't interested in downloading messages automatically
|
||||
add_task(async function setupTest() {
|
||||
// We aren't interested in downloading messages automatically.
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.server1.autosync_offline_stores",
|
||||
false
|
||||
|
@ -96,16 +81,14 @@ function setup() {
|
|||
message.messageId = gMsgId1;
|
||||
message.xGmMsgid = gXGmMsgid1;
|
||||
message.xGmThrid = gXGmThrid1;
|
||||
message.xGmLabels = gXGmLabels11; // With labels excluding "//INBOX"
|
||||
message.xGmLabels = gXGmLabels11; // With labels excluding "//INBOX".
|
||||
IMAPPump.mailbox.addMessage(message);
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function* updateFolder() {
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
|
||||
function* selectInboxMsg() {
|
||||
add_task(async function selectInboxMsg() {
|
||||
// Select mesasage1 from inbox which makes message1 available in offline store.
|
||||
let imapService = Cc[
|
||||
"@mozilla.org/messenger/messageservice;1?type=imap"
|
||||
|
@ -113,41 +96,45 @@ function* selectInboxMsg() {
|
|||
let db = IMAPPump.inbox.msgDatabase;
|
||||
let msg1 = db.getMsgHdrForMessageID(gMsgId1);
|
||||
let url = {};
|
||||
let streamListener = new PromiseTestUtils.PromiseStreamListener();
|
||||
let urlListener = new PromiseTestUtils.PromiseUrlListener();
|
||||
imapService.DisplayMessage(
|
||||
IMAPPump.inbox.getUriForMsg(msg1),
|
||||
streamListener,
|
||||
null,
|
||||
asyncUrlListener,
|
||||
urlListener,
|
||||
null,
|
||||
url
|
||||
);
|
||||
yield false;
|
||||
}
|
||||
await urlListener.promise;
|
||||
});
|
||||
|
||||
function* StreamMessageInbox() {
|
||||
// Stream message1 from inbox
|
||||
add_task(async function StreamMessageInbox() {
|
||||
// Stream message1 from inbox.
|
||||
let newMsgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId1);
|
||||
let msgURI = newMsgHdr.folder.getUriForMsg(newMsgHdr);
|
||||
let messenger = Cc["@mozilla.org/messenger;1"].createInstance(
|
||||
Ci.nsIMessenger
|
||||
);
|
||||
let msgServ = messenger.messageServiceFromURI(msgURI);
|
||||
msgServ.streamMessage(msgURI, gStreamListener, null, null, false, "", false);
|
||||
gImapInboxOfflineStoreSizeInitial = IMAPPump.inbox.filePath.fileSize; // Initial Size of Inbox
|
||||
yield false;
|
||||
}
|
||||
let streamLister = new PromiseTestUtils.PromiseStreamListener();
|
||||
msgServ.streamMessage(msgURI, streamLister, null, null, false, "", false);
|
||||
gImapInboxOfflineStoreSizeInitial = IMAPPump.inbox.filePath.fileSize; // Initial Size of Inbox.
|
||||
await streamLister.promise;
|
||||
});
|
||||
|
||||
function* createAndUpdate() {
|
||||
add_task(async function createAndUpdate() {
|
||||
let rootFolder = IMAPPump.incomingServer.rootFolder;
|
||||
fooFolder = rootFolder
|
||||
.getChildNamed("foo")
|
||||
.QueryInterface(Ci.nsIMsgImapMailFolder); // We have created the mailbox earlier.
|
||||
fooFolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
fooFolder.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function addFoo() {
|
||||
// Adding our test message
|
||||
add_task(function addToFoo() {
|
||||
// Adding our test message.
|
||||
let message = new imapMessage(
|
||||
specForFileName(gMessage1),
|
||||
fooBox.uidnext++,
|
||||
|
@ -156,7 +143,7 @@ function addFoo() {
|
|||
message.messageId = gMsgId1;
|
||||
message.xGmMsgid = gXGmMsgid1;
|
||||
message.xGmThrid = gXGmThrid1;
|
||||
message.xGmLabels = gXGmLabels12; // With labels excluding "foo"
|
||||
message.xGmLabels = gXGmLabels12; // With labels excluding "foo".
|
||||
fooBox.addMessage(message);
|
||||
// Adding another message so that fooFolder behaves as LocalFolder while calculating it's size.
|
||||
let message1 = new imapMessage(
|
||||
|
@ -169,45 +156,49 @@ function addFoo() {
|
|||
message1.xGmThrid = gXGmThrid2;
|
||||
message1.xGmLabels = gXGmLabels2;
|
||||
fooBox.addMessage(message1);
|
||||
}
|
||||
});
|
||||
|
||||
function* updateFoo() {
|
||||
fooFolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
add_task(async function updateFoo() {
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
fooFolder.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function* selectFooMsg() {
|
||||
add_task(async function selectFooMsg() {
|
||||
// Select message2 from fooFolder, which makes fooFolder a local folder.
|
||||
let imapService = Cc[
|
||||
"@mozilla.org/messenger/messageservice;1?type=imap"
|
||||
].getService(Ci.nsIMsgMessageService);
|
||||
let msg1 = fooFolder.msgDatabase.getMsgHdrForMessageID(gMsgId2);
|
||||
let url = {};
|
||||
let streamListener = new PromiseTestUtils.PromiseStreamListener();
|
||||
let urlListener = new PromiseTestUtils.PromiseUrlListener();
|
||||
imapService.DisplayMessage(
|
||||
fooFolder.getUriForMsg(msg1),
|
||||
streamListener,
|
||||
null,
|
||||
asyncUrlListener,
|
||||
urlListener,
|
||||
null,
|
||||
url
|
||||
);
|
||||
yield false;
|
||||
}
|
||||
await urlListener.promise;
|
||||
});
|
||||
|
||||
function* StreamMessageFoo() {
|
||||
// Stream message2 from fooFolder
|
||||
add_task(async function StreamMessageFoo() {
|
||||
// Stream message2 from fooFolder.
|
||||
let newMsgHdr = fooFolder.msgDatabase.getMsgHdrForMessageID(gMsgId2);
|
||||
let msgURI = newMsgHdr.folder.getUriForMsg(newMsgHdr);
|
||||
let messenger = Cc["@mozilla.org/messenger;1"].createInstance(
|
||||
Ci.nsIMessenger
|
||||
);
|
||||
let msgServ = messenger.messageServiceFromURI(msgURI);
|
||||
msgServ.streamMessage(msgURI, gStreamListener, null, null, false, "", false);
|
||||
let streamListener = new PromiseTestUtils.PromiseStreamListener();
|
||||
msgServ.streamMessage(msgURI, streamListener, null, null, false, "", false);
|
||||
gFooOfflineStoreSizeInitial = fooFolder.filePath.fileSize;
|
||||
yield false;
|
||||
}
|
||||
await streamListener.promise;
|
||||
});
|
||||
|
||||
function* crossStreaming() {
|
||||
add_task(async function crossStreaming() {
|
||||
/**
|
||||
* Streaming message1 from fooFolder. message1 is present in
|
||||
* offline store of inbox. We now test that streaming the message1
|
||||
|
@ -223,7 +214,9 @@ function* crossStreaming() {
|
|||
);
|
||||
let msgServ = messenger.messageServiceFromURI(msgURI);
|
||||
// pass true for aLocalOnly since message should be in offline store of Inbox.
|
||||
msgServ.streamMessage(msgURI, gStreamListener, null, null, false, "", true);
|
||||
let streamListener = new PromiseTestUtils.PromiseStreamListener();
|
||||
msgServ.streamMessage(msgURI, streamListener, null, null, false, "", true);
|
||||
await streamListener.promise;
|
||||
gFooOfflineStoreSizeFinal = fooFolder.filePath.fileSize;
|
||||
gImapInboxOfflineStoreSizeFinal = IMAPPump.inbox.filePath.fileSize;
|
||||
Assert.equal(gFooOfflineStoreSizeFinal, gFooOfflineStoreSizeInitial);
|
||||
|
@ -231,75 +224,19 @@ function* crossStreaming() {
|
|||
gImapInboxOfflineStoreSizeFinal,
|
||||
gImapInboxOfflineStoreSizeInitial
|
||||
);
|
||||
yield false;
|
||||
}
|
||||
});
|
||||
|
||||
function teardown() {
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* helper functions
|
||||
*/
|
||||
|
||||
asyncUrlListener.callback = function(aUrl, aExitCode) {
|
||||
Assert.equal(aExitCode, 0);
|
||||
};
|
||||
|
||||
// We use this as a display consumer
|
||||
var streamListener = {
|
||||
_data: "",
|
||||
|
||||
QueryInterface: ChromeUtils.generateQI([
|
||||
"nsIStreamListener",
|
||||
"nsIRequestObserver",
|
||||
]),
|
||||
|
||||
// nsIRequestObserver
|
||||
onStartRequest(aRequest) {},
|
||||
onStopRequest(aRequest, aStatusCode) {
|
||||
Assert.equal(aStatusCode, 0);
|
||||
},
|
||||
|
||||
// nsIStreamListener
|
||||
onDataAvailable(aRequest, aInputStream, aOffset, aCount) {
|
||||
let scriptStream = Cc[
|
||||
"@mozilla.org/scriptableinputstream;1"
|
||||
].createInstance(Ci.nsIScriptableInputStream);
|
||||
|
||||
scriptStream.init(aInputStream);
|
||||
|
||||
scriptStream.read(aCount);
|
||||
},
|
||||
};
|
||||
|
||||
var gStreamListener = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIStreamListener"]),
|
||||
_stream: null,
|
||||
_data: null,
|
||||
onStartRequest(aRequest) {
|
||||
this._data = "";
|
||||
},
|
||||
onStopRequest(aRequest, aStatusCode) {
|
||||
async_driver();
|
||||
this._stream = null;
|
||||
},
|
||||
onDataAvailable(aRequest, aInputStream, aOff, aCount) {
|
||||
if (this._stream == null) {
|
||||
this._stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
);
|
||||
this._stream.init(aInputStream);
|
||||
}
|
||||
this._data += this._stream.read(aCount);
|
||||
},
|
||||
};
|
||||
|
||||
// given a test file, return the file uri spec
|
||||
/**
|
||||
* 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);
|
||||
|
|
|
@ -6,12 +6,12 @@
|
|||
* Tests imap save and detach attachments.
|
||||
*/
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
var { MessageGenerator } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/MessageGenerator.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
// javascript mime emitter functions
|
||||
var mimeMsg = {};
|
||||
|
@ -20,21 +20,64 @@ var { MailServices } = ChromeUtils.import(
|
|||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
|
||||
// IMAP pump
|
||||
|
||||
var kAttachFileName = "bob.txt";
|
||||
function SaveAttachmentCallback() {
|
||||
this.attachments = null;
|
||||
this._promise = new Promise((resolve, reject) => {
|
||||
this._resolve = resolve;
|
||||
this._reject = reject;
|
||||
});
|
||||
}
|
||||
|
||||
setupIMAPPump();
|
||||
SaveAttachmentCallback.prototype = {
|
||||
callback: function saveAttachmentCallback_callback(aMsgHdr, aMimeMessage) {
|
||||
this.attachments = aMimeMessage.allAttachments;
|
||||
this._resolve();
|
||||
},
|
||||
get promise() {
|
||||
return this._promise;
|
||||
},
|
||||
};
|
||||
var gCallbackObject = new SaveAttachmentCallback();
|
||||
|
||||
// Dummy message window so we can say the inbox is open in a window.
|
||||
var dummyMsgWindow = Cc["@mozilla.org/messenger/msgwindow;1"].createInstance(
|
||||
Ci.nsIMsgWindow
|
||||
);
|
||||
|
||||
var tests = [loadImapMessage, startMime, startDetach, testDetach, endTest];
|
||||
function MsgsDeletedListener() {
|
||||
this._promise = new Promise(resolve => (this._resolve = resolve));
|
||||
}
|
||||
MsgsDeletedListener.prototype = {
|
||||
msgsDeleted(aMsgArray) {
|
||||
this._resolve();
|
||||
},
|
||||
get promise() {
|
||||
return this._promise;
|
||||
},
|
||||
};
|
||||
var trackDeletionMessageListener = new MsgsDeletedListener();
|
||||
|
||||
add_task(function setupTest() {
|
||||
setupIMAPPump();
|
||||
|
||||
// Add folder listeners that will capture async events
|
||||
MailServices.mfn.addListener(
|
||||
trackDeletionMessageListener,
|
||||
Ci.nsIMsgFolderNotificationService.msgsDeleted
|
||||
);
|
||||
|
||||
// We need to register the dummyMsgWindow so that when we've finished running
|
||||
// the append url, in nsImapMailFolder::OnStopRunningUrl, we'll think the
|
||||
// Inbox is open in a folder and update it, which the detach code relies
|
||||
// on to finish the detach.
|
||||
|
||||
dummyMsgWindow.openFolder = IMAPPump.inbox;
|
||||
MailServices.mailSession.AddMsgWindow(dummyMsgWindow);
|
||||
});
|
||||
|
||||
// load and update a message in the imap fake server
|
||||
function* loadImapMessage() {
|
||||
add_task(async function loadImapMessage() {
|
||||
let gMessageGenerator = new MessageGenerator();
|
||||
// create a synthetic message with attachment
|
||||
let smsg = gMessageGenerator.makeMessage({
|
||||
|
@ -47,30 +90,29 @@ function* loadImapMessage() {
|
|||
let imapInbox = IMAPPump.daemon.getMailbox("INBOX");
|
||||
let message = new imapMessage(msgURI.spec, imapInbox.uidnext++, []);
|
||||
IMAPPump.mailbox.addMessage(message);
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
Assert.equal(1, IMAPPump.inbox.getTotalMessages(false));
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
Assert.ok(msgHdr instanceof Ci.nsIMsgDBHdr);
|
||||
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
// process the message through mime
|
||||
function* startMime() {
|
||||
add_task(async function startMime() {
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
|
||||
mimeMsg.MsgHdrToMimeMessage(
|
||||
msgHdr,
|
||||
gCallbackObject,
|
||||
gCallbackObject.callback,
|
||||
true /* allowDownload */
|
||||
true // allowDownload
|
||||
);
|
||||
yield false;
|
||||
}
|
||||
await gCallbackObject.promise;
|
||||
});
|
||||
|
||||
// detach any found attachments
|
||||
function* startDetach() {
|
||||
add_task(async function startDetach() {
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
let msgURI = msgHdr.folder.generateMessageURI(msgHdr.messageKey);
|
||||
|
||||
|
@ -88,14 +130,11 @@ function* startDetach() {
|
|||
null
|
||||
);
|
||||
// deletion of original message should kick async_driver.
|
||||
yield false;
|
||||
}
|
||||
await trackDeletionMessageListener.promise;
|
||||
});
|
||||
|
||||
// test that the detachment was successful
|
||||
function* testDetach() {
|
||||
// This test seems to fail on Linux without the following delay.
|
||||
mailTestUtils.do_timeout_function(200, async_driver);
|
||||
yield false;
|
||||
add_task(function testDetach() {
|
||||
// Check that the file attached to the message now exists in the profile
|
||||
// directory.
|
||||
let checkFile = do_get_profile().clone();
|
||||
|
@ -110,40 +149,12 @@ function* testDetach() {
|
|||
Assert.ok(msgHdr !== null);
|
||||
let messageContent = getContentFromMessage(msgHdr);
|
||||
Assert.ok(messageContent.includes("AttachmentDetached"));
|
||||
}
|
||||
});
|
||||
|
||||
// Cleanup
|
||||
function endTest() {
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function SaveAttachmentCallback() {
|
||||
this.attachments = null;
|
||||
}
|
||||
|
||||
SaveAttachmentCallback.prototype = {
|
||||
callback: function saveAttachmentCallback_callback(aMsgHdr, aMimeMessage) {
|
||||
this.attachments = aMimeMessage.allAttachments;
|
||||
async_driver();
|
||||
},
|
||||
};
|
||||
var gCallbackObject = new SaveAttachmentCallback();
|
||||
|
||||
function run_test() {
|
||||
// Add folder listeners that will capture async events
|
||||
const nsIMFNService = Ci.nsIMsgFolderNotificationService;
|
||||
MailServices.mfn.addListener(mfnListener, nsIMFNService.msgsDeleted);
|
||||
|
||||
// We need to register the dummyMsgWindow so that when we've finished running
|
||||
// the append url, in nsImapMailFolder::OnStopRunningUrl, we'll think the
|
||||
// Inbox is open in a folder and update it, which the detach code relies
|
||||
// on to finish the detach.
|
||||
|
||||
dummyMsgWindow.openFolder = IMAPPump.inbox;
|
||||
MailServices.mailSession.AddMsgWindow(dummyMsgWindow);
|
||||
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Get the full message content.
|
||||
|
@ -162,7 +173,7 @@ function getContentFromMessage(aMsgHdr) {
|
|||
let streamListener = Cc[
|
||||
"@mozilla.org/network/sync-stream-listener;1"
|
||||
].createInstance(Ci.nsISyncStreamListener);
|
||||
// pass true for aLocalOnly since message should be in offline store.
|
||||
// Pass true for aLocalOnly since message should be in offline store.
|
||||
messenger
|
||||
.messageServiceFromURI(msgUri)
|
||||
.streamMessage(msgUri, streamListener, null, null, false, "", true);
|
||||
|
@ -174,10 +185,3 @@ function getContentFromMessage(aMsgHdr) {
|
|||
sis.close();
|
||||
return content;
|
||||
}
|
||||
|
||||
var mfnListener = {
|
||||
msgsDeleted(aMsgArray) {
|
||||
dump("msg deleted\n");
|
||||
async_driver();
|
||||
},
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// This tests various features of imap autosync
|
||||
// N.B. We need to beware of messageInjection, since it turns off
|
||||
// N.B. We need to beware of MessageInjection, since it turns off
|
||||
// imap autosync.
|
||||
|
||||
// Our general approach is to attach an nsIAutoSyncMgrListener to the
|
||||
|
@ -17,24 +17,15 @@
|
|||
// We also test that folders that have messages added to them via move/copy
|
||||
// get put in the front of the queue.
|
||||
|
||||
// IMAP pump
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
|
||||
/* import-globals-from ../../../test/resources/alertTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
load("../../../resources/alertTestUtils.js");
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
|
||||
// Globals
|
||||
var { MailServices } = ChromeUtils.import(
|
||||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
|
||||
setupIMAPPump();
|
||||
var { MessageGenerator } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/MessageGenerator.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
var msgFlagOffline = Ci.nsMsgMessageFlags.Offline;
|
||||
var nsIAutoSyncMgrListener = Ci.nsIAutoSyncMgrListener;
|
||||
|
@ -42,33 +33,27 @@ var nsIAutoSyncMgrListener = Ci.nsIAutoSyncMgrListener;
|
|||
var gAutoSyncManager = Cc["@mozilla.org/imap/autosyncmgr;1"].getService(
|
||||
Ci.nsIAutoSyncManager
|
||||
);
|
||||
|
||||
// Definition of tests
|
||||
var tests = [
|
||||
test_createTargetFolder,
|
||||
test_checkForNewMessages,
|
||||
test_triggerAutoSyncIdle,
|
||||
test_moveMessageToTargetFolder,
|
||||
test_waitForTargetUpdate,
|
||||
endTest,
|
||||
];
|
||||
|
||||
var gTargetFolder;
|
||||
|
||||
function* test_createTargetFolder() {
|
||||
add_task(function setupTest() {
|
||||
setupIMAPPump();
|
||||
addMessageToFolder(IMAPPump.inbox);
|
||||
});
|
||||
|
||||
add_task(async function test_createTargetFolder() {
|
||||
gAutoSyncManager.addListener(gAutoSyncListener);
|
||||
|
||||
IMAPPump.incomingServer.rootFolder.createSubfolder("targetFolder", null);
|
||||
yield false;
|
||||
await PromiseTestUtils.promiseFolderAdded("targetFolder");
|
||||
gTargetFolder = IMAPPump.incomingServer.rootFolder.getChildNamed(
|
||||
"targetFolder"
|
||||
);
|
||||
Assert.ok(gTargetFolder instanceof Ci.nsIMsgImapMailFolder);
|
||||
// set folder to be checked for new messages when inbox is checked.
|
||||
gTargetFolder.setFlag(Ci.nsMsgFolderFlags.CheckNew);
|
||||
}
|
||||
});
|
||||
|
||||
function* test_checkForNewMessages() {
|
||||
add_task(function test_checkForNewMessages() {
|
||||
addMessageToFolder(gTargetFolder);
|
||||
// This will update the INBOX and STATUS targetFolder. We only care about
|
||||
// the latter.
|
||||
|
@ -76,10 +61,9 @@ function* test_checkForNewMessages() {
|
|||
IMAPPump.server.performTest("STATUS");
|
||||
// Now we'd like to make autosync update folders it knows about, to
|
||||
// get the initial autosync out of the way.
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
function test_triggerAutoSyncIdle() {
|
||||
add_task(function test_triggerAutoSyncIdle() {
|
||||
// wait for both folders to get updated.
|
||||
gAutoSyncListener._waitingForDiscoveryList.push(IMAPPump.inbox);
|
||||
gAutoSyncListener._waitingForDiscoveryList.push(gTargetFolder);
|
||||
|
@ -87,29 +71,30 @@ function test_triggerAutoSyncIdle() {
|
|||
let observer = gAutoSyncManager.QueryInterface(Ci.nsIObserver);
|
||||
observer.observe(null, "mail-startup-done", "");
|
||||
observer.observe(null, "mail:appIdle", "idle");
|
||||
}
|
||||
});
|
||||
|
||||
// move the message to a diffent folder
|
||||
function* test_moveMessageToTargetFolder() {
|
||||
add_task(async function test_moveMessageToTargetFolder() {
|
||||
let observer = gAutoSyncManager.QueryInterface(Ci.nsIObserver);
|
||||
observer.observe(null, "mail:appIdle", "back");
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
Assert.ok(msgHdr !== null);
|
||||
|
||||
let listener = new PromiseTestUtils.PromiseCopyListener();
|
||||
// Now move this message to the target folder.
|
||||
MailServices.copy.copyMessages(
|
||||
IMAPPump.inbox,
|
||||
[msgHdr],
|
||||
gTargetFolder,
|
||||
true,
|
||||
asyncCopyListener,
|
||||
listener,
|
||||
null,
|
||||
false
|
||||
);
|
||||
yield false;
|
||||
}
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function* test_waitForTargetUpdate() {
|
||||
add_task(async function test_waitForTargetUpdate() {
|
||||
// After the copy, now we expect to get notified of the gTargetFolder
|
||||
// getting updated, after we simulate going idle.
|
||||
gAutoSyncListener._waitingForUpdate = true;
|
||||
|
@ -117,81 +102,61 @@ function* test_waitForTargetUpdate() {
|
|||
gAutoSyncManager
|
||||
.QueryInterface(Ci.nsIObserver)
|
||||
.observe(null, "mail:appIdle", "idle");
|
||||
// Need two yield here to get results of both onDownloadCompleted and onDiscoveryQProcessed
|
||||
yield false;
|
||||
yield false;
|
||||
}
|
||||
await gAutoSyncListener.promiseOnDownloadCompleted;
|
||||
await gAutoSyncListener.promiseOnDiscoveryQProcessed;
|
||||
});
|
||||
|
||||
// Cleanup
|
||||
function endTest() {
|
||||
add_task(function endTest() {
|
||||
let numMsgs = 0;
|
||||
for (let header of gTargetFolder.messages) {
|
||||
numMsgs++;
|
||||
Assert.notEqual(header.flags & msgFlagOffline, 0);
|
||||
Assert.notEqual(header.flags & Ci.nsMsgMessageFlags.Offline, 0);
|
||||
}
|
||||
Assert.equal(2, numMsgs);
|
||||
Assert.equal(gAutoSyncListener._waitingForUpdateList.length, 0);
|
||||
Assert.ok(!gAutoSyncListener._waitingForDiscovery);
|
||||
Assert.ok(!gAutoSyncListener._waitingForUpdate);
|
||||
teardownIMAPPump();
|
||||
});
|
||||
|
||||
function autoSyncListenerPromise() {
|
||||
this._inQFolderList = [];
|
||||
this._runnning = false;
|
||||
this._lastMessage = {};
|
||||
this._waitingForUpdateList = [];
|
||||
this._waitingForUpdate = false;
|
||||
this._waitingForDiscoveryList = [];
|
||||
this._waitingForDiscovery = false;
|
||||
|
||||
this._promiseOnDownloadCompleted = new Promise(resolve => {
|
||||
this._resolveOnDownloadCompleted = resolve;
|
||||
});
|
||||
this._promiseOnDiscoveryQProcessed = new Promise(resolve => {
|
||||
this._resolveOnDiscoveryQProcessed = resolve;
|
||||
});
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
// Add folder listeners that will capture async events
|
||||
const nsIMFNService = Ci.nsIMsgFolderNotificationService;
|
||||
let flags =
|
||||
nsIMFNService.folderAdded |
|
||||
nsIMFNService.msgsMoveCopyCompleted |
|
||||
nsIMFNService.msgAdded;
|
||||
MailServices.mfn.addListener(mfnListener, flags);
|
||||
addMessageToFolder(IMAPPump.inbox);
|
||||
|
||||
async_run_tests(tests);
|
||||
}
|
||||
|
||||
// listeners for various events to drive the tests.
|
||||
|
||||
var mfnListener = {
|
||||
msgsMoveCopyCompleted(aMove, aSrcMsgs, aDestFolder, aDestMsgs) {
|
||||
dump("msgsMoveCopyCompleted to folder " + aDestFolder.name + "\n");
|
||||
},
|
||||
folderAdded(aFolder) {
|
||||
// we are only using async yield on the target folder add
|
||||
if (aFolder.name == "targetFolder") {
|
||||
async_driver();
|
||||
}
|
||||
},
|
||||
|
||||
msgAdded(aMsg) {},
|
||||
};
|
||||
|
||||
var gAutoSyncListener = {
|
||||
_inQFolderList: [],
|
||||
_runnning: false,
|
||||
_lastMessage: {},
|
||||
_waitingForUpdateList: [],
|
||||
_waitingForUpdate: false,
|
||||
_waitingForDiscoveryList: [],
|
||||
_waitingForDiscovery: false,
|
||||
|
||||
autoSyncListenerPromise.prototype = {
|
||||
onStateChanged(running) {
|
||||
this._runnning = running;
|
||||
},
|
||||
|
||||
onFolderAddedIntoQ(queue, folder) {
|
||||
dump("folder added into Q " + this.qName(queue) + " " + folder.URI + "\n");
|
||||
console.trace(
|
||||
"folder added into Q " + this.qName(queue) + " " + folder.URI + "\n"
|
||||
);
|
||||
},
|
||||
onFolderRemovedFromQ(queue, folder) {
|
||||
dump(
|
||||
console.trace(
|
||||
"folder removed from Q " + this.qName(queue) + " " + folder.URI + "\n"
|
||||
);
|
||||
},
|
||||
onDownloadStarted(folder, numOfMessages, totalPending) {
|
||||
dump("folder download started" + folder.URI + "\n");
|
||||
console.trace("folder download started" + folder.URI + "\n");
|
||||
},
|
||||
|
||||
onDownloadCompleted(folder) {
|
||||
dump("folder download completed" + folder.URI + "\n");
|
||||
console.trace("folder download completed" + folder.URI + "\n");
|
||||
if (folder instanceof Ci.nsIMsgFolder) {
|
||||
let index = mailTestUtils.non_strict_index_of(
|
||||
this._waitingForUpdateList,
|
||||
|
@ -203,19 +168,19 @@ var gAutoSyncListener = {
|
|||
if (this._waitingForUpdate && this._waitingForUpdateList.length == 0) {
|
||||
dump("got last folder update looking for\n");
|
||||
this._waitingForUpdate = false;
|
||||
async_driver();
|
||||
this._resolveOnDownloadCompleted();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onDownloadError(folder) {
|
||||
if (folder instanceof Ci.nsIMsgFolder) {
|
||||
dump("OnDownloadError: " + folder.prettyName + "\n");
|
||||
console.trace("OnDownloadError: " + folder.prettyName + "\n");
|
||||
}
|
||||
},
|
||||
|
||||
onDiscoveryQProcessed(folder, numOfHdrsProcessed, leftToProcess) {
|
||||
dump("onDiscoveryQProcessed: " + folder.prettyName + "\n");
|
||||
console.trace("onDiscoveryQProcessed: " + folder.prettyName + "\n");
|
||||
let index = mailTestUtils.non_strict_index_of(
|
||||
this._waitingForDiscoveryList,
|
||||
folder
|
||||
|
@ -227,26 +192,33 @@ var gAutoSyncListener = {
|
|||
this._waitingForDiscovery &&
|
||||
this._waitingForDiscoveryList.length == 0
|
||||
) {
|
||||
dump("got last folder discovery looking for\n");
|
||||
console.trace("got last folder discovery looking for\n");
|
||||
this._waitingForDiscovery = false;
|
||||
async_driver();
|
||||
this._resolveOnDiscoveryQProcessed();
|
||||
}
|
||||
},
|
||||
|
||||
onAutoSyncInitiated(folder) {},
|
||||
qName(queueType) {
|
||||
if (queueType == nsIAutoSyncMgrListener.PriorityQueue) {
|
||||
if (queueType == Ci.nsIAutoSyncMgrListener.PriorityQueue) {
|
||||
return "priorityQ";
|
||||
}
|
||||
if (queueType == nsIAutoSyncMgrListener.UpdateQueue) {
|
||||
if (queueType == Ci.nsIAutoSyncMgrListener.UpdateQueue) {
|
||||
return "updateQ";
|
||||
}
|
||||
if (queueType == nsIAutoSyncMgrListener.DiscoveryQueue) {
|
||||
if (queueType == Ci.nsIAutoSyncMgrListener.DiscoveryQueue) {
|
||||
return "discoveryQ";
|
||||
}
|
||||
return "";
|
||||
},
|
||||
get promiseOnDownloadCompleted() {
|
||||
return this._promiseOnDownloadCompleted;
|
||||
},
|
||||
get promiseOnDiscoveryQProcessed() {
|
||||
return this._promiseOnDiscoveryQProcessed;
|
||||
},
|
||||
};
|
||||
var gAutoSyncListener = new autoSyncListenerPromise();
|
||||
|
||||
/*
|
||||
* helper functions
|
||||
|
|
|
@ -1,60 +1,63 @@
|
|||
/* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
*
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/licenses/publicdomain/
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/* 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 content length for the IMAP protocol. This focuses on necko URLs
|
||||
* that are run externally.
|
||||
*/
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
|
||||
var { MailServices } = ChromeUtils.import(
|
||||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
var gMsgHdr = null;
|
||||
|
||||
// Take a multipart message as we're testing attachment URLs as well
|
||||
var gFile = do_get_file("../../../data/multipart-complex2");
|
||||
|
||||
var tests = [setup, addMessageToServer, verifyContentLength, teardown];
|
||||
add_task(function setup() {
|
||||
setupIMAPPump();
|
||||
|
||||
// Set up nsIMsgFolderListener to get the header when it's received
|
||||
MailServices.mfn.addListener(msgAddedListener, MailServices.mfn.msgAdded);
|
||||
|
||||
IMAPPump.inbox.clearFlag(Ci.nsMsgFolderFlags.Offline);
|
||||
});
|
||||
|
||||
// Adds some messages directly to a mailbox (eg new mail)
|
||||
function* addMessageToServer() {
|
||||
add_task(async function addMessageToServer() {
|
||||
let URI = Services.io.newFileURI(gFile).QueryInterface(Ci.nsIFileURL);
|
||||
IMAPPump.mailbox.addMessage(
|
||||
new imapMessage(URI.spec, IMAPPump.mailbox.uidnext++, [])
|
||||
);
|
||||
|
||||
IMAPPump.inbox.updateFolder(null);
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
var msgFolderListener = {
|
||||
function MsgAddedListener() {
|
||||
this._promise = new Promise(resolve => {
|
||||
this._resolve = resolve;
|
||||
});
|
||||
}
|
||||
MsgAddedListener.prototype = {
|
||||
msgAdded(aMsgHdr) {
|
||||
gMsgHdr = aMsgHdr;
|
||||
executeSoon(async_driver);
|
||||
this._resolve();
|
||||
},
|
||||
get promise() {
|
||||
return this._promise;
|
||||
},
|
||||
};
|
||||
var msgAddedListener = new MsgAddedListener();
|
||||
|
||||
function setup() {
|
||||
setupIMAPPump();
|
||||
|
||||
// Set up nsIMsgFolderListener to get the header when it's received
|
||||
MailServices.mfn.addListener(msgFolderListener, MailServices.mfn.msgAdded);
|
||||
|
||||
IMAPPump.inbox.clearFlag(Ci.nsMsgFolderFlags.Offline);
|
||||
}
|
||||
|
||||
function verifyContentLength() {
|
||||
add_task(async function verifyContentLength() {
|
||||
await msgAddedListener.promise;
|
||||
let messageUri = IMAPPump.inbox.getUriForMsg(gMsgHdr);
|
||||
// Convert this to a URI that necko can run
|
||||
let messenger = Cc["@mozilla.org/messenger;1"].createInstance(
|
||||
|
@ -90,13 +93,9 @@ function verifyContentLength() {
|
|||
// Currently attachments have their content length set to the length of the
|
||||
// entire message
|
||||
Assert.equal(attachmentChannel.contentLength, gFile.fileSize);
|
||||
}
|
||||
});
|
||||
|
||||
function teardown() {
|
||||
MailServices.mfn.removeListener(msgFolderListener);
|
||||
add_task(function endTest() {
|
||||
MailServices.mfn.removeListener(msgAddedListener);
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -8,70 +8,54 @@
|
|||
|
||||
Services.prefs.setIntPref("mailnews.tcptimeout", 2);
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/alertTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/alertTestUtils.js");
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
|
||||
// IMAP pump
|
||||
|
||||
// Globals
|
||||
var { MessageGenerator } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/MessageGenerator.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
var { MailServices } = ChromeUtils.import(
|
||||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
|
||||
setupIMAPPump();
|
||||
|
||||
var gGotAlert = false;
|
||||
var gGotMsgAdded = false;
|
||||
var gTargetFolder;
|
||||
var alertResolve;
|
||||
var alertPromise = new Promise(resolve => {
|
||||
alertResolve = resolve;
|
||||
});
|
||||
|
||||
/* exported alert */
|
||||
// to alertTestUtils.js
|
||||
function alert(aDialogTitle, aText) {
|
||||
Assert.ok(aText.startsWith("Connection to server localhost timed out."));
|
||||
gGotAlert = true;
|
||||
async_driver();
|
||||
alertResolve(aText);
|
||||
}
|
||||
|
||||
var CopyListener = {
|
||||
OnStartCopy() {},
|
||||
OnProgress(aProgress, aProgressMax) {},
|
||||
SetMessageKey(aMsgKey) {},
|
||||
GetMessageId() {},
|
||||
OnStopCopy(aStatus) {
|
||||
async_driver();
|
||||
},
|
||||
};
|
||||
add_task(function setupTest() {
|
||||
setupIMAPPump();
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.default.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
// Definition of tests
|
||||
var tests = [
|
||||
createTargetFolder,
|
||||
loadImapMessage,
|
||||
moveMessageToTargetFolder,
|
||||
waitForOfflinePlayback,
|
||||
updateTargetFolder,
|
||||
endTest,
|
||||
];
|
||||
|
||||
var gTargetFolder;
|
||||
function* createTargetFolder() {
|
||||
add_task(async function createTargetFolder() {
|
||||
IMAPPump.daemon.copySleep = 5000;
|
||||
IMAPPump.incomingServer.rootFolder.createSubfolder("targetFolder", null);
|
||||
yield false;
|
||||
await PromiseTestUtils.promiseFolderAdded("targetFolder");
|
||||
gTargetFolder = IMAPPump.incomingServer.rootFolder.getChildNamed(
|
||||
"targetFolder"
|
||||
);
|
||||
Assert.ok(gTargetFolder instanceof Ci.nsIMsgImapMailFolder);
|
||||
gTargetFolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
gTargetFolder.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
// load and update a message in the imap fake server
|
||||
function* loadImapMessage() {
|
||||
add_task(async function loadImapMessage() {
|
||||
let messages = [];
|
||||
let gMessageGenerator = new MessageGenerator();
|
||||
messages = messages.concat(gMessageGenerator.makeMessage());
|
||||
|
@ -82,49 +66,50 @@ function* loadImapMessage() {
|
|||
let imapInbox = IMAPPump.daemon.getMailbox("INBOX");
|
||||
var gMessage = new imapMessage(msgURI.spec, imapInbox.uidnext++, []);
|
||||
IMAPPump.mailbox.addMessage(gMessage);
|
||||
IMAPPump.inbox.updateFolder(null);
|
||||
yield false;
|
||||
|
||||
let promiseUrlListener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, promiseUrlListener);
|
||||
await promiseUrlListener.promise;
|
||||
Assert.equal(1, IMAPPump.inbox.getTotalMessages(false));
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
Assert.ok(msgHdr instanceof Ci.nsIMsgDBHdr);
|
||||
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
// move the message to a diffent folder
|
||||
function* moveMessageToTargetFolder() {
|
||||
add_task(async function moveMessageToTargetFolder() {
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
|
||||
// This should cause the move to be done as an offline imap operation
|
||||
// that's played back immediately.
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener();
|
||||
MailServices.copy.copyMessages(
|
||||
IMAPPump.inbox,
|
||||
[msgHdr],
|
||||
gTargetFolder,
|
||||
true,
|
||||
CopyListener,
|
||||
copyListener,
|
||||
gDummyMsgWindow,
|
||||
true
|
||||
);
|
||||
yield false;
|
||||
}
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
function* waitForOfflinePlayback() {
|
||||
// just wait for the alert about timed out connection.
|
||||
yield false;
|
||||
// then, wait for a second so we don't get our next url aborted.
|
||||
do_timeout(1000, async_driver);
|
||||
yield false;
|
||||
}
|
||||
add_task(async function waitForOfflinePlayback() {
|
||||
// Just wait for the alert about timed out connection.
|
||||
let alertText = await alertPromise;
|
||||
Assert.ok(alertText.startsWith("Connection to server localhost timed out."));
|
||||
});
|
||||
|
||||
function* updateTargetFolder() {
|
||||
gTargetFolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
add_task(async function updateTargetFolderAndInbox() {
|
||||
let urlListenerTargetFolder = new PromiseTestUtils.PromiseUrlListener();
|
||||
gTargetFolder.updateFolderWithListener(null, urlListenerTargetFolder);
|
||||
await urlListenerTargetFolder.promise;
|
||||
let urlListenerInbox = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, urlListenerInbox);
|
||||
await urlListenerInbox.promise;
|
||||
});
|
||||
|
||||
// Cleanup
|
||||
function endTest() {
|
||||
Assert.ok(gGotAlert);
|
||||
add_task(async function endTest() {
|
||||
// Make sure neither source nor target folder have offline events.
|
||||
Assert.ok(!IMAPPump.inbox.getFlag(Ci.nsMsgFolderFlags.OfflineEvents));
|
||||
Assert.ok(!gTargetFolder.getFlag(Ci.nsMsgFolderFlags.OfflineEvents));
|
||||
|
@ -134,34 +119,4 @@ function endTest() {
|
|||
// retried.
|
||||
Assert.equal(gTargetFolder.getTotalMessages(false), 1);
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
// listeners
|
||||
|
||||
var mfnListener = {
|
||||
folderAdded(aFolder) {
|
||||
// we are only using async yield on the target folder add
|
||||
if (aFolder.name == "targetFolder") {
|
||||
async_driver();
|
||||
}
|
||||
},
|
||||
|
||||
msgAdded(aMsg) {
|
||||
if (!gGotMsgAdded) {
|
||||
async_driver();
|
||||
}
|
||||
gGotMsgAdded = true;
|
||||
},
|
||||
};
|
||||
|
||||
function run_test() {
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.default.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
// Add folder listeners that will capture async events
|
||||
const nsIMFNService = Ci.nsIMsgFolderNotificationService;
|
||||
let flags = nsIMFNService.folderAdded | nsIMFNService.msgAdded;
|
||||
MailServices.mfn.addListener(mfnListener, flags);
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,128 +1,24 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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 imap flag changes made from a different profile/machine
|
||||
* are stored in db.
|
||||
*/
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
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;
|
||||
|
||||
var tests = [
|
||||
setup,
|
||||
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.
|
||||
gSecondFolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function* simulateForwardFlagSet() {
|
||||
gMessage.setFlag("$Forwarded");
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function* checkForwardedFlagSet() {
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(
|
||||
gSynthMessage.messageId
|
||||
);
|
||||
Assert.equal(
|
||||
msgHdr.flags & Ci.nsMsgMessageFlags.Forwarded,
|
||||
Ci.nsMsgMessageFlags.Forwarded
|
||||
);
|
||||
gSecondFolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function* clearForwardedFlag() {
|
||||
gMessage.clearFlag("$Forwarded");
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function* checkForwardedFlagCleared() {
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(
|
||||
gSynthMessage.messageId
|
||||
);
|
||||
Assert.equal(msgHdr.flags & Ci.nsMsgMessageFlags.Forwarded, 0);
|
||||
gSecondFolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function* setSeenFlag() {
|
||||
gMessage.setFlag("\\Seen");
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function* checkSeenFlagSet() {
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(
|
||||
gSynthMessage.messageId
|
||||
);
|
||||
Assert.equal(
|
||||
msgHdr.flags & Ci.nsMsgMessageFlags.Read,
|
||||
Ci.nsMsgMessageFlags.Read
|
||||
);
|
||||
gSecondFolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function* simulateRepliedFlagSet() {
|
||||
gMessage.setFlag("\\Answered");
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function* checkRepliedFlagSet() {
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(
|
||||
gSynthMessage.messageId
|
||||
);
|
||||
Assert.equal(
|
||||
msgHdr.flags & Ci.nsMsgMessageFlags.Replied,
|
||||
Ci.nsMsgMessageFlags.Replied
|
||||
);
|
||||
gSecondFolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function* simulateTagAdded() {
|
||||
gMessage.setFlag("randomtag");
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function* checkTagSet() {
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(
|
||||
gSynthMessage.messageId
|
||||
);
|
||||
let keywords = msgHdr.getStringProperty("keywords");
|
||||
Assert.ok(keywords.includes("randomtag"));
|
||||
gSecondFolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function* clearTag() {
|
||||
gMessage.clearFlag("randomtag");
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function checkTagCleared() {
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(
|
||||
gSynthMessage.messageId
|
||||
);
|
||||
let keywords = msgHdr.getStringProperty("keywords");
|
||||
Assert.ok(!keywords.includes("randomtag"));
|
||||
},
|
||||
teardown,
|
||||
];
|
||||
|
||||
function* setup() {
|
||||
add_task(async function setupTest() {
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.default.autosync_offline_stores",
|
||||
false
|
||||
|
@ -145,18 +41,138 @@ function* setup() {
|
|||
IMAPPump.mailbox.addMessage(gMessage);
|
||||
|
||||
// update folder to download header.
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
asyncUrlListener.callback = function(aUrl, aExitCode) {
|
||||
Assert.equal(aExitCode, 0);
|
||||
};
|
||||
add_task(async function switchAwayFromInbox() {
|
||||
let rootFolder = IMAPPump.incomingServer.rootFolder;
|
||||
gSecondFolder = rootFolder
|
||||
.getChildNamed("secondFolder")
|
||||
.QueryInterface(Ci.nsIMsgImapMailFolder);
|
||||
|
||||
function teardown() {
|
||||
// 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 simulateForwardFlagSet() {
|
||||
gMessage.setFlag("$Forwarded");
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(async function checkForwardedFlagSet() {
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(
|
||||
gSynthMessage.messageId
|
||||
);
|
||||
Assert.equal(
|
||||
msgHdr.flags & Ci.nsMsgMessageFlags.Forwarded,
|
||||
Ci.nsMsgMessageFlags.Forwarded
|
||||
);
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
gSecondFolder.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(async function clearForwardedFlag() {
|
||||
gMessage.clearFlag("$Forwarded");
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(async function checkForwardedFlagCleared() {
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(
|
||||
gSynthMessage.messageId
|
||||
);
|
||||
Assert.equal(msgHdr.flags & Ci.nsMsgMessageFlags.Forwarded, 0);
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
gSecondFolder.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(async function setSeenFlag() {
|
||||
gMessage.setFlag("\\Seen");
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(async function checkSeenFlagSet() {
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(
|
||||
gSynthMessage.messageId
|
||||
);
|
||||
Assert.equal(
|
||||
msgHdr.flags & Ci.nsMsgMessageFlags.Read,
|
||||
Ci.nsMsgMessageFlags.Read
|
||||
);
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
gSecondFolder.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(async function simulateRepliedFlagSet() {
|
||||
gMessage.setFlag("\\Answered");
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(async function checkRepliedFlagSet() {
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(
|
||||
gSynthMessage.messageId
|
||||
);
|
||||
Assert.equal(
|
||||
msgHdr.flags & Ci.nsMsgMessageFlags.Replied,
|
||||
Ci.nsMsgMessageFlags.Replied
|
||||
);
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
gSecondFolder.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(async function simulateTagAdded() {
|
||||
gMessage.setFlag("randomtag");
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(async function checkTagSet() {
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(
|
||||
gSynthMessage.messageId
|
||||
);
|
||||
let keywords = msgHdr.getStringProperty("keywords");
|
||||
Assert.ok(keywords.includes("randomtag"));
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
gSecondFolder.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(async function clearTag() {
|
||||
gMessage.clearFlag("randomtag");
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(function checkTagCleared() {
|
||||
let msgHdr = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(
|
||||
gSynthMessage.messageId
|
||||
);
|
||||
let keywords = msgHdr.getStringProperty("keywords");
|
||||
Assert.ok(!keywords.includes("randomtag"));
|
||||
});
|
||||
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
/* 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/. */
|
||||
|
||||
// This file tests the folder copying with IMAP. In particular, we're
|
||||
// going to test copying local folders to imap servers, but other tests
|
||||
// could be added.
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
var { MessageGenerator } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/MessageGenerator.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
var gEmptyLocal1, gEmptyLocal2, gEmptyLocal3, gNotEmptyLocal4;
|
||||
|
||||
|
@ -15,97 +19,7 @@ var { MailServices } = ChromeUtils.import(
|
|||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
|
||||
var tests = [
|
||||
setup,
|
||||
function* copyFolder1() {
|
||||
dump("gEmpty1 " + gEmptyLocal1.URI + "\n");
|
||||
MailServices.copy.copyFolder(
|
||||
gEmptyLocal1,
|
||||
IMAPPump.inbox,
|
||||
false,
|
||||
CopyListener,
|
||||
null
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function* copyFolder2() {
|
||||
dump("gEmpty2 " + gEmptyLocal2.URI + "\n");
|
||||
MailServices.copy.copyFolder(
|
||||
gEmptyLocal2,
|
||||
IMAPPump.inbox,
|
||||
false,
|
||||
CopyListener,
|
||||
null
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function* copyFolder3() {
|
||||
dump("gEmpty3 " + gEmptyLocal3.URI + "\n");
|
||||
MailServices.copy.copyFolder(
|
||||
gEmptyLocal3,
|
||||
IMAPPump.inbox,
|
||||
false,
|
||||
CopyListener,
|
||||
null
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function verifyFolders() {
|
||||
let folder1 = IMAPPump.inbox.getChildNamed("empty 1");
|
||||
dump("found folder1\n");
|
||||
let folder2 = IMAPPump.inbox.getChildNamed("empty 2");
|
||||
dump("found folder2\n");
|
||||
let folder3 = IMAPPump.inbox.getChildNamed("empty 3");
|
||||
dump("found folder3\n");
|
||||
Assert.ok(folder1 !== null);
|
||||
Assert.ok(folder2 !== null);
|
||||
Assert.ok(folder3 !== null);
|
||||
},
|
||||
function* moveImapFolder1() {
|
||||
let folder1 = IMAPPump.inbox.getChildNamed("empty 1");
|
||||
let folder2 = IMAPPump.inbox.getChildNamed("empty 2");
|
||||
MailServices.copy.copyFolder(folder2, folder1, true, CopyListener, null);
|
||||
yield false;
|
||||
},
|
||||
function* moveImapFolder2() {
|
||||
let folder1 = IMAPPump.inbox.getChildNamed("empty 1");
|
||||
let folder3 = IMAPPump.inbox.getChildNamed("empty 3");
|
||||
MailServices.copy.copyFolder(folder3, folder1, true, CopyListener, null);
|
||||
yield false;
|
||||
},
|
||||
function verifyImapFolders() {
|
||||
let folder1 = IMAPPump.inbox.getChildNamed("empty 1");
|
||||
dump("found folder1\n");
|
||||
let folder2 = folder1.getChildNamed("empty 2");
|
||||
dump("found folder2\n");
|
||||
let folder3 = folder1.getChildNamed("empty 3");
|
||||
dump("found folder3\n");
|
||||
Assert.ok(folder1 !== null);
|
||||
Assert.ok(folder2 !== null);
|
||||
Assert.ok(folder3 !== null);
|
||||
},
|
||||
function* testImapFolderCopyFailure() {
|
||||
IMAPPump.daemon.commandToFail = "APPEND";
|
||||
// we expect NS_MSG_ERROR_IMAP_COMMAND_FAILED;
|
||||
CopyListener._expectedStatus = 0x80550021;
|
||||
MailServices.copy.copyFolder(
|
||||
gNotEmptyLocal4,
|
||||
IMAPPump.inbox,
|
||||
false,
|
||||
CopyListener,
|
||||
null
|
||||
);
|
||||
|
||||
// In failure case OnStopCopy is sent twice, the first one comes from
|
||||
// nsMsgCopyService, the second one comes from nsImapFolderCopyState.
|
||||
yield false;
|
||||
|
||||
yield false;
|
||||
},
|
||||
teardown,
|
||||
];
|
||||
|
||||
function setup() {
|
||||
add_task(function setupTest() {
|
||||
setupIMAPPump();
|
||||
|
||||
gEmptyLocal1 = localAccountUtils.rootFolder.createLocalSubfolder("empty 1");
|
||||
|
@ -126,27 +40,99 @@ function setup() {
|
|||
// then remove the INBOX folder since it's not verified.
|
||||
IMAPPump.inbox.hierarchyDelimiter = "/";
|
||||
IMAPPump.inbox.verifiedAsOnlineFolder = true;
|
||||
}
|
||||
});
|
||||
|
||||
// nsIMsgCopyServiceListener implementation - runs next test when copy
|
||||
// is completed.
|
||||
var CopyListener = {
|
||||
_expectedStatus: 0,
|
||||
OnStartCopy() {},
|
||||
OnProgress(aProgress, aProgressMax) {},
|
||||
SetMessageKey(aKey) {},
|
||||
SetMessageId(aMessageId) {},
|
||||
OnStopCopy(aStatus) {
|
||||
// Check: message successfully copied.
|
||||
Assert.equal(aStatus, this._expectedStatus);
|
||||
async_driver();
|
||||
},
|
||||
};
|
||||
add_task(async function copyFolder1() {
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener();
|
||||
MailServices.copy.copyFolder(
|
||||
gEmptyLocal1,
|
||||
IMAPPump.inbox,
|
||||
false,
|
||||
copyListener,
|
||||
null
|
||||
);
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
function teardown() {
|
||||
add_task(async function copyFolder2() {
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener();
|
||||
MailServices.copy.copyFolder(
|
||||
gEmptyLocal2,
|
||||
IMAPPump.inbox,
|
||||
false,
|
||||
copyListener,
|
||||
null
|
||||
);
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
add_task(async function copyFolder3() {
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener();
|
||||
MailServices.copy.copyFolder(
|
||||
gEmptyLocal3,
|
||||
IMAPPump.inbox,
|
||||
false,
|
||||
copyListener,
|
||||
null
|
||||
);
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
add_task(function verifyFolders() {
|
||||
let folder1 = IMAPPump.inbox.getChildNamed("empty 1");
|
||||
let folder2 = IMAPPump.inbox.getChildNamed("empty 2");
|
||||
let folder3 = IMAPPump.inbox.getChildNamed("empty 3");
|
||||
Assert.ok(folder1 !== null);
|
||||
Assert.ok(folder2 !== null);
|
||||
Assert.ok(folder3 !== null);
|
||||
});
|
||||
|
||||
add_task(async function moveImapFolder1() {
|
||||
let folder1 = IMAPPump.inbox.getChildNamed("empty 1");
|
||||
let folder2 = IMAPPump.inbox.getChildNamed("empty 2");
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener();
|
||||
MailServices.copy.copyFolder(folder2, folder1, true, copyListener, null);
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
add_task(async function moveImapFolder2() {
|
||||
let folder1 = IMAPPump.inbox.getChildNamed("empty 1");
|
||||
let folder3 = IMAPPump.inbox.getChildNamed("empty 3");
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener();
|
||||
MailServices.copy.copyFolder(folder3, folder1, true, copyListener, null);
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
add_task(function verifyImapFolders() {
|
||||
let folder1 = IMAPPump.inbox.getChildNamed("empty 1");
|
||||
let folder2 = folder1.getChildNamed("empty 2");
|
||||
let folder3 = folder1.getChildNamed("empty 3");
|
||||
Assert.ok(folder1 !== null);
|
||||
Assert.ok(folder2 !== null);
|
||||
Assert.ok(folder3 !== null);
|
||||
});
|
||||
|
||||
add_task(async function testImapFolderCopyFailure() {
|
||||
IMAPPump.daemon.commandToFail = "APPEND";
|
||||
// we expect NS_MSG_ERROR_IMAP_COMMAND_FAILED;
|
||||
const NS_MSG_ERROR_IMAP_COMMAND_FAILED = 0x80550021;
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener();
|
||||
MailServices.copy.copyFolder(
|
||||
gNotEmptyLocal4,
|
||||
IMAPPump.inbox,
|
||||
false,
|
||||
copyListener,
|
||||
null
|
||||
);
|
||||
await Assert.rejects(
|
||||
copyListener.promise,
|
||||
e => {
|
||||
return e === NS_MSG_ERROR_IMAP_COMMAND_FAILED;
|
||||
},
|
||||
"NS_MSG_ERROR_IMAP_COMMAND_FAILED should be the cause of the error"
|
||||
);
|
||||
});
|
||||
|
||||
add_task(function teardown() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -6,65 +6,103 @@
|
|||
* Tests imap msg header download chunking
|
||||
*/
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
|
||||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
var { MailServices } = ChromeUtils.import(
|
||||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
// javascript mime emitter functions
|
||||
var { MessageGenerator, MessageScenarioFactory } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/MessageGenerator.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
var { TestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/TestUtils.jsm"
|
||||
);
|
||||
|
||||
// IMAP pump
|
||||
|
||||
setupIMAPPump();
|
||||
/**
|
||||
* Keep it so that OVERALL_MESSAGES % CHUNKING_SIZE !== 0.
|
||||
* With a modulo operator for CHUNKING_SIZE and a prime number for
|
||||
* OVERALL_MESSAGES this should prove that there have been a
|
||||
* chunking process without being depended on the first chunk.
|
||||
*/
|
||||
const CHUNKING_SIZE = 3;
|
||||
const OVERALL_MESSAGES = 137;
|
||||
|
||||
// Dummy message window so we can say the inbox is open in a window.
|
||||
var dummyMsgWindow = {
|
||||
openFolder: IMAPPump.inbox,
|
||||
QueryInterface: ChromeUtils.generateQI([
|
||||
"nsIMsgWindow",
|
||||
"nsISupportsWeakReference",
|
||||
]),
|
||||
};
|
||||
var dummyMsgWindow = Cc["@mozilla.org/messenger/msgwindow;1"].createInstance(
|
||||
Ci.nsIMsgWindow
|
||||
);
|
||||
|
||||
var gFolderListener = {
|
||||
_gotNewMailBiff: false,
|
||||
function FolderIntPropertyChangedListener() {
|
||||
this._promise = new Promise(resolve => {
|
||||
this._resolve = resolve;
|
||||
});
|
||||
this._gotNewMailBiff = false;
|
||||
}
|
||||
|
||||
FolderIntPropertyChangedListener.prototype = {
|
||||
onFolderIntPropertyChanged(aItem, aProperty, aOldValue, aNewValue) {
|
||||
if (
|
||||
aProperty == "BiffState" &&
|
||||
aNewValue == Ci.nsIMsgFolder.nsMsgBiffState_NewMail
|
||||
) {
|
||||
this._gotNewMailBiff = true;
|
||||
async_driver();
|
||||
this._resolve();
|
||||
}
|
||||
},
|
||||
get promise() {
|
||||
return this._promise;
|
||||
},
|
||||
get gotNewMailBiff() {
|
||||
return this._gotNewMailBiff;
|
||||
},
|
||||
};
|
||||
|
||||
var tests = [
|
||||
uploadImapMessages,
|
||||
testMessageFetched,
|
||||
testHdrsDownloaded,
|
||||
endTest,
|
||||
];
|
||||
var gFolderListener = new FolderIntPropertyChangedListener();
|
||||
/** Used to store a listener between tasks for inspecting chunking behaviour. */
|
||||
var gListener = new PromiseTestUtils.PromiseUrlListener();
|
||||
|
||||
// upload messages to the imap fake server Inbox
|
||||
function* uploadImapMessages() {
|
||||
// make 10 messages
|
||||
add_task(async function setupTest() {
|
||||
Assert.equal(
|
||||
OVERALL_MESSAGES % CHUNKING_SIZE !== 0,
|
||||
true,
|
||||
"const sanity check"
|
||||
);
|
||||
setupIMAPPump();
|
||||
// We need to register the dummyMsgWindow so that we'll think the
|
||||
// Inbox is open in a folder and fetch headers in chunks.
|
||||
dummyMsgWindow.openFolder = IMAPPump.inbox;
|
||||
MailServices.mailSession.AddMsgWindow(dummyMsgWindow);
|
||||
MailServices.mailSession.AddFolderListener(
|
||||
gFolderListener,
|
||||
Ci.nsIFolderListener.intPropertyChanged
|
||||
);
|
||||
|
||||
// Set chunk size to CHUNKING_SIZE, so we'll have to chain several requests to get
|
||||
// OVERALL_MESSAGES headers.
|
||||
Services.prefs.setIntPref("mail.imap.hdr_chunk_size", CHUNKING_SIZE);
|
||||
// Turn off offline sync to avoid complications in verifying that we can
|
||||
// run a url after the first header chunk.
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.server1.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
// Upload messages to the imap fake server Inbox.
|
||||
add_task(async function uploadImapMessages() {
|
||||
// make OVERALL_MESSAGES messages
|
||||
let messageGenerator = new MessageGenerator();
|
||||
let scenarioFactory = new MessageScenarioFactory(messageGenerator);
|
||||
|
||||
// build up a list of messages
|
||||
let messages = [];
|
||||
messages = messages.concat(scenarioFactory.directReply(10));
|
||||
messages = messages.concat(scenarioFactory.directReply(OVERALL_MESSAGES));
|
||||
|
||||
// Add 10 messages with uids 1-10.
|
||||
// Add OVERALL_MESSAGES messages with uids 1,2,3...,OVERALL_MESSAGES.
|
||||
let imapInbox = IMAPPump.daemon.getMailbox("INBOX");
|
||||
// Create the imapMessages and store them on the mailbox
|
||||
// Create the imapMessages and store them on the mailbox.
|
||||
messages.forEach(function(message) {
|
||||
let dataUri = Services.io.newURI(
|
||||
"data:text/plain;base64," + btoa(message.toMessageString())
|
||||
|
@ -73,50 +111,59 @@ function* uploadImapMessages() {
|
|||
new imapMessage(dataUri.spec, imapInbox.uidnext++, [])
|
||||
);
|
||||
});
|
||||
// Do not wait for the listener to finish.
|
||||
// We want to observe the message batches in the update process.
|
||||
// updateFolderWithListener with null for nsIMsgWindow makes biff notify.
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
IMAPPump.inbox.updateFolderWithListener(null, gListener);
|
||||
});
|
||||
|
||||
function* testMessageFetched() {
|
||||
add_task(async function testMessageFetched() {
|
||||
// If we're really chunking, then the message fetch should have started before
|
||||
// we finished the updateFolder URL.
|
||||
Assert.ok(gFolderListener._gotNewMailBiff);
|
||||
// Should have only downloaded first chunk of headers when message
|
||||
// has finished streaming.
|
||||
Assert.equal(IMAPPump.inbox.msgDatabase.dBFolderInfo.numMessages, 3);
|
||||
yield false;
|
||||
}
|
||||
await TestUtils.waitForCondition(() => {
|
||||
return gFolderListener.gotNewMailBiff === true;
|
||||
});
|
||||
Assert.ok(gFolderListener.gotNewMailBiff);
|
||||
|
||||
function* testHdrsDownloaded() {
|
||||
// Make sure we got all 10 headers.
|
||||
Assert.equal(IMAPPump.inbox.msgDatabase.dBFolderInfo.numMessages, 10);
|
||||
yield true;
|
||||
}
|
||||
// We do not check for the first chunk as this is unreliable without explicit
|
||||
// listeners/events.
|
||||
// Instead we are checking if there's no rest of the division with
|
||||
// CHUNKING_SIZE while the chunking process is ongoing.
|
||||
// It's important that the chunking is intact and aswell not failing
|
||||
// randomly in the test infrastructure.
|
||||
// See at the CHUNKING_SIZE and OVERALL_MESSAGES declarations.
|
||||
//
|
||||
// HINT:
|
||||
// If this causes future problems because stuff getting faster,
|
||||
// try to increase the overall message count.
|
||||
await TestUtils.waitForCondition(() => {
|
||||
let messagesDBFolder = IMAPPump.inbox.msgDatabase.dBFolderInfo.numMessages;
|
||||
if (messagesDBFolder !== 0) {
|
||||
Assert.equal(
|
||||
messagesDBFolder % CHUNKING_SIZE,
|
||||
0,
|
||||
`${messagesDBFolder} messages in folder should be of chunk size ${CHUNKING_SIZE}`
|
||||
); // This is the primary test.
|
||||
return true;
|
||||
} else if (messagesDBFolder === OVERALL_MESSAGES) {
|
||||
throw new Error(
|
||||
`Batching failed in sizes of ${CHUNKING_SIZE} found instead ${OVERALL_MESSAGES} immediately`
|
||||
);
|
||||
}
|
||||
return false; // Rerun waitForCondition.
|
||||
}, 50);
|
||||
});
|
||||
|
||||
add_task(async function testHdrsDownloaded() {
|
||||
await gListener.promise; // Now we wait for the finished update of the Folder.
|
||||
// Make sure that we got all OVERALL_MESSAGES headers.
|
||||
Assert.equal(
|
||||
IMAPPump.inbox.msgDatabase.dBFolderInfo.numMessages,
|
||||
OVERALL_MESSAGES
|
||||
);
|
||||
});
|
||||
|
||||
// Cleanup
|
||||
function endTest() {
|
||||
add_task(async function endTest() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
// We need to register the dummyMsgWindow so that we'll think the
|
||||
// Inbox is open in a folder and fetch headers in chunks.
|
||||
MailServices.mailSession.AddMsgWindow(dummyMsgWindow);
|
||||
MailServices.mailSession.AddFolderListener(
|
||||
gFolderListener,
|
||||
Ci.nsIFolderListener.intPropertyChanged
|
||||
);
|
||||
|
||||
// Set chunk size to 3, so we'll have to chain 4 requests to get
|
||||
// 10 headers.
|
||||
Services.prefs.setIntPref("mail.imap.hdr_chunk_size", 3);
|
||||
// Turn off offline sync to avoid complications in verifying that we can
|
||||
// run a url after the first header chunk.
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.server1.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
/* 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/. */
|
||||
|
||||
/* 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/. */
|
||||
|
||||
/**
|
||||
* This test checks if the imap message service code streams headers correctly.
|
||||
* It checks that streaming headers for messages stored for offline use works.
|
||||
|
@ -5,56 +13,21 @@
|
|||
* because that's not implemented yet, and it's unclear if anyone will want it.
|
||||
*/
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
/* import-globals-from ../../../test/resources/messageInjection.js */
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
load("../../../resources/messageInjection.js");
|
||||
|
||||
// IMAP pump
|
||||
var { MessageGenerator } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/MessageGenerator.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
setupIMAPPump();
|
||||
|
||||
var gMsgFile1 = do_get_file("../../../data/bugmail10");
|
||||
var gMsgId1 = "200806061706.m56H6RWT004933@mrapp54.mozilla.org";
|
||||
|
||||
// We use this as a display consumer
|
||||
var streamListener = {
|
||||
_data: "",
|
||||
_stream: null,
|
||||
|
||||
QueryInterface: ChromeUtils.generateQI([
|
||||
"nsIStreamListener",
|
||||
"nsIRequestObserver",
|
||||
]),
|
||||
|
||||
// nsIRequestObserver
|
||||
onStartRequest(aRequest) {},
|
||||
onStopRequest(aRequest, aStatusCode) {
|
||||
Assert.equal(aStatusCode, 0);
|
||||
Assert.ok(this._data.includes("Content-Type"));
|
||||
async_driver();
|
||||
},
|
||||
|
||||
// nsIStreamListener
|
||||
onDataAvailable(aRequest, aInputStream, aOffset, aCount) {
|
||||
if (this._stream == null) {
|
||||
this._stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
);
|
||||
this._stream.init(aInputStream);
|
||||
}
|
||||
this._data += this._stream.read(aCount);
|
||||
},
|
||||
};
|
||||
|
||||
// Adds some messages directly to a mailbox (eg new mail)
|
||||
// Adds some messages directly to a mailbox (e.g. new mail).
|
||||
function addMessagesToServer(messages, mailbox) {
|
||||
// For every message we have, we need to convert it to a file:/// URI
|
||||
// For every message we have, we need to convert it to a file:/// URI.
|
||||
messages.forEach(function(message) {
|
||||
let URI = Services.io
|
||||
.newFileURI(message.file)
|
||||
|
@ -64,9 +37,9 @@ function addMessagesToServer(messages, mailbox) {
|
|||
});
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
add_task(async function setup_test() {
|
||||
// Add a couple of messages to the INBOX
|
||||
// this is synchronous, afaik
|
||||
// this is synchronous, afaik.
|
||||
addMessagesToServer(
|
||||
[{ file: gMsgFile1, messageId: gMsgId1 }],
|
||||
IMAPPump.daemon.getMailbox("INBOX")
|
||||
|
@ -75,37 +48,30 @@ function run_test() {
|
|||
"mail.server.server1.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
async_run_tests(tests);
|
||||
}
|
||||
// Update IMAP Folder.
|
||||
let listenerUpdate = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listenerUpdate);
|
||||
await listenerUpdate.promise;
|
||||
// Download all for offline.
|
||||
let listenerDownload = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.downloadAllForOffline(listenerDownload, null);
|
||||
await listenerDownload.promise;
|
||||
});
|
||||
|
||||
var tests = [
|
||||
test_updateFolder,
|
||||
test_downloadForOffline,
|
||||
test_streamHeaders,
|
||||
endTest,
|
||||
];
|
||||
|
||||
function* test_updateFolder() {
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
|
||||
function* test_downloadForOffline() {
|
||||
IMAPPump.inbox.downloadAllForOffline(asyncUrlListener, null);
|
||||
yield false;
|
||||
}
|
||||
|
||||
function* test_streamHeaders() {
|
||||
add_task(async function test_streamHeaders() {
|
||||
let newMsgHdr = IMAPPump.inbox.GetMessageHeader(1);
|
||||
let msgURI = newMsgHdr.folder.getUriForMsg(newMsgHdr);
|
||||
let messenger = Cc["@mozilla.org/messenger;1"].createInstance(
|
||||
Ci.nsIMessenger
|
||||
);
|
||||
let msgServ = messenger.messageServiceFromURI(msgURI);
|
||||
msgServ.streamHeaders(msgURI, streamListener, asyncUrlListener, true);
|
||||
yield false;
|
||||
}
|
||||
// We use this as a display consumer
|
||||
let streamListener = new PromiseTestUtils.PromiseStreamListener();
|
||||
msgServ.streamHeaders(msgURI, streamListener, null, true);
|
||||
let data = await streamListener.promise;
|
||||
Assert.ok(data.includes("Content-Type"));
|
||||
});
|
||||
|
||||
function endTest() {
|
||||
add_task(async function endTest() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* Test to ensure that offline imap moves handle extremely high highwater
|
||||
* marks.
|
||||
*/
|
||||
/* 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/. */
|
||||
|
||||
/* import-globals-from ../../../test/resources/alertTestUtils.js */
|
||||
load("../../../resources/alertTestUtils.js");
|
||||
|
||||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
var { MailServices } = ChromeUtils.import(
|
||||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/alertTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/alertTestUtils.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
var { MessageGenerator, MessageScenarioFactory } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/MessageGenerator.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
var gIMAPDaemon, gServer, gIMAPIncomingServer;
|
||||
|
||||
|
@ -33,7 +32,7 @@ function addMessagesToServer(messages, mailbox) {
|
|||
});
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
add_task(function setupTest() {
|
||||
localAccountUtils.loadLocalMailAccount();
|
||||
|
||||
/*
|
||||
|
@ -70,10 +69,9 @@ function run_test() {
|
|||
);
|
||||
// Don't prompt about offline download when going offline
|
||||
Services.prefs.setIntPref("offline.download.download_messages", 2);
|
||||
actually_run_test();
|
||||
}
|
||||
});
|
||||
|
||||
function* setupFolders() {
|
||||
add_task(function setupFolders() {
|
||||
// make 10 messages
|
||||
let messageGenerator = new MessageGenerator();
|
||||
let scenarioFactory = new MessageScenarioFactory(messageGenerator);
|
||||
|
@ -95,18 +93,19 @@ function* setupFolders() {
|
|||
gIMAPInbox = gRootFolder
|
||||
.getFolderWithFlags(Ci.nsMsgFolderFlags.Inbox)
|
||||
.QueryInterface(Ci.nsIMsgImapMailFolder);
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
function* doMoves() {
|
||||
add_task(async function doMoves() {
|
||||
// update folders to download headers.
|
||||
gIMAPInbox.updateFolderWithListener(null, UrlListener);
|
||||
yield false;
|
||||
let urlListenerInbox = new PromiseTestUtils.PromiseUrlListener();
|
||||
gIMAPInbox.updateFolderWithListener(null, urlListenerInbox);
|
||||
await urlListenerInbox.promise;
|
||||
gFolder1 = gRootFolder
|
||||
.getChildNamed("folder 1")
|
||||
.QueryInterface(Ci.nsIMsgImapMailFolder);
|
||||
gFolder1.updateFolderWithListener(null, UrlListener);
|
||||
yield false;
|
||||
let urlListenerFolder1 = new PromiseTestUtils.PromiseUrlListener();
|
||||
gFolder1.updateFolderWithListener(null, urlListenerFolder1);
|
||||
await urlListenerFolder1.promise;
|
||||
// get five messages to move from Inbox to folder 1.
|
||||
let headers1 = [];
|
||||
let count = 0;
|
||||
|
@ -120,20 +119,29 @@ function* doMoves() {
|
|||
count++;
|
||||
}
|
||||
// this will add dummy headers with keys > 0xffffff80
|
||||
let copyListenerDummyHeaders = new PromiseTestUtils.PromiseCopyListener();
|
||||
MailServices.copy.copyMessages(
|
||||
gIMAPInbox,
|
||||
headers1,
|
||||
gFolder1,
|
||||
true,
|
||||
CopyListener,
|
||||
copyListenerDummyHeaders,
|
||||
gDummyMsgWindow,
|
||||
true
|
||||
);
|
||||
yield false;
|
||||
gIMAPInbox.updateFolderWithListener(null, UrlListener);
|
||||
yield false;
|
||||
gFolder1.updateFolderWithListener(gDummyMsgWindow, UrlListener);
|
||||
yield false;
|
||||
await copyListenerDummyHeaders.promise;
|
||||
|
||||
let urlListenerInboxAfterDummy = new PromiseTestUtils.PromiseUrlListener();
|
||||
gIMAPInbox.updateFolderWithListener(null, urlListenerInboxAfterDummy);
|
||||
await urlListenerInboxAfterDummy.promise;
|
||||
|
||||
let urlListenerFolder1AfterDummy = new PromiseTestUtils.PromiseUrlListener();
|
||||
gFolder1.updateFolderWithListener(
|
||||
gDummyMsgWindow,
|
||||
urlListenerFolder1AfterDummy
|
||||
);
|
||||
await urlListenerFolder1AfterDummy.promise;
|
||||
|
||||
// Check that playing back offline events gets rid of dummy
|
||||
// headers, and thus highWater is recalculated.
|
||||
Assert.equal(gFolder1.msgDatabase.dBFolderInfo.highWater, 6);
|
||||
|
@ -152,64 +160,36 @@ function* doMoves() {
|
|||
// It will thrown an exception if it can't.
|
||||
let msgHdr = gFolder1.msgDatabase.CreateNewHdr(0xfffffffd);
|
||||
gFolder1.msgDatabase.AddNewHdrToDB(msgHdr, false);
|
||||
let copyListenerHighWater = new PromiseTestUtils.PromiseCopyListener();
|
||||
MailServices.copy.copyMessages(
|
||||
gIMAPInbox,
|
||||
headers1,
|
||||
gFolder1,
|
||||
true,
|
||||
CopyListener,
|
||||
copyListenerHighWater,
|
||||
gDummyMsgWindow,
|
||||
true
|
||||
);
|
||||
yield false;
|
||||
await copyListenerHighWater.promise;
|
||||
gServer.performTest("UID COPY");
|
||||
|
||||
gFolder1.msgDatabase.DeleteHeader(msgHdr, null, true, false);
|
||||
gIMAPInbox.updateFolderWithListener(null, UrlListener);
|
||||
yield false;
|
||||
let urlListenerInboxAfterDelete = new PromiseTestUtils.PromiseUrlListener();
|
||||
gIMAPInbox.updateFolderWithListener(null, urlListenerInboxAfterDelete);
|
||||
await urlListenerInboxAfterDelete.promise;
|
||||
// this should clear the dummy headers.
|
||||
gFolder1.updateFolderWithListener(gDummyMsgWindow, UrlListener);
|
||||
yield false;
|
||||
let urlListenerFolder1AfterDelete = new PromiseTestUtils.PromiseUrlListener();
|
||||
gFolder1.updateFolderWithListener(
|
||||
gDummyMsgWindow,
|
||||
urlListenerFolder1AfterDelete
|
||||
);
|
||||
await urlListenerFolder1AfterDelete.promise;
|
||||
Assert.equal(gFolder1.msgDatabase.dBFolderInfo.highWater, 11);
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
var UrlListener = {
|
||||
OnStartRunningUrl(url) {},
|
||||
OnStopRunningUrl(url, rc) {
|
||||
// Check for ok status.
|
||||
Assert.equal(rc, 0);
|
||||
async_driver();
|
||||
},
|
||||
};
|
||||
|
||||
// nsIMsgCopyServiceListener implementation
|
||||
var CopyListener = {
|
||||
OnStartCopy() {},
|
||||
OnProgress(aProgress, aProgressMax) {},
|
||||
SetMessageKey(aKey) {},
|
||||
SetMessageId(aMessageId) {},
|
||||
OnStopCopy(aStatus) {
|
||||
Assert.equal(aStatus, 0);
|
||||
async_driver();
|
||||
},
|
||||
};
|
||||
|
||||
// Definition of tests
|
||||
var tests = [setupFolders, doMoves, endTest];
|
||||
|
||||
function actually_run_test() {
|
||||
async_run_tests(tests);
|
||||
}
|
||||
|
||||
function* endTest() {
|
||||
add_task(function endTest() {
|
||||
Services.io.offline = true;
|
||||
gServer.performTest("LOGOUT");
|
||||
// gIMAPIncomingServer.closeCachedConnections();
|
||||
gIMAPIncomingServer.closeCachedConnections();
|
||||
gServer.stop();
|
||||
let thread = gThreadManager.currentThread;
|
||||
while (thread.hasPendingEvents()) {
|
||||
thread.processNextEvent(true);
|
||||
}
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -8,58 +8,37 @@ var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|||
var { MailServices } = ChromeUtils.import(
|
||||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
|
||||
setupIMAPPump();
|
||||
|
||||
var tests = [setup, test_rename];
|
||||
|
||||
function* setup() {
|
||||
add_task(async function setupTest() {
|
||||
setupIMAPPump();
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.default.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
// Add folder listeners that will capture async events
|
||||
MailServices.mfn.addListener(mfnListener, MailServices.mfn.folderAdded);
|
||||
|
||||
IMAPPump.incomingServer.rootFolder.createSubfolder("folder 1", null);
|
||||
yield false;
|
||||
await PromiseTestUtils.promiseFolderAdded("folder 1");
|
||||
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function* test_rename() {
|
||||
add_task(async function test_rename() {
|
||||
let rootFolder = IMAPPump.incomingServer.rootFolder;
|
||||
let targetFolder = rootFolder.getChildNamed("folder 1");
|
||||
|
||||
targetFolder.rename("folder \u00e1", null);
|
||||
|
||||
IMAPPump.server.performTest("RENAME");
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
|
||||
let folder = rootFolder.getChildNamed("folder \u00e1");
|
||||
Assert.ok(folder.msgDatabase.summaryValid);
|
||||
Assert.equal("folder &AOE-", folder.filePath.leafName);
|
||||
Assert.equal("folder \u00e1", folder.prettyName);
|
||||
|
||||
yield true;
|
||||
}
|
||||
|
||||
var mfnListener = {
|
||||
folderAdded(aFolder) {
|
||||
// we are only using async yield on the target folder add
|
||||
if (aFolder.name == "folder 1") {
|
||||
async_driver();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -7,11 +7,9 @@
|
|||
* Original author: Kent James <kent@caspia.com>
|
||||
*/
|
||||
|
||||
// async support
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
// headers we will store in db
|
||||
// set value of headers we want parsed into the db
|
||||
|
@ -19,10 +17,9 @@ Services.prefs.setCharPref(
|
|||
"mailnews.customDBHeaders",
|
||||
"x-spam-status oneliner twoliner threeliner nospace withspace"
|
||||
);
|
||||
dump(
|
||||
"set mailnews.customDBHeaders to " +
|
||||
Services.prefs.getCharPref("mailnews.customDBHeaders") +
|
||||
"\n"
|
||||
Assert.equal(
|
||||
Services.prefs.getCharPref("mailnews.customDBHeaders"),
|
||||
"x-spam-status oneliner twoliner threeliner nospace withspace"
|
||||
);
|
||||
|
||||
// set customHeaders, which post-bug 363238 should get added to the db. Note that all headers but the last
|
||||
|
@ -32,18 +29,9 @@ Services.prefs.setCharPref(
|
|||
"x-uidl: x-bugzilla-watch-reason: x-bugzilla-component: received: x-spam-checker-version"
|
||||
);
|
||||
|
||||
// IMAP pump
|
||||
|
||||
// Globals
|
||||
|
||||
// Messages to load must have CRLF line endings, that is Windows style
|
||||
var gMessage = "bugmail12"; // message file used as the test message
|
||||
|
||||
setupIMAPPump();
|
||||
|
||||
// Definition of tests
|
||||
var tests = [loadImapMessage, testSearch, endTest];
|
||||
|
||||
/*
|
||||
/*
|
||||
* Testing of general mail search features.
|
||||
|
@ -299,58 +287,54 @@ var searchTests = [
|
|||
},
|
||||
];
|
||||
|
||||
// load and update a message in the imap fake server
|
||||
function* loadImapMessage() {
|
||||
add_task(async function setupTest() {
|
||||
setupIMAPPump();
|
||||
|
||||
// don't use offline store
|
||||
IMAPPump.inbox.clearFlag(Ci.nsMsgFolderFlags.Offline);
|
||||
|
||||
// Load imap message.
|
||||
IMAPPump.mailbox.addMessage(
|
||||
new imapMessage(specForFileName(gMessage), IMAPPump.mailbox.uidnext++, [])
|
||||
);
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
|
||||
Assert.equal(1, IMAPPump.inbox.getTotalMessages(false));
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
// process each test from queue, calls itself upon completion of each search
|
||||
function* testSearch() {
|
||||
add_task(async function testSearch() {
|
||||
while (searchTests.length) {
|
||||
let test = searchTests.shift();
|
||||
if (test.dbHeader) {
|
||||
// test of a custom db header
|
||||
dump("testing dbHeader " + test.dbHeader + "\n");
|
||||
// Test of a custom db header.
|
||||
let customValue = mailTestUtils
|
||||
.firstMsgHdr(IMAPPump.inbox)
|
||||
.getProperty(test.dbHeader);
|
||||
Assert.equal(customValue, test.testString);
|
||||
} else {
|
||||
dump("testing for string '" + test.testString + "'\n");
|
||||
new TestSearch(
|
||||
IMAPPump.inbox,
|
||||
test.testString,
|
||||
test.testAttribute,
|
||||
test.op,
|
||||
test.count,
|
||||
async_driver,
|
||||
null,
|
||||
test.customHeader ? test.customHeader : "X-Bugzilla-Watch-Reason"
|
||||
);
|
||||
yield false;
|
||||
await new Promise(resolve => {
|
||||
new TestSearch(
|
||||
IMAPPump.inbox,
|
||||
test.testString,
|
||||
test.testAttribute,
|
||||
test.op,
|
||||
test.count,
|
||||
resolve,
|
||||
null,
|
||||
test.customHeader ? test.customHeader : "X-Bugzilla-Watch-Reason"
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
// Cleanup at end
|
||||
function endTest() {
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
// don't use offline store
|
||||
IMAPPump.inbox.clearFlag(Ci.nsMsgFolderFlags.Offline);
|
||||
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* helper function
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
/* 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/. */
|
||||
|
||||
// This file tests that checking folders for new mail with STATUS
|
||||
// doesn't leave db's open.
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
var gFolder1, gFolder2;
|
||||
|
||||
var tests = [setup, check, teardown];
|
||||
|
||||
function* setup() {
|
||||
add_task(function setupTest() {
|
||||
Services.prefs.setBoolPref("mail.check_all_imap_folders_for_new", true);
|
||||
|
||||
setupIMAPPump();
|
||||
|
@ -26,26 +27,22 @@ function* setup() {
|
|||
|
||||
IMAPPump.inbox.getNewMessages(null, null);
|
||||
IMAPPump.server.performTest("STATUS");
|
||||
Assert.ok(IMAPPump.server.isTestFinished());
|
||||
// don't know if this will work, but we'll try. Wait for
|
||||
// second status response
|
||||
IMAPPump.server.performTest("STATUS");
|
||||
mailTestUtils.do_timeout_function(1000, async_driver);
|
||||
yield false;
|
||||
}
|
||||
Assert.ok(IMAPPump.server.isTestFinished());
|
||||
});
|
||||
|
||||
function check() {
|
||||
add_task(function check() {
|
||||
const gDbService = Cc["@mozilla.org/msgDatabase/msgDBService;1"].getService(
|
||||
Ci.nsIMsgDBService
|
||||
);
|
||||
Assert.ok(gDbService.cachedDBForFolder(IMAPPump.inbox) !== null);
|
||||
Assert.ok(gDbService.cachedDBForFolder(gFolder1) === null);
|
||||
Assert.ok(gDbService.cachedDBForFolder(gFolder2) === null);
|
||||
}
|
||||
});
|
||||
|
||||
function teardown() {
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/* 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/. */
|
||||
|
||||
/**
|
||||
* This test checks if the imap protocol code saves message to
|
||||
* offline stores correctly, when we fetch the message for display.
|
||||
|
@ -8,15 +12,12 @@
|
|||
* - Message with mix of attachment types.
|
||||
*/
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
/* import-globals-from ../../../test/resources/messageInjection.js */
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
load("../../../resources/messageInjection.js");
|
||||
var { MessageGenerator } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/MessageGenerator.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
var gMessageGenerator = new MessageGenerator();
|
||||
|
||||
|
@ -31,36 +32,9 @@ var gFirstNewMsg;
|
|||
var gFirstMsgSize;
|
||||
var gImapInboxOfflineStoreSize;
|
||||
|
||||
// We use this as a display consumer
|
||||
var streamListener = {
|
||||
_data: "",
|
||||
|
||||
QueryInterface: ChromeUtils.generateQI([
|
||||
"nsIStreamListener",
|
||||
"nsIRequestObserver",
|
||||
]),
|
||||
|
||||
// nsIRequestObserver
|
||||
onStartRequest(aRequest) {},
|
||||
onStopRequest(aRequest, aStatusCode) {
|
||||
Assert.equal(aStatusCode, 0);
|
||||
},
|
||||
|
||||
// nsIStreamListener
|
||||
onDataAvailable(aRequest, aInputStream, aOffset, aCount) {
|
||||
let scriptStream = Cc[
|
||||
"@mozilla.org/scriptableinputstream;1"
|
||||
].createInstance(Ci.nsIScriptableInputStream);
|
||||
|
||||
scriptStream.init(aInputStream);
|
||||
|
||||
scriptStream.read(aCount);
|
||||
},
|
||||
};
|
||||
|
||||
// Adds some messages directly to a mailbox (eg new mail)
|
||||
// Adds some messages directly to a mailbox (e.g. new mail).
|
||||
function addMessagesToServer(messages, mailbox) {
|
||||
// For every message we have, we need to convert it to a file:/// URI
|
||||
// For every message we have, we need to convert it to a file:/// URI.
|
||||
messages.forEach(function(message) {
|
||||
let URI = Services.io
|
||||
.newFileURI(message.file)
|
||||
|
@ -70,30 +44,28 @@ function addMessagesToServer(messages, mailbox) {
|
|||
});
|
||||
}
|
||||
|
||||
function setup() {
|
||||
// We aren't interested in downloading messages automatically
|
||||
add_task(async function setupTest() {
|
||||
// We aren't interested in downloading messages automatically.
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.server1.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
Services.prefs.setBoolPref("mail.server.server1.offline_download", true);
|
||||
// make small threshold for mpod so our test messages don't have to be big.
|
||||
// Make small threshold for mpod so our test messages don't have to be big.
|
||||
// XXX We can't set this pref until the fake server supports body structure.
|
||||
// So for now, we'll leave it at the default value, which is larger than any of
|
||||
// our test messages.
|
||||
// our test messages.
|
||||
// Services.prefs.setIntPref("mail.imap.mime_parts_on_demand_threshold", 3000);
|
||||
|
||||
setupIMAPPump();
|
||||
|
||||
// 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.
|
||||
// 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.
|
||||
IMAPPump.inbox.hierarchyDelimiter = "/";
|
||||
IMAPPump.inbox.verifiedAsOnlineFolder = true;
|
||||
|
||||
// Add a couple of messages to the INBOX
|
||||
// this is synchronous, afaik
|
||||
addMessagesToServer(
|
||||
[
|
||||
{ file: gMsgFile1, messageId: gMsgId1 },
|
||||
|
@ -102,175 +74,162 @@ function setup() {
|
|||
],
|
||||
IMAPPump.daemon.getMailbox("INBOX")
|
||||
);
|
||||
}
|
||||
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
var gIMAPService;
|
||||
|
||||
var tests = [
|
||||
setup,
|
||||
function* updateFolder() {
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function* selectFirstMsg() {
|
||||
// We postpone creating the imap service until after we've set the prefs
|
||||
// that it reads on its startup.
|
||||
gIMAPService = Cc[
|
||||
"@mozilla.org/messenger/messageservice;1?type=imap"
|
||||
].getService(Ci.nsIMsgMessageService);
|
||||
add_task(async function selectFirstMsg() {
|
||||
// We postpone creating the imap service until after we've set the prefs
|
||||
// that it reads on its startup.
|
||||
gIMAPService = Cc[
|
||||
"@mozilla.org/messenger/messageservice;1?type=imap"
|
||||
].getService(Ci.nsIMsgMessageService);
|
||||
|
||||
let db = IMAPPump.inbox.msgDatabase;
|
||||
let msg1 = db.getMsgHdrForMessageID(gMsgId1);
|
||||
let url = {};
|
||||
gIMAPService.DisplayMessage(
|
||||
IMAPPump.inbox.getUriForMsg(msg1),
|
||||
streamListener,
|
||||
null,
|
||||
asyncUrlListener,
|
||||
null,
|
||||
url
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function* select2ndMsg() {
|
||||
let msg1 = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId1);
|
||||
Assert.notEqual(msg1.flags & Ci.nsMsgMessageFlags.Offline, 0);
|
||||
let db = IMAPPump.inbox.msgDatabase;
|
||||
let msg2 = db.getMsgHdrForMessageID(gMsgId2);
|
||||
let url = {};
|
||||
gIMAPService.DisplayMessage(
|
||||
IMAPPump.inbox.getUriForMsg(msg2),
|
||||
streamListener,
|
||||
null,
|
||||
asyncUrlListener,
|
||||
null,
|
||||
url
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function* select3rdMsg() {
|
||||
let msg2 = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId2);
|
||||
Assert.notEqual(msg2.flags & Ci.nsMsgMessageFlags.Offline, 0);
|
||||
let db = IMAPPump.inbox.msgDatabase;
|
||||
let msg3 = db.getMsgHdrForMessageID(gMsgId3);
|
||||
let url = {};
|
||||
gIMAPService.DisplayMessage(
|
||||
IMAPPump.inbox.getUriForMsg(msg3),
|
||||
streamListener,
|
||||
null,
|
||||
asyncUrlListener,
|
||||
null,
|
||||
url
|
||||
);
|
||||
yield false;
|
||||
let db = IMAPPump.inbox.msgDatabase;
|
||||
let msg1 = db.getMsgHdrForMessageID(gMsgId1);
|
||||
let url = {};
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener({
|
||||
OnStopRunningUrl: (aUrl, aExitCode) => {
|
||||
Assert.equal(aExitCode, 0);
|
||||
},
|
||||
});
|
||||
// We use the streamListener as a display consumer.
|
||||
let streamListener = new PromiseTestUtils.PromiseStreamListener();
|
||||
gIMAPService.DisplayMessage(
|
||||
IMAPPump.inbox.getUriForMsg(msg1),
|
||||
streamListener,
|
||||
null,
|
||||
listener,
|
||||
null,
|
||||
url
|
||||
);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(async function select2ndMsg() {
|
||||
let msg1 = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId1);
|
||||
Assert.notEqual(msg1.flags & Ci.nsMsgMessageFlags.Offline, 0);
|
||||
let db = IMAPPump.inbox.msgDatabase;
|
||||
let msg2 = db.getMsgHdrForMessageID(gMsgId2);
|
||||
let url = {};
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener({
|
||||
OnStopRunningUrl: (aUrl, aExitCode) => {
|
||||
Assert.equal(aExitCode, 0);
|
||||
},
|
||||
});
|
||||
// We use the streamListener as a display consumer.
|
||||
let streamListener = new PromiseTestUtils.PromiseStreamListener();
|
||||
gIMAPService.DisplayMessage(
|
||||
IMAPPump.inbox.getUriForMsg(msg2),
|
||||
streamListener,
|
||||
null,
|
||||
listener,
|
||||
null,
|
||||
url
|
||||
);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(async function select3rdMsg() {
|
||||
let msg2 = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId2);
|
||||
Assert.notEqual(msg2.flags & Ci.nsMsgMessageFlags.Offline, 0);
|
||||
let db = IMAPPump.inbox.msgDatabase;
|
||||
let msg3 = db.getMsgHdrForMessageID(gMsgId3);
|
||||
let url = {};
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
// We use the streamListener as a display consumer.
|
||||
let streamListener = new PromiseTestUtils.PromiseStreamListener();
|
||||
gIMAPService.DisplayMessage(
|
||||
IMAPPump.inbox.getUriForMsg(msg3),
|
||||
streamListener,
|
||||
null,
|
||||
listener,
|
||||
null,
|
||||
url
|
||||
);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(
|
||||
{
|
||||
// Can't turn this on because our fake server doesn't support body structure.
|
||||
skip_if: () => true,
|
||||
},
|
||||
function verify3rdMsg() {
|
||||
// let msg3 =
|
||||
IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId3);
|
||||
// can't turn this on because our fake server doesn't support body structure.
|
||||
// do_check_eq(msg3.flags & Ci.nsMsgMessageFlags.Offline, 0);
|
||||
},
|
||||
function* addNewMsgs() {
|
||||
let mbox = IMAPPump.daemon.getMailbox("INBOX");
|
||||
// make a couple of messages
|
||||
let messages = [];
|
||||
let bodyString = "";
|
||||
for (let i = 0; i < 100; i++) {
|
||||
bodyString +=
|
||||
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\n";
|
||||
}
|
||||
let db = IMAPPump.inbox.msgDatabase;
|
||||
let msg3 = db.getMsgHdrForMessageID(gMsgId3);
|
||||
Assert.equal(msg3.flags & Ci.nsMsgMessageFlags.Offline, 0);
|
||||
}
|
||||
);
|
||||
|
||||
gMessageGenerator = new MessageGenerator();
|
||||
messages = messages.concat(
|
||||
gMessageGenerator.makeMessage({
|
||||
body: { body: bodyString, contentType: "text/plain" },
|
||||
})
|
||||
add_task(async function addNewMsgs() {
|
||||
let mbox = IMAPPump.daemon.getMailbox("INBOX");
|
||||
// Make a couple of messages.
|
||||
let messages = [];
|
||||
let bodyString = "";
|
||||
for (let i = 0; i < 100; i++) {
|
||||
bodyString +=
|
||||
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\n";
|
||||
}
|
||||
|
||||
gMessageGenerator = new MessageGenerator();
|
||||
messages = messages.concat(
|
||||
gMessageGenerator.makeMessage({
|
||||
body: { body: bodyString, contentType: "text/plain" },
|
||||
})
|
||||
);
|
||||
|
||||
gFirstNewMsg = mbox.uidnext;
|
||||
// Need to account for x-mozilla-status, status2, and envelope.
|
||||
gFirstMsgSize = messages[0].toMessageString().length + 102;
|
||||
|
||||
messages.forEach(function(message) {
|
||||
let dataUri = Services.io.newURI(
|
||||
"data:text/plain;base64," + btoa(message.toMessageString())
|
||||
);
|
||||
mbox.addMessage(new imapMessage(dataUri.spec, mbox.uidnext++, []));
|
||||
});
|
||||
|
||||
gFirstNewMsg = mbox.uidnext;
|
||||
// need to account for x-mozilla-status, status2, and envelope.
|
||||
gFirstMsgSize = messages[0].toMessageString().length + 102;
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
add_task(async function test_queuedOfflineDownload() {
|
||||
// Make sure that streaming the same message and then trying to download
|
||||
// it for offline use doesn't end up in it getting added to the offline
|
||||
// store twice.
|
||||
gImapInboxOfflineStoreSize = IMAPPump.inbox.filePath.fileSize + gFirstMsgSize;
|
||||
let newMsgHdr = IMAPPump.inbox.GetMessageHeader(gFirstNewMsg);
|
||||
let msgURI = newMsgHdr.folder.getUriForMsg(newMsgHdr);
|
||||
let messenger = Cc["@mozilla.org/messenger;1"].createInstance(
|
||||
Ci.nsIMessenger
|
||||
);
|
||||
let msgServ = messenger.messageServiceFromURI(msgURI);
|
||||
let listener = new PromiseTestUtils.PromiseStreamListener();
|
||||
msgServ.streamMessage(msgURI, listener, null, null, false, "", false);
|
||||
await listener.promise;
|
||||
});
|
||||
add_task(async function firstStreamFinished() {
|
||||
// nsIMsgFolder.downloadMessagesForOffline does not take a listener, so
|
||||
// we invoke nsIImapService.downloadMessagesForOffline directly
|
||||
// with a listener.
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
MailServices.imap.downloadMessagesForOffline(
|
||||
gFirstNewMsg,
|
||||
IMAPPump.inbox,
|
||||
listener,
|
||||
null
|
||||
);
|
||||
await listener.promise;
|
||||
});
|
||||
add_task(function checkOfflineStoreSize() {
|
||||
Assert.ok(IMAPPump.inbox.filePath.fileSize <= gImapInboxOfflineStoreSize);
|
||||
});
|
||||
|
||||
messages.forEach(function(message) {
|
||||
let dataUri = Services.io.newURI(
|
||||
"data:text/plain;base64," + btoa(message.toMessageString())
|
||||
);
|
||||
mbox.addMessage(new imapMessage(dataUri.spec, mbox.uidnext++, []));
|
||||
});
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function* testQueuedOfflineDownload() {
|
||||
// Make sure that streaming the same message and then trying to download
|
||||
// it for offline use doesn't end up in it getting added to the offline
|
||||
// store twice.
|
||||
gImapInboxOfflineStoreSize =
|
||||
IMAPPump.inbox.filePath.fileSize + gFirstMsgSize;
|
||||
let newMsgHdr = IMAPPump.inbox.GetMessageHeader(gFirstNewMsg);
|
||||
let msgURI = newMsgHdr.folder.getUriForMsg(newMsgHdr);
|
||||
let messenger = Cc["@mozilla.org/messenger;1"].createInstance(
|
||||
Ci.nsIMessenger
|
||||
);
|
||||
let msgServ = messenger.messageServiceFromURI(msgURI);
|
||||
msgServ.streamMessage(
|
||||
msgURI,
|
||||
gStreamListener,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
"",
|
||||
false
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function* firstStreamFinished() {
|
||||
// nsIMsgFolder.downloadMessagesForOffline does not take a listener, so
|
||||
// we invoke nsIImapService.downloadMessagesForOffline directly with a
|
||||
// listener.
|
||||
MailServices.imap.downloadMessagesForOffline(
|
||||
gFirstNewMsg,
|
||||
IMAPPump.inbox,
|
||||
asyncUrlListener,
|
||||
null
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function checkOfflineStoreSize() {
|
||||
dump("checking offline store size\n");
|
||||
Assert.ok(IMAPPump.inbox.filePath.fileSize <= gImapInboxOfflineStoreSize);
|
||||
},
|
||||
teardown,
|
||||
];
|
||||
|
||||
var gStreamListener = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIStreamListener"]),
|
||||
_stream: null,
|
||||
_data: null,
|
||||
onStartRequest(aRequest) {
|
||||
this._data = "";
|
||||
},
|
||||
onStopRequest(aRequest, aStatusCode) {
|
||||
async_driver();
|
||||
},
|
||||
onDataAvailable(aRequest, aInputStream, aOff, aCount) {
|
||||
if (this._stream == null) {
|
||||
this._stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
);
|
||||
this._stream.init(aInputStream);
|
||||
}
|
||||
this._data += this._stream.read(aCount);
|
||||
},
|
||||
};
|
||||
|
||||
asyncUrlListener.callback = function(aUrl, aExitCode) {
|
||||
Assert.equal(aExitCode, 0);
|
||||
};
|
||||
|
||||
function teardown() {
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/* 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/. */
|
||||
|
||||
// This file tests undoing of an imap delete to the trash.
|
||||
// There are three main cases:
|
||||
// 1. Normal undo
|
||||
|
@ -6,14 +10,12 @@
|
|||
//
|
||||
// Original Author: David Bienvenu <bienvenu@nventure.com>
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
|
||||
var { MailServices } = ChromeUtils.import(
|
||||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
var gRootFolder;
|
||||
var gMessages = [];
|
||||
|
@ -50,61 +52,11 @@ alertListener.prototype = {
|
|||
reset() {},
|
||||
|
||||
onAlert(aMessage, aMsgWindow) {
|
||||
dump("got alert " + aMessage + "\n");
|
||||
do_throw("TEST FAILED " + aMessage);
|
||||
throw new Error("got alert - TEST FAILED " + aMessage);
|
||||
},
|
||||
};
|
||||
|
||||
var tests = [
|
||||
setup,
|
||||
function* updateFolder() {
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function* deleteMessage() {
|
||||
let msgToDelete = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId1);
|
||||
gMessages.push(msgToDelete);
|
||||
IMAPPump.inbox.deleteMessages(
|
||||
gMessages,
|
||||
gMsgWindow,
|
||||
false,
|
||||
true,
|
||||
asyncCopyListener,
|
||||
true
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function* expunge() {
|
||||
IMAPPump.inbox.expunge(asyncUrlListener, gMsgWindow);
|
||||
yield false;
|
||||
|
||||
// Ensure that the message has been surely deleted.
|
||||
Assert.equal(IMAPPump.inbox.msgDatabase.dBFolderInfo.numMessages, 3);
|
||||
},
|
||||
function* undoDelete() {
|
||||
gMsgWindow.transactionManager.undoTransaction();
|
||||
// after undo, we select the trash and then the inbox, so that we sync
|
||||
// up with the server, and clear out the effects of having done the
|
||||
// delete offline.
|
||||
let trash = gRootFolder.getChildNamed("Trash");
|
||||
trash
|
||||
.QueryInterface(Ci.nsIMsgImapMailFolder)
|
||||
.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function* goBackToInbox() {
|
||||
IMAPPump.inbox.updateFolderWithListener(gMsgWindow, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function verifyFolders() {
|
||||
let msgRestored = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId1);
|
||||
Assert.ok(msgRestored !== null);
|
||||
Assert.equal(IMAPPump.inbox.msgDatabase.dBFolderInfo.numMessages, 4);
|
||||
},
|
||||
teardown,
|
||||
];
|
||||
|
||||
function setup() {
|
||||
add_task(function setupTest() {
|
||||
setupIMAPPump();
|
||||
|
||||
var listener1 = new alertListener();
|
||||
|
@ -140,13 +92,64 @@ function setup() {
|
|||
],
|
||||
IMAPPump.mailbox
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
asyncUrlListener.callback = function(aUrl, aExitCode) {
|
||||
Assert.equal(aExitCode, 0);
|
||||
};
|
||||
add_task(async function updateFolder() {
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function teardown() {
|
||||
add_task(async function deleteMessage() {
|
||||
let msgToDelete = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId1);
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener();
|
||||
gMessages.push(msgToDelete);
|
||||
IMAPPump.inbox.deleteMessages(
|
||||
gMessages,
|
||||
gMsgWindow,
|
||||
false,
|
||||
true,
|
||||
copyListener,
|
||||
true
|
||||
);
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
add_task(async function expunge() {
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.expunge(listener, gMsgWindow);
|
||||
await listener.promise;
|
||||
|
||||
// Ensure that the message has been surely deleted.
|
||||
Assert.equal(IMAPPump.inbox.msgDatabase.dBFolderInfo.numMessages, 3);
|
||||
});
|
||||
|
||||
add_task(async function undoDelete() {
|
||||
gMsgWindow.transactionManager.undoTransaction();
|
||||
// after undo, we select the trash and then the inbox, so that we sync
|
||||
// up with the server, and clear out the effects of having done the
|
||||
// delete offline.
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
let trash = gRootFolder.getChildNamed("Trash");
|
||||
trash
|
||||
.QueryInterface(Ci.nsIMsgImapMailFolder)
|
||||
.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(async function goBackToInbox() {
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(gMsgWindow, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(function verifyFolders() {
|
||||
let msgRestored = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(gMsgId1);
|
||||
Assert.ok(msgRestored !== null);
|
||||
Assert.equal(IMAPPump.inbox.msgDatabase.dBFolderInfo.numMessages, 4);
|
||||
});
|
||||
|
||||
add_task(function endTest() {
|
||||
// Cleanup, null out everything, close all cached connections and stop the
|
||||
// server
|
||||
gMessages = [];
|
||||
|
@ -154,8 +157,4 @@ function teardown() {
|
|||
gMsgWindow = null;
|
||||
gRootFolder = null;
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
/* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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 downloadAllForOffline works correctly for large imap
|
||||
* stores, i.e., over 4 GiB.
|
||||
*/
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
var { MessageGenerator, MessageScenarioFactory } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/MessageGenerator.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
Services.prefs.setCharPref(
|
||||
"mail.serverDefaultStoreContractID",
|
||||
|
@ -18,9 +21,7 @@ Services.prefs.setCharPref(
|
|||
|
||||
var gOfflineStoreSize;
|
||||
|
||||
var tests = [setup, check_result, teardown];
|
||||
|
||||
function run_test() {
|
||||
add_task(async function setupTest() {
|
||||
setupIMAPPump();
|
||||
|
||||
// Figure out the name of the IMAP inbox
|
||||
|
@ -38,9 +39,7 @@ function run_test() {
|
|||
"@mozilla.org/windows-registry-key;1" in Cc &&
|
||||
mailTestUtils.get_file_system(inboxFile) != "NTFS"
|
||||
) {
|
||||
dump("On Windows, this test only works on NTFS volumes.\n");
|
||||
teardown();
|
||||
return;
|
||||
throw new Error("On Windows, this test only works on NTFS volumes.\n");
|
||||
}
|
||||
|
||||
let isFileSparse = mailTestUtils.mark_file_region_sparse(
|
||||
|
@ -49,23 +48,15 @@ function run_test() {
|
|||
0x10000000f
|
||||
);
|
||||
let freeDiskSpace = inboxFile.diskSpaceAvailable;
|
||||
info("Free disk space = " + mailTestUtils.toMiBString(freeDiskSpace));
|
||||
if (!isFileSparse && freeDiskSpace < neededFreeSpace) {
|
||||
info(
|
||||
"This test needs " +
|
||||
mailTestUtils.toMiBString(neededFreeSpace) +
|
||||
" free space to run. Aborting."
|
||||
);
|
||||
todo_check_true(false);
|
||||
Assert.ok(
|
||||
isFileSparse && freeDiskSpace > neededFreeSpace,
|
||||
"This test needs " +
|
||||
mailTestUtils.toMiBString(neededFreeSpace) +
|
||||
" free space to run."
|
||||
);
|
||||
});
|
||||
|
||||
teardown();
|
||||
return;
|
||||
}
|
||||
|
||||
async_run_tests(tests);
|
||||
}
|
||||
|
||||
function* setup() {
|
||||
add_task(async function addOfflineMessages() {
|
||||
// Create a couple test messages on the IMAP server.
|
||||
let messages = [];
|
||||
let messageGenerator = new MessageGenerator();
|
||||
|
@ -98,24 +89,26 @@ function* setup() {
|
|||
|
||||
// Save initial file size.
|
||||
gOfflineStoreSize = IMAPPump.inbox.filePath.fileSize;
|
||||
info(
|
||||
console.trace(
|
||||
"Offline store size (before 1st downloadAllForOffline()) = " +
|
||||
gOfflineStoreSize
|
||||
);
|
||||
|
||||
// Download for offline use, to append created messages to local IMAP inbox.
|
||||
IMAPPump.inbox.downloadAllForOffline(asyncUrlListener, null);
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.downloadAllForOffline(listener, null);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function* check_result() {
|
||||
add_task(async function check_result() {
|
||||
// Call downloadAllForOffline() a second time.
|
||||
IMAPPump.inbox.downloadAllForOffline(asyncUrlListener, null);
|
||||
yield false;
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.downloadAllForOffline(listener, null);
|
||||
await listener.promise;
|
||||
|
||||
// Make sure offline store grew (i.e., we were not writing over data).
|
||||
let offlineStoreSize = IMAPPump.inbox.filePath.fileSize;
|
||||
info(
|
||||
console.trace(
|
||||
"Offline store size (after 2nd downloadAllForOffline()) = " +
|
||||
offlineStoreSize +
|
||||
". (Msg hdr offsets should be close to it.)"
|
||||
|
@ -125,21 +118,18 @@ function* check_result() {
|
|||
// Verify that the message headers have the offline flag set.
|
||||
for (let header of IMAPPump.inbox.msgDatabase.EnumerateMessages()) {
|
||||
// Verify that each message has been downloaded and looks OK.
|
||||
if (
|
||||
!(
|
||||
header instanceof Ci.nsIMsgDBHdr &&
|
||||
header.flags & Ci.nsMsgMessageFlags.Offline
|
||||
)
|
||||
) {
|
||||
do_throw("Message not downloaded for offline use");
|
||||
}
|
||||
Assert.ok(
|
||||
header instanceof Ci.nsIMsgDBHdr &&
|
||||
header.flags & Ci.nsMsgMessageFlags.Offline,
|
||||
"Message downloaded for offline use"
|
||||
);
|
||||
|
||||
// Make sure we don't fall over if we ask to read the message.
|
||||
IMAPPump.inbox.getSlicedOfflineFileStream(header.messageKey).close();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function teardown() {
|
||||
add_task(function teardown() {
|
||||
// Free up disk space - if you want to look at the file after running
|
||||
// this test, comment out this line.
|
||||
if (IMAPPump.inbox) {
|
||||
|
@ -147,4 +137,4 @@ function teardown() {
|
|||
}
|
||||
|
||||
teardownIMAPPump();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
/* 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/. */
|
||||
|
||||
// This file tests that listing folders on startup because we're not using
|
||||
// subscription doesn't leave db's open.
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
var { MessageGenerator } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/MessageGenerator.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
var gSub3;
|
||||
|
||||
var tests = [setup, updateInbox, checkCachedDBForFolder, teardown];
|
||||
|
||||
function* setup() {
|
||||
add_task(async function setupTest() {
|
||||
setupIMAPPump();
|
||||
|
||||
IMAPPump.daemon.createMailbox("folder1", { subscribed: true });
|
||||
|
@ -35,26 +37,22 @@ function* setup() {
|
|||
gSub3 = sub2.addSubfolder("sub3");
|
||||
IMAPPump.server.performTest("LIST");
|
||||
|
||||
do_timeout(1000, async_driver);
|
||||
yield false;
|
||||
}
|
||||
await PromiseTestUtils.promiseDelay(1000);
|
||||
});
|
||||
|
||||
function* updateInbox() {
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
add_task(async function updateInbox() {
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function checkCachedDBForFolder() {
|
||||
add_task(function checkCachedDBForFolder() {
|
||||
const gDbService = Cc["@mozilla.org/msgDatabase/msgDBService;1"].getService(
|
||||
Ci.nsIMsgDBService
|
||||
);
|
||||
Assert.equal(gDbService.cachedDBForFolder(gSub3), null);
|
||||
}
|
||||
});
|
||||
|
||||
function teardown() {
|
||||
add_task(function teardown() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -12,34 +12,23 @@
|
|||
* http://bugzilla.zimbra.com/show_bug.cgi?id=78794
|
||||
*/
|
||||
|
||||
// async support
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/alertTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/alertTestUtils.js");
|
||||
|
||||
// IMAP pump
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// Globals
|
||||
add_task(async function setupTest() {
|
||||
// Zimbra is one of the servers that supports LIST-EXTENDED
|
||||
// it also has a bug that causes a server crash in certain setups
|
||||
setupIMAPPump("Zimbra");
|
||||
|
||||
// Zimbra is one of the servers that supports LIST-EXTENDED
|
||||
// it also has a bug that causes a server crash in certain setups
|
||||
setupIMAPPump("Zimbra");
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.server1.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
|
||||
// Definition of tests
|
||||
var tests = [
|
||||
setupMailboxes,
|
||||
testListSubscribed,
|
||||
testZimbraServerVersions,
|
||||
endTest,
|
||||
];
|
||||
|
||||
// setup the mailboxes that will be used for this test
|
||||
function* setupMailboxes() {
|
||||
// Setup the mailboxes that will be used for this test.
|
||||
IMAPPump.mailbox.subscribed = true;
|
||||
IMAPPump.daemon.createMailbox("folder1", {
|
||||
subscribed: true,
|
||||
|
@ -56,12 +45,13 @@ function* setupMailboxes() {
|
|||
IMAPPump.daemon.createMailbox("folder3", {});
|
||||
|
||||
// select the inbox to force folder discovery, etc.
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
// tests that LIST (SUBSCRIBED) returns the proper response
|
||||
function* testListSubscribed() {
|
||||
add_task(async function testListSubscribed() {
|
||||
// check that we have \Noselect and \Noinferiors flags - these would not have
|
||||
// been returned if we had used LSUB instead of LIST(SUBSCRIBED)
|
||||
let rootFolder = IMAPPump.incomingServer.rootFolder;
|
||||
|
@ -85,11 +75,9 @@ function* testListSubscribed() {
|
|||
} catch (ex) {}
|
||||
// do_check_false(folder1.getFlag(Ci.nsMsgFolderFlags.Subscribed));
|
||||
Assert.equal(null, folder3);
|
||||
});
|
||||
|
||||
yield true;
|
||||
}
|
||||
|
||||
function* testZimbraServerVersions() {
|
||||
add_task(async function testZimbraServerVersions() {
|
||||
// older versions of Zimbra can crash if we send LIST (SUBSCRIBED) so we want
|
||||
// to make sure that we are checking for versions
|
||||
|
||||
|
@ -114,8 +102,9 @@ function* testZimbraServerVersions() {
|
|||
IMAPPump.incomingServer.closeCachedConnections();
|
||||
IMAPPump.incomingServer.performExpand(null);
|
||||
// select inbox is just to wait on performExpand since performExpand does not have listener
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
// if we send LSUB instead of LIST(SUBSCRIBED), then we should not have \NoSelect flag
|
||||
let rootFolder = IMAPPump.incomingServer.rootFolder;
|
||||
let folder1 = rootFolder.getChildNamed("folder1");
|
||||
|
@ -124,17 +113,9 @@ function* testZimbraServerVersions() {
|
|||
testValues[i].expectedResult
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Cleanup at end
|
||||
function endTest() {
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.server1.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/* 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/. */
|
||||
|
||||
/*
|
||||
* This file tests copies of multiple messages using filters
|
||||
* from incoming POP3, with filter actions copying and moving
|
||||
|
@ -7,152 +11,151 @@
|
|||
* Original author: Kent James <kent@caspia.com>
|
||||
*/
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/**
|
||||
* NOTE:
|
||||
* There's a problem with this test in chaos mode (mach xpcshell-test --verify)
|
||||
* with the filter applying.
|
||||
* It's either a problem with the POP3Pump implementation (testing infrastructure failure)
|
||||
* or a problem with the copy filter.
|
||||
*/
|
||||
|
||||
/* import-globals-from ../../../test/resources/POP3pump.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/POP3pump.js");
|
||||
|
||||
var { MailServices } = ChromeUtils.import(
|
||||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
var gEmptyLocal1, gEmptyLocal2;
|
||||
var gMessages = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
|
||||
var gFiles = ["../../../data/bugmail1", "../../../data/draft1"];
|
||||
|
||||
var tests = [
|
||||
setup,
|
||||
function* copyFolder1() {
|
||||
dump("gEmpty1 " + gEmptyLocal1.URI + "\n");
|
||||
MailServices.copy.copyFolder(
|
||||
gEmptyLocal1,
|
||||
IMAPPump.inbox,
|
||||
false,
|
||||
CopyListener,
|
||||
null
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function* copyFolder2() {
|
||||
dump("gEmpty2 " + gEmptyLocal2.URI + "\n");
|
||||
MailServices.copy.copyFolder(
|
||||
gEmptyLocal2,
|
||||
IMAPPump.inbox,
|
||||
false,
|
||||
CopyListener,
|
||||
null
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function* getLocalMessages() {
|
||||
// setup copy then move mail filters on the inbox
|
||||
let filterList = gPOP3Pump.fakeServer.getFilterList(null);
|
||||
let filter = filterList.createFilter("copyThenMoveAll");
|
||||
let searchTerm = filter.createTerm();
|
||||
searchTerm.matchAll = true;
|
||||
filter.appendTerm(searchTerm);
|
||||
let copyAction = filter.createAction();
|
||||
copyAction.type = Ci.nsMsgFilterAction.CopyToFolder;
|
||||
copyAction.targetFolderUri = IMAPPump.inbox.getChildNamed("empty 1").URI;
|
||||
filter.appendAction(copyAction);
|
||||
let moveAction = filter.createAction();
|
||||
moveAction.type = Ci.nsMsgFilterAction.MoveToFolder;
|
||||
moveAction.targetFolderUri = IMAPPump.inbox.getChildNamed("empty 2").URI;
|
||||
filter.appendAction(moveAction);
|
||||
filter.enabled = true;
|
||||
filterList.insertFilterAt(0, filter);
|
||||
|
||||
gPOP3Pump.files = gFiles;
|
||||
gPOP3Pump.onDone = async_driver;
|
||||
gPOP3Pump.run();
|
||||
yield false;
|
||||
},
|
||||
function* update1() {
|
||||
let folder1 = IMAPPump.inbox
|
||||
.getChildNamed("empty 1")
|
||||
.QueryInterface(Ci.nsIMsgImapMailFolder);
|
||||
folder1.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function* update2() {
|
||||
let folder2 = IMAPPump.inbox
|
||||
.getChildNamed("empty 2")
|
||||
.QueryInterface(Ci.nsIMsgImapMailFolder);
|
||||
folder2.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function verifyFolders() {
|
||||
let folder1 = IMAPPump.inbox.getChildNamed("empty 1");
|
||||
listMessages(folder1);
|
||||
let folder2 = IMAPPump.inbox.getChildNamed("empty 2");
|
||||
listMessages(folder2);
|
||||
listMessages(localAccountUtils.inboxFolder);
|
||||
Assert.ok(folder1 !== null);
|
||||
Assert.ok(folder2 !== null);
|
||||
// folder 1 and 2 should each now have 2 messages in them.
|
||||
Assert.equal(folderCount(folder1), 2);
|
||||
Assert.equal(folderCount(folder2), 2);
|
||||
// the local inbox folder should now be empty, since the second
|
||||
// operation was a move
|
||||
Assert.equal(folderCount(localAccountUtils.inboxFolder), 0);
|
||||
},
|
||||
teardown,
|
||||
];
|
||||
|
||||
function folderCount(folder) {
|
||||
return [...folder.msgDatabase.EnumerateMessages()].length;
|
||||
}
|
||||
|
||||
function setup() {
|
||||
add_task(async function setupTest() {
|
||||
setupIMAPPump();
|
||||
let emptyFolder1Listener = PromiseTestUtils.promiseFolderAdded("empty 1");
|
||||
gEmptyLocal1 = localAccountUtils.rootFolder.createLocalSubfolder("empty 1");
|
||||
await emptyFolder1Listener;
|
||||
let emptyFolder2Listener = PromiseTestUtils.promiseFolderAdded("empty 2");
|
||||
gEmptyLocal2 = localAccountUtils.rootFolder.createLocalSubfolder("empty 2");
|
||||
await emptyFolder2Listener;
|
||||
|
||||
// these hacks are required because we've created the inbox before
|
||||
// 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.
|
||||
IMAPPump.inbox.hierarchyDelimiter = "/";
|
||||
IMAPPump.inbox.verifiedAsOnlineFolder = true;
|
||||
}
|
||||
});
|
||||
|
||||
// nsIMsgCopyServiceListener implementation - runs next test when copy
|
||||
// is completed.
|
||||
var CopyListener = {
|
||||
OnStartCopy() {},
|
||||
OnProgress(aProgress, aProgressMax) {},
|
||||
SetMessageKey(aKey) {},
|
||||
SetMessageId(aMessageId) {},
|
||||
OnStopCopy(aStatus) {
|
||||
// Check: message successfully copied.
|
||||
Assert.equal(aStatus, 0);
|
||||
async_driver();
|
||||
},
|
||||
};
|
||||
add_task(async function copyFolder1() {
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener();
|
||||
MailServices.copy.copyFolder(
|
||||
gEmptyLocal1,
|
||||
IMAPPump.inbox,
|
||||
false,
|
||||
copyListener,
|
||||
null
|
||||
);
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
asyncUrlListener.callback = function(aUrl, aExitCode) {
|
||||
Assert.equal(aExitCode, 0);
|
||||
};
|
||||
add_task(async function updateTrash() {
|
||||
let trashFolder = IMAPPump.incomingServer.rootFolder
|
||||
.getChildNamed("Trash")
|
||||
.QueryInterface(Ci.nsIMsgImapMailFolder);
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
// hack to force uid validity to get initialized for trash.
|
||||
trashFolder.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function listMessages(folder) {
|
||||
var msgCount = 0;
|
||||
dump("listing messages for " + folder.prettyName + "\n");
|
||||
for (let hdr of folder.msgDatabase.EnumerateMessages()) {
|
||||
msgCount++;
|
||||
dump(msgCount + ": " + hdr.subject + "\n");
|
||||
}
|
||||
}
|
||||
add_task(async function copyFolder2() {
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener();
|
||||
MailServices.copy.copyFolder(
|
||||
gEmptyLocal2,
|
||||
IMAPPump.inbox,
|
||||
false,
|
||||
copyListener,
|
||||
null
|
||||
);
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
function teardown() {
|
||||
add_task(async function getLocalMessages() {
|
||||
// setup copy then move mail filters on the inbox
|
||||
let filterList = gPOP3Pump.fakeServer.getFilterList(null);
|
||||
let filter = filterList.createFilter("copyThenMoveAll");
|
||||
let searchTerm = filter.createTerm();
|
||||
searchTerm.matchAll = true;
|
||||
filter.appendTerm(searchTerm);
|
||||
let copyAction = filter.createAction();
|
||||
copyAction.type = Ci.nsMsgFilterAction.CopyToFolder;
|
||||
copyAction.targetFolderUri = IMAPPump.inbox.getChildNamed("empty 1").URI;
|
||||
filter.appendAction(copyAction);
|
||||
let moveAction = filter.createAction();
|
||||
moveAction.type = Ci.nsMsgFilterAction.MoveToFolder;
|
||||
moveAction.targetFolderUri = IMAPPump.inbox.getChildNamed("empty 2").URI;
|
||||
filter.appendAction(moveAction);
|
||||
filter.enabled = true;
|
||||
filterList.insertFilterAt(0, filter);
|
||||
let resolveOnDone;
|
||||
let promiseOnDone = new Promise(resolve => {
|
||||
resolveOnDone = resolve;
|
||||
});
|
||||
gPOP3Pump.files = gFiles;
|
||||
gPOP3Pump.onDone = resolveOnDone;
|
||||
gPOP3Pump.run();
|
||||
|
||||
await promiseOnDone;
|
||||
});
|
||||
|
||||
add_task(async function test_update1_copyFilter() {
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
let folder1 = IMAPPump.inbox
|
||||
.getChildNamed("empty 1")
|
||||
.QueryInterface(Ci.nsIMsgImapMailFolder);
|
||||
folder1.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
Assert.ok(folder1 !== null);
|
||||
Assert.equal(
|
||||
folderCount(folder1),
|
||||
2,
|
||||
"the two filtered messages should be in empty 1"
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function test_update2_moveFilter() {
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
let folder2 = IMAPPump.inbox
|
||||
.getChildNamed("empty 2")
|
||||
.QueryInterface(Ci.nsIMsgImapMailFolder);
|
||||
folder2.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
Assert.ok(folder2 !== null);
|
||||
Assert.equal(
|
||||
folderCount(folder2),
|
||||
2,
|
||||
"the two filtered messages should be in empty 2"
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function verifyLocalFolder() {
|
||||
// the local inbox folder should now be empty, since the second
|
||||
// operation was a move
|
||||
Assert.equal(folderCount(localAccountUtils.inboxFolder), 0);
|
||||
});
|
||||
|
||||
add_task(function endTest() {
|
||||
gMessages.clear();
|
||||
gEmptyLocal1 = null;
|
||||
gEmptyLocal2 = null;
|
||||
gPOP3Pump = null;
|
||||
teardownIMAPPump();
|
||||
}
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
function folderCount(folder) {
|
||||
return [...folder.msgDatabase.EnumerateMessages()].length;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
*
|
||||
*/
|
||||
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
var { MailServices } = ChromeUtils.import(
|
||||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
|
@ -22,42 +25,26 @@ Services.prefs.setCharPref(
|
|||
/* import-globals-from ../../../test/resources/POP3pump.js */
|
||||
load("../../../resources/POP3pump.js");
|
||||
|
||||
// async support
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
|
||||
// IMAP pump
|
||||
|
||||
setupIMAPPump();
|
||||
|
||||
var gFinishedRunningURL = -1;
|
||||
var gSubfolder;
|
||||
|
||||
// tests
|
||||
add_task(function setupTest() {
|
||||
setupIMAPPump();
|
||||
// quarantine messages
|
||||
Services.prefs.setBoolPref("mailnews.downloadToTempFile", true);
|
||||
});
|
||||
|
||||
var quarantineTests = [
|
||||
createSubfolder,
|
||||
getLocalMessages,
|
||||
updateSubfolderAndTest,
|
||||
get2Messages,
|
||||
updateSubfolderAndTest2,
|
||||
endTest,
|
||||
];
|
||||
|
||||
function* createSubfolder() {
|
||||
add_task(async function createSubfolder() {
|
||||
let folderAddedListener = PromiseTestUtils.promiseFolderAdded("subfolder");
|
||||
IMAPPump.incomingServer.rootFolder.createSubfolder("subfolder", null);
|
||||
dl("wait for folderAdded notification");
|
||||
yield false;
|
||||
await folderAddedListener;
|
||||
gSubfolder = IMAPPump.incomingServer.rootFolder.getChildNamed("subfolder");
|
||||
Assert.ok(gSubfolder instanceof Ci.nsIMsgImapMailFolder);
|
||||
gSubfolder.updateFolderWithListener(null, urlListener);
|
||||
dl("wait for OnStopRunningURL");
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
gSubfolder.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function* getLocalMessages() {
|
||||
add_task(async function getLocalMessages() {
|
||||
// setup copy then move mail filters on the inbox
|
||||
let filterList = gPOP3Pump.fakeServer.getFilterList(null);
|
||||
let filter = filterList.createFilter("copyThenMoveAll");
|
||||
|
@ -71,139 +58,60 @@ function* getLocalMessages() {
|
|||
filter.enabled = true;
|
||||
filterList.insertFilterAt(0, filter);
|
||||
|
||||
let resolveDone;
|
||||
let promise = new Promise(resolve => {
|
||||
resolveDone = resolve;
|
||||
});
|
||||
gPOP3Pump.files = ["../../../data/bugmail1"];
|
||||
gPOP3Pump.onDone = function() {
|
||||
dump("POP3Pump done\n");
|
||||
async_driver();
|
||||
};
|
||||
gPOP3Pump.onDone = resolveDone;
|
||||
gPOP3Pump.run();
|
||||
dl("waiting for POP3Pump done");
|
||||
yield false;
|
||||
}
|
||||
await promise;
|
||||
});
|
||||
|
||||
function checkResult() {
|
||||
if (gFinishedRunningURL == 1) {
|
||||
async_driver();
|
||||
gFinishedRunningURL = -1;
|
||||
} else if (gFinishedRunningURL == 0) {
|
||||
gSubfolder.updateFolderWithListener(null, urlListener);
|
||||
do_timeout(100, checkResult);
|
||||
}
|
||||
// Else just ignore it.
|
||||
}
|
||||
add_task(async function updateSubfolderAndTest() {
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
let folderLoaded = PromiseTestUtils.promiseFolderEvent(
|
||||
gSubfolder,
|
||||
"FolderLoaded"
|
||||
);
|
||||
gSubfolder.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
await folderLoaded;
|
||||
|
||||
function* updateSubfolderAndTest() {
|
||||
// The previous function does an append, which may take a bit of time to
|
||||
// complete. Unfortunately updateFolderWithListener succeeds successfully
|
||||
// if there is a url running, but doesn't tell us that is the case. So we
|
||||
// have to run updateFolderWithListener several times to actually find out
|
||||
// when we are done.
|
||||
gFinishedRunningURL = 0;
|
||||
gSubfolder.updateFolderWithListener(null, urlListener);
|
||||
dl("wait for OnStopRunningURL");
|
||||
do_timeout(100, checkResult);
|
||||
yield false;
|
||||
|
||||
// kill some time
|
||||
do_timeout(200, async_driver);
|
||||
yield false;
|
||||
|
||||
// test
|
||||
listMessages(gSubfolder);
|
||||
listMessages(localAccountUtils.inboxFolder);
|
||||
Assert.equal(folderCount(gSubfolder), 1);
|
||||
Assert.equal(folderCount(localAccountUtils.inboxFolder), 1);
|
||||
}
|
||||
});
|
||||
|
||||
function* get2Messages() {
|
||||
add_task(async function get2Messages() {
|
||||
let resolveDone;
|
||||
let promise = new Promise(resolve => {
|
||||
resolveDone = resolve;
|
||||
});
|
||||
gPOP3Pump.files = ["../../../data/bugmail10", "../../../data/draft1"];
|
||||
gPOP3Pump.onDone = function() {
|
||||
dump("POP3Pump done\n");
|
||||
async_driver();
|
||||
};
|
||||
gPOP3Pump.onDone = resolveDone;
|
||||
gPOP3Pump.run();
|
||||
dl("waiting for POP3Pump done");
|
||||
yield false;
|
||||
}
|
||||
await promise;
|
||||
});
|
||||
|
||||
function* updateSubfolderAndTest2() {
|
||||
// The previous function does an append, which may take a bit of time to
|
||||
// complete. Unfortunately updateFolderWithListener succeeds successfully
|
||||
// if there is a url running, but doesn't tell us that is the case. So we
|
||||
// have to run updateFolderWithListener several times to actually find out
|
||||
// when we are done.
|
||||
gFinishedRunningURL = 0;
|
||||
gSubfolder.updateFolderWithListener(null, urlListener);
|
||||
dl("wait for OnStopRunningURL");
|
||||
do_timeout(1000, checkResult);
|
||||
yield false;
|
||||
|
||||
// kill some time
|
||||
do_timeout(1000, async_driver);
|
||||
yield false;
|
||||
|
||||
// test
|
||||
listMessages(gSubfolder);
|
||||
listMessages(localAccountUtils.inboxFolder);
|
||||
add_task(async function updateSubfolderAndTest2() {
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
let folderLoaded = PromiseTestUtils.promiseFolderEvent(
|
||||
gSubfolder,
|
||||
"FolderLoaded"
|
||||
);
|
||||
gSubfolder.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
await folderLoaded;
|
||||
Assert.equal(folderCount(gSubfolder), 3);
|
||||
Assert.equal(folderCount(localAccountUtils.inboxFolder), 3);
|
||||
}
|
||||
});
|
||||
|
||||
function endTest() {
|
||||
add_task(function endTest() {
|
||||
// Cleanup, null out everything, close all cached connections and stop the
|
||||
// server
|
||||
dl("Exiting mail tests");
|
||||
gPOP3Pump = null;
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
// listeners
|
||||
|
||||
var mfnListener = {
|
||||
folderAdded(aFolder) {
|
||||
dl("folderAdded <" + aFolder.name + ">");
|
||||
// we are only using async yield on the Subfolder add
|
||||
if (aFolder.name == "subfolder") {
|
||||
async_driver();
|
||||
}
|
||||
},
|
||||
|
||||
msgAdded(aMsg) {
|
||||
dl(
|
||||
"msgAdded to folder <" +
|
||||
aMsg.folder.name +
|
||||
"> subject <" +
|
||||
aMsg.subject +
|
||||
">"
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
var urlListener = {
|
||||
OnStartRunningUrl(aUrl) {
|
||||
dl("OnStartRunningUrl");
|
||||
},
|
||||
OnStopRunningUrl(aUrl, aExitCode) {
|
||||
dl("OnStopRunningUrl");
|
||||
gFinishedRunningURL = 1;
|
||||
checkResult();
|
||||
},
|
||||
};
|
||||
|
||||
// main test startup
|
||||
|
||||
function run_test() {
|
||||
// quarantine messages
|
||||
Services.prefs.setBoolPref("mailnews.downloadToTempFile", true);
|
||||
|
||||
// Add folder listeners that will capture async events
|
||||
const nsIMFNService = Ci.nsIMsgFolderNotificationService;
|
||||
let flags = nsIMFNService.folderAdded | nsIMFNService.msgAdded;
|
||||
MailServices.mfn.addListener(mfnListener, flags);
|
||||
|
||||
// start first test
|
||||
async_run_tests(quarantineTests);
|
||||
}
|
||||
});
|
||||
|
||||
// helper functions
|
||||
|
||||
|
@ -211,18 +119,3 @@ function run_test() {
|
|||
function folderCount(folder) {
|
||||
return [...folder.msgDatabase.EnumerateMessages()].length;
|
||||
}
|
||||
|
||||
// display of message subjects in a folder
|
||||
function listMessages(folder) {
|
||||
var msgCount = 0;
|
||||
dl("listing messages for " + folder.prettyName);
|
||||
for (let hdr of folder.msgDatabase.EnumerateMessages()) {
|
||||
msgCount++;
|
||||
dl(msgCount + ": " + hdr.subject);
|
||||
}
|
||||
}
|
||||
|
||||
// shorthand output of a line of text
|
||||
function dl(text) {
|
||||
dump(text + "\n");
|
||||
}
|
||||
|
|
|
@ -7,27 +7,22 @@
|
|||
// see: bug 495318
|
||||
// see: RFC 5258 - http://tools.ietf.org/html/rfc5258
|
||||
|
||||
// async support
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/alertTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/alertTestUtils.js");
|
||||
|
||||
// IMAP pump
|
||||
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// Globals
|
||||
add_task(function setupTest() {
|
||||
setupIMAPPump();
|
||||
|
||||
setupIMAPPump();
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.server1.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
// Definition of tests
|
||||
var tests = [setupMailboxes, testLsub, endTest];
|
||||
|
||||
// setup the mailboxes that will be used for this test
|
||||
function* setupMailboxes() {
|
||||
// Setup the mailboxes that will be used for this test.
|
||||
add_task(async function setupMailboxes() {
|
||||
IMAPPump.mailbox.subscribed = true;
|
||||
IMAPPump.daemon.createMailbox("folder1", {
|
||||
subscribed: true,
|
||||
|
@ -44,48 +39,39 @@ function* setupMailboxes() {
|
|||
IMAPPump.daemon.createMailbox("folder3", {});
|
||||
|
||||
// select the inbox to force folder discovery, etc.
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
// tests that LSUB returns the proper response
|
||||
function* testLsub() {
|
||||
// check that we have \Noselect and \Noinferiors flags - these would not have
|
||||
// been returned if we had used LSUB instead of LIST(SUBSCRIBED)
|
||||
// Tests that LSUB returns the proper response.
|
||||
add_task(function testLsub() {
|
||||
// Check that we have \Noselect and \Noinferiors flags - these would not have
|
||||
// been returned if we had used LSUB instead of LIST(SUBSCRIBED).
|
||||
let rootFolder = IMAPPump.incomingServer.rootFolder;
|
||||
let folder1 = rootFolder.getChildNamed("folder1");
|
||||
Assert.ok(folder1.getFlag(Ci.nsMsgFolderFlags.ImapNoselect));
|
||||
Assert.ok(!folder1.getFlag(Ci.nsMsgFolderFlags.ImapNoinferiors));
|
||||
|
||||
// make sure the above test was not a fluke
|
||||
// Make sure the above test was not a fluke.
|
||||
let folder11 = folder1.getChildNamed("folder11");
|
||||
Assert.ok(!folder11.getFlag(Ci.nsMsgFolderFlags.ImapNoselect));
|
||||
Assert.ok(folder11.getFlag(Ci.nsMsgFolderFlags.ImapNoinferiors));
|
||||
|
||||
// test that \NonExistent implies \Noselect
|
||||
// Test that \NonExistent implies \Noselect.
|
||||
rootFolder.getChildNamed("folder2");
|
||||
Assert.ok(folder1.getFlag(Ci.nsMsgFolderFlags.ImapNoselect));
|
||||
|
||||
// should not get a folder3 since it is not subscribed
|
||||
// Should not get a folder3 since it is not subscribed.
|
||||
let folder3;
|
||||
try {
|
||||
folder3 = rootFolder.getChildNamed("folder3");
|
||||
} catch (ex) {}
|
||||
// do_check_false(folder1.getFlag(Ci.nsMsgFolderFlags.Subscribed));
|
||||
Assert.equal(false, folder1.getFlag(Ci.nsMsgFolderFlags.Subscribed));
|
||||
Assert.equal(null, folder3);
|
||||
});
|
||||
|
||||
yield true;
|
||||
}
|
||||
|
||||
// Cleanup at end
|
||||
function endTest() {
|
||||
// Cleanup at end.
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.server1.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,19 +1,23 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
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 ä
|
||||
|
||||
function* setup() {
|
||||
add_task(async function setupTest() {
|
||||
setupIMAPPump();
|
||||
|
||||
IMAPPump.daemon.createMailbox(folderName1, { subscribed: true });
|
||||
|
@ -25,61 +29,52 @@ function* setup() {
|
|||
// Get the server list...
|
||||
IMAPPump.server.performTest("LIST");
|
||||
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
var tests = [
|
||||
setup,
|
||||
function* checkDiscovery() {
|
||||
dump("in check discovery\n");
|
||||
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"));
|
||||
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 i18nChild = rootFolder.getChildNamed(folderName1);
|
||||
|
||||
MailServices.imap.renameLeaf(
|
||||
i18nChild,
|
||||
folderName2,
|
||||
asyncUrlListener,
|
||||
null
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function* checkRename() {
|
||||
let rootFolder = IMAPPump.incomingServer.rootFolder;
|
||||
Assert.ok(rootFolder.containsChildNamed(folderName2));
|
||||
let newChild = rootFolder
|
||||
.getChildNamed(folderName2)
|
||||
.QueryInterface(Ci.nsIMsgImapMailFolder);
|
||||
newChild.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
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.
|
||||
}
|
||||
},
|
||||
teardown,
|
||||
];
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
MailServices.imap.renameLeaf(i18nChild, folderName2, listener, null);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function teardown() {
|
||||
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();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -8,44 +8,39 @@
|
|||
* See Bug 805626
|
||||
*/
|
||||
|
||||
// async support
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
|
||||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
var { MailServices } = ChromeUtils.import(
|
||||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
|
||||
// IMAP pump
|
||||
|
||||
setupIMAPPump();
|
||||
|
||||
// Definition of tests
|
||||
|
||||
var tests = [
|
||||
createDraftsFolder,
|
||||
goOffline,
|
||||
saveDraft,
|
||||
goOnline,
|
||||
checkResult,
|
||||
endTest,
|
||||
];
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
var { TestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/TestUtils.jsm"
|
||||
);
|
||||
|
||||
var gDraftsFolder;
|
||||
|
||||
function* createDraftsFolder() {
|
||||
add_task(function setupTest() {
|
||||
setupIMAPPump();
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.default.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function createDraftsFolder() {
|
||||
IMAPPump.incomingServer.rootFolder.createSubfolder("Drafts", null);
|
||||
yield false;
|
||||
await PromiseTestUtils.promiseFolderAdded("Drafts");
|
||||
gDraftsFolder = IMAPPump.incomingServer.rootFolder.getChildNamed("Drafts");
|
||||
Assert.ok(gDraftsFolder instanceof Ci.nsIMsgImapMailFolder);
|
||||
gDraftsFolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
function* goOffline() {
|
||||
// Don't prompt about offline download when going offline
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
gDraftsFolder.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(async function goOffline() {
|
||||
// Don't prompt about offline download when going offline.
|
||||
Services.prefs.setIntPref("offline.download.download_messages", 2);
|
||||
|
||||
IMAPPump.incomingServer.closeCachedConnections();
|
||||
|
@ -53,15 +48,11 @@ function* goOffline() {
|
|||
while (thread.hasPendingEvents()) {
|
||||
thread.processNextEvent(true);
|
||||
}
|
||||
|
||||
do_timeout(2000, async_driver);
|
||||
yield false;
|
||||
|
||||
IMAPPump.server.stop();
|
||||
Services.io.offline = true;
|
||||
}
|
||||
});
|
||||
|
||||
function* saveDraft() {
|
||||
add_task(async function saveDraft() {
|
||||
let msgCompose = Cc["@mozilla.org/messengercompose/compose;1"].createInstance(
|
||||
Ci.nsIMsgCompose
|
||||
);
|
||||
|
@ -74,13 +65,14 @@ function* saveDraft() {
|
|||
params.composeFields = fields;
|
||||
msgCompose.initialize(params);
|
||||
|
||||
// Set up the identity
|
||||
// Set up the identity.
|
||||
let identity = MailServices.accounts.createIdentity();
|
||||
identity.draftFolder = gDraftsFolder.URI;
|
||||
|
||||
let progress = Cc["@mozilla.org/messenger/progress;1"].createInstance(
|
||||
Ci.nsIMsgProgress
|
||||
);
|
||||
let progressListener = new WebProgressListener();
|
||||
progress.registerListener(progressListener);
|
||||
msgCompose.sendMsg(
|
||||
Ci.nsIMsgSend.nsMsgSaveAsDraft,
|
||||
|
@ -89,12 +81,12 @@ function* saveDraft() {
|
|||
null,
|
||||
progress
|
||||
);
|
||||
yield false;
|
||||
// verify that message is not on the server yet
|
||||
await progressListener.promise;
|
||||
// Verify that message is not on the server yet.
|
||||
Assert.equal(IMAPPump.daemon.getMailbox("Drafts")._messages.length, 0);
|
||||
}
|
||||
});
|
||||
|
||||
function* goOnline() {
|
||||
add_task(async function goOnline() {
|
||||
let offlineManager = Cc[
|
||||
"@mozilla.org/messenger/offline-manager;1"
|
||||
].getService(Ci.nsIMsgOfflineManager);
|
||||
|
@ -104,70 +96,34 @@ function* goOnline() {
|
|||
IMAPPump.server.start();
|
||||
offlineManager.inProgress = true;
|
||||
offlineManager.goOnline(false, true, null);
|
||||
let waitForNotInProgress = function() {
|
||||
if (offlineManager.inProgress) {
|
||||
do_timeout(250, waitForNotInProgress);
|
||||
} else {
|
||||
async_driver();
|
||||
}
|
||||
};
|
||||
waitForNotInProgress();
|
||||
yield false;
|
||||
}
|
||||
|
||||
function* checkResult() {
|
||||
// verify that message is now on the server
|
||||
Assert.equal(IMAPPump.daemon.getMailbox("Drafts")._messages.length, 1);
|
||||
yield true;
|
||||
}
|
||||
|
||||
function* endTest() {
|
||||
teardownIMAPPump();
|
||||
yield true;
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.default.autosync_offline_stores",
|
||||
false
|
||||
// There seem to be some untraceable postprocessing with 100ms.
|
||||
// (Found through xpcshell-test --verify)
|
||||
await PromiseTestUtils.promiseDelay(100);
|
||||
await TestUtils.waitForCondition(
|
||||
() => !offlineManager.inProgress,
|
||||
"wait for offlineManager not in progress"
|
||||
);
|
||||
// Verify that message is now on the server.
|
||||
Assert.equal(IMAPPump.daemon.getMailbox("Drafts")._messages.length, 1);
|
||||
});
|
||||
|
||||
// Add folder listeners that will capture async events
|
||||
const nsIMFNService = Ci.nsIMsgFolderNotificationService;
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
});
|
||||
|
||||
let flags =
|
||||
nsIMFNService.msgsMoveCopyCompleted |
|
||||
nsIMFNService.folderAdded |
|
||||
nsIMFNService.msgAdded;
|
||||
MailServices.mfn.addListener(mfnListener, flags);
|
||||
/*
|
||||
* helper functions
|
||||
*/
|
||||
|
||||
// start first test
|
||||
async_run_tests(tests);
|
||||
function WebProgressListener() {
|
||||
this._promise = new Promise(resolve => {
|
||||
this._resolve = resolve;
|
||||
});
|
||||
}
|
||||
|
||||
var mfnListener = {
|
||||
msgsMoveCopyCompleted(aMove, aSrcMsgs, aDestFolder, aDestMsgs) {
|
||||
dl("msgsMoveCopyCompleted to folder " + aDestFolder.name);
|
||||
},
|
||||
|
||||
folderAdded(aFolder) {
|
||||
dl("folderAdded <" + aFolder.name + ">");
|
||||
// we are only using async add on the Junk folder
|
||||
if (aFolder.name == "Drafts") {
|
||||
async_driver();
|
||||
}
|
||||
},
|
||||
|
||||
msgAdded(aMsg) {
|
||||
dl("msgAdded with subject <" + aMsg.subject + ">");
|
||||
},
|
||||
};
|
||||
|
||||
var progressListener = {
|
||||
WebProgressListener.prototype = {
|
||||
onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
|
||||
if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) {
|
||||
dl("onStateChange");
|
||||
async_driver();
|
||||
this._resolve();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -188,13 +144,8 @@ var progressListener = {
|
|||
"nsIWebProgressListener",
|
||||
"nsISupportsWeakReference",
|
||||
]),
|
||||
|
||||
get promise() {
|
||||
return this._promise;
|
||||
},
|
||||
};
|
||||
|
||||
/*
|
||||
* helper functions
|
||||
*/
|
||||
|
||||
// quick shorthand for output of a line of text.
|
||||
function dl(text) {
|
||||
dump(text + "\n");
|
||||
}
|
||||
|
|
|
@ -1,32 +1,38 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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 code that writes to the imap offline store deals
|
||||
* with offline store locking correctly.
|
||||
*/
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
/* import-globals-from ../../../test/resources/alertTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
load("../../../resources/alertTestUtils.js");
|
||||
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
var { MessageGenerator } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/MessageGenerator.jsm"
|
||||
);
|
||||
|
||||
var { MailServices } = ChromeUtils.import(
|
||||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
|
||||
// Globals
|
||||
var gIMAPTrashFolder, gMsgImapInboxFolder;
|
||||
var gGotAlert = false;
|
||||
var gMovedMsgId;
|
||||
|
||||
/* exported alert */
|
||||
// to alertTestUtils.js
|
||||
var gAlertResolve;
|
||||
var gGotAlert = new Promise(resolve => {
|
||||
gAlertResolve = resolve;
|
||||
});
|
||||
|
||||
/* exported alert to alertTestUtils.js */
|
||||
function alert(aDialogTitle, aText) {
|
||||
// do_check_true(aText.startsWith("Connection to server Mail for timed out."));
|
||||
gGotAlert = true;
|
||||
gAlertResolve(aText);
|
||||
}
|
||||
|
||||
function addGeneratedMessagesToServer(messages, mailbox) {
|
||||
|
@ -41,133 +47,7 @@ function addGeneratedMessagesToServer(messages, mailbox) {
|
|||
|
||||
var gStreamedHdr = null;
|
||||
|
||||
var tests = [
|
||||
setup,
|
||||
function* downloadForOffline() {
|
||||
// ...and download for offline use.
|
||||
dump("Downloading for offline use\n");
|
||||
IMAPPump.inbox.downloadAllForOffline(asyncUrlListener, null);
|
||||
yield false;
|
||||
},
|
||||
function* deleteOneMsg() {
|
||||
let enumerator = IMAPPump.inbox.msgDatabase.EnumerateMessages();
|
||||
let msgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
|
||||
IMAPPump.inbox.deleteMessages(
|
||||
[msgHdr],
|
||||
null,
|
||||
false,
|
||||
true,
|
||||
CopyListener,
|
||||
false
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function* compactOneFolder() {
|
||||
let enumerator = IMAPPump.inbox.msgDatabase.EnumerateMessages();
|
||||
let msgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
|
||||
gStreamedHdr = msgHdr;
|
||||
// mark the message as not being offline, and then we'll make sure that
|
||||
// streaming the message while we're compacting doesn't result in the
|
||||
// message being marked for offline use.
|
||||
// Luckily, compaction compacts the offline store first, so it should
|
||||
// lock the offline store.
|
||||
IMAPPump.inbox.msgDatabase.MarkOffline(msgHdr.messageKey, false, null);
|
||||
let msgURI = msgHdr.folder.getUriForMsg(msgHdr);
|
||||
let messenger = Cc["@mozilla.org/messenger;1"].createInstance(
|
||||
Ci.nsIMessenger
|
||||
);
|
||||
let msgServ = messenger.messageServiceFromURI(msgURI);
|
||||
// UrlListener will get called when both expunge and offline store
|
||||
// compaction are finished. dummyMsgWindow is required to make the backend
|
||||
// compact the offline store.
|
||||
IMAPPump.inbox.compact(asyncUrlListener, gDummyMsgWindow);
|
||||
// Stream the message w/o a stream listener in an attempt to get the url
|
||||
// started more quickly, while the compact is still going on.
|
||||
msgServ.streamMessage(
|
||||
msgURI,
|
||||
null,
|
||||
null,
|
||||
asyncUrlListener,
|
||||
false,
|
||||
"",
|
||||
false
|
||||
);
|
||||
yield false;
|
||||
|
||||
// Because we're streaming the message while compaction is going on,
|
||||
// we should not have stored it for offline use.
|
||||
Assert.equal(false, gStreamedHdr.flags & Ci.nsMsgMessageFlags.Offline);
|
||||
|
||||
yield false;
|
||||
},
|
||||
function* deleteAnOtherMsg() {
|
||||
let enumerator = IMAPPump.inbox.msgDatabase.EnumerateMessages();
|
||||
let msgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
|
||||
IMAPPump.inbox.deleteMessages(
|
||||
[msgHdr],
|
||||
null,
|
||||
false,
|
||||
true,
|
||||
CopyListener,
|
||||
false
|
||||
);
|
||||
yield false;
|
||||
},
|
||||
function* updateTrash() {
|
||||
gIMAPTrashFolder = IMAPPump.incomingServer.rootFolder
|
||||
.getChildNamed("Trash")
|
||||
.QueryInterface(Ci.nsIMsgImapMailFolder);
|
||||
// hack to force uid validity to get initialized for trash.
|
||||
gIMAPTrashFolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function* downloadTrashForOffline() {
|
||||
// ...and download for offline use.
|
||||
dump("Downloading for offline use\n");
|
||||
gIMAPTrashFolder.downloadAllForOffline(asyncUrlListener, null);
|
||||
yield false;
|
||||
},
|
||||
function testOfflineBodyCopy() {
|
||||
// In order to check that offline copy of messages doesn't try to copy
|
||||
// the body if the offline store is locked, we're going to go offline.
|
||||
// Thunderbird itself does move/copies pseudo-offline, but that's too
|
||||
// hard to test because of the half-second delay.
|
||||
IMAPPump.server.stop();
|
||||
Services.io.offline = true;
|
||||
let enumerator = gIMAPTrashFolder.msgDatabase.EnumerateMessages();
|
||||
let msgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
|
||||
gMovedMsgId = msgHdr.messageId;
|
||||
IMAPPump.inbox.compact(asyncUrlListener, gDummyMsgWindow);
|
||||
MailServices.copy.copyMessages(
|
||||
gIMAPTrashFolder,
|
||||
[msgHdr],
|
||||
IMAPPump.inbox,
|
||||
true,
|
||||
CopyListener,
|
||||
null,
|
||||
true
|
||||
);
|
||||
},
|
||||
function* verifyNoOfflineMsg() {
|
||||
try {
|
||||
let movedMsg = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(
|
||||
gMovedMsgId
|
||||
);
|
||||
Assert.equal(false, movedMsg.flags & Ci.nsMsgMessageFlags.Offline);
|
||||
} catch (ex) {
|
||||
dump(ex);
|
||||
}
|
||||
yield false;
|
||||
yield false;
|
||||
},
|
||||
teardown,
|
||||
];
|
||||
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
}
|
||||
|
||||
function setup() {
|
||||
add_task(async function setupTest() {
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.default.autosync_offline_stores",
|
||||
false
|
||||
|
@ -200,24 +80,146 @@ function setup() {
|
|||
}
|
||||
|
||||
addGeneratedMessagesToServer(messages, IMAPPump.daemon.getMailbox("INBOX"));
|
||||
}
|
||||
// ...and download for offline use.
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
// nsIMsgCopyServiceListener implementation - runs next test when copy
|
||||
// is completed.
|
||||
var CopyListener = {
|
||||
OnStartCopy() {},
|
||||
OnProgress(aProgress, aProgressMax) {},
|
||||
SetMessageKey(aKey) {},
|
||||
SetMessageId(aMessageId) {},
|
||||
OnStopCopy(aStatus) {
|
||||
// Check: message successfully copied.
|
||||
Assert.equal(aStatus, 0);
|
||||
async_driver();
|
||||
},
|
||||
};
|
||||
add_task(async function downloadForOffline() {
|
||||
// ...and download for offline use.
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.downloadAllForOffline(listener, null);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function teardown() {
|
||||
Assert.ok(gGotAlert);
|
||||
add_task(async function deleteOneMsg() {
|
||||
let enumerator = IMAPPump.inbox.msgDatabase.EnumerateMessages();
|
||||
let msgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener();
|
||||
IMAPPump.inbox.deleteMessages(
|
||||
[msgHdr],
|
||||
null,
|
||||
false,
|
||||
true,
|
||||
copyListener,
|
||||
false
|
||||
);
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
add_task(async function compactOneFolder() {
|
||||
let enumerator = IMAPPump.inbox.msgDatabase.EnumerateMessages();
|
||||
let msgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
|
||||
gStreamedHdr = msgHdr;
|
||||
// Mark the message as not being offline, and then we'll make sure that
|
||||
// streaming the message while we're compacting doesn't result in the
|
||||
// message being marked for offline use.
|
||||
// Luckily, compaction compacts the offline store first, so it should
|
||||
// lock the offline store.
|
||||
IMAPPump.inbox.msgDatabase.MarkOffline(msgHdr.messageKey, false, null);
|
||||
let msgURI = msgHdr.folder.getUriForMsg(msgHdr);
|
||||
let messenger = Cc["@mozilla.org/messenger;1"].createInstance(
|
||||
Ci.nsIMessenger
|
||||
);
|
||||
let msgServ = messenger.messageServiceFromURI(msgURI);
|
||||
// UrlListener will get called when both expunge and offline store
|
||||
// compaction are finished. dummyMsgWindow is required to make the backend
|
||||
// compact the offline store.
|
||||
let compactUrlListener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.compact(compactUrlListener, gDummyMsgWindow);
|
||||
// Stream the message w/o a stream listener in an attempt to get the url
|
||||
// started more quickly, while the compact is still going on.
|
||||
let urlListener = new PromiseTestUtils.PromiseUrlListener({});
|
||||
await PromiseTestUtils.promiseDelay(100); // But don't be too fast.
|
||||
msgServ.streamMessage(msgURI, null, null, urlListener, false, "", false);
|
||||
await compactUrlListener.promise;
|
||||
|
||||
// Because we're streaming the message while compaction is going on,
|
||||
// we should not have stored it for offline use.
|
||||
Assert.equal(false, gStreamedHdr.flags & Ci.nsMsgMessageFlags.Offline);
|
||||
|
||||
await urlListener.promise;
|
||||
});
|
||||
|
||||
add_task(async function deleteAnOtherMsg() {
|
||||
let enumerator = IMAPPump.inbox.msgDatabase.EnumerateMessages();
|
||||
let msgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener();
|
||||
IMAPPump.inbox.deleteMessages(
|
||||
[msgHdr],
|
||||
null,
|
||||
false,
|
||||
true,
|
||||
copyListener,
|
||||
false
|
||||
);
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
add_task(async function updateTrash() {
|
||||
gIMAPTrashFolder = IMAPPump.incomingServer.rootFolder
|
||||
.getChildNamed("Trash")
|
||||
.QueryInterface(Ci.nsIMsgImapMailFolder);
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
// hack to force uid validity to get initialized for trash.
|
||||
gIMAPTrashFolder.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(async function downloadTrashForOffline() {
|
||||
// ...and download for offline use.
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
gIMAPTrashFolder.downloadAllForOffline(listener, null);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
add_task(async function testOfflineBodyCopy() {
|
||||
// In order to check that offline copy of messages doesn't try to copy
|
||||
// the body if the offline store is locked, we're going to go offline.
|
||||
// Thunderbird itself does move/copies pseudo-offline, but that's too
|
||||
// hard to test because of the half-second delay.
|
||||
IMAPPump.server.stop();
|
||||
Services.io.offline = true;
|
||||
let enumerator = gIMAPTrashFolder.msgDatabase.EnumerateMessages();
|
||||
let msgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
|
||||
gMovedMsgId = msgHdr.messageId;
|
||||
let urlListener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.compact(urlListener, gDummyMsgWindow);
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener();
|
||||
MailServices.copy.copyMessages(
|
||||
gIMAPTrashFolder,
|
||||
[msgHdr],
|
||||
IMAPPump.inbox,
|
||||
true,
|
||||
copyListener,
|
||||
null,
|
||||
true
|
||||
);
|
||||
|
||||
// Verify that the moved Msg is not offline.
|
||||
try {
|
||||
let movedMsg = IMAPPump.inbox.msgDatabase.getMsgHdrForMessageID(
|
||||
gMovedMsgId
|
||||
);
|
||||
Assert.equal(0, movedMsg.flags & Ci.nsMsgMessageFlags.Offline);
|
||||
} catch (ex) {
|
||||
throw new Error(ex);
|
||||
}
|
||||
await urlListener.promise;
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
add_task(async function test_checkAlert() {
|
||||
let alertText = await gGotAlert;
|
||||
Assert.ok(
|
||||
alertText.startsWith(
|
||||
"The folder 'Inbox on Mail for ' cannot be compacted because another operation is in progress. Please try again later."
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
add_task(function teardown() {
|
||||
gMsgImapInboxFolder = null;
|
||||
gIMAPTrashFolder = null;
|
||||
|
||||
|
@ -230,10 +232,10 @@ function teardown() {
|
|||
);
|
||||
serverSink.abortQueuedUrls();
|
||||
} catch (ex) {
|
||||
dump(ex);
|
||||
throw new Error(ex);
|
||||
}
|
||||
let thread = gThreadManager.currentThread;
|
||||
while (thread.hasPendingEvents()) {
|
||||
thread.processNextEvent(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -6,36 +6,24 @@
|
|||
* Tests that you can stream a message without the attachments. Tests the
|
||||
* MsgHdrToMimeMessage API that exposes this.
|
||||
*/
|
||||
|
||||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
Services.prefs.setIntPref("mail.imap.mime_parts_on_demand_threshold", 1000);
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
var { MessageGenerator } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/MessageGenerator.jsm"
|
||||
);
|
||||
|
||||
// javascript mime emitter functions
|
||||
var mimeMsg = {};
|
||||
ChromeUtils.import("resource:///modules/gloda/MimeMessage.jsm", mimeMsg);
|
||||
|
||||
// IMAP pump
|
||||
|
||||
setupIMAPPump();
|
||||
|
||||
var tests = [
|
||||
setPrefs,
|
||||
loadImapMessage,
|
||||
startMime,
|
||||
testAllInlineMessage,
|
||||
updateCounts,
|
||||
testNotRead,
|
||||
endTest,
|
||||
];
|
||||
|
||||
// make sure we are in the optimal conditions!
|
||||
function* setPrefs() {
|
||||
add_task(function setupTest() {
|
||||
setupIMAPPump();
|
||||
Services.prefs.setIntPref("mail.imap.mime_parts_on_demand_threshold", 20);
|
||||
Services.prefs.setBoolPref("mail.imap.mime_parts_on_demand", true);
|
||||
Services.prefs.setBoolPref(
|
||||
|
@ -45,12 +33,10 @@ function* setPrefs() {
|
|||
Services.prefs.setBoolPref("mail.server.server1.offline_download", false);
|
||||
Services.prefs.setBoolPref("mail.server.server1.download_on_biff", false);
|
||||
Services.prefs.setIntPref("browser.cache.disk.capacity", 0);
|
||||
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
// load and update a message in the imap fake server
|
||||
function* loadImapMessage() {
|
||||
add_task(async function loadImapMessage() {
|
||||
let file = do_get_file("../../../data/bodystructuretest1");
|
||||
let msgURI = Services.io.newFileURI(file).QueryInterface(Ci.nsIFileURL);
|
||||
|
||||
|
@ -64,72 +50,70 @@ function* loadImapMessage() {
|
|||
msgURI = Services.io.newFileURI(file).QueryInterface(Ci.nsIFileURL);
|
||||
message = new imapMessage(msgURI.spec, imapInbox.uidnext++, []);
|
||||
IMAPPump.mailbox.addMessage(message);
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
|
||||
Assert.equal(2, IMAPPump.inbox.getTotalMessages(false));
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
Assert.ok(msgHdr instanceof Ci.nsIMsgDBHdr);
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
// process the message through mime
|
||||
function* startMime() {
|
||||
add_task(async function startMime() {
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
|
||||
mimeMsg.MsgHdrToMimeMessage(
|
||||
msgHdr,
|
||||
this,
|
||||
function(aMsgHdr, aMimeMessage) {
|
||||
let url = aMimeMessage.allUserAttachments[0].url;
|
||||
// A URL containing this string indicates that the attachment will be
|
||||
// downloaded on demand.
|
||||
Assert.ok(url.includes("/;section="));
|
||||
async_driver();
|
||||
},
|
||||
true /* allowDownload */,
|
||||
{ partsOnDemand: true, examineEncryptedParts: true }
|
||||
);
|
||||
yield false;
|
||||
}
|
||||
|
||||
// test that we don't mark all inline messages as read.
|
||||
function* testAllInlineMessage() {
|
||||
for (let msg of IMAPPump.inbox.msgDatabase.EnumerateMessages()) {
|
||||
await new Promise(resolve => {
|
||||
mimeMsg.MsgHdrToMimeMessage(
|
||||
msg,
|
||||
msgHdr,
|
||||
this,
|
||||
function(aMsgHdr, aMimeMessage) {
|
||||
async_driver();
|
||||
let url = aMimeMessage.allUserAttachments[0].url;
|
||||
// A URL containing this string indicates that the attachment will be
|
||||
// downloaded on demand.
|
||||
Assert.ok(url.includes("/;section="));
|
||||
resolve();
|
||||
},
|
||||
true /* allowDownload */,
|
||||
{ partsOnDemand: true }
|
||||
{ partsOnDemand: true, examineEncryptedParts: true }
|
||||
);
|
||||
yield false;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function* updateCounts() {
|
||||
// test that we don't mark all inline messages as read.
|
||||
add_task(async function testAllInlineMessage() {
|
||||
for (let msg of IMAPPump.inbox.msgDatabase.EnumerateMessages()) {
|
||||
await new Promise(resolve => {
|
||||
mimeMsg.MsgHdrToMimeMessage(
|
||||
msg,
|
||||
this,
|
||||
function(aMsgHdr, aMimeMessage) {
|
||||
resolve();
|
||||
},
|
||||
true, // allowDownload
|
||||
{ partsOnDemand: true }
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function updateCounts() {
|
||||
// select the trash, then the inbox again, to force an update of the
|
||||
// read state of messages.
|
||||
let trash = IMAPPump.incomingServer.rootFolder.getChildNamed("Trash");
|
||||
Assert.ok(trash instanceof Ci.nsIMsgImapMailFolder);
|
||||
trash.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
let trashListener = new PromiseTestUtils.PromiseUrlListener();
|
||||
trash.updateFolderWithListener(null, trashListener);
|
||||
await trashListener.promise;
|
||||
let inboxListener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, inboxListener);
|
||||
await inboxListener.promise;
|
||||
});
|
||||
|
||||
function* testNotRead() {
|
||||
add_task(function testNotRead() {
|
||||
Assert.equal(2, IMAPPump.inbox.getNumUnread(false));
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
// Cleanup
|
||||
function endTest() {
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -5,121 +5,78 @@
|
|||
// This tests that arbitrary message header properties are preserved
|
||||
// during online move of an imap message.
|
||||
|
||||
// async support
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
|
||||
// IMAP pump
|
||||
|
||||
// Globals
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
var { MailServices } = ChromeUtils.import(
|
||||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
|
||||
var gMessage = "bugmail10"; // message file used as the test message
|
||||
|
||||
setupIMAPPump();
|
||||
|
||||
// Definition of tests
|
||||
var tests = [
|
||||
createSubfolder,
|
||||
loadImapMessage,
|
||||
moveMessageToSubfolder,
|
||||
testPropertyOnMove,
|
||||
endTest,
|
||||
];
|
||||
|
||||
var gSubfolder;
|
||||
function* createSubfolder() {
|
||||
|
||||
add_task(function setupTest() {
|
||||
setupIMAPPump();
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.default.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function createSubfolder() {
|
||||
IMAPPump.incomingServer.rootFolder.createSubfolder("Subfolder", null);
|
||||
dl("wait for folderAdded notification");
|
||||
yield false;
|
||||
await PromiseTestUtils.promiseFolderAdded("Subfolder");
|
||||
gSubfolder = IMAPPump.incomingServer.rootFolder.getChildNamed("Subfolder");
|
||||
Assert.ok(gSubfolder instanceof Ci.nsIMsgImapMailFolder);
|
||||
gSubfolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
dl("wait for OnStopRunningURL");
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
gSubfolder.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
// load and update a message in the imap fake server
|
||||
function* loadImapMessage() {
|
||||
add_task(async function loadImapMessage() {
|
||||
IMAPPump.mailbox.addMessage(
|
||||
new imapMessage(specForFileName(gMessage), IMAPPump.mailbox.uidnext++, [])
|
||||
);
|
||||
IMAPPump.inbox.updateFolder(null);
|
||||
dl("wait for msgAdded notification");
|
||||
yield false;
|
||||
await PromiseTestUtils.promiseFolderNotification(IMAPPump.inbox, "msgAdded");
|
||||
Assert.equal(1, IMAPPump.inbox.getTotalMessages(false));
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
Assert.ok(msgHdr instanceof Ci.nsIMsgDBHdr);
|
||||
|
||||
// set an arbitrary property
|
||||
msgHdr.setStringProperty("testprop", "somevalue");
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
// move the message to a subfolder
|
||||
function* moveMessageToSubfolder() {
|
||||
add_task(async function moveMessageToSubfolder() {
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener();
|
||||
MailServices.copy.copyMessages(
|
||||
IMAPPump.inbox, // srcFolder
|
||||
[msgHdr], // messages
|
||||
gSubfolder, // dstFolder
|
||||
true, // isMove
|
||||
asyncCopyListener, // listener
|
||||
copyListener, // listener
|
||||
null, // msgWindow
|
||||
false // allowUndo
|
||||
);
|
||||
dl("wait for OnStopCopy");
|
||||
yield false;
|
||||
}
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
function* testPropertyOnMove() {
|
||||
gSubfolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
dl("wait for msgAdded");
|
||||
yield false; // wait for msgAdded notification
|
||||
dl("wait for OnStopRunningURL");
|
||||
yield false; // wait for OnStopRunningUrl
|
||||
add_task(async function testPropertyOnMove() {
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
gSubfolder.updateFolderWithListener(null, listener);
|
||||
await PromiseTestUtils.promiseFolderNotification(gSubfolder, "msgAdded");
|
||||
await listener.promise;
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(gSubfolder);
|
||||
Assert.equal(msgHdr.getStringProperty("testprop"), "somevalue");
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
// Cleanup
|
||||
function endTest() {
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
// listeners
|
||||
|
||||
var mfnListener = {
|
||||
folderAdded(aFolder) {
|
||||
dl("folderAdded <" + aFolder.name + ">");
|
||||
// we are only using async yield on the Subfolder add
|
||||
if (aFolder.name == "Subfolder") {
|
||||
async_driver();
|
||||
}
|
||||
},
|
||||
|
||||
msgAdded(aMsg) {
|
||||
dl("msgAdded with subject <" + aMsg.subject + ">");
|
||||
async_driver();
|
||||
},
|
||||
};
|
||||
|
||||
function run_test() {
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.default.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
// Add folder listeners that will capture async events
|
||||
const nsIMFNService = Ci.nsIMsgFolderNotificationService;
|
||||
let flags = nsIMFNService.folderAdded | nsIMFNService.msgAdded;
|
||||
MailServices.mfn.addListener(mfnListener, flags);
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* helper functions
|
||||
|
@ -131,8 +88,3 @@ function specForFileName(aFileName) {
|
|||
let msgfileuri = Services.io.newFileURI(file).QueryInterface(Ci.nsIFileURL);
|
||||
return msgfileuri.spec;
|
||||
}
|
||||
|
||||
// shorthand output of a line of text
|
||||
function dl(text) {
|
||||
dump(text + "\n");
|
||||
}
|
||||
|
|
|
@ -7,57 +7,55 @@
|
|||
* marked as unread.
|
||||
*/
|
||||
|
||||
// async support
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
|
||||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
var { MailServices } = ChromeUtils.import(
|
||||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
|
||||
// IMAP pump
|
||||
|
||||
setupIMAPPump();
|
||||
|
||||
// Definition of tests
|
||||
|
||||
var tests = [createDraftsFolder, saveDraft, updateDrafts, checkResult, endTest];
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
var gDraftsFolder;
|
||||
function* createDraftsFolder() {
|
||||
|
||||
add_task(function setupTest() {
|
||||
setupIMAPPump();
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.default.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function createDraftsFolder() {
|
||||
IMAPPump.incomingServer.rootFolder.createSubfolder("Drafts", null);
|
||||
dl("wait for folderAdded");
|
||||
yield false;
|
||||
await PromiseTestUtils.promiseFolderAdded("Drafts");
|
||||
gDraftsFolder = IMAPPump.incomingServer.rootFolder.getChildNamed("Drafts");
|
||||
Assert.ok(gDraftsFolder instanceof Ci.nsIMsgImapMailFolder);
|
||||
gDraftsFolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
dl("wait for OnStopRunningURL");
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
gDraftsFolder.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function* saveDraft() {
|
||||
var msgCompose = Cc["@mozilla.org/messengercompose/compose;1"].createInstance(
|
||||
add_task(async function saveDraft() {
|
||||
let msgCompose = Cc["@mozilla.org/messengercompose/compose;1"].createInstance(
|
||||
Ci.nsIMsgCompose
|
||||
);
|
||||
var fields = Cc[
|
||||
let fields = Cc[
|
||||
"@mozilla.org/messengercompose/composefields;1"
|
||||
].createInstance(Ci.nsIMsgCompFields);
|
||||
var params = Cc[
|
||||
let params = Cc[
|
||||
"@mozilla.org/messengercompose/composeparams;1"
|
||||
].createInstance(Ci.nsIMsgComposeParams);
|
||||
params.composeFields = fields;
|
||||
msgCompose.initialize(params);
|
||||
|
||||
// Set up the identity
|
||||
var identity = MailServices.accounts.createIdentity();
|
||||
let identity = MailServices.accounts.createIdentity();
|
||||
identity.draftFolder = gDraftsFolder.URI;
|
||||
|
||||
var progress = Cc["@mozilla.org/messenger/progress;1"].createInstance(
|
||||
let progress = Cc["@mozilla.org/messenger/progress;1"].createInstance(
|
||||
Ci.nsIMsgProgress
|
||||
);
|
||||
let progressListener = new ProgressListener();
|
||||
progress.registerListener(progressListener);
|
||||
msgCompose.sendMsg(
|
||||
Ci.nsIMsgSend.nsMsgSaveAsDraft,
|
||||
|
@ -66,69 +64,34 @@ function* saveDraft() {
|
|||
null,
|
||||
progress
|
||||
);
|
||||
yield false;
|
||||
}
|
||||
await progressListener.promise;
|
||||
});
|
||||
|
||||
function* updateDrafts() {
|
||||
dump("updating drafts\n");
|
||||
gDraftsFolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
add_task(async function updateDrafts() {
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
gDraftsFolder.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function* checkResult() {
|
||||
dump("checking result\n");
|
||||
add_task(function checkResult() {
|
||||
Assert.equal(gDraftsFolder.getTotalMessages(false), 1);
|
||||
Assert.equal(gDraftsFolder.getNumUnread(false), 1);
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
function* endTest() {
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
yield true;
|
||||
});
|
||||
|
||||
function ProgressListener() {
|
||||
this._promise = new Promise(resolve => {
|
||||
this._resolve = resolve;
|
||||
});
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.default.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
|
||||
// Add folder listeners that will capture async events
|
||||
const nsIMFNService = Ci.nsIMsgFolderNotificationService;
|
||||
|
||||
let flags =
|
||||
nsIMFNService.msgsMoveCopyCompleted |
|
||||
nsIMFNService.folderAdded |
|
||||
nsIMFNService.msgAdded;
|
||||
MailServices.mfn.addListener(mfnListener, flags);
|
||||
|
||||
// start first test
|
||||
async_run_tests(tests);
|
||||
}
|
||||
|
||||
var mfnListener = {
|
||||
msgsMoveCopyCompleted(aMove, aSrcMsgs, aDestFolder, aDestMsgs) {
|
||||
dl("msgsMoveCopyCompleted to folder " + aDestFolder.name);
|
||||
},
|
||||
|
||||
folderAdded(aFolder) {
|
||||
dl("folderAdded <" + aFolder.name + ">");
|
||||
// we are only using async add on the Junk folder
|
||||
if (aFolder.name == "Drafts") {
|
||||
async_driver();
|
||||
}
|
||||
},
|
||||
|
||||
msgAdded(aMsg) {
|
||||
dl("msgAdded with subject <" + aMsg.subject + ">");
|
||||
},
|
||||
};
|
||||
|
||||
var progressListener = {
|
||||
ProgressListener.prototype = {
|
||||
onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
|
||||
if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) {
|
||||
dl("onStateChange");
|
||||
async_driver();
|
||||
this._resolve();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -149,13 +112,7 @@ var progressListener = {
|
|||
"nsIWebProgressListener",
|
||||
"nsISupportsWeakReference",
|
||||
]),
|
||||
get promise() {
|
||||
return this._promise;
|
||||
},
|
||||
};
|
||||
|
||||
/*
|
||||
* helper functions
|
||||
*/
|
||||
|
||||
// quick shorthand for output of a line of text.
|
||||
function dl(text) {
|
||||
dump(text + "\n");
|
||||
}
|
||||
|
|
|
@ -12,22 +12,23 @@ var { MailServices } = ChromeUtils.import(
|
|||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
var { MailUtils } = ChromeUtils.import("resource:///modules/MailUtils.jsm");
|
||||
var { MessageGenerator } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/MessageGenerator.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
|
||||
// IMAP pump
|
||||
|
||||
setupIMAPPump();
|
||||
|
||||
var tests = [loadImapMessage, saveAsTemplate, endTest];
|
||||
add_task(function setupTest() {
|
||||
setupIMAPPump();
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.default.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
// load and update a message in the imap fake server
|
||||
function* loadImapMessage() {
|
||||
add_task(async function loadImapMessage() {
|
||||
let gMessageGenerator = new MessageGenerator();
|
||||
// create a synthetic message with attachment
|
||||
let smsg = gMessageGenerator.makeMessage();
|
||||
|
@ -38,36 +39,18 @@ function* loadImapMessage() {
|
|||
let imapInbox = IMAPPump.daemon.getMailbox("INBOX");
|
||||
let message = new imapMessage(msgURI.spec, imapInbox.uidnext++, []);
|
||||
IMAPPump.mailbox.addMessage(message);
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
MailServices.mfn.addListener(mfnListener, MailServices.mfn.msgAdded);
|
||||
yield true;
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
function* endTest() {
|
||||
teardownIMAPPump();
|
||||
yield true;
|
||||
}
|
||||
|
||||
function saveAsUrlListener(aUri, aIdentity) {
|
||||
this.uri = aUri;
|
||||
this.identity = aIdentity;
|
||||
}
|
||||
|
||||
saveAsUrlListener.prototype = {
|
||||
OnStartRunningUrl(aUrl) {},
|
||||
OnStopRunningUrl(aUrl, aExitCode) {
|
||||
let messenger = Cc["@mozilla.org/messenger;1"].createInstance(
|
||||
Ci.nsIMessenger
|
||||
);
|
||||
messenger.saveAs(this.uri, false, this.identity, null);
|
||||
},
|
||||
};
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
// This is similar to the method in mailCommands.js, to test the way that
|
||||
// it creates a new templates folder before saving the message as a template.
|
||||
function* saveAsTemplate() {
|
||||
add_task(async function saveAsTemplate() {
|
||||
// Prepare msgAddedListener for this test.
|
||||
let msgAddedListener = new MsgAddedListener();
|
||||
MailServices.mfn.addListener(msgAddedListener, MailServices.mfn.msgAdded);
|
||||
|
||||
let hdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
let uri = IMAPPump.inbox.getUriForMsg(hdr);
|
||||
let identity = MailServices.accounts.getFirstIdentityForServer(
|
||||
|
@ -79,23 +62,36 @@ function* saveAsTemplate() {
|
|||
// Verify that Templates folder doesn't exist, and then create it.
|
||||
Assert.equal(templates.parent, null);
|
||||
templates.setFlag(Ci.nsMsgFolderFlags.Templates);
|
||||
templates.createStorageIfMissing(new saveAsUrlListener(uri, identity));
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener({
|
||||
OnStopRunningUrl() {
|
||||
let messenger = Cc["@mozilla.org/messenger;1"].createInstance(
|
||||
Ci.nsIMessenger
|
||||
);
|
||||
messenger.saveAs(uri, false, identity, null);
|
||||
},
|
||||
});
|
||||
templates.createStorageIfMissing(listener);
|
||||
await listener.promise;
|
||||
|
||||
await msgAddedListener.promise;
|
||||
});
|
||||
|
||||
// Cleanup
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
});
|
||||
|
||||
// listener for saveAsTemplate adding a message to the templates folder.
|
||||
var mfnListener = {
|
||||
function MsgAddedListener() {
|
||||
this._promise = new Promise(resolve => {
|
||||
this._resolve = resolve;
|
||||
});
|
||||
}
|
||||
|
||||
MsgAddedListener.prototype = {
|
||||
msgAdded(aMsg) {
|
||||
// Check this is the templates folder.
|
||||
Assert.equal(aMsg.folder.prettyName, "Templates");
|
||||
async_driver();
|
||||
this._resolve();
|
||||
},
|
||||
};
|
||||
|
||||
function run_test() {
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.default.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
async_run_tests(tests);
|
||||
}
|
||||
|
|
|
@ -1,42 +1,45 @@
|
|||
/* 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/. */
|
||||
|
||||
/**
|
||||
* This test checks that we handle the server dropping the connection
|
||||
* on starttls. Since fakeserver doesn't support STARTTLS, I've made
|
||||
* it drop the connection when it's attempted.
|
||||
*/
|
||||
|
||||
/* import-globals-from ../../../test/resources/alertTestUtils.js */
|
||||
load("../../../resources/alertTestUtils.js");
|
||||
|
||||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
var { MailServices } = ChromeUtils.import(
|
||||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/alertTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/alertTestUtils.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
var gAlertResolve;
|
||||
var gGotAlert = new Promise(resolve => {
|
||||
gAlertResolve = resolve;
|
||||
});
|
||||
|
||||
var gGotAlert = false;
|
||||
|
||||
/* exported alert */
|
||||
// to asyncTestUtils.js
|
||||
/* exported alert to alertTestUtils.js */
|
||||
function alert(aDialogTitle, aText) {
|
||||
Assert.ok(aText.startsWith("Server localhost has disconnected"));
|
||||
gGotAlert = true;
|
||||
gAlertResolve(aText);
|
||||
}
|
||||
|
||||
var tests = [setup, check_alert, teardown];
|
||||
|
||||
function* setup() {
|
||||
// set up IMAP fakeserver and incoming server
|
||||
add_task(async function setupTest() {
|
||||
// Set up IMAP fakeserver and incoming server.
|
||||
IMAPPump.daemon = new imapDaemon();
|
||||
IMAPPump.server = makeServer(IMAPPump.daemon, "", { dropOnStartTLS: true });
|
||||
IMAPPump.incomingServer = createLocalIMAPServer(IMAPPump.server.port);
|
||||
IMAPPump.incomingServer.socketType = Ci.nsMsgSocketType.alwaysSTARTTLS;
|
||||
|
||||
// we need a local account for the IMAP server to have its sent messages in
|
||||
// We need a local account for the IMAP server to have its sent messages in.
|
||||
localAccountUtils.loadLocalMailAccount();
|
||||
|
||||
// We need an identity so that updateFolder doesn't fail
|
||||
// We need an identity so that updateFolder doesn't fail.
|
||||
let imapAccount = MailServices.accounts.createAccount();
|
||||
let identity = MailServices.accounts.createIdentity();
|
||||
imapAccount.addIdentity(identity);
|
||||
|
@ -44,9 +47,9 @@ function* setup() {
|
|||
imapAccount.incomingServer = IMAPPump.incomingServer;
|
||||
MailServices.accounts.defaultAccount = imapAccount;
|
||||
|
||||
// The server doesn't support more than one connection
|
||||
// The server doesn't support more than one connection.
|
||||
Services.prefs.setIntPref("mail.server.server1.max_cached_connections", 1);
|
||||
// We aren't interested in downloading messages automatically
|
||||
// We aren't interested in downloading messages automatically.
|
||||
Services.prefs.setBoolPref("mail.server.server1.download_on_biff", false);
|
||||
|
||||
IMAPPump.inbox = IMAPPump.incomingServer.rootFolder
|
||||
|
@ -55,28 +58,23 @@ function* setup() {
|
|||
|
||||
registerAlertTestUtils();
|
||||
|
||||
IMAPPump.inbox.updateFolderWithListener(gDummyMsgWindow, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(gDummyMsgWindow, listener);
|
||||
await listener.promise
|
||||
.then(res => {
|
||||
throw new Error("updateFolderWithListener has to fail");
|
||||
})
|
||||
.catch(exitCode => {
|
||||
Assert.ok(!Components.isSuccessCode(exitCode));
|
||||
});
|
||||
});
|
||||
|
||||
asyncUrlListener.callback = function(aUrl, aExitCode) {
|
||||
Assert.ok(!Components.isSuccessCode(aExitCode));
|
||||
};
|
||||
add_task(async function check_alert() {
|
||||
let alertText = await gGotAlert;
|
||||
Assert.ok(alertText.startsWith("Server localhost has disconnected"));
|
||||
});
|
||||
|
||||
function check_alert() {
|
||||
Assert.ok(gGotAlert);
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
add_task(function teardown() {
|
||||
IMAPPump.incomingServer.closeCachedConnections();
|
||||
IMAPPump.server.stop();
|
||||
|
||||
var thread = gThreadManager.currentThread;
|
||||
while (thread.hasPendingEvents()) {
|
||||
thread.processNextEvent(true);
|
||||
}
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -10,14 +10,12 @@ var { MailServices } = ChromeUtils.import(
|
|||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
|
||||
setupIMAPPump();
|
||||
var { MessageGenerator } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/MessageGenerator.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
function stop_server() {
|
||||
IMAPPump.incomingServer.closeCachedConnections();
|
||||
|
@ -28,27 +26,15 @@ function stop_server() {
|
|||
}
|
||||
}
|
||||
|
||||
var asyncCopyListener = {
|
||||
OnStartCopy() {},
|
||||
SetMessageKey(aMsgKey) {},
|
||||
GetMessageId() {},
|
||||
OnProgress(aProgress, aProgressMax) {
|
||||
stop_server();
|
||||
},
|
||||
OnStopCopy(aStatus) {
|
||||
Assert.equal(aStatus, 0);
|
||||
async_driver();
|
||||
},
|
||||
};
|
||||
|
||||
var tests = [setup_messages, move_messages, check_messages];
|
||||
|
||||
function* setup_messages() {
|
||||
add_task(function setupTest() {
|
||||
setupIMAPPump();
|
||||
Services.prefs.setBoolPref(
|
||||
"mail.server.default.autosync_offline_stores",
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function setup_messages() {
|
||||
let messageGenerator = new MessageGenerator();
|
||||
let messageString = messageGenerator.makeMessage().toMessageString();
|
||||
let dataUri = Services.io.newURI(
|
||||
|
@ -57,52 +43,54 @@ function* setup_messages() {
|
|||
let imapMsg = new imapMessage(dataUri.spec, IMAPPump.mailbox.uidnext++, []);
|
||||
IMAPPump.mailbox.addMessage(imapMsg);
|
||||
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function* move_messages() {
|
||||
add_task(async function move_messages() {
|
||||
let msg = IMAPPump.inbox.msgDatabase.GetMsgHdrForKey(
|
||||
IMAPPump.mailbox.uidnext - 1
|
||||
);
|
||||
let copyListener = new PromiseTestUtils.PromiseCopyListener({
|
||||
OnProgress(aProgress, aProgressMax) {
|
||||
stop_server();
|
||||
},
|
||||
});
|
||||
MailServices.copy.copyMessages(
|
||||
IMAPPump.inbox,
|
||||
[msg],
|
||||
localAccountUtils.inboxFolder,
|
||||
true,
|
||||
asyncCopyListener,
|
||||
copyListener,
|
||||
null,
|
||||
false
|
||||
);
|
||||
yield false;
|
||||
}
|
||||
await copyListener.promise;
|
||||
});
|
||||
|
||||
function* check_messages() {
|
||||
add_task(function check_messages() {
|
||||
Assert.equal(IMAPPump.inbox.getTotalMessages(false), 1);
|
||||
Assert.equal(localAccountUtils.inboxFolder.getTotalMessages(false), 0);
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
registerCleanupFunction(function() {
|
||||
// IMAPPump.server.performTest() brings this test to a halt,
|
||||
// so we need teardownIMAPPump() without IMAPPump.server.performTest().
|
||||
IMAPPump.inbox = null;
|
||||
IMAPPump.server.resetTest();
|
||||
try {
|
||||
IMAPPump.incomingServer.closeCachedConnections();
|
||||
let serverSink = IMAPPump.incomingServer.QueryInterface(
|
||||
Ci.nsIImapServerSink
|
||||
);
|
||||
serverSink.abortQueuedUrls();
|
||||
} catch (ex) {
|
||||
dump(ex);
|
||||
}
|
||||
IMAPPump.server.stop();
|
||||
let thread = gThreadManager.currentThread;
|
||||
while (thread.hasPendingEvents()) {
|
||||
thread.processNextEvent(true);
|
||||
}
|
||||
});
|
||||
async_run_tests(tests);
|
||||
}
|
||||
add_task(function endTest() {
|
||||
// IMAPPump.server.performTest() brings this test to a halt,
|
||||
// so we need teardownIMAPPump() without IMAPPump.server.performTest().
|
||||
IMAPPump.inbox = null;
|
||||
IMAPPump.server.resetTest();
|
||||
try {
|
||||
IMAPPump.incomingServer.closeCachedConnections();
|
||||
let serverSink = IMAPPump.incomingServer.QueryInterface(
|
||||
Ci.nsIImapServerSink
|
||||
);
|
||||
serverSink.abortQueuedUrls();
|
||||
} catch (ex) {
|
||||
dump(ex);
|
||||
}
|
||||
IMAPPump.server.stop();
|
||||
let thread = gThreadManager.currentThread;
|
||||
while (thread.hasPendingEvents()) {
|
||||
thread.processNextEvent(true);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,52 +1,25 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
load("../../../resources/MessageGenerator.jsm");
|
||||
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;
|
||||
|
||||
var tests = [
|
||||
setup,
|
||||
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.
|
||||
gSecondFolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function* simulateMailboxEmptied() {
|
||||
gMessage.setFlag("\\Deleted");
|
||||
IMAPPump.inbox.expunge(asyncUrlListener, null);
|
||||
yield false;
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
},
|
||||
function checkMailboxEmpty() {
|
||||
Assert.equal(IMAPPump.inbox.getTotalMessages(false), 0);
|
||||
},
|
||||
teardown,
|
||||
];
|
||||
|
||||
function* setup() {
|
||||
add_task(async function setupTest() {
|
||||
/*
|
||||
* Set up an IMAP server.
|
||||
*/
|
||||
|
@ -66,18 +39,42 @@ function* setup() {
|
|||
IMAPPump.mailbox.addMessage(gMessage);
|
||||
|
||||
// update folder to download header.
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
asyncUrlListener.callback = function(aUrl, aExitCode) {
|
||||
Assert.equal(aExitCode, 0);
|
||||
};
|
||||
add_task(async function switchAwayFromInbox() {
|
||||
let rootFolder = IMAPPump.incomingServer.rootFolder;
|
||||
gSecondFolder = rootFolder
|
||||
.getChildNamed("secondFolder")
|
||||
.QueryInterface(Ci.nsIMsgImapMailFolder);
|
||||
|
||||
function teardown() {
|
||||
// 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();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
async_run_tests(tests);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -11,13 +11,9 @@
|
|||
* adapted from test_filterNeedsBody.js
|
||||
*/
|
||||
|
||||
// async support
|
||||
/* import-globals-from ../../../test/resources/logHelper.js */
|
||||
/* import-globals-from ../../../test/resources/asyncTestUtils.js */
|
||||
load("../../../resources/logHelper.js");
|
||||
load("../../../resources/asyncTestUtils.js");
|
||||
|
||||
// IMAP pump
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
// Globals
|
||||
var { MailServices } = ChromeUtils.import(
|
||||
|
@ -25,37 +21,43 @@ var { MailServices } = ChromeUtils.import(
|
|||
);
|
||||
|
||||
var gMessage = "SpamAssassinYes"; // message file used as the test message
|
||||
|
||||
setupIMAPPump();
|
||||
|
||||
// Definition of tests
|
||||
|
||||
var tests = [
|
||||
createJunkFolder,
|
||||
loadImapMessage,
|
||||
testMessageInJunk,
|
||||
markMessageAsGood,
|
||||
updateFoldersAndCheck,
|
||||
endTest,
|
||||
];
|
||||
|
||||
var gJunkFolder;
|
||||
function* createJunkFolder() {
|
||||
|
||||
add_task(function setupTest() {
|
||||
setupIMAPPump();
|
||||
let server = IMAPPump.incomingServer;
|
||||
let spamSettings = server.spamSettings;
|
||||
server.setBoolValue("useServerFilter", true);
|
||||
server.setCharValue("serverFilterName", "SpamAssassin");
|
||||
server.setIntValue(
|
||||
"serverFilterTrustFlags",
|
||||
Ci.nsISpamSettings.TRUST_POSITIVES
|
||||
);
|
||||
server.setBoolValue("moveOnSpam", true);
|
||||
server.setIntValue(
|
||||
"moveTargetMode",
|
||||
Ci.nsISpamSettings.MOVE_TARGET_MODE_ACCOUNT
|
||||
);
|
||||
server.setCharValue("spamActionTargetAccount", server.serverURI);
|
||||
|
||||
spamSettings.initialize(server);
|
||||
});
|
||||
|
||||
add_task(async function createJunkFolder() {
|
||||
IMAPPump.incomingServer.rootFolder.createSubfolder("Junk", null);
|
||||
dl("wait for folderAdded");
|
||||
yield false;
|
||||
await PromiseTestUtils.promiseFolderAdded("Junk");
|
||||
gJunkFolder = IMAPPump.incomingServer.rootFolder.getChildNamed("Junk");
|
||||
Assert.ok(gJunkFolder instanceof Ci.nsIMsgImapMailFolder);
|
||||
gJunkFolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
dl("wait for OnStopRunningURL");
|
||||
yield false;
|
||||
}
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
gJunkFolder.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
/*
|
||||
* Load and update a message in the imap fake server, should move
|
||||
* SpamAssassin-marked junk message to junk folder
|
||||
*/
|
||||
function* loadImapMessage() {
|
||||
add_task(async function loadImapMessage() {
|
||||
IMAPPump.mailbox.addMessage(
|
||||
new imapMessage(specForFileName(gMessage), IMAPPump.mailbox.uidnext++, [])
|
||||
);
|
||||
|
@ -64,20 +66,21 @@ function* loadImapMessage() {
|
|||
* to the junk folder
|
||||
*/
|
||||
IMAPPump.inbox.updateFolder(null);
|
||||
dl("wait for msgsMoveCopyCompleted");
|
||||
yield false;
|
||||
gJunkFolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
dl("wait for OnStopRunningURL");
|
||||
yield false;
|
||||
}
|
||||
await PromiseTestUtils.promiseFolderNotification(
|
||||
gJunkFolder,
|
||||
"msgsMoveCopyCompleted"
|
||||
);
|
||||
let listener = new PromiseTestUtils.PromiseUrlListener();
|
||||
gJunkFolder.updateFolderWithListener(null, listener);
|
||||
await listener.promise;
|
||||
});
|
||||
|
||||
function* testMessageInJunk() {
|
||||
add_task(function testMessageInJunk() {
|
||||
Assert.equal(0, IMAPPump.inbox.getTotalMessages(false));
|
||||
Assert.equal(1, gJunkFolder.getTotalMessages(false));
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
function* markMessageAsGood() {
|
||||
add_task(async function markMessageAsGood() {
|
||||
/*
|
||||
* This is done in the application in nsMsgDBView, which is difficult
|
||||
* to test in xpcshell tests. We aren't really trying to test that here
|
||||
|
@ -104,76 +107,27 @@ function* markMessageAsGood() {
|
|||
null, // msgWindow
|
||||
false // allowUndo
|
||||
);
|
||||
dl("wait for msgsMoveCopyCompleted");
|
||||
yield false;
|
||||
}
|
||||
await PromiseTestUtils.promiseFolderNotification(
|
||||
IMAPPump.inbox,
|
||||
"msgsMoveCopyCompleted"
|
||||
);
|
||||
});
|
||||
|
||||
function* updateFoldersAndCheck() {
|
||||
IMAPPump.inbox.updateFolderWithListener(null, asyncUrlListener);
|
||||
dl("wait for OnStopRunningURL");
|
||||
yield false;
|
||||
gJunkFolder.updateFolderWithListener(null, asyncUrlListener);
|
||||
dl("wait for OnStopRunningURL");
|
||||
yield false;
|
||||
add_task(async function updateFoldersAndCheck() {
|
||||
let inboxUrlListener = new PromiseTestUtils.PromiseUrlListener();
|
||||
IMAPPump.inbox.updateFolderWithListener(null, inboxUrlListener);
|
||||
await inboxUrlListener.promise;
|
||||
let junkUrlListener = new PromiseTestUtils.PromiseUrlListener();
|
||||
gJunkFolder.updateFolderWithListener(null, junkUrlListener);
|
||||
await junkUrlListener.promise;
|
||||
// bug 540385 causes this test to fail
|
||||
Assert.equal(1, IMAPPump.inbox.getTotalMessages(false));
|
||||
Assert.equal(0, gJunkFolder.getTotalMessages(false));
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
||||
function endTest() {
|
||||
add_task(function endTest() {
|
||||
teardownIMAPPump();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
let server = IMAPPump.incomingServer;
|
||||
let spamSettings = server.spamSettings;
|
||||
server.setBoolValue("useServerFilter", true);
|
||||
server.setCharValue("serverFilterName", "SpamAssassin");
|
||||
server.setIntValue(
|
||||
"serverFilterTrustFlags",
|
||||
Ci.nsISpamSettings.TRUST_POSITIVES
|
||||
);
|
||||
server.setBoolValue("moveOnSpam", true);
|
||||
server.setIntValue(
|
||||
"moveTargetMode",
|
||||
Ci.nsISpamSettings.MOVE_TARGET_MODE_ACCOUNT
|
||||
);
|
||||
server.setCharValue("spamActionTargetAccount", server.serverURI);
|
||||
|
||||
spamSettings.initialize(server);
|
||||
|
||||
// Add folder listeners that will capture async events
|
||||
const nsIMFNService = Ci.nsIMsgFolderNotificationService;
|
||||
|
||||
let flags =
|
||||
nsIMFNService.msgsMoveCopyCompleted |
|
||||
nsIMFNService.folderAdded |
|
||||
nsIMFNService.msgAdded;
|
||||
MailServices.mfn.addListener(mfnListener, flags);
|
||||
|
||||
// start first test
|
||||
async_run_tests(tests);
|
||||
}
|
||||
|
||||
var mfnListener = {
|
||||
msgsMoveCopyCompleted(aMove, aSrcMsgs, aDestFolder, aDestMsgs) {
|
||||
dl("msgsMoveCopyCompleted to folder " + aDestFolder.name);
|
||||
async_driver();
|
||||
},
|
||||
|
||||
folderAdded(aFolder) {
|
||||
dl("folderAdded <" + aFolder.name + ">");
|
||||
// we are only using async add on the Junk folder
|
||||
if (aFolder.name == "Junk") {
|
||||
async_driver();
|
||||
}
|
||||
},
|
||||
|
||||
msgAdded(aMsg) {
|
||||
dl("msgAdded with subject <" + aMsg.subject + ">");
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
/*
|
||||
* helper functions
|
||||
|
|
|
@ -3,59 +3,88 @@ head = head_server.js
|
|||
tail =
|
||||
|
||||
[test_autosync_date_constraints.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_bccProperty.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_bug460636.js]
|
||||
[test_chunkLastLF.js]
|
||||
[test_compactOfflineStore.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_converterImap.js]
|
||||
[test_copyThenMove.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_customCommandReturnsFetchResponse.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_dod.js]
|
||||
[test_dontStatNoSelect.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_downloadOffline.js]
|
||||
[test_fetchCustomAttribute.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_filterCustomHeaders.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_filterNeedsBody.js]
|
||||
[test_folderOfflineFlags.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_gmailAttributes.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_gmailOfflineMsgStore.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_imapAttachmentSaves.js]
|
||||
[test_imapAuthMethods.js]
|
||||
# Disabled per bug 553764
|
||||
skip-if = true
|
||||
[test_imapAutoSync.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_imapChunks.js]
|
||||
[test_imapClientid.js]
|
||||
[test_imapContentLength.js]
|
||||
[test_imapCopyTimeout.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_imapFilterActions.js]
|
||||
run-sequentially = failed once when run in parallel
|
||||
[test_imapFilterActionsPostplugin.js]
|
||||
run-sequentially = test depends on delays for async completion
|
||||
[test_imapFlagChange.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_imapFolderCopy.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_imapHdrChunking.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_imapHdrStreaming.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_imapHighWater.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_imapID.js]
|
||||
[test_imapMove.js]
|
||||
[test_imapPasswordFailure.js]
|
||||
[test_imapProtocols.js]
|
||||
[test_imapProxy.js]
|
||||
[test_imapRename.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_imapSearch.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_imapStatusCloseDBs.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_imapStoreMsgOffline.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_imapUndo.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_imapUrls.js]
|
||||
[test_largeOfflineStore.js]
|
||||
skip-if = os == 'mac'
|
||||
[test_listClosesDB.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_listSubscribed.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_localToImapFilter.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_localToImapFilterQuarantine.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_lsub.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_mailboxes.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_nsIMsgFolderListenerIMAP.js]
|
||||
[test_offlineCopy.js]
|
||||
[test_offlineDraftDataloss.js]
|
||||
|
@ -63,17 +92,24 @@ run-sequentially = Starts server twice.
|
|||
[test_offlinePlayback.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_offlineStoreLocking.js]
|
||||
# Doesn't currently work on Windows or Mac, bug 782625
|
||||
skip-if = os == 'win' || os == 'mac'
|
||||
run-sequentially = Starts server twice.
|
||||
[test_partsOnDemand.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_preserveDataOnMove.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_saveImapDraft.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_saveTemplate.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_starttlsFailure.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_stopMovingToLocalFolder.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_subfolderLocation.js]
|
||||
[test_syncChanges.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_trustSpamAssassin.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_cacheParts.js]
|
||||
|
||||
[include:xpcshell_maildir.ini]
|
||||
|
|
|
@ -6,8 +6,6 @@ tail =
|
|||
[test_bccProperty.js]
|
||||
[test_bug460636.js]
|
||||
[test_compactOfflineStore.js]
|
||||
# Disabled until bug 870864 is resolved
|
||||
skip-if = true
|
||||
[test_copyThenMove.js]
|
||||
[test_customCommandReturnsFetchResponse.js]
|
||||
[test_dontStatNoSelect.js]
|
||||
|
@ -19,29 +17,18 @@ skip-if = true
|
|||
[test_gmailAttributes.js]
|
||||
[test_gmailOfflineMsgStore.js]
|
||||
[test_imapAttachmentSaves.js]
|
||||
# Disabled until bug 870864 is resolved
|
||||
skip-if = true
|
||||
[test_imapAutoSync.js]
|
||||
[test_imapCopyTimeout.js]
|
||||
# Disabled until bug 870864 is resolved
|
||||
skip-if = true
|
||||
[test_imapFilterActions.js]
|
||||
run-sequentially = failed once when run in parallel
|
||||
[test_imapFilterActionsPostplugin.js]
|
||||
[test_imapFlagChange.js]
|
||||
[test_imapFolderCopy.js]
|
||||
[test_imapHdrChunking.js]
|
||||
# Disabled until bug 870864 is resolved
|
||||
skip-if = true
|
||||
[test_imapHdrStreaming.js]
|
||||
[test_imapHighWater.js]
|
||||
# Disabled until bug 870864 is resolved
|
||||
skip-if = true
|
||||
[test_imapID.js]
|
||||
[test_imapMove.js]
|
||||
[test_imapPasswordFailure.js]
|
||||
# Disabled until bug 870864 is resolved
|
||||
skip-if = true
|
||||
[test_imapRename.js]
|
||||
[test_imapSearch.js]
|
||||
[test_imapStatusCloseDBs.js]
|
||||
|
@ -56,20 +43,13 @@ skip-if = true
|
|||
[test_nsIMsgFolderListenerIMAP.js]
|
||||
[test_offlineCopy.js]
|
||||
[test_offlineDraftDataloss.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_offlinePlayback.js]
|
||||
run-sequentially = Starts server twice.
|
||||
[test_offlineStoreLocking.js]
|
||||
# Doesn't currently work on Windows, bug 782625
|
||||
# Disabled until bug 870864 is resolved
|
||||
skip-if = true
|
||||
[test_partsOnDemand.js]
|
||||
[test_preserveDataOnMove.js]
|
||||
[test_saveImapDraft.js]
|
||||
[test_saveTemplate.js]
|
||||
[test_starttlsFailure.js]
|
||||
# Disabled until bug 870864 is resolved
|
||||
skip-if = true
|
||||
[test_stopMovingToLocalFolder.js]
|
||||
[test_subfolderLocation.js]
|
||||
[test_syncChanges.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче