Bug 495527 Fix up send later unit tests and create alertTestUtils.js resource. r=bienvenu
This commit is contained in:
Родитель
463d47413a
Коммит
d95adf6f10
|
@ -5,80 +5,27 @@
|
|||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
load("../../mailnews/resources/alertTestUtils.js");
|
||||
|
||||
// This allows us to check that we get alerts at the right time without
|
||||
// involking the UI.
|
||||
var prompts = {
|
||||
mDialogTitle: null,
|
||||
mText: null,
|
||||
var gDialogTitle = null;
|
||||
var gText = null;
|
||||
|
||||
// not part of the nsIPrompt interface, just makes it easier to test.
|
||||
reset: function() {
|
||||
this.mDialogTitle = null;
|
||||
this.mText = null;
|
||||
},
|
||||
function reset() {
|
||||
gDialogTitle = null;
|
||||
gText = null;
|
||||
}
|
||||
|
||||
// nsIPrompt
|
||||
alert: function(aDialogTitle, aText) {
|
||||
do_check_eq(this.mDialogTitle, null);
|
||||
do_check_eq(this.mText, null);
|
||||
function alert(aDialogTitle, aText) {
|
||||
do_check_eq(gDialogTitle, null);
|
||||
do_check_eq(gText, null);
|
||||
|
||||
this.mDialogTitle = aDialogTitle;
|
||||
this.mText = aText;
|
||||
},
|
||||
|
||||
alertCheck: function(aDialogTitle, aText, aCheckMsg, aCheckState) {},
|
||||
|
||||
confirm: function(aDialogTitle, aText) {},
|
||||
|
||||
confirmCheck: function(aDialogTitle, aText, aCheckMsg, aCheckState) {},
|
||||
|
||||
confirmEx: function(aDialogTitle, aText, aButtonFlags, aButton0Title,
|
||||
aButton1Title, aButton2Title, aCheckMsg, aCheckState) {},
|
||||
|
||||
prompt: function(aDialogTitle, aText, aValue, aCheckMsg, aCheckState) {},
|
||||
|
||||
promptUsernameAndPassword: function(aDialogTitle, aText, aUsername,
|
||||
aPassword, aCheckMsg, aCheckState) {},
|
||||
|
||||
promptPassword: function(aDialogTitle, aText, aPassword, aCheckMsg,
|
||||
aCheckState) {},
|
||||
|
||||
select: function(aDialogTitle, aText, aCount, aSelectList,
|
||||
aOutSelection) {},
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIPrompt])
|
||||
};
|
||||
|
||||
var WindowWatcher = {
|
||||
getNewPrompter: function(aParent) {
|
||||
return prompts;
|
||||
},
|
||||
|
||||
getNewAuthPrompter: function(aParent) {
|
||||
return prompts;
|
||||
},
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowWatcher])
|
||||
};
|
||||
|
||||
var WindowWatcherFactory = {
|
||||
createInstance: function createInstance(outer, iid) {
|
||||
if (outer != null)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
return WindowWatcher.QueryInterface(iid);
|
||||
}
|
||||
};
|
||||
|
||||
Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar)
|
||||
.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
|
||||
"Fake Window Watcher",
|
||||
"@mozilla.org/embedcomp/window-watcher;1",
|
||||
WindowWatcherFactory);
|
||||
gDialogTitle = aDialogTitle;
|
||||
gText = aText;
|
||||
}
|
||||
|
||||
var msgWindow = {
|
||||
get promptDialog() {
|
||||
return prompts;
|
||||
return alertUtilsPrompts;
|
||||
},
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIMsgWindow])
|
||||
|
@ -124,31 +71,31 @@ function run_test()
|
|||
|
||||
// Test - No listeners, check alert tries to alert the user.
|
||||
|
||||
prompts.reset();
|
||||
reset();
|
||||
|
||||
msgUrl._msgWindow = msgWindow;
|
||||
|
||||
mailSession.alertUser("test message", msgUrl);
|
||||
|
||||
// The dialog title doesn't get set at the moment.
|
||||
do_check_eq(prompts.mDialogTitle, null);
|
||||
do_check_eq(prompts.mText, "test message");
|
||||
do_check_eq(gDialogTitle, null);
|
||||
do_check_eq(gText, "test message");
|
||||
|
||||
// Test - No listeners and no msgWindow, check no alerts.
|
||||
|
||||
prompts.reset();
|
||||
reset();
|
||||
|
||||
msgUrl._msgWindow = null;
|
||||
|
||||
mailSession.alertUser("test no message", msgUrl);
|
||||
|
||||
// The dialog title doesn't get set at the moment.
|
||||
do_check_eq(prompts.mDialogTitle, null);
|
||||
do_check_eq(prompts.mText, null);
|
||||
do_check_eq(gDialogTitle, null);
|
||||
do_check_eq(gText, null);
|
||||
|
||||
// Test - One listener, returning false (prompt should still happen).
|
||||
|
||||
prompts.reset();
|
||||
reset();
|
||||
|
||||
var listener1 = new alertListener();
|
||||
listener1.mReturn = false;
|
||||
|
@ -159,8 +106,8 @@ function run_test()
|
|||
|
||||
mailSession.alertUser("message test", msgUrl);
|
||||
|
||||
do_check_eq(prompts.mDialogTitle, null);
|
||||
do_check_eq(prompts.mText, "message test");
|
||||
do_check_eq(gDialogTitle, null);
|
||||
do_check_eq(gText, "message test");
|
||||
|
||||
do_check_eq(listener1.mMessage, "message test");
|
||||
do_check_neq(listener1.mMsgWindow, null);
|
||||
|
@ -168,20 +115,20 @@ function run_test()
|
|||
// Test - One listener, returning false, no msg window (prompt shouldn't
|
||||
// happen).
|
||||
|
||||
prompts.reset();
|
||||
reset();
|
||||
listener1.reset();
|
||||
|
||||
mailSession.alertUser("message test no prompt", null);
|
||||
|
||||
do_check_eq(prompts.mDialogTitle, null);
|
||||
do_check_eq(prompts.mText, null);
|
||||
do_check_eq(gDialogTitle, null);
|
||||
do_check_eq(gText, null);
|
||||
|
||||
do_check_eq(listener1.mMessage, "message test no prompt");
|
||||
do_check_eq(listener1.mMsgWindow, null);
|
||||
|
||||
// Test - Two listeners, both returning false (prompt should happen).
|
||||
|
||||
prompts.reset();
|
||||
reset();
|
||||
listener1.reset();
|
||||
|
||||
var listener2 = new alertListener();
|
||||
|
@ -193,8 +140,8 @@ function run_test()
|
|||
|
||||
mailSession.alertUser("two listeners", msgUrl);
|
||||
|
||||
do_check_eq(prompts.mDialogTitle, null);
|
||||
do_check_eq(prompts.mText, "two listeners");
|
||||
do_check_eq(gDialogTitle, null);
|
||||
do_check_eq(gText, "two listeners");
|
||||
|
||||
do_check_eq(listener1.mMessage, "two listeners");
|
||||
do_check_neq(listener1.mMsgWindow, null);
|
||||
|
@ -204,7 +151,7 @@ function run_test()
|
|||
|
||||
// Test - Two listeners, one returning true (prompt shouldn't happen).
|
||||
|
||||
prompts.reset();
|
||||
reset();
|
||||
listener1.reset();
|
||||
listener2.reset();
|
||||
|
||||
|
@ -214,8 +161,8 @@ function run_test()
|
|||
|
||||
mailSession.alertUser("no prompt", msgUrl);
|
||||
|
||||
do_check_eq(prompts.mDialogTitle, null);
|
||||
do_check_eq(prompts.mText, null);
|
||||
do_check_eq(gDialogTitle, null);
|
||||
do_check_eq(gText, null);
|
||||
|
||||
do_check_eq(listener1.mMessage, "no prompt");
|
||||
do_check_neq(listener1.mMsgWindow, null);
|
||||
|
@ -225,7 +172,7 @@ function run_test()
|
|||
|
||||
// Test - Remove a listener.
|
||||
|
||||
prompts.reset();
|
||||
reset();
|
||||
listener1.reset();
|
||||
listener2.reset();
|
||||
|
||||
|
@ -235,8 +182,8 @@ function run_test()
|
|||
|
||||
mailSession.alertUser("remove listener", msgUrl);
|
||||
|
||||
do_check_eq(prompts.mDialogTitle, null);
|
||||
do_check_eq(prompts.mText, null);
|
||||
do_check_eq(gDialogTitle, null);
|
||||
do_check_eq(gText, null);
|
||||
|
||||
do_check_eq(listener1.mMessage, null);
|
||||
do_check_eq(listener1.mMsgWindow, null);
|
||||
|
@ -246,7 +193,7 @@ function run_test()
|
|||
|
||||
// Test - Remove the other listener.
|
||||
|
||||
prompts.reset();
|
||||
reset();
|
||||
listener1.reset();
|
||||
listener2.reset();
|
||||
|
||||
|
@ -256,8 +203,8 @@ function run_test()
|
|||
|
||||
mailSession.alertUser("no listeners", msgUrl);
|
||||
|
||||
do_check_eq(prompts.mDialogTitle, null);
|
||||
do_check_eq(prompts.mText, "no listeners");
|
||||
do_check_eq(gDialogTitle, null);
|
||||
do_check_eq(gText, "no listeners");
|
||||
|
||||
do_check_eq(listener1.mMessage, null);
|
||||
do_check_eq(listener1.mMsgWindow, null);
|
||||
|
|
|
@ -64,7 +64,8 @@ function do_check_transaction(real, expected) {
|
|||
|
||||
// This listener is designed just to call OnStopCopy() when its OnStopCopy
|
||||
// function is called - the rest of the functions are unneeded for a lot of
|
||||
// tests.
|
||||
// tests (but we can't use asyncCopyListener because we need the
|
||||
// nsIMsgSendListener interface as well).
|
||||
var copyListener = {
|
||||
// nsIMsgSendListener
|
||||
onStartSending: function (aMsgID, aMsgSize) {},
|
||||
|
|
|
@ -28,19 +28,27 @@ msll.prototype = {
|
|||
_initialTotal: 0,
|
||||
|
||||
// nsIMsgSendLaterListener
|
||||
onStartSending: function (aTotal) {
|
||||
onStartSending: function (aTotalMessageCount) {
|
||||
this._initialTotal = 1;
|
||||
do_check_eq(msgSendLater.sendingMessages, true);
|
||||
},
|
||||
onProgress: function (aCurrentMessage, aTotal) {
|
||||
onMessageStartSending: function (aCurrentMessage, aTotalMessageCount,
|
||||
aMessageHeader, aIdentity) {
|
||||
},
|
||||
onMessageSendProgress: function (aCurrentMessage, aTotalMessageCount,
|
||||
aMessageSendPercent, aMessageCopyPercent) {
|
||||
// XXX Enable this function
|
||||
},
|
||||
onStopSending: function (aStatus, aMsg, aTotal, aSuccessful) {
|
||||
onMessageSendError: function (aCurrentMessage, aMessageHeader, aStatus,
|
||||
aMsg) {
|
||||
do_throw("onMessageSendError should not have been called, status: " + aStatus);
|
||||
},
|
||||
onStopSending: function (aStatus, aMsg, aTotalTried, aSuccessful) {
|
||||
do_test_finished();
|
||||
print("msll onStopSending\n");
|
||||
try {
|
||||
do_check_eq(aStatus, 0);
|
||||
do_check_eq(aTotal, 1);
|
||||
do_check_eq(aTotalTried, 1);
|
||||
do_check_eq(aSuccessful, 1);
|
||||
do_check_eq(this._initialTotal, 1);
|
||||
do_check_eq(msgSendLater.sendingMessages, false);
|
||||
|
|
|
@ -32,15 +32,22 @@ msll.prototype = {
|
|||
do_check_eq(gMsgSendLater.sendingMessages, true);
|
||||
do_check_eq(aTotal, 1);
|
||||
},
|
||||
onProgress: function (aCurrentMessage, aTotal) {
|
||||
// XXX Enable this function
|
||||
onMessageStartSending: function (aCurrentMessage, aTotalMessageCount,
|
||||
aMessageHeader, aIdentity) {
|
||||
},
|
||||
onStopSending: function (aStatus, aMsg, aTotal, aSuccessful) {
|
||||
onMessageSendProgress: function (aCurrentMessage, aTotalMessageCount,
|
||||
aMessageSendPercent, aMessageCopyPercent) {
|
||||
},
|
||||
onMessageSendError: function (aCurrentMessage, aMessageHeader, aStatus,
|
||||
aMsg) {
|
||||
do_throw("onMessageSendError should not have been called, status: " + aStatus);
|
||||
},
|
||||
onStopSending: function (aStatus, aMsg, aTotalTried, aSuccessful) {
|
||||
do_test_finished();
|
||||
print("msll onStopSending\n");
|
||||
try {
|
||||
do_check_eq(aStatus, 0);
|
||||
do_check_eq(aTotal, 1);
|
||||
do_check_eq(aTotalTried, 1);
|
||||
do_check_eq(aSuccessful, 1);
|
||||
do_check_eq(this._initialTotal, 1);
|
||||
do_check_eq(gMsgSendLater.sendingMessages, false);
|
||||
|
|
|
@ -33,21 +33,32 @@ function msll() {
|
|||
|
||||
msll.prototype = {
|
||||
_initialTotal: 0,
|
||||
_startedSending: false,
|
||||
|
||||
// nsIMsgSendLaterListener
|
||||
onStartSending: function (aTotal) {
|
||||
onStartSending: function (aTotalMessageCount) {
|
||||
this._initialTotal = 1;
|
||||
do_check_eq(msgSendLater.sendingMessages, true);
|
||||
},
|
||||
onProgress: function (aCurrentMessage, aTotal) {
|
||||
onMessageStartSending: function (aCurrentMessage, aTotalMessageCount,
|
||||
aMessageHeader, aIdentity) {
|
||||
this._startedSending = true;
|
||||
},
|
||||
onMessageSendProgress: function (aCurrentMessage, aTotalMessageCount,
|
||||
aMessageSendPercent, aMessageCopyPercent) {
|
||||
// XXX Enable this function
|
||||
},
|
||||
onStopSending: function (aStatus, aMsg, aTotal, aSuccessful) {
|
||||
onMessageSendError: function (aCurrentMessage, aMessageHeader, aStatus,
|
||||
aMsg) {
|
||||
do_throw("onMessageSendError should not have been called, status: " + aStatus);
|
||||
},
|
||||
onStopSending: function (aStatus, aMsg, aTotalTried, aSuccessful) {
|
||||
do_test_finished();
|
||||
print("msll onStopSending\n");
|
||||
try {
|
||||
do_check_eq(this._startedSending, true);
|
||||
do_check_eq(aStatus, 0);
|
||||
do_check_eq(aTotal, 1);
|
||||
do_check_eq(aTotalTried, 1);
|
||||
do_check_eq(aSuccessful, 1);
|
||||
do_check_eq(this._initialTotal, 1);
|
||||
do_check_eq(msgSendLater.sendingMessages, false);
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
* required), when we fix bug 136871 we should be able to enable the multiple
|
||||
* messages option.
|
||||
*/
|
||||
|
||||
load("../../mailnews/resources/asyncTestUtils.js");
|
||||
|
||||
var test = "sendMessageLater";
|
||||
var server = null;
|
||||
var gSentFolder;
|
||||
|
@ -27,6 +30,12 @@ var gMsgOrder = [];
|
|||
var gCurTestNum = 0;
|
||||
var gLastSentMessage = 0;
|
||||
|
||||
// gMessageSendStatus
|
||||
// 0 = initial value
|
||||
// 1 = send completed before exiting sendUnsentMessages
|
||||
// 2 = sendUnsentMessages has exited.
|
||||
var gMessageSendStatus = 0;
|
||||
|
||||
const kSender = "from@invalid.com";
|
||||
const kTo = "to@invalid.com";
|
||||
|
||||
|
@ -39,57 +48,44 @@ function msll() {
|
|||
}
|
||||
|
||||
msll.prototype = {
|
||||
checkMessageSend: function(aCurrentMessage) {
|
||||
do_check_transaction(transaction,
|
||||
["EHLO test",
|
||||
"MAIL FROM:<" + kSender + "> SIZE=" + gMsgFileData[gMsgOrder[aCurrentMessage - 1]].length,
|
||||
"RCPT TO:<" + kTo + ">",
|
||||
"DATA"]);
|
||||
transaction = null;
|
||||
|
||||
// Compare data file to what the server received
|
||||
do_check_eq(gMsgFileData[gMsgOrder[aCurrentMessage - 1]], server._handler.post);
|
||||
},
|
||||
|
||||
// nsIMsgSendLaterListener
|
||||
onStartSending: function (aTotal) {
|
||||
onStartSending: function (aTotalMessageCount) {
|
||||
do_check_eq(aTotal, gMsgOrder.length);
|
||||
do_check_eq(msgSendLater.sendingMessages, true);
|
||||
},
|
||||
onProgress: function (aCurrentMessage, aTotal) {
|
||||
try {
|
||||
do_check_eq(aTotal, gMsgOrder.length);
|
||||
do_check_eq(gLastSentMessage + 1, aCurrentMessage);
|
||||
gLastSentMessage = aCurrentMessage;
|
||||
do_check_eq(msgSendLater.sendingMessages, true);
|
||||
|
||||
do_check_transaction(transaction,
|
||||
["EHLO test",
|
||||
"MAIL FROM:<" + kSender + "> SIZE=" + gMsgFileData[gMsgOrder[aCurrentMessage - 1]].length,
|
||||
"RCPT TO:<" + kTo + ">",
|
||||
"DATA"]);
|
||||
transaction = null;
|
||||
|
||||
// Compare data file to what the server received
|
||||
do_check_eq(gMsgFileData[gMsgOrder[aCurrentMessage - 1]], server._handler.post);
|
||||
|
||||
// XXX We've got more messages to receive so restart the server for the
|
||||
// new connection, at least until bug 136871 is fixed - we reset and stop
|
||||
// the server on exit, the next test runs the server for the next message.
|
||||
do_timeout(0, "doTest(++gCurTestNum)");
|
||||
} catch (e) {
|
||||
do_throw(e);
|
||||
} finally {
|
||||
// Reset
|
||||
server.resetTest();
|
||||
|
||||
// XXX This is the way we currently try and restart the server which
|
||||
// doesn't always work, once we fix bug 136871 just calling resetTest and
|
||||
// ensuring we play the transaction should be enough.
|
||||
server.stop();
|
||||
|
||||
var thread = gThreadManager.currentThread;
|
||||
while (thread.hasPendingEvents())
|
||||
thread.processNextEvent(true);
|
||||
server.start(SMTP_PORT);
|
||||
|
||||
var thread = gThreadManager.currentThread;
|
||||
while (thread.hasPendingEvents())
|
||||
thread.processNextEvent(true);
|
||||
}
|
||||
onMessageStartSending: function (aCurrentMessage, aTotalMessageCount,
|
||||
aMessageHeader, aIdentity) {
|
||||
if (gLastSentMessage > 0)
|
||||
this.checkMessageSend(aCurrentMessage);
|
||||
do_check_eq(gLastSentMessage + 1, aCurrentMessage);
|
||||
gLastSentMessage = aCurrentMessage;
|
||||
},
|
||||
onStopSending: function (aStatus, aMsg, aTotal, aSuccessful) {
|
||||
onMessageSendProgress: function (aCurrentMessage, aTotalMessageCount,
|
||||
aMessageSendPercent, aMessageCopyPercent) {
|
||||
do_check_eq(aTotalMessageCount, gMsgOrder.length);
|
||||
do_check_eq(gLastSentMessage, aCurrentMessage);
|
||||
do_check_eq(msgSendLater.sendingMessages, true);
|
||||
},
|
||||
onMessageSendError: function (aCurrentMessage, aMessageHeader, aStatus,
|
||||
aMsg) {
|
||||
do_throw("onMessageSendError should not have been called, status: " + aStatus);
|
||||
},
|
||||
onStopSending: function (aStatus, aMsg, aTotalTried, aSuccessful) {
|
||||
try {
|
||||
do_check_eq(aStatus, 0);
|
||||
do_check_eq(aTotal, aSuccessful);
|
||||
do_check_eq(aTotalTried, aSuccessful);
|
||||
do_check_eq(msgSendLater.sendingMessages, false);
|
||||
|
||||
// Check that the send later service now thinks we don't have messages to
|
||||
|
@ -102,17 +98,7 @@ msll.prototype = {
|
|||
transaction = server.playTransaction();
|
||||
}
|
||||
|
||||
do_check_transaction(transaction,
|
||||
["EHLO test",
|
||||
"MAIL FROM:<" + kSender + "> SIZE=" + gMsgFileData[gMsgOrder[aTotal - 1]].length,
|
||||
"RCPT TO:<" + kTo + ">",
|
||||
"DATA"]);
|
||||
transaction = null;
|
||||
|
||||
// Compare data file to what the server received
|
||||
do_check_eq(gMsgFileData[gMsgOrder[aTotal - 1]], server._handler.post);
|
||||
|
||||
do_timeout(0, "doTest(++gCurTestNum)");
|
||||
this.checkMessageSend(gLastSentMessage);
|
||||
} catch (e) {
|
||||
dump(e);
|
||||
do_throw(e);
|
||||
|
@ -122,7 +108,15 @@ msll.prototype = {
|
|||
|
||||
var thread = gThreadManager.currentThread;
|
||||
while (thread.hasPendingEvents())
|
||||
thread.processNextEvent(true);
|
||||
thread.processNextEvent(true);
|
||||
}
|
||||
if (gMessageSendStatus == 0) {
|
||||
dump("gMessageSendStatus to 1\n");
|
||||
gMessageSendStatus = 1;
|
||||
}
|
||||
else if (gMessageSendStatus == 2) {
|
||||
dump("next driver\n");
|
||||
async_driver();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -145,7 +139,7 @@ function OnStopCopy(aStatus)
|
|||
|
||||
// Start the next step after a brief time so that functions can finish
|
||||
// properly
|
||||
do_timeout(0, "doTest(++gCurTestNum);");
|
||||
async_driver();
|
||||
}
|
||||
|
||||
function sendMessageLater(aTestFileIndex)
|
||||
|
@ -167,18 +161,19 @@ function sendMessageLater(aTestFileIndex)
|
|||
msgSend.sendMessageFile(identity, "", compFields, gMsgFile[aTestFileIndex],
|
||||
false, false, Ci.nsIMsgSend.nsMsgQueueForLater,
|
||||
null, copyListener, null, null);
|
||||
return false;
|
||||
}
|
||||
|
||||
function resetCounts()
|
||||
{
|
||||
gMsgOrder = [];
|
||||
gLastSentMessage = 0;
|
||||
do_timeout(0, "doTest(++gCurTestNum);");
|
||||
}
|
||||
|
||||
// This function does the actual send later
|
||||
function sendUnsentMessages()
|
||||
{
|
||||
gMessageSendStatus = 0;
|
||||
// Handle the server in a try/catch/finally loop so that we always will stop
|
||||
// the server if something fails.
|
||||
try {
|
||||
|
@ -187,7 +182,6 @@ function sendUnsentMessages()
|
|||
|
||||
// Send the unsent message
|
||||
msgSendLater.sendUnsentMessages(identity);
|
||||
|
||||
server.performTest();
|
||||
|
||||
transaction = server.playTransaction();
|
||||
|
@ -200,6 +194,10 @@ function sendUnsentMessages()
|
|||
while (thread.hasPendingEvents())
|
||||
thread.processNextEvent(true);
|
||||
}
|
||||
if (!gMessageSendStatus)
|
||||
gMessageSendStatus = 2;
|
||||
|
||||
return gMessageSendStatus == 1;
|
||||
}
|
||||
|
||||
function runServerTest()
|
||||
|
@ -209,38 +207,33 @@ function runServerTest()
|
|||
transaction = server.playTransaction();
|
||||
}
|
||||
|
||||
// Beware before commenting out a test
|
||||
// -- later tests might just depend on earlier ones
|
||||
const gTestArray =
|
||||
[
|
||||
// Copying message from file to folder.
|
||||
function testSendLater1() { sendMessageLater(0); },
|
||||
function actually_run_test() {
|
||||
dump("in actually_run_test\n");
|
||||
|
||||
// Now send unsent message
|
||||
function testSendUnsentMessages1() { sendUnsentMessages(); },
|
||||
dump("Copy Mesage from file to folder\n");
|
||||
yield async_run({func: sendMessageLater, args: [0]});
|
||||
|
||||
function testSentEmpty() {
|
||||
do_check_eq(gSentFolder.getTotalMessages(false), 0);
|
||||
doTest(++gCurTestNum);
|
||||
},
|
||||
dump("Send unsent message\n");
|
||||
yield async_run({func: sendUnsentMessages});
|
||||
|
||||
// This function just resets a few counts where necessary.
|
||||
function testResetCounts() { resetCounts(); },
|
||||
// Check sent folder is now empty.
|
||||
do_check_eq(gSentFolder.getTotalMessages(false), 0);
|
||||
|
||||
// Now copy more messages...
|
||||
function testCopyFileMessage2() {
|
||||
sendMessageLater(1);
|
||||
// XXX Only do one the second time round, as described at the start of the
|
||||
// file.
|
||||
// sendMessageLater(0);
|
||||
},
|
||||
// ...and send again
|
||||
function testSendUnsentMessages2() { sendUnsentMessages(); },
|
||||
// and reset counts
|
||||
resetCounts();
|
||||
|
||||
// XXX This may be needed if sending more than one message in the second
|
||||
// stage.
|
||||
// function testRunServer() { runServerTest(); }
|
||||
];
|
||||
dump("Copy more messages\n");
|
||||
yield async_run({func: sendMessageLater, args: [1]});
|
||||
|
||||
// XXX Only do one the second time round, as described at the start of the
|
||||
// file.
|
||||
// yield async_run({func: sendMessageLater, args: [0]});
|
||||
|
||||
dump("Test send again\n");
|
||||
yield async_run({func: sendUnsentMessages});
|
||||
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
// Load in the test files so we have a record of length and their data.
|
||||
|
@ -290,28 +283,5 @@ function run_test() {
|
|||
do_test_pending();
|
||||
|
||||
// Do the test
|
||||
doTest(1);
|
||||
}
|
||||
|
||||
function doTest(test)
|
||||
{
|
||||
dump("doTest " + test + "\n");
|
||||
if (test <= gTestArray.length) {
|
||||
gCurTestNum = test;
|
||||
|
||||
var testFn = gTestArray[test-1];
|
||||
|
||||
// Set a limit in case the notifications haven't arrived (i.e. a problem)
|
||||
do_timeout(10000, "if (gCurTestNum == "+test+") \
|
||||
do_throw('Notifications not received in 10000 ms for operation "+testFn.name+", current status is '+gCurrStatus);");
|
||||
try {
|
||||
testFn();
|
||||
} catch(ex) {
|
||||
dump(ex);
|
||||
do_throw(ex);
|
||||
}
|
||||
}
|
||||
else {
|
||||
do_test_finished(); // for the one in run_test()
|
||||
}
|
||||
async_run({func: actually_run_test});
|
||||
}
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
* - A correct status response.
|
||||
* - A correct state at the end of attempting to send.
|
||||
*/
|
||||
|
||||
load("../../mailnews/resources/alertTestUtils.js");
|
||||
|
||||
var type = null;
|
||||
var test = null;
|
||||
var server;
|
||||
|
@ -23,73 +26,9 @@ const kTo = "to@invalid.com";
|
|||
var msgSendLater = Cc["@mozilla.org/messengercompose/sendlater;1"]
|
||||
.getService(Ci.nsIMsgSendLater);
|
||||
|
||||
// This allows the send code to attempt to display errors to the user without
|
||||
// failing.
|
||||
var prompts = {
|
||||
alert: function(aDialogTitle, aText) {
|
||||
dump("Hiding Alert {\n" + aText + "\n} End Alert\n");
|
||||
},
|
||||
|
||||
alertCheck: function(aDialogTitle, aText, aCheckMsg, aCheckState) {},
|
||||
|
||||
confirm: function(aDialogTitle, aText) {},
|
||||
|
||||
confirmCheck: function(aDialogTitle, aText, aCheckMsg, aCheckState) {},
|
||||
|
||||
confirmEx: function(aDialogTitle, aText, aButtonFlags, aButton0Title,
|
||||
aButton1Title, aButton2Title, aCheckMsg, aCheckState) {},
|
||||
|
||||
prompt: function(aDialogTitle, aText, aValue, aCheckMsg, aCheckState) {},
|
||||
|
||||
promptUsernameAndPassword: function(aDialogTitle, aText, aUsername,
|
||||
aPassword, aCheckMsg, aCheckState) {},
|
||||
|
||||
promptPassword: function(aDialogTitle, aText, aPassword, aCheckMsg,
|
||||
aCheckState) {},
|
||||
|
||||
select: function(aDialogTitle, aText, aCount, aSelectList,
|
||||
aOutSelection) {},
|
||||
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Components.interfaces.nsIPrompt)
|
||||
|| iid.equals(Components.interfaces.nsISupports))
|
||||
return this;
|
||||
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
|
||||
var WindowWatcher = {
|
||||
getNewPrompter: function(aParent) {
|
||||
return prompts;
|
||||
},
|
||||
|
||||
getNewAuthPrompter: function(aParent) {
|
||||
return prompts;
|
||||
},
|
||||
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Ci.nsIWindowWatcher) || iid.equals(Ci.nsISupports)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
|
||||
var WindowWatcherFactory = {
|
||||
createInstance: function createInstance(outer, iid) {
|
||||
if (outer != null)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
return WindowWatcher.QueryInterface(iid);
|
||||
}
|
||||
};
|
||||
|
||||
Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar)
|
||||
.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
|
||||
"Fake Window Watcher",
|
||||
"@mozilla.org/embedcomp/window-watcher;1",
|
||||
WindowWatcherFactory);
|
||||
function alert(aDialogTitle, aText) {
|
||||
dump("Hiding Alert {\n" + aText + "\n} End Alert\n");
|
||||
}
|
||||
|
||||
// This listener handles the post-sending of the actual message and checks the
|
||||
// sequence and ensures the data is correct.
|
||||
|
@ -98,13 +37,22 @@ function msll() {
|
|||
|
||||
msll.prototype = {
|
||||
_initialTotal: 0,
|
||||
_errorRaised: false,
|
||||
|
||||
// nsIMsgSendLaterListener
|
||||
onStartSending: function (aTotal) {
|
||||
this._initialTotal = 1;
|
||||
do_check_eq(msgSendLater.sendingMessages, true);
|
||||
},
|
||||
onProgress: function (aCurrentMessage, aTotal) {
|
||||
onMessageStartSending: function (aCurrentMessage, aTotalMessageCount,
|
||||
aMessageHeader, aIdentity) {
|
||||
},
|
||||
onMessageSendProgress: function (aCurrentMessage, aTotalMessageCount,
|
||||
aMessageSendPercent, aMessageCopyPercent) {
|
||||
},
|
||||
onMessageSendError: function (aCurrentMessage, aMessageHeader, aStatus,
|
||||
aMsg) {
|
||||
this._errorRaised = true;
|
||||
},
|
||||
onStopSending: function (aStatus, aMsg, aTotal, aSuccessful) {
|
||||
print("msll onStopSending\n");
|
||||
|
@ -114,6 +62,7 @@ msll.prototype = {
|
|||
do_check_eq(aTotal, 1);
|
||||
do_check_eq(aSuccessful, 0);
|
||||
do_check_eq(this._initialTotal, 1);
|
||||
do_check_eq(this._errorRaised, true);
|
||||
do_check_eq(msgSendLater.sendingMessages, false);
|
||||
// Check that the send later service still thinks we have messages to send.
|
||||
do_check_eq(msgSendLater.hasUnsentMessages(identity), true);
|
||||
|
@ -164,6 +113,8 @@ function sendMessageLater()
|
|||
}
|
||||
|
||||
function run_test() {
|
||||
registerAlertTestUtils();
|
||||
|
||||
// Test file - for bug 429891
|
||||
originalData = loadFileToString(testFile);
|
||||
|
||||
|
|
|
@ -0,0 +1,162 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* This file provides support for writing mailnews tests that require hooking
|
||||
* into the alerts system. Normally these tests would require a UI and fail in
|
||||
* debug mode, but with this method you can hook into the alerts system and
|
||||
* avoid the UI.
|
||||
*
|
||||
* To register the system:
|
||||
*
|
||||
* function run_test() {
|
||||
* registerAlertTestUtils();
|
||||
* // ...
|
||||
* }
|
||||
*
|
||||
* You can then hook into the alerts just by defining a function of the same
|
||||
* name as the interface function:
|
||||
*
|
||||
* function alert(aDialogTitle, aText) {
|
||||
* // do my check
|
||||
* }
|
||||
*
|
||||
* Interface functions that do not have equivalent functions defined and get
|
||||
* called will be treated as unexpected, and therefore they will call
|
||||
* do_throw().
|
||||
*/
|
||||
|
||||
|
||||
// This allows the send code to attempt to display errors to the user without
|
||||
// failing.
|
||||
var alertUtilsPrompts = {
|
||||
alert: function(aDialogTitle, aText) {
|
||||
if (typeof alert == "function") {
|
||||
alert(aDialogTitle, aText);
|
||||
return;
|
||||
}
|
||||
|
||||
do_throw("alert unexpectedly called\n");
|
||||
},
|
||||
|
||||
alertCheck: function(aDialogTitle, aText, aCheckMsg, aCheckState) {
|
||||
if (typeof alertCheck == "function") {
|
||||
alertCheck(aDialogTitle, aText, aCheckMsg, aCheckState);
|
||||
return;
|
||||
}
|
||||
|
||||
do_throw("alertCheck unexpectedly called\n");
|
||||
},
|
||||
|
||||
confirm: function(aDialogTitle, aText) {
|
||||
if (typeof confirm == "function") {
|
||||
confirm(aDialogTitle, aText);
|
||||
return;
|
||||
}
|
||||
|
||||
do_throw("confirm unexpectedly called\n");
|
||||
},
|
||||
|
||||
confirmCheck: function(aDialogTitle, aText, aCheckMsg, aCheckState) {
|
||||
if (typeof confirmCheck == "function") {
|
||||
confirmCheck(aDialogTitle, aText, aCheckMsg, aCheckState);
|
||||
return;
|
||||
}
|
||||
|
||||
do_throw("confirmCheck unexpectedly called\n");
|
||||
},
|
||||
|
||||
confirmEx: function(aDialogTitle, aText, aButtonFlags, aButton0Title,
|
||||
aButton1Title, aButton2Title, aCheckMsg, aCheckState) {
|
||||
if (typeof confirmEx == "function") {
|
||||
confirmEx(aDialogTitle, aText, aButtonFlags, aButton0Title,
|
||||
aButton1Title, aButton2Title, aCheckMsg, aCheckState);
|
||||
return;
|
||||
}
|
||||
|
||||
do_throw("confirmEx unexpectedly called\n");
|
||||
},
|
||||
|
||||
prompt: function(aDialogTitle, aText, aValue, aCheckMsg, aCheckState) {
|
||||
if (typeof prompt == "function") {
|
||||
prompt(aDialogTitle, aText, aValue, aCheckMsg, aCheckState);
|
||||
return;
|
||||
}
|
||||
|
||||
do_throw("prompt unexpectedly called\n");
|
||||
},
|
||||
|
||||
promptUsernameAndPassword: function(aDialogTitle, aText, aUsername,
|
||||
aPassword, aCheckMsg, aCheckState) {
|
||||
if (typeof promptUsernameAndPassword == "function") {
|
||||
promptUsernameAndPassword(aDialogTitle, aText, aUsername,
|
||||
aPassword, aCheckMsg, aCheckState);
|
||||
return;
|
||||
}
|
||||
|
||||
do_throw("promptUsernameAndPassword unexpectedly called\n");
|
||||
},
|
||||
|
||||
promptPassword: function(aDialogTitle, aText, aPassword, aCheckMsg,
|
||||
aCheckState) {
|
||||
if (typeof promptPassword == "function") {
|
||||
promptPassword(aDialogTitle, aText, aPassword, aCheckMsg,
|
||||
aCheckState);
|
||||
return;
|
||||
}
|
||||
|
||||
do_throw("promptPassword unexpectedly called\n");
|
||||
},
|
||||
|
||||
select: function(aDialogTitle, aText, aCount, aSelectList,
|
||||
aOutSelection) {
|
||||
if (typeof select == "function") {
|
||||
select(aDialogTitle, aText, aCount, aSelectList,
|
||||
aOutSelection);
|
||||
return;
|
||||
}
|
||||
|
||||
do_throw("select unexpectedly called\n");
|
||||
},
|
||||
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Components.interfaces.nsIPrompt)
|
||||
|| iid.equals(Components.interfaces.nsISupports))
|
||||
return this;
|
||||
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
|
||||
var alertUtilsWindowWatcher = {
|
||||
getNewPrompter: function(aParent) {
|
||||
return alertUtilsPrompts;
|
||||
},
|
||||
|
||||
getNewAuthPrompter: function(aParent) {
|
||||
return alertUtilsPrompts;
|
||||
},
|
||||
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Ci.nsIWindowWatcher) || iid.equals(Ci.nsISupports)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
|
||||
function registerAlertTestUtils()
|
||||
{
|
||||
var WindowWatcherFactory = {
|
||||
createInstance: function createInstance(outer, iid) {
|
||||
if (outer != null)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
return alertUtilsWindowWatcher.QueryInterface(iid);
|
||||
}
|
||||
};
|
||||
|
||||
Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar)
|
||||
.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
|
||||
"Fake Window Watcher",
|
||||
"@mozilla.org/embedcomp/window-watcher;1",
|
||||
WindowWatcherFactory);
|
||||
}
|
Загрузка…
Ссылка в новой задаче