Mobile/Fennec Unittests/NewTests

From MozillaWiki
Jump to: navigation, search

Overview

To create unittests on fennec, we will be focusing on [Browser-Chrome] type of tests. As time goes on we might make a focus for reftest, crashtest, plain mochitest, chrome mochitest, a11y mochitests, or even xpcshell. I am leaving Talos off the plate for now, but that is the other type of tests we have created to date.

A Sample Browser-Chrome Test

[bookmarks]

gTests.push({
  desc: "Test adding a bookmark with the Star button",
  _currenttab: null,

  run: function() {
    this._currenttab = Browser.addTab(testURL_01, true);

    // Need to wait until the page is loaded
    this._currenttab.browser.addEventListener("load", 
    function() {
      gCurrentTest._currenttab.browser.removeEventListener("load", arguments.callee, true);
      gCurrentTest.onPageReady();
    }, 
    true);
  },
  
  onPageReady: function() {
    var starbutton = document.getElementById("tool-star");
    starbutton.click();    
    
    var bookmarkItem = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01));
    ok(bookmarkItem != -1, testURL_01 + " should be added.");

    Browser.closeTab(gCurrentTest._currenttab);
    
    runNextTest();
  }  
});

Creating and Debugging

Creating a browser-chrome test is pretty much pure javascript that runs inside of chrome (for access to xul elements and full privilege content) extension. We run this via the mochitest harness.

Currently we have a set of [tests developed], and all future tests should go in the same location.

To create a test, either add a new test case into an existing file or start with a new file. Please use existing tests cases as an example of how to add tests and access components.

While creating tests, I highly recommend installing [DOM inspector] (NOTE: this is a hacked up 2.0.3 version to install in fennec). This doesn't work well on mobile devices, but running on a desktop build will be very powerful. In order to use this in Fennec, you need to install it, restart, then type CTRL+SHIFT+I (similar to [these instructions].)

List of Tests We Need

[Tracking Bug] for different areas that need test cases


bugs that have been fixed that we should add test cases for: