Electrolysis/e10s test tips

From MozillaWiki
< Electrolysis
Revision as of 18:23, 30 November 2015 by Amccreight (talk | contribs) (Describe importInMainProcess)
Jump to navigation Jump to search

There isn't a standard formula to use to fix broken tests for e10s. Instead, one has to read the test and look for potential problem areas. Sometimes, it's pretty obvious (there are a lot of browser-chrome tests that use contentWindow or contentDocument). Other times it's much more subtle.

Here are a few tips to look for.

About CPOWs

CPOWs are allowed in tests but tend to be a little flaky (search for "dead CPOW" in bugzilla) so it's probably worth spending a little extra time to use message passing and setting things up "correctly".

Mochitest (plain)

  • Setting prefs
    • Prefs should only be set using SpecialPowers (pushPrefEnv).
    • Getting prefs is fine.
  • Setting permissions
    • SpecialPowers.addPermission() is racy, so use SpecialPowers.pushPermissions() instead.
  • Observers:
    • Only receive observer notifications for the content process (possibly OK).
    • SpecialPowers.addObserver does the Right Thing (TM).
  • Services
    • Some services are only available in the parent process (form history, window watcher, etc).
    • SpecialPowers.loadChromeScript allows you to have a "worker" in the parent process with which to communicate.
    • SpecialPowers.importInMainProcess("resource://gre/modules/SomeService.jsm") will call Cu.import in the main process with the given URI, which is useful when your test needs to start some main process service.
  • SpecialPowers.wrap
    • Sometimes OK (getting window utils, controller, etc.)
    • Sometimes not (getting the chrome window).
    • Fixing might require something like loadChromeScript.
  • SpecialPowers.Cc
    • Big red flag. Especially for windowwatcher!

Browser-chrome

  • Use BrowserTestUtils!
    • Lots of examples in the tree.
    • This + ContentTask.spawn make for nice control flow.
    • Can also use browser.messageManager.loadFrameScript("data:,(" + fn.toString() + ")()")
  • browser.contentWindow/contentDocument
    • Tests that use this are asking to fail!
    • Replace uses with ContentTask.spawn to retrieve needed information.