Your Search Results

    MailNews xpcshell-tests

    Draft
    This page is not complete.

    MailNews xpcshell-tests are written and run in the same manner as the core xpcshell-tests. This page describes additional resources and facilities that MailNews has developed to support the xpcshell-tests; see the core xpcshell-tests page for more information on how to develop these.

    Workaround for mach problems

    At the moment, mozilla/mach xpcshell-test does not work (see Bug 934170). As a workaround, use the following:

    • First, switch to the object directory after building Thunderbird.
    • To run all xpcshell tests, use: make xpcshell-tests
    • To run a single xpcshell test, use (e.g.): make xpcshell-tests TEST_PATH=mailnews/news/test/unit/test_server.js
    • To run all xpcshell tests in a given directory, use (e.g.): make xpcshell-tests TEST_PATH=mailnews/news

    Review Requirements for new tests

    See MailNews Review Requirements.

    Memory Leaks

    When running the xpcshell-tests or check-one commands, if the test is successful and there are no reference count leaks, it will output:

    TEST-PASS | /Users/moztest/comm/main/tb/mozilla/_tests/xpcshell/test_mailnewsbase/unit/test_nsIMsgFolderListener.js | test passed
    

    If the test is successful, and there are reference count leaks, it will output something similar to:

    TEST-PASS | /Users/moztest/comm/main/tb/mozilla/_tests/xpcshell/test_mailnewsbase/unit/test_nsIMsgFolderListenerLocal.js | test passed
    
    == BloatView: ALL (cumulative) LEAK STATISTICS
    
         |<----------------Class--------------->|<-----Bytes------>|<----------------Objects---------------->|<--------------References-------------->|
                                                  Per-Inst   Leaked    Total      Rem      Mean       StdDev     Total      Rem      Mean       StdDev
       0 TOTAL                                          32      300    14949        6 (  155.82 +/-   189.73)    51641        6 (  148.25 +/-   229.91)
      28 morkObject                                     44      132      481        3 (   54.62 +/-    15.38)     1362        3 (   76.49 +/-    20.87)
      29 morkRowObject                                  56      168       97        3 (   17.40 +/-     4.96)      127        3 (   17.05 +/-     5.46)
    
    nsTraceRefcntImpl::DumpStatistics: 199 entries
    

    There are some mailnews tests which are currently known to leak, these are covered by the tracking bug bug 498147 and bug 438922. The general policy is that new tests shouldn't leak, unless covered by existing bugs. If new tests really need to land with leaks, then they must have bugs covering the leak.

    Test Startup and Profile Details

    All MailNews xpcshell-test directories have a head_*.js file that imports mailDirService.js. This file:

    • Will remove any existing files in the directory <objdir>/mozilla/_tests/mailtest.
    • Will set up an nsIDirectoryServiceProvider which will register <objdir>/mozilla/_tests/mailtest as the profile directory to use for each xpcshell-tests.
    • Provides a gProfileDir global variable that contains a nsIFile set up to point at <objdir>/mozilla/_tests/mailtest.

    Test Shutdown

    All MailNews xpcshell-tests directories should have a tail_*.js file that imports mailShutdown.js. This is done so that mailnews is shutdown correctly at the end of the unit tests which in turn ensures representative leak logs. The shutdown sequence is as follows:

    1. Do a cycle collection to clean up any js objects that are no longer required.
    2. Post the following shutdown notifications via the observer service:
      1. quit-application
      2. profile-change-net-teardown
      3. profile-change-teardown
      4. profile-before-change
    3. Unregisters the profile directory provider.

    Helper Resources

    Fake Servers

    The MailNews xpcshell-tests have available a selection of fake servers that are used to simulate IMAP, POP3, NNTP and SMTP servers. More information is available here.

    General Helpers

    There are a variety of helper functions and objects in the files within the http://mxr.mozilla.org/comm-central/source/mailnews/test/resources/ directory. These give facilities such as:

    To load these into xpcshell-tests use the command:

    load("../../mailnews/resources/<filename>");
    

     

    Document Tags and Contributors

    Contributors to this page: jenzed, tessarakt4, Standard8, Sheppy
    Last updated by: tessarakt4,