Friday, July 11, 2008

FUEL: history listener almost done

I finished the implementation of the history listener, after doing a few manual tests from the error console, and later by writing the browser_History.js test file, the history properties (count, currentPage, size...) seemed to be working as they should. They worked better when called manually from the error console because in there each property is being called manually.

The first step was to get through the page loading, took me a day to get it working right. It was a little tough at first because I didn't know what was going on when I was trying to load the pages, the browser would immediately load the last page in the array. It turned out I had to wait for one page to finish loading, of course, before i start loading the next in order for the history listener to register it. That's what it ended up looking like [URLs is an array of strings]:

// Load a few pages
function loadPage(aIndex) {
tab.load(url(URLs[aIndex]));
count++;

tab.events.removeListener("load", null);

tab.events.addListener("load", function() {
setTimeout(function() { (aIndex < URLs.length - 1) ? loadPage(aIndex + 1) : continueTests(); }, 1000)
});
}

loadPage(0);

So this little function basically waits for each page to load before loading the next one and when done it calls the next function to continue the tests:
function continueTests() {
tab.events.removeListener("load", null);

is(tab.history.count, count, "Check history load");

// remove first entry
tab.history.remove(1);

count -= 1;

is(tab.history.count, count, "Check history remove");

document.getElementById('Browser:Back').doCommand();
is(tab.history.currentPage, 0, "Check history current page");
}

The initial tests were successful, so far. I can't test them properly because the registration of the history listener isn't working:
this._history.addSHistoryListener(this);
It returns an error telling me that the object is not registered as a nsIWeakReference object. I've tried to debug it with GDB on Xcode but the only result that I got was that it's not registered as a nsIWeakReference, but I did see:
QueryInterface : XPCOMUtils.generateQI([Ci.fuelIBrowserHistory, Ci.nsISHistoryListener, Ci.nsISimpleEnumerator, Ci.nsIWeakReference])
The only outcome from my debugging was that I learned how to debug firefox using Xcode :D

0 comments: