Login for advanced functionality like tracking watched videos!

Cheatsheet

Repositories

Debugging XUL apps

  • Preferences should be in a .js file in the directory %appname%/defaults/preferences/.
  • pref("browser.dom.window.dump.enabled", true);
    pref("javascript.options.showInConsole", true);
    pref("javascript.options.strict", true);
    pref("nglayout.debug.disable_xul_cache", true);
    pref("nglayout.debug.disable_xul_fastload", true);

  • To write to the Error Console:

    Components.utils.reportError("0");

  • To write to the console:

    dump("hello world!");

Command Line

  • -purgecaches use when changing XUL, XBL, JSM, ...
  • -no-remote allows you to run multiple instances of the program with different profiles
  • -console starts the application with a debug console
  • -ProfileManager starts the application with the profile manager
  • -P "profilename" starts the application with the specified profile
  • -console starts firefox with an extra console, you can then enable extra logs like app.update.log in about:config
  • Other command line options

Crashes

Useful links if you are an employee

Coding style

  • Line length: 80 chars or less
  • Indenting: 2 spaces (no tabs)
  • Function definitions, braces on newlines
  • Conditionals and loops:

    if (condition) { }

  • Multiline, align with parentheses:

    if (argument1 == paramvalue1 && argument2 == paramvalue2 &&     argument3 == paramvalue3 && argument4 == paramValue4) { }

  • Comments, use space after comment indicator
  • More info on coding style

Build commands

  • Full build of Firefox: (~ 1.5h when run the first time)

    mach build

  • To clean: (~2min)

    mach clobber

  • Incremental builds (~1min, see below section)

    mach build

  • Redirect output for faster builds

    mach build >out.txt 2>&1

Example .mozconfig files (Gecko 2.0 and up)

  • Firefox Debug .mozconfig contents: (Using mozilla-central)

    mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/objdir-ff-debug
    ac_add_options --enable-application=browser
    ac_add_options --enable-debug
    ac_add_options --disable-optimize
    ac_add_options --enable-tests

  • Firefox Release .mozconfig contents: (Using mozilla-central)

    mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/objdir-ff-debug
    ac_add_options --enable-application=browser
    ac_add_options --enable-optimize
    ac_add_options --enable-debug-symbols

  • xulrunner .mozconfig contents: (Using mozilla-central)

    mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/objdir-xulrunner-debug
    ac_add_options --enable-application=xulrunner
    ac_add_options --enable-debug
    ac_add_options --disable-optimize

  • Thunderbird .mozconfig contents: (Using comm-central)

    mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/objdir-tb-debug
    ac_add_options --enable-application=mail
    ac_add_options --enable-debug
    ac_add_options --disable-optimize
    #If you also want Lightning
    ac_add_options --enable-calendar

  • SeaMonkey .mozconfig contents: (Using comm-central)

    mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/objdir-seamonkey-debug
    ac_add_options --enable-application=suite
    ac_add_options --enable-debug
    ac_add_options --disable-optimize

  • Sunbird .mozconfig contents: (Using comm-central)

    mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/objdir-sunbird-debug
    ac_add_options --enable-application=calendar
    ac_add_options --enable-debug
    ac_add_options --disable-optimize

  • Fennec Win32 .mozconfig

    mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/objdir
    ac_add_options --enable-application=mobile
    # For improved compile speeds, all optional.
    mk_add_options MOZ_MAKE_FLAGS=-j4
    #export CCACHE_HARDLINK=1
    #export MOZ_DEBUG_SYMBOLS=1
    ac_add_options --enable-debug
    ac_add_options --disable-optimize
    # Needed on Win32 to fix problem with Windows Vista SDK
    ac_add_options --disable-accessibility

  • Windows 8 Metro .mozconfig

    mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/objdir
    mk_add_options MOZ_MAKE_FLAGS=-j4
    ac_add_options --enable-debug
    ac_add_options --disable-optimize
    ac_add_options --enable-tests

  • > ac\_add\_options --enable-metro

Incremental builds

  • Example if you have changes to /widget:
    mach build widget

Logging

  • Logging Javascript with Firebug/Chromebug/web console:
    console.log("my output");
    console.log("%s is %d years old.", "Bob", 42).

  • Netscape portable runtime logging (PR_LOG): Environment variables:
    NSPR_LOG_FILE = WinDebug and it will output to the debug output window or use NSPR_LOG_FILE=C:\nspr-log.txt to output to a file by that name
    NSPR_LOG_MODULES can specify which modules to log with the, example NSPR_LOG_MODULES = nsWindowsWidgets:5 (5 is the log level)
    You can use NSPR_LOG_MODULES=all:5 to enable all module logging

Finding source of regressions

  • Do a binary search on the nightly builds until you narrow down a build that introduced the regression
  • Use the push log to review changes in that time span
  • Use MozRegression

Submitting a patch for review

  • You don't have commit access at first, instead create a patch.
  • Setup your author information (your ~/.hgrc or ~/mercurial.ini on Windows):
    [ui]
    username = Your Name <your@email.com>

  • Use the mq extension, add to your ~/.hgrc or ~/mercurial.ini on Windows
    [extensions]
    hgext.mq =

  • When submitting do this

Working with hg and patches

  • To create a patch:

    hg qnew bugXXXXXX.patch

    On popup:
    Bug XXXXXX - Description of your fix

  • To take a file out of a patch:

    hg qrefresh -X re:regexp_pattern_of_files_to_remove

  • To refresh changes into your patch:

    hg qrefresh

  • To see the status of changes: (after you take out files it should re-appear in the changes)

    hg status

  • Undo application of a patch in your MQ patch queue: (Removes the patch from your commit tree and working directory)

    hg qpop (To unapply the last applied patch)
    hg qpop -a (To unapply all patches)
    hg qpop name.patch (To unapply all patches up to but not including the specified patch)

  • Apply a patch which is in your MQ patch queue: (Re-adds the patch to your commit tree and working directory, you can apply more than one patch)

    hg qpush (To apply the next patch in the series)
    hg qpush -a (To apply all patches)
    hg qpush name.patch (To apply all patches in the series up to and including the named patch)

  • List which patches are in your MQ patch queue:

    hg qseries

  • List which patches in your MQ patch queue are applied (pushed):

    hg qapplied

  • List which patches in your MQ patch queue are not yet applied (pushed):

    qunapplied

  • To delete a patch from your MQ patch queue: (Patch must first be unapplied)

    hg qdelete

  • To turn a patch into a permanent changeset: (Patch must first be applied)

    hg qfinish

  • To turn a normal changeset into a patch: (Patch must first be unapplied)

    hg qimport -r tip

  • Convert a patch to a finalized changeset: (Patch must first be applied)

    hg qfinish tip
    hg qfinish -a (for all of the patches

  • To make a backup of your patches directory: (Saves the patches backup to .hg/patches.N)

    hg qsave

  • To import someone else's patch into your MQ patch queue:

    hg qimport patchname.patch (You must later also apply it with qpush, also works with HTTP URLs)

  • To import someone else' patch with a different patch strip count:

    patch -pN (to apply the patch, where N is the strip count of the patch)
    qnew (to create a new patch)
    hg addremove (to pickup any files added/removed by the patch)
    qrefresh (to refresh the patch)

  • To change the ordering of how patches are applied
    Manually edit your .hg/patches/series file, one patch name per line.

  • To rollup several patches into one

    hg diff -r qparent > rollup.patch

  • See last 50 pushed

    hg log -l 50

  • Undoing a qfinish or remove last commit into a patch

    hg qimport -r tip (Make sure you have no other patches applied)

  • To backout a revision

    hg backout revnumber

  • Folding a patch in your queue onto another one

    hg qgoto base_patch.patch
    hg qfold patch_to_fold_in_base_patch.patch

  • Renaming a patch

    hg qrename new_patch_name.patch

  • Merge all changes from parent repo into your branch

    cd yourbranchdir
    hg update
    hg pull other-repo
    hg merge
    hg commit
    hg push

  • Clone a repository up until a specific changeset

  • > hg clone -r revisionid http://hg.mozilla.org/mozilla-central/ repo\_name
  • Remove a changeset and all of its decendants

    hg strip changesetid

  • Rebase one repository to another by beheading the old tip

    cd repo_you_want_to_change
    hg pull repo_to_change_to
    hg heads .
    hg update -r revisin_to_forget_about
    hg commit --close-branch
    hg update -r revision_to_use
    hg push --force

Testing and QA

  • Automated testing Link 1 and Link 2

  • Litmus (Manual testing)
  • Mochitest for testing via pages (HTML, XHTML, SVG, XUL, XBL) (mochitest-plain, mochitest-chrome, mochitest-browser-chrome, mochitest-a11y or mochitest-ipc)

  • Browser Chrome Browser chrome mochitest) for testing via JS

  • Reftests for testing if 2 pages that should render the same actually do

  • Compiled code tests
  • XPCShell tests for testing XPCOM components

Automated test run examples (TODO: Needs updating use mach instead)

  • All xpcshell tests

    ./mach xpcshell-test

  • xpcshell entire directory

    ./mach xpcshell-test dir-path

  • xpcshell single test:

    ./mach xpcshell-test file-path

  • All reftests:

    ./mach reftest

  • All reftests in a .list file:

    ./mach reftest file-path.list

  • Reftest single test:

    ./mach reftest file-path.list --filter .testname.

  • mochitest-plain:

    ./mach mochitest-plain

  • mochitest-chrome: (like a mochitest but with chrome privs)

    ./mach mochitest-chrome

  • mochitest-browser

    ./mach mochitest-browser

Troubleshooting build problems

  • I built on windows, and had crashes on startup:
    The reason ended up being because I was using the same profile as my FF4 and some extensions were causing the crash (Firebug in particular). Simply disabling the extensions fixed the problem.

  • If you are building on Windows with VC2010, and get the error, install the Win 7.0 SDK instead. Alternatively if you really want to use 7.1 you may need to patch your guess-msvc.bat.

about: URIs

  • Blank page:
    about:blank

  • Addons:
    about:addons

  • To adjust settings:
    about:config

  • To see how your Firefox was built:
    about:buildconfig

  • To see all of your crash reports:
    about:crashes

  • Other

Common about:config prefs

  • Allow remote XUL from local computer:

    dom.allow_XUL_XBL_for_file: true;

XPCOM objects in JavaScript

  • Creating an XPCOM component:

    var cid = "@brianbondy.com/componentname;1"
    var obj = Components.classes[cid].createInstance();
    obj = obj.QueryInterface(Components.interfaces.IMyInterface)

  • Listing XPCOM components:

    for (var c in Components.classes) { print(c); }

  • Listing XPCOM interfaces:

    for (var i in Components.interfaces) { print(i); }

How to push to try

  • Need commit access level 1
  • Try server info
  • TryChooser - try command line generator
  • Build bot results
  • In ~/.hgrc (or mercurial.ini on Windows) add:

    [paths]
    try = ssh://hg.mozilla.org/try

  • To push the applied hg queue patches to the try server:

    hg qrefresh --message "try: -b do -p all -u all -t all"
    hg push -f try

  • See the section on: SSH config for try or inbound on hg.mozilla.org
  • Sometimes after pushing you can't qpop because it says: "abort: popping would remove an immutable revision". Use:

    hg phase -f -d qtip
    hg qpop -a

How to push a changeset from your MQ

  • If you want your patch to land on Aurora, or Firefox Beta you need to request it in Bugzilla. only for severe security, stability, or regressions recently introduced. Provide risk/reward in ticket.
  • Need commit access level 3
  • In .hgrc (or mercurial.ini) add:

    [paths]
    mozilla-inbound = http://hg.mozilla.org/integration/mozilla-inbound/

  • To push:
    Move your patch to the top of your queue

    hg pull
    hg update
    hg qpush
    hg qrefresh -m "Bug xxx - Blah. Blah. Blah. r=xyz"
    hg qfinish -a
    hg push mozilla-inbound

  • Rules for pushing

Bugzilla keywords

  • addon-compat: If your change may affect addon compatibility
  • dev-doc-needed: If your change may need documentation
  • regression: If your bug is a regression
  • checkin-needed: If a checkin is needed for a patch but the author can't do it themselves because of privs or some other reason
  • Others

Firefox UI debugging

  • Open the Web Console (Ctrl+Shift+K on Windows/Linux, Cmd+Opt+K on Mac), open the settings pane (gear icon) and enable remote and chrome debugging.
  • You can use the Browser Console from the Tools > Web Developer menu to evaluate JS against the main Firefox Window
  • You can use Scratchpad from the Tools > Web Developer menu as well. Be sure to set the Environment to "Browser" from the menu inside Scratchpad.
  • You can use the Browser Debugger to debug JS running in the browser chrome.
  • You can use the --jsconsole and --jsdebugger commandline arguments to start the browser console/debugger when starting Firefox.
  • Download the DOM Inspector add-on to inspect the XUL tree and its CSS while Firefox is running.

  • Extension Developer Extension

Doing Code Reviews

  • Code Review Guide
  • Quick Points:
    • MultiByte vs. Wide character set comm-central defaults to ASCII
    • Check if Windows platform API available on WinXP and above
    • Does it pass try?
    • Formatting? (But don't be too strict)
    • Comments, typos, spelling
    • Did you test in scenario X?
    • New import libs in toolkit/library?
    • Should it have tests?
    • Interface change? Change IID, sr required, addon-compat keyword
    • Documentation needed?
    • Mark keywords for post-fix work: dev-doc-needed, privacy-review-needed, sec-review-needed, user-doc-needed, addon-compat, release tracking flags, in-testsuite flag

Commit flags

  • Append to the end of patches:
    • reviewed by: r=nickname
    • approved by: a=nickname
    • super reviewed by: sr=nickname

Mentoring bugs

  • Add who the mentor is to Bugzilla whiteboard [mentor=bbondy]
  • Add which language it is to the Bugzilla whiteboard [lang=c++]
  • More info

Debugging

  • Use Firebug and Chromebug to debug XUL, XBL, JavaScript
  • Debug C++ src in Windows: Open VS2010, select open project, select dist/bin/firefox.exe in your obj dir. Press F5. Change source, do an incremental build, open the source and set breakpoints in VS2010.
  • To avoid having debug assertions and to have them show up in the log instead, set this environment variable: XPCOM_DEBUG_BREAK=warn

Release cycle

Personal files on people.mozilla.com

  • Add to your C:\Users\bbondy.ssh\config file:

    Host people.mozilla.com
    User netzen@gmail.com
    IdentityFile C:\Users\bbondy.ssh\bbondy.pub

  • The IdentityFile entry should only be needed on Windows. If you're on anything else it'll automatically find the key, use:

    ssh-add path-to-key.ppk

  • Your must already have L1 commit access, i.e. your public key is already on the server.
  • You can upload files to a URL like: http://people.mozilla.com/~bbondy
    Anything under the /home/bbondy/public_html will show up at the http address above.

  • On Windows connect with putty sftp:

    psftp bbondy@people.mozilla.com
    Enter your private key password
    put filename.ext

SSH config for try or inbound on hg.mozilla.org

  • Add to your C:\Users\bbondy.ssh\config file:

    Host hg.mozilla.org
    User netzen@gmail.com
    IdentityFile C:\Users\bbondy.ssh\bbondy.pub

  • The IdentityFile entry should only be needed on Windows. If you're on anything else it'll automatically find the key, use:

    ssh-add path-to-key.ppk

  • Your must already have L1 commit access for pushing to try, or commit access level 3 for pushing to an integration branch. i.e. your public key is already on the server.
  • To test access to ssh make sure the ssh command gives an output of "No interactive shells allowed here!". Use Putty for Windows:

    ssh hg.mozilla.org

Project Branches

Plugins

  • Copy to: <installDir>\Plugins
  • Environment variable MOZ_DEBUG_CHILD_PROCESS=1 can be used to delay 30 seconds when loading plugin-container before the plugin is loaded.
  • Plugin development