Your Search Results


    In This Article
    1. Running tests
      1. Running the whole test suite
      2. Running select tests
      3. Running tests without mach
    2. Running tests on comm-central (Thunderbird, SeaMonkey)
    3. Running specific tests
      1. Running mochitests under Electrolysis (e10s) for Fennec
      2. Running mochitests under Electrolysis (e10s) for Desktop builds.
      3. Running and debugging mochitests on Android
      4. Running failed tests
      5. Debugging individual tests
      6. Finding errors
      7. Logging results
      8. Diverting X output
      9. Other options
    4. Writing tests
      1. Try to avoid Mochitest
      2. Best practices
      3. Test templates
      4. Asynchronous Tests
      5. Test functions
      6. Helper functions
    5. Adding tests to the tree
      1. Choosing a location
      2. Add an entry to mochitest.ini
      3. Building and running new tests
    6. SSL and https-enabled tests
      1. How it works
    7. Getting Stack Traces
    8. FAQ
      1. What if my tests aren't done when onload fires?
      2. How can I get the full log output for my test in automation for debugging?
      3. What if I need to change a preference to run my test?
      4. Can tests be run under a chrome URL?
      5. How can I get around the error "Permission denied to get property XPCComponents.classes"?
      6. How do I change the HTTP headers or status sent with a file used in a Mochitest?
      7. How do I test issues which only show up when tests are run across domains?
      8. How do I write tests that check header values, method types, etc. of HTTP requests?
        1. Properties and methods of Request object
      9. How do I keep state across loads of different server-side scripts?
      10. How do I write a SJS script which responds asynchronously
      11. How do I get access to the files on the server as XPCOM objects from an SJS script? (1.9.3 or later)

    Mochitest is an automated testing framework built on top of the MochiKit JavaScript libraries. It's just one of the automated regression testing frameworks used by Mozilla. Tests report success or failure to the test harness using JavaScript function calls.

    Mochitest's use of JavaScript function calls to communicate test success or failure can make it unsuitable for certain types of test. Only things that can in some way be tested using JavaScript (with chrome privileges!) can be tested with this framework. Given some creativity, that's actually much more than you might first think, but it's not possible to write Mochitest tests to directly test a non-scripted C++ component, for example.  (Use a compiled-code test to do that.)

    Browser chrome tests are similar to mochitests, but are typically used to test browser chrome features. The tests are defined in a JavaScript file instead of an HTML, XHTML, or SVG file.

    Running tests

    The Mozilla build machines run Mochitest as part of the build process, so we get to know pretty quickly if someone commits a change to the source code that breaks something. However, you should still run Mochitest yourself before you commit any risky new code. You don't want to be the one who wastes everyone's time by breaking the tree if you can help it. :-)

    Running the whole test suite

    To run Mochitest, first build Mozilla with your changes; then run

    ./mach mochitest-plain


    Note: you should keep focus on the browser window while the test are being run, as some may fail otherwise (like the one for bug 330705 for example). Linux users can save themselves this inconvenience by using a dummy X server (see Diverting X output below).

    Running select tests

    To run a single test (perhaps a new test you just added) or a subset of the entire Mochitest suite, pass a path parameter to the mach command. For example, to run only the test test_CrossSiteXHR.html in the Mozilla source tree, you would run this command:

    ./mach mochitest-plain dom/base/test/test_CrossSiteXHR.html

    Note that mochitest-plain is an example. There are multiple categories of mochitests. Depending on the test you want to run, use either mochitest-plain, mochitest-chrome, mochitest-browser-chrome, mochitest-a11y or mochitest-ipcplugins.

    Running individual tests on the b2g emulators will always cause a timeout. Run all the tests in a directory instead for b2g emulators locally.

    To run all the tests in dom/svg/, this command would work:

    ./mach mochitest-plain dom/svg/

    Note that the path specified is the path to the test or directory within the Mozilla source tree. If the path is a directory, then the tests in that directory and all of its subdirectories will be loaded.

    Running tests without mach

    You can also run tests without a build environment or mach.  The easiest way to do this is to downlaod the file corresponding to your platform, and extract it, and then follow these directions, which assume you have both pip and virtualenv installed.

    cd $tests_zip
    virtualenv venv # create your virtualenv
    source venv/bin/activate # activate your virtualenv
    cd config
    pip install -r mozbase_requirements.txt
    cd ../mochitest
    python --help

    Running tests on comm-central (Thunderbird, SeaMonkey)

    Currently (as of August 2013) you cannot use mach to run tests in comm-central applications. You need to run the "old" pymake commands inside the obj-dir (if you use one). See pymake for how to use pymake on Windows. For example, to run only the test test_CrossSiteXHR.html in the Mozilla source tree, you would run this command:

    TEST_PATH=content/base/test/test_CrossSiteXHR.html make -C $(OBJDIR) mochitest-plain

    Note that mochitest-plain is an example. There are multiple categories of mochitests. Depending on the test you want to run, use either mochitest-plain, mochitest-chrome, mochitest-browser-chrome, mochitest-a11y or mochitest-ipcplugins.

    To run all the tests in, this command would work:

    TEST_PATH=suite/common/ make -C $(OBJDIR) mochitest-chrome

    Note that currently (due to bug 907434) you must not specify any objdir in your .mozconfig. You need to use the default one to be able to run tests! If you don't like the default choice, you can use symbolic links (also works on Windows, see the bug for details) to redirect the objdir to another folder.

    Running specific tests

    You can easily run mochitest-1 through mochitest-5 by specifying them on the make command line. For example:

    make mochitest-1

    Or, using mach

    ./mach test mochitest-1

    This lets you mimic the buildbot behavior instead of having to run the entire test suite or dig through the buildbot code to figure out the syntax to run tests for specific issues found by the try server.

    To run a specific mochitest 1-9 for b2g emulators, do:

    ./mach mochitest-remote --total-chunks 9 --this-chunk N // N here is which mochitest suite. e.g. 3 for mochitest 3

    Running mochitests under Electrolysis (e10s) for Fennec

    To run your mochitest in a child tab process, all you need to do is run it in a tree that's built for fennec, i.e. was configured with

    ac_add_options --enable-application=mobile

    OMG it's so easy!  (This works for Linux desktop fennec builds, and ought to for Windows and Android builds.  OSX may vary depending on the state of our e10s implementation there.)

    On Mac, it is necessary to patch to remove the unconditional "-bin" appended to the appname, and then run mochitests with the following invocation:


    Running mochitests under Electrolysis (e10s) for Desktop builds.

    To run your mochitest in an electrolysis environment for desktop, specify an --e10s option to mach's mochitest command (eg, ./mach mochitest-browser --e10s ...).  This will cause the profile created for testing to have the preference browser.tabs.remote set to true before starting the test suite.

    Running and debugging mochitests on Android

    Instructions on how to run Mochitests in Firefox Mobile (Fennec) on Android are over on, as are instruction on how to use remote debugging to debug Mochitests on Firefox Mobile (Fennec) on Android.

    Running failed tests

    After running mochitests, you might have some errors.  If you do, you can run make mochitest-plain-rerun-failures to run just the tests that failed

    make mochitest-plain
    make mochitest-plain-rerun-failures

    This feature is possible by writing a failures.json file to the root of the mochitest directory ($(objdir)/_tests/testing/mochitest) during the first run.  When rerunning the failures, it uses the --run-only-tests flag to just run the tests in the failures.json file.

    Debugging individual tests

    If you need to debug an individual test, you can generally use the aforementioned method for running only that test, attach a debugger to Firefox, and just reload the page containing the test with the debugger attached.  If attaching a debugger before the problem shows up is hard (for example, if the browser crashes as the test is loading), you can specify a debugger when you run mochitest:

    ./mach mochitest-plain --debugger=gdb ...

    See also the --debugger-args and --debugger-interactive arguments.

    Finding errors

    Search for the string "TEST-UNEXPECTED-FAIL" to find unexpected failures. You can also search for "SimpleTest FINISHED" to see the final test summary. This is particularly useful when viewing full Tinderbox logs, since the Mochitest output isn't necessarily at the end of the combined log.

    Logging results

    The output from a test run can be sent to the console and/or a file (by default the results are only displayed in the browser). There are several levels of detail to choose from. The levels are DEBUG, INFO, WARNING, ERROR and CRITICAL, where DEBUG produces the highest detail (everything), and CRITICAL produces the least.

    Mochitest uses structured logging. This means that you can use a set of command line arguments to configure the log output. To log to stdout using the mach formatter and log to a file the raw json logs, you can use --log-mach=- --log-raw=mochitest.log. By default the file logging level for all your formatters is INFO but you can change this using --log-mach-level=LEVEL.

    To turn on logging to the console use --console-level=LEVEL.

    For example, to log test run output with the default (tbpl) formatter to the file ~/mochitest.log at DEBUG level detail you would use:

    python --log-tbpl=~/mochitest.log --log-tbpl-level=DEBUG

    Diverting X output

    The tests must run in a focused window, which effectively prevents any other user activity on the engaged computer. Linux users can reclaim their boxes by telling the suite to use a hidden virtual desktop. If xvfb is or can be installed, the following command launches the tests without blocking the active session:

    nice xvfb-run python _tests/testing/mochitest/ --log-tbpl=./mochitest-plain.log --log-tbpl-level=DEBUG --autorun --close-when-done --console-level=DEBUG

    Other possible configurations have also been discussed in bug 434365.

    Other options

    The script recognizes several other options - use the --help option to get a list. Note that there is separate documentation for the --chrome, --browser-chrome and --a11y options.

    Running a test with extensions installed

    Writing tests

    A Mochitest test is simply an HTML, XHTML or XUL file that contains some JavaScript to test for some condition(s).

    You can use Mochitest maker to run most tests without having to build Mozilla.

    Try to avoid Mochitest

    Yes, really. For many things Mochitest is overkill. In general you should always try to use one of the lighter-weight testing frameworks. For example, if you only want to test a single XPCOM component then you should use xpcshell. On the other hand there are some things that Mochitest cannot do, or isn't designed to do. For example, for visual output tests you should try to use the reftest framework. For more information on the different types of automated testing frameworks see Mozilla automated testing.

    Best practices

    Please follow the tips for Avoiding intermittent test failures when writing tests.

    Test templates

    You can avoid typing out boilerplate by using the perl script to generate a test template. This script takes two optional arguments:

    1. -b : a bug number
    2. -type : template type. {html|xhtml|xul|chrome}. defaults to html.

    For example:

    cd testing/mochitest/
    perl -b=123456 > path/to/test_bug123456.html
    perl -b=123456 --type=xul > path/to/test_bug123456.xul

    Note that Mochitest requires the file name of all tests to begin with the string "test_", while mochitest-browser-chrome tests must begin with "browser_". See the section below for help on deciding where your tests should go in the tree.

    In addition to Mochitest boilerplate code, the script will generate an element with the id 'content' and an element with the id 'display'. Your test may manipulate these elements as well as other elements you add to the page.

    Asynchronous Tests

    Sometimes tests involve asynchronous patterns, such as waiting for events or observers. In these cases, you will need to call waitForExplicitFinish and finish like so:

    addEventListener("keypress", function() {
      // ... run test ...
    }, false);
    // ... simulate key press ...

    When writing async tests, you can use the add_task method with Promises. See the xpcshell documentation for more information about this.

    If you need more time, requestLongerTimeout(number) can be quite useful.  requestLongerTimeout() takes an integer factor that is a multiplier for the the default 30 seconds timeout. So a factor of 2 means: "Wait for at last 60s (2*30s)". This is really useful if you want to pause exection to do a little debugging.

    Test functions

    Each test must contain some JavaScript that will run and tell Mochitest whether the test has passed or failed. SimpleTest.js provides a number of functions for the test to use that communicate the pass/fail to Mochitest. These include:

    • ok(expressionThatShouldBeTrue, "Description of the check") -- tests a value for truthiness
    • is(actualValue, expectedValue, "Description of the check") -- compares two values (using ==, not ===)
    • isnot(actualValue, unexpectedValue, "Description of the check") -- opposite of is()

    If you want to include a test for something that currently fails, don't just comment it out!  Instead, use one of the "todo" equivalents so Tinderbox can notice if it suddenly starts passing (at which point the test can be reenabled):

    • todo(falseButShouldBeTrue, "Description of the check")
    • todo_is(actualValue, expectedValue, "Description of the check")
    • todo_isnot(actualValue, unexpectedValue, "Description of the check")

    Additionally, tests can use the assertion methods provided by Assert.jsm. It implements the CommonJS Unit Testing specification version 1.1, which provides a basic, standardized interface for performing in-code logical assertions with optional, customizable error reporting. It is highly recommended to use these assertion methods, instead of the ones mentioned above.
    These function include:

    • export_assertions() - Call this function to tack all the assertion methods defined in Assert.jsm to the tests' global scope. These methods are already available on the global Assert object, but authors might find this not convenient enough.
    • Assert.ok(value, message)
    • Assert.equal(actual, expected, message)
    • Assert.notEqual(actual, expected, message)
    • Assert.deepEqual(actual, expected, message)
    • Assert.notDeepEqual(actual, expected, message)
    • Assert.strictEqual(actual, expected, message)
    • Assert.notStrictEqual(actual, expected, message)
    • Assert.throws(block, expected, message)

    Tests can call a function info("Message string") to write a message to the test log.

    Helper functions

    Right now, useful helpers derived from MochiKit are available in testing/mochitest/tests/SimpleTest/SimpleTest.js, but all of Mochikit is available at testing/mochitest/MochiKit, but please only include files that you require to minimize test load times. bug 367569 added sendChar, sendKey, and sendString helpers. These are available in testing/mochitest/tests/SimpleTest/EventUtils.js.

    If you need to access some data files from your mochitest, you can get an URI for them, by using SimpleTest.getTestFileURL("relative/path/to/data.file") . Then you can eventually fetch their content by using XMLHttpRequest.

    Adding tests to the tree

    Once you've written a new test you need to add it to the Mozilla source tree and tell the build system about it so that the Mozilla tinderboxes will run it automatically.

    Choosing a location

    New Mochitest tests should go somewhere close to the code they are testing, hopefully in the same module, so that ownership of the test cases is clear. For example, if you create a new test for some HTML feature, you probably want to put the test in content/html/content/test or content/html/document/test. If a test directory does not exist near the code you are testing you can add a new test directory as the patch in bug 368531 demonstrates.

    Add an entry to mochitest.ini

    To tell the build system about your new test you need to add your test file to the mochitest.ini in your test's directory. For example, let's say you are adding a new test called 'test_new_feature.html'. Simply edit the mochitest.ini (or chrome.ini etc. depending on the mochitest flavor) in the same directory and add a new line:


    Optionally you can specify metadata for your test, like whether to skip the test on certain platforms:

    skip-if = os == 'win'

    The mochitest.ini format, recognized by the parser, defines a long list of metadata.

    Building and running new tests

    Before committing a new test you should check that the changes are correct and that your tests pass as you expect them to. To check your test, first export it to the Mochitest directory by running the command:

    ./mach build path

    giving the path of the directory that contains the test file. Now run Mochitest as explained above.

    SSL and https-enabled tests

    Mochitests must be run from http://mochi.test/ to succeed; however, some tests may require use of additional protocols, hosts, or ports to test cross-origin functionality.  The Mochitest harness addresses this need by mirroring all content of the original server onto a variety of other servers through the magic of proxy autoconfig and SSL tunneling.  The full list of schemes, hosts, and ports on which tests are served, all of which serve exactly the same content as http://mochi.test/, is specified in build/pgo/server-locations.txt.  Note, however, that not all origins described there are equivalent: some specify particular SSL certificates for testing purposes, while some allow pages on that server to request elevated privileges; read the file for full details.

    How it works

    The Mochitest harness includes preference values which cause the browser to use proxy autoconfig to match requested URLs with servers.  The network.proxy.autoconfig_url preference is set to a data: URL which encodes a JavaScript function, FindProxyForURL, which determines the host to which a given URL is mapped.  In the case of SSL sites to be mirrored, the function maps them to an SSL tunnel which transparently forwards the traffic to the actual server, as per the description of the CONNECT method given in RFC 2817.  In this manner a single HTTP server at can successfully emulate dozens of servers at distinct locations.

    For further details on Mochitest SSL functionality and how to modify it to change a certificate or add a new https server, see Modifying Mochitest SSL behavior.

    Getting Stack Traces

    To get stack when Mochitest crashes:

    1. Get a minidump_stackwalk binary for your platform from
    2. Set the MINIDUMP_STACKWALK environment variable to point to the absolute path of the binary.

    If the resulting stack trace doesn't have line numbers, run make buildsymbols to generate the requisite symbol files.  See Building Firefox with Debug Symbols for more information.


    What if my tests aren't done when onload fires?

    Call SimpleTest.waitForExplicitFinish() before onload fires. Then, when you're done, call SimpleTest.finish().

    How can I get the full log output for my test in automation for debugging?

    Add the following to your test:


    What if I need to change a preference to run my test?

    The SpecialPowers object provides APIs to get and set preferences.

    var oldVal = SpecialPowers.getIntPref("dom.max_script_run_time");
    SpecialPowers.setIntPref("dom.max_script_run_time", 0);
    // do what you need
    SpecialPowers.setIntPref("dom.max_script_run_time", oldVal);

    Note that on b2g pref setting happens asynchronously. Use PushPrefEnv instead, which offers a completion callback you can start your test from after the change has propagated to the parent process.

    If you need to change a pref when running a test locally, you can set the environment variable EXTRA_TEST_ARGS when running the mochitest-plain make target.


    If you need to change a string pref, enclose the value in backslash-escaped double quotes:


    Can tests be run under a chrome URL?

    Yes, use ./mach mochitest-chrome. Keep in mind that the xpcshell test harness should be your first choice for XPCOM testing. Only use mochitest if you need events, browser features, networking, etc.

    How can I get around the error "Permission denied to get property XPCComponents.classes"?

    If your test needs to perform very specific privileged actions, you should either use one of the existing SpecialPowers APIs, or see if you can add a new API to the SpecialPowers object. If your test needs to use a wide variety of privileged objects and APIs, you should write your test as a Chrome Mochitest instead.

    Do not use enablePrivilege in new tests. It will be removed in a future version of Gecko.

    How do I change the HTTP headers or status sent with a file used in a Mochitest?

    Create a text file next to the file whose headers you want to modify. The name of the text file should be the name of the file whose headers you're modifying followed by ^headers^. For example, if you have a file foo.jpg, the text file should be named foo.jpg^headers^. (Don't try to actually use the headers file in any other way in the test, because the HTTP server's hidden-file functionality prevents any file ending in exactly one ^ from being served.) Edit the file to contain the headers and/or status you want to set, like so:

    HTTP 404 Not Found
    Content-Type: text/html
    Random-Header-of-Doom: 17

    The first line sets the HTTP status and (optionally a) description associated with the file. This line is optional; you don't need it if you're fine with the normal response status and description. Any other lines in the file describe additional headers which you want to add or overwrite (most typically the Content-Type header, for the latter case) on the response. The format follows the conventions of HTTP, except that you don't need to have HTTP line endings and you can't use a header more than once (the last line for a particular header wins). The file may end with at most one blank line to match Unix text file conventions, but the trailing newline isn't strictly necessary.

    How do I test issues which only show up when tests are run across domains?

    The Mochitest harness runs one web server to serve tests, but through the magic of proxy autoconfig, all test files are available on a variety of different domains and ports. The full list of domains and ports on which tests are served, all of which serve exactly the same content as http://mochi.test/, is specified in build/pgo/server-locations.txt. If your test needs to violate cross-origin security to test something, please consult with a Mochitest peer about your options, as they are still in development.

    Do not use enablePrivilege in new tests. It will be removed in a future version of Gecko.

    How do I write tests that check header values, method types, etc. of HTTP requests?

    To write such a test, you simply need to write an SJS (server-side JavaScript) for it. An SJS is simply a JavaScript file with the extension .sjs which is loaded in a sandbox. Don't forget to reference it from your "mochitest.ini" file too!

      support-files =

    The global property handleRequest defined by the script is then executed with request and response objects, and the script populates the response based on the information in the request.

    Here's an example of a simple SJS:

    function handleRequest(request, response) {
      //Allow cross-origin, so you can XHR to it! 
      response.setHeader("Access-Control-Allow-Origin", "*", false);  
      // avoid confusing cache behaviors
      response.setHeader("Cache-Control", "no-cache", false);
      response.setHeader("Content-Type", "text/plain", false);
      response.write("Hello world!");

    The file is run, for example, at etiher http://mochi.test:8888/tests/PATH/TO/YOUR/test_file.sjshttp://{server-location}/tests/PATH/TO/YOUR/test_file.sjs - see build/pgo/server-locations.txt for server locations! Note the "test/tests" bit at the front of the URL. If you want to actually execute the file, you need to reference it somehow. For instance, you can XHR to it OR you could use a HTML element:

    var xhr = new XMLHttpRequest();"GET", "http://test/tests/dom/manifest/test/test_file.sjs"); 
    xhr.onload = function(e){ console.log("loaded!", this.responseText)}

    The exact properties of the request and response parameters are defined in the nsIHttpRequestMetadata and nsIHttpResponse interfaces in nsIHttpServer.idl. However, here are a few useful ones:

    Properties and methods of Request object

    string, the scheme of the request.
    string, the host of the request
    string, the port of the request.
    string, the HTTP method.
    string, the protocol version, typically "1.1".
    string, path of the request,
    object, name and values representing the headers.
    string, the query string of the requested URL.
    .getHeader( name )
    Gets a request header by name.
    .hasHeader( name )
    Boolean, checks if a header was provided with the request.

    Note: the browser is free to cache responses generated by your script, so if you ever want an SJS to return different data for multiple requests to the same URL, you should add a Cache-Control: no-cache header to the response to prevent the test from accidentally failing if it's manually run multiple times in the same Mochitest session.

    How do I keep state across loads of different server-side scripts?

    Server-side scripts in Mochitest are run inside sandboxes, with a new sandbox created for each new load.  Consequently, any variables set in a handler don't persist across loads.  To support state storage, use the getState(k) and setState(k, v) methods defined on the global object.  These methods expose a key-value storage mechanism for the server, with keys and values as strings.  (Use JSON to store objects and other structured data.)  Note that because the myriad servers in Mochitest are in reality a single server with some proxying and tunnelling magic, stored state is the same in all servers at all times.

    The getState and setState methods are scoped to the path being loaded.  For example, the absolute URLs /foo/bar/baz/foo/bar/baz?quux, and /foo/bar/baz#fnord all share the same state; the state for /foo/bar is entirely separate.  You should use per-path state whenever possible to avoid inter-test dependencies and bugs.  However, in rare cases it may be necessary for two scripts to collaborate in some manner, and it may not be possible to use a custom query string to request divergent behaviors from the script.  For this use case only you should use the getSharedState(k, v) and setSharedState(k, v) methods defined on the global object.  No restrictions are placed on access to this whole-server shared state, and any script may add new state that any other script may delete.  To avoid conflicts, you should use a key within a faux namespace so as to avoid accidental conflicts as far as is possible; for example, if you needed shared state for an HTML5 video test, you might use a key like

    A further form of state storage is provided by the getObjectState(k) and setObjectState(k, v) methods, which will store any nsISupports object.  These methods reside on the nsIHttpServer interface in this form, but a limitation of the sandbox object used by the server to process SJS responses means that the former is present in the SJS request handler's global environment with the signature getObjectState(k, callback), where callback is a function to be invoked by getObjectState with the object corresponding to the provided key as the sole argument.  Note that this value mapping requires the value to be an XPCOM object; an arbitrary JavaScript object with no QueryInterface method is insufficient.  If you wish to store a JavaScript object, you may find it useful to provide the object with a QueryInterface implementation and then make use of wrappedJSObject to reveal the actual JavaScript object through the wrapping performed by XPConnect.

    For further details on state-saving mechanisms provided by httpd.js, see netwerk/test/httpserver/nsIHttpServer.idl and the nsIHttpServer.get(Shared|Object)?State methods.

    How do I write a SJS script which responds asynchronously

    Sometimes you need to respond to a request asynchronously, for example after waiting for a short period of time. You can do this by using the processAsync() and finish() functions on the response object passed to the handleRequest() function.

    processAsync() must be called before returning from handleRequest(). Once called, you can at any point call methods on the request object to send more of the response. Once you are done, call the finish() function. For example you can use the setState()/getState() functions described above to store a request and later retrieve and finish it. However be aware the the browser often reorders requests and so your code must be resilient to that to avoid intermittent failures.

    var timer = null;
    function handleRequest(request, response)
      response.setHeader("Content-Type", "text/plain", false);
      timer = Components.classes[";1"].createInstance(Components.interfaces.nsITimer);
      }, 5 * 1000 /* milliseconds */, Components.interfaces.nsITimer.TYPE_ONE_SHOT);

    For more details, see the processAsync() function documentation in netwerk/test/httpserver/nsIHttpServer.idl.

    How do I get access to the files on the server as XPCOM objects from an SJS script? (1.9.3 or later)

    If you need access to a file, say, because it's easier to store image data in a file than directly in an SJS script, use the presupplied SERVER_ROOT object state available to SJS scripts running in Mochitest:

    function handleRequest(req, res)
      var file;
      getObjectState("SERVER_ROOT", function(serverRoot)
        file = serverRoot.getFile("tests/content/media/test/320x240.ogv");
      // file is now an XPCOM object referring to the given file
      res.write("file: " + file);

    The path you specify is used as a path relative to the root directory served by httpd.js , and an nsIFile corresponding to the file at that location is returned.  Beware of typos: the file you specify doesn't actually have to exist because file objects are mere encapsulations of string paths.