MailNews:Fakeserver
Fakeserver is a testing server that implements a generic text-based protocol common to all major mailnews protocols (POP, IMAP, SMTP, and NNTP) designed for use in automated tests. It can also be used in manual QA tests.
Basic Structure
Fakeserver is situated entirely under mailnews/test/fakeserver/. It is comprised of three major components: a daemon, a handler, and the server itself.
The server itself is found in mailnews/test/fakeserver/maild.js and was largely based off of the httpd fakeserver from network code. It utilizes UTF-8 as its transport mechanism and is capable of performing proper pipelining of commands.
The other two components are specific to the protocol type and found under similar files in the same directory (e.g., smtpd.js).
A daemon is information about the server that can be manipulated. An example of such a manipulation is adding a folder or adding messages. Daemons should usually persist for the entirety of the test.
The handler is the glue between the server and the daemon. This area will be the most diverse of all components, as edge cases with quirky servers being liberal with the specs will require different handlers.
Writing a new fakeserver
Since the number of protocols we use is very small, most people shouldn't have to write an entirely new daemon and handler setup by themselves. That said, someone writing a new test may have to take into account a new handler.
A handler will contain the following methods:
| Name | Arguments | Returns | Notes |
|---|---|---|---|
| [command] | rest of sent line | Server's response | The name is normalized to be uppercase. |
| onError | command, rest of sent line | Server's response | Called if handler does not define the command function. |
| onStartup | none | Server's response | Called when a connection is made. |
| onMultiline | sent line | Server's response or nothing | Called when in multi-line mode. |
| postCommand | Server object | none | Called after every command. |
The server is smart about the responses and will normalize all occurrences of '\n' (but not '\r') to '\r\n' for you, as well as append the '\r\n' to the response if not present. It will also properly queue all messages sent in pipelining mode and will present lines without any EOL characters. In addition, it uses UTF-8 as the transmission medium.
The server presents the following API to the handler:
| Name | Arguments | Returns | Description |
|---|---|---|---|
| closeSocket | none | nothing | Closes the socket and stops the test. |
| setMultiline | the new value of multiline | nothing | The value is a boolean, with true invoking multiline mode. It is off by default. |
Extending a handler to provide different mechanisms is a process not defined here; please check the documentation of the corresponding handler for instructions.
Using fakeserver in xpcshell tests
Using fakeserver in QA testing
Specific fakeserver guidelines
POP
No POP fakeserver exists yet.
IMAP
No IMAP fakeserver exists yet.
SMTP
The SMTP fakeserver is still unfinished.
NNTP
The NNTP fakeserver is still unfinished.