The first step is to (re)build with the enable-tests option by placing "ac_add_options --enable-tests" in .mozconfig
Now we'll need to write our test() function using assertions; ok(), is(), isnot()
ok(val, "val exists!"); // Tests existence is(val1, val2, "val1 equals val2"); // Tests equality isnot(val1, val2, "val1 does not equal val2"); // Tests if not equal
My test script looks like this:
function test() {
var firstTab = gBrowser.addTab();
var tabs = gBrowser.tabs;
is(tabs.length, 2, "2 tabs are open");
is(gBrowser.selectedTab._tPos, 0, "First tab is selected");
var newTab = gBrowser.addTab();
is(gBrowser.selectedTab._tPos, 0, "first tab selected");
is(tabs[2]._tPos, newTab._tPos, "Was inserted at #3");
gBrowser.moveTabTo(newTab,0);
is(newTab._tPos,0, "moved new tab to first position");
var tempLen = tabs.length;
gBrowser.removeTab(newTab);
is(tabs.length, tempLen-1 ,"deleted newTab");
while (tabs.length > 1)
gBrowser.removeCurrentTab();
}
So where do we put this file?
src\obj-i686-pc-mingw32\_tests\testing\mochitest\browser\browser\base\content\test\browser_tab_test.js
To run the test script run navigate to the src directory and run:
TEST_PATH=browser/base/content/test/YOUR_TEST_SCRIPT.js make -C $(OBJDIR) mochitest-browser-chrome
When the test finishes you should see the results as either TEST-PASS or TEST-UNEXPECTED-FAIL.
No comments:
Post a Comment