Bug 900519 - Make fakeserver into JS modules - maild.js part. r=Standard8
This commit is contained in:
Родитель
cb8cb47ddd
Коммит
0ba2f554fd
|
@ -18,7 +18,7 @@ load("../../../resources/localAccountUtils.js");
|
|||
load("../../../resources/abSetup.js");
|
||||
|
||||
// Import the smtp server scripts
|
||||
load("../../../fakeserver/maild.js");
|
||||
Components.utils.import("resource://testing-common/mailnews/maild.js");
|
||||
load("../../../fakeserver/auth.js");
|
||||
load("../../../fakeserver/smtpd.js");
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ var CC = Components.Constructor;
|
|||
var gProfileDir = ProfileDir.initialize(do_get_profile());
|
||||
|
||||
// Import fakeserver
|
||||
load(gDEPTH + "mailnews/fakeserver/maild.js");
|
||||
Components.utils.import("resource://testing-common/mailnews/maild.js");
|
||||
load(gDEPTH + "mailnews/fakeserver/auth.js");
|
||||
load(gDEPTH + "mailnews/fakeserver/imapd.js");
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ var gDEPTH = "../../../../";
|
|||
load("../../../resources/localAccountUtils.js");
|
||||
|
||||
// Import the pop3 server scripts
|
||||
load("../../../fakeserver/maild.js");
|
||||
Components.utils.import("resource://testing-common/mailnews/maild.js");
|
||||
load("../../../fakeserver/auth.js");
|
||||
load("../../../fakeserver/pop3d.js");
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ var CC = Components.Constructor;
|
|||
var gProfileDir = ProfileDir.initialize(do_get_profile());
|
||||
|
||||
// Import the servers
|
||||
load("../../../fakeserver/maild.js");
|
||||
Components.utils.import("resource://testing-common/mailnews/maild.js");
|
||||
load("../../../fakeserver/nntpd.js");
|
||||
|
||||
// Generic mailnews resource scripts
|
||||
|
|
|
@ -8,18 +8,22 @@
|
|||
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// Make sure we execute this file exactly once
|
||||
var gMaild_js__;
|
||||
if (!gMaild_js__) {
|
||||
gMaild_js__ = true;
|
||||
var EXPORTED_SYMBOLS = [
|
||||
'nsMailServer',
|
||||
'gThreadManager', // TODO: kill this export
|
||||
'fsDebugNone', 'fsDebugAll', 'fsDebugRecv', 'fsDebugRecvSend'
|
||||
];
|
||||
|
||||
var Cc = Components.classes;
|
||||
var Ci = Components.interfaces;
|
||||
var Cr = Components.results;
|
||||
var CC = Components.Constructor;
|
||||
|
||||
/** The XPCOM thread manager. */
|
||||
var gThreadManager = null;
|
||||
/**
|
||||
* The XPCOM thread manager. This declaration is obsolete and exists only
|
||||
* because deleting it breaks several dozen tests at the moment.
|
||||
*/
|
||||
var gThreadManager = Services.tm;
|
||||
|
||||
const fsDebugNone = 0;
|
||||
const fsDebugRecv = 1;
|
||||
|
@ -78,16 +82,13 @@ const TIMEOUT = 3*60*1000;
|
|||
* // Finished with tests
|
||||
* server.stop();
|
||||
*
|
||||
* var thread = gThreadManager.currentThread;
|
||||
* var thread = Services.tm.currentThread;
|
||||
* while (thread.hasPendingEvents())
|
||||
* thread.processNextEvent(true);
|
||||
*
|
||||
* do_test_finished();
|
||||
*****************************************************************************/
|
||||
function nsMailServer(handlerCreator, daemon) {
|
||||
if (!gThreadManager)
|
||||
gThreadManager = Services.tm;
|
||||
|
||||
this._debug = fsDebugNone;
|
||||
|
||||
/** The port on which this server listens. */
|
||||
|
@ -124,7 +125,7 @@ function nsMailServer(handlerCreator, daemon) {
|
|||
nsMailServer.prototype = {
|
||||
onSocketAccepted : function (socket, trans) {
|
||||
if (this._debug != fsDebugNone)
|
||||
print("Received Connection from " + trans.host + ":" + trans.port);
|
||||
dump("Received Connection from " + trans.host + ":" + trans.port + '\n');
|
||||
|
||||
const SEGMENT_SIZE = 1024;
|
||||
const SEGMENT_COUNT = 1024;
|
||||
|
@ -140,13 +141,13 @@ nsMailServer.prototype = {
|
|||
// Note: must use main thread here, or we might get a GC that will cause
|
||||
// threadsafety assertions. We really need to fix XPConnect so that
|
||||
// you can actually do things in multi-threaded JS. :-(
|
||||
input.asyncWait(reader, 0, 0, gThreadManager.mainThread);
|
||||
input.asyncWait(reader, 0, 0, Services.tm.mainThread);
|
||||
this._test = true;
|
||||
},
|
||||
|
||||
onStopListening : function (socket, status) {
|
||||
if (this._debug != fsDebugNone)
|
||||
print("Connection Lost " + status);
|
||||
dump("Connection Lost " + status + '\n');
|
||||
|
||||
this._socketClosed = true;
|
||||
// We've been killed or we've stopped, reset the handler to the original
|
||||
|
@ -192,7 +193,7 @@ nsMailServer.prototype = {
|
|||
return;
|
||||
|
||||
// spin an event loop and wait for the socket-close notification
|
||||
let thr = gThreadManager.currentThread;
|
||||
let thr = Services.tm.currentThread;
|
||||
while (!this._socketClosed)
|
||||
// Don't wait for the next event, just in case there isn't one.
|
||||
thr.processNextEvent(false);
|
||||
|
@ -232,7 +233,7 @@ nsMailServer.prototype = {
|
|||
performTest : function (watchWord) {
|
||||
this._watchWord = watchWord;
|
||||
|
||||
let thread = gThreadManager.currentThread;
|
||||
let thread = Services.tm.currentThread;
|
||||
while (!this.isTestFinished())
|
||||
thread.processNextEvent(false);
|
||||
},
|
||||
|
@ -388,7 +389,7 @@ nsMailReader.prototype = {
|
|||
var line = this._lines.shift();
|
||||
|
||||
if (this._debug != fsDebugNone)
|
||||
print("RECV: " + line);
|
||||
dump("RECV: " + line + '\n');
|
||||
|
||||
var response;
|
||||
try {
|
||||
|
@ -411,7 +412,7 @@ nsMailReader.prototype = {
|
|||
command = command.toUpperCase();
|
||||
|
||||
if (this._debug == fsDebugAll)
|
||||
print("Received command " + command);
|
||||
dump("Received command " + command + '\n');
|
||||
|
||||
if (command in this._handler)
|
||||
response = this._handler[command](args);
|
||||
|
@ -442,11 +443,11 @@ nsMailReader.prototype = {
|
|||
response = response + "\r\n";
|
||||
|
||||
if (this._debug == fsDebugRecvSend) {
|
||||
print("SEND: " + response.split(" ", 1)[0]);
|
||||
dump("SEND: " + response.split(" ", 1)[0] + '\n');
|
||||
}
|
||||
else if (this._debug == fsDebugAll) {
|
||||
var responses = response.split("\n");
|
||||
responses.forEach(function (line) { print("SEND: " + line); });
|
||||
responses.forEach(function (line) { dump("SEND: " + line + '\n'); });
|
||||
}
|
||||
|
||||
if (this.transaction)
|
||||
|
@ -461,7 +462,7 @@ nsMailReader.prototype = {
|
|||
}
|
||||
|
||||
if (this._isRunning) {
|
||||
stream.asyncWait(this, 0, 0, gThreadManager.currentThread);
|
||||
stream.asyncWait(this, 0, 0, Services.tm.currentThread);
|
||||
this.timer.initWithCallback(this.observer, TIMEOUT,
|
||||
Ci.nsITimer.TYPE_ONE_SHOT);
|
||||
}
|
||||
|
@ -505,41 +506,3 @@ nsMailReader.prototype = {
|
|||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new fakeserver listening for loopback traffic on the given port,
|
||||
* starts it, runs the server until the server processes a shutdown request,
|
||||
* spinning an event loop so that events posted by the server's socket are
|
||||
* processed, and returns the server transaction log.
|
||||
*
|
||||
* This method is primarily intended for use in running this script manually
|
||||
* from within xpcshell and running a functional fakeserver without having to
|
||||
* deal with entire testing frameworks. For example, it could be connected to
|
||||
* from telnet or a non-testing version of mailnews for non-automated tests.
|
||||
* Actual testing code should abstain from using this method because the
|
||||
* server does not persist for multiple tests and it hogs the main thread when
|
||||
* called.
|
||||
*
|
||||
* Note that running multiple servers using variants of this method probably
|
||||
* doesn't work, simply due to how the internal event loop is spun and stopped.
|
||||
*
|
||||
* @param port
|
||||
* the port on which the server will run, or -1 if there exists no preference
|
||||
* for a specific port; note that attempting to use some values for this
|
||||
* parameter (particularly those below 1024) may cause this method to throw or
|
||||
* may result in the server being prematurely shut down
|
||||
* @param handler
|
||||
* the handler (as defined in the documentation comment above nsMailReader) to
|
||||
* use on the server
|
||||
* @param daemon
|
||||
* the daemon (as defined in the documentation comment above nsMailReader) to
|
||||
* use on the server
|
||||
*/
|
||||
function server(port, handler, daemon) {
|
||||
var srv = new nsMailServer(handler, daemon);
|
||||
srv.start(port);
|
||||
srv.performTest();
|
||||
return srv.playTransaction();
|
||||
}
|
||||
|
||||
} // gMaild_js__
|
||||
|
|
|
@ -24,8 +24,7 @@ if (typeof gDEPTH == "undefined")
|
|||
|
||||
// add imap fake server methods if missing
|
||||
|
||||
if (typeof gMaild_js__ == "undefined")
|
||||
load(gDEPTH + "mailnews/fakeserver/maild.js");
|
||||
Components.utils.import("resource://testing-common/mailnews/maild.js");
|
||||
if (typeof AuthPLAIN == "undefined")
|
||||
load(gDEPTH + "mailnews/fakeserver/auth.js");
|
||||
if (typeof imapDaemon == "undefined")
|
||||
|
|
|
@ -23,8 +23,7 @@ if (typeof gDEPTH == "undefined")
|
|||
do_throw("gDEPTH must be defined when using IMAPpump.js");
|
||||
|
||||
// Import the pop3 server scripts
|
||||
if (typeof nsMailServer == 'undefined')
|
||||
load(gDEPTH + "mailnews/fakeserver/maild.js");
|
||||
Components.utils.import("resource://testing-common/mailnews/maild.js");
|
||||
if (typeof AuthPLAIN == 'undefined')
|
||||
load(gDEPTH + "mailnews/fakeserver/auth.js");
|
||||
if (typeof pop3Daemon == 'undefined')
|
||||
|
@ -63,7 +62,7 @@ POP3Pump.prototype._urlListener =
|
|||
// If we have an error, clean up nicely.
|
||||
gPOP3Pump._server.stop();
|
||||
|
||||
var thread = gThreadManager.currentThread;
|
||||
var thread = Services.tm.currentThread;
|
||||
while (thread.hasPendingEvents())
|
||||
thread.processNextEvent(true);
|
||||
}
|
||||
|
@ -116,7 +115,7 @@ POP3Pump.prototype._checkBusy = function _checkBusy()
|
|||
|
||||
if (this._finalCleanup)
|
||||
{
|
||||
if (gThreadManager.currentThread.hasPendingEvents())
|
||||
if (Services.tm.currentThread.hasPendingEvents())
|
||||
do_timeout(20, _checkPumpBusy);
|
||||
else
|
||||
{
|
||||
|
@ -176,7 +175,7 @@ POP3Pump.prototype._testNext = function _testNext()
|
|||
do_throw(e);
|
||||
} finally
|
||||
{
|
||||
var thread = gThreadManager.currentThread;
|
||||
var thread = Services.tm.currentThread;
|
||||
while (thread.hasPendingEvents())
|
||||
thread.processNextEvent(true);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче