Test case for bug 387579. r/sr=Neil
git-svn-id: svn://10.0.0.236/trunk@246312 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
122
mozilla/mailnews/compose/test/unit/test_nsMsgCompose2.js
Normal file
122
mozilla/mailnews/compose/test/unit/test_nsMsgCompose2.js
Normal file
@@ -0,0 +1,122 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* Test suite for nsMsgMailSession functions relating to listeners.
|
||||
*/
|
||||
|
||||
const MsgComposeContractID = "@mozilla.org/messengercompose/compose;1";
|
||||
const nsIMsgCompose = Components.interfaces.nsIMsgCompose;
|
||||
|
||||
var testnum = 0;
|
||||
|
||||
var gMsgCompose = Components.classes[MsgComposeContractID]
|
||||
.createInstance(nsIMsgCompose);
|
||||
|
||||
const numSendListenerFunctions = 6;
|
||||
|
||||
var gSLAll = new Array(numSendListenerFunctions + 1);
|
||||
|
||||
function sendListener() {}
|
||||
|
||||
sendListener.prototype = {
|
||||
mReceived: 0,
|
||||
mAutoRemoveItem: 0,
|
||||
|
||||
onStartSending: function (aMsgID, aMsgSize) {
|
||||
this.mReceived |= 0x01;
|
||||
if (this.mAutoRemoveItem == 0x01)
|
||||
gMsgCompose.removeMsgSendListener(this);
|
||||
},
|
||||
onProgress: function (aMsgID, aProgress, aProgressMax) {
|
||||
this.mReceived |= 0x02;
|
||||
if (this.mAutoRemoveItem == 0x02)
|
||||
gMsgCompose.removeMsgSendListener(this);
|
||||
},
|
||||
onStatus: function (aMsgID, aMsg) {
|
||||
this.mReceived |= 0x04;
|
||||
if (this.mAutoRemoveItem == 0x04)
|
||||
gMsgCompose.removeMsgSendListener(this);
|
||||
},
|
||||
onStopSending: function (aMsgID, aStatus, aMsg, aReturnFile) {
|
||||
this.mReceived |= 0x08;
|
||||
if (this.mAutoRemoveItem == 0x08)
|
||||
gMsgCompose.removeMsgSendListener(this);
|
||||
},
|
||||
onGetDraftFolderURI: function (aFolderURI) {
|
||||
this.mReceived |= 0x10;
|
||||
if (this.mAutoRemoveItem == 0x10)
|
||||
gMsgCompose.removeMsgSendListener(this);
|
||||
},
|
||||
onSendNotPerformed: function (aMsgID, aStatus) {
|
||||
this.mReceived |= 0x20;
|
||||
if (this.mAutoRemoveItem == 0x20)
|
||||
gMsgCompose.removeMsgSendListener(this);
|
||||
}
|
||||
};
|
||||
|
||||
function NotifySendListeners() {
|
||||
gMsgCompose.onStartSending(null, null);
|
||||
gMsgCompose.onProgress(null, null, null);
|
||||
gMsgCompose.onStatus(null, null);
|
||||
gMsgCompose.onStopSending(null, null, null, null);
|
||||
gMsgCompose.onGetDraftFolderURI(null);
|
||||
gMsgCompose.onSendNotPerformed(null, null);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
try {
|
||||
var i;
|
||||
|
||||
do_check_true(gMsgCompose != null);
|
||||
|
||||
++testnum; // Test 1 - Add a listener
|
||||
|
||||
for (i = 0; i < numSendListenerFunctions + 1; ++i) {
|
||||
gSLAll[i] = new sendListener();
|
||||
gMsgCompose.addMsgSendListener(gSLAll[i]);
|
||||
}
|
||||
|
||||
++testnum; // Test 2 - Notify all listeners
|
||||
|
||||
NotifySendListeners();
|
||||
|
||||
for (i = 0; i < numSendListenerFunctions + 1; ++i) {
|
||||
do_check_eq(gSLAll[i].mReceived, 0x3F);
|
||||
gSLAll[i].mReceived = 0;
|
||||
|
||||
// And prepare for test 3.
|
||||
gSLAll[i].mAutoRemoveItem = 1 << i;
|
||||
}
|
||||
|
||||
++testnum; // Test 3 - Remove some listeners as we go
|
||||
|
||||
NotifySendListeners();
|
||||
|
||||
var currentReceived = 0;
|
||||
|
||||
for (i = 0; i < numSendListenerFunctions + 1; ++i) {
|
||||
if (i < numSendListenerFunctions)
|
||||
currentReceived += 1 << i;
|
||||
|
||||
do_check_eq(gSLAll[i].mReceived, currentReceived);
|
||||
gSLAll[i].mReceived = 0;
|
||||
}
|
||||
|
||||
++testnum; // Test 4 - Ensure the listeners have been removed.
|
||||
|
||||
NotifySendListeners();
|
||||
|
||||
for (i = 0; i < numSendListenerFunctions + 1; ++i) {
|
||||
if (i < numSendListenerFunctions)
|
||||
do_check_eq(gSLAll[i].mReceived, 0);
|
||||
else
|
||||
do_check_eq(gSLAll[i].mReceived, 0x3F);
|
||||
}
|
||||
|
||||
++testnum; // Test 5 - Remove main listener
|
||||
|
||||
gMsgCompose.removeMsgSendListener(gSLAll[numSendListenerFunctions]);
|
||||
}
|
||||
catch (e) {
|
||||
throw "FAILED in test #" + testnum + ": i is " + i + " : " + e;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user