Friday, July 18, 2008

Test file complete and marked for review

I finally got the test to flow nicely and uploaded my browser_History.js to the bug. Now I'm waiting for Mark Finkle to review it and tell me how it is. Writing the test file had a little more to it than I thought, but all in all I had fun doing it.

First I had the problem where I couldn't get each page to load one at a time, and I thought that using the setTimeout was inefficient, but then I get told that we're using local html files so the setTimeout isn't much of a problem anymore so I got past the "loading one at a time" problem.

Then there was the issue where the test counters weren't in sync with the history counter. After throwing a bunch of console outputs to look monitor the counters from both sides I find that after the last page is loaded the test counters aren't updated, so I had to increment it manually in the function called after the last page is loaded. Problem solved.

The third problem, is the "I love learning as I'm going" part. There was the part where I had to test the reload, goBack, goForward, and gotoIndex listeners. There is the way where I could just call document.getElementById('Browser:Back') and same for Forward and Reload, but it wasn't the "proper" way of doing it. After going back to the nsISHistoryListener it told me that the event is fired when the goBack is called from nsIWebNavigation. Perfect let's use it... but how...

In comes the last problem, how to use it. After snooping around I found a few examples. So after staring at it, it was obvious that I needed to getBrowser().webNavigation. So I went ahead and tried Application.activeWindow.getBrowser().webNavigation since a Window in FUEL holds a reference to the browser. But that didn't work. So I then tried:
var nsIWindowMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var webNavigator = nsIWindowMediator.getMostRecentWindow("navigator:browser")
.getBrowser().webNavigation;

which solved the problem and when ran the test all results came back positive :)

0 comments: