Learning about XPCShell & Unit Tests

As of today – Friday, I have tightened my belt and stepped into the world of Mozilla. Taking baby steps I have begun to do some research into the focus of my selected project – which will involve collaboration with those writing patches on (bug 248970). You can’t just begin coding and racing to the finish line. I will take my time doing research to understand what I am committed towards achieving. In essence, I will be writing unit tests for special test cases for the new private browsing mode currently slated for Firefox 3.1

Referred to a tutorial on XPCShell Unit Testing by a collaborator, I took 15 minutes and tinkered around with it. Having watched Ted Mielczarek’s demo during Mozilla’s visit to Seneca, I wasn’t entirely sure of its purpose. Rather than just act as a JavaScript shell, XPCShell taps into XPCom functionality – which I assume lets your JavaScript tests have access to other functionality of Mozilla.

Simply changing values in the sample file sample-test.js, I was able to receive status of PASS or FAIL

Not much code was in the sample-test.js file, just

function run_test() {
  do_check_eq(57, 57)
  do_check_neq(1, 2)
  do_timeout(100, "do_test_finished();");

I merely changed the second parameter of the first function


which performs an assert to check if two objects are equal. If not equal, an exception is logged and the test case is halted.


Resulted in a FAIL

*** TEST-UNEXPECTED-FAIL | */test_sample.js | 57 == 47

So XPCShell works.. at least from the tutorial I followed here

Seeing this simple example, it will be interesting to see how tests will be used to test the functionality of patches submitted according to the test plan. Testing areas include cookies, history, cache, user passwords, downloads, DOM storage etc.

My next step will be to maybe write an extremely simple XPCShell Unit Test with XPCOM interaction.

Stay tuned,

Aaron (AaronMT)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: