Tip:
Highlight text to annotate it
X
The XPCShell is a JavaScript shell that has access to XPCOM.
It also has access to things like JavaScript modules.
Now "XPC" in XPCShell stands for XPConnect I believe.
And XPConnect is basically just a way for JavaScript to access XPCOM.
Now an XPCShell test is what we're going to cover in this video.
It's basically just a test that's written using [written for] the XPCShell.
So to start off, what I'm going to do is that I'm going to open up the XPCShell.
And we're just going to run a little bit of JavaScript in there, just so you can see what the XPCShell is itself.
Assuming you already have a build, you can find the XPCShell binary in your object directory.
Which is obj- something, /dist/bin/xpcshell
I'm going to hit enter.
And this is basically just a JavaScript shell, and like I said before it has access to XPCOM and it has access to JavaScript modules.
So I can go like: 1 + 2, it'll give me 3.
I can dump messages like 'hello world'
And it'll display that there for me.
And to show you that it has access to XPCOM for example,
I can go for (c in Components.classes) dump(c + '\n');
So basically I'm just dumping all the XPCOM component class names.
And you can see that it's just displaying the long list of them there.
So I also want to show you that you can access JavaScript modules.
So for example if I do Components.utils.import
Then I can type the path to a JavaScript module here, I'll use the OSFile one.
osfile.jsm
And you can see that it gave us some output there, so it looks like it worked.
And if I do OS.File.read for example, you'll see that it shows the function there.
So it actually did import it.
And if I would have tried OS.File.read before doing the import above, it would have showed no output.
So I'm just going to quit out of that.
And I'm back to my terminal here.
Now to run an XPCShell test.
All you basically do is go to your root there, like I am in the root of the source code directory.
And you type mach xpcshell-test, and hit enter.
And what that's going to do, is it's going to run through every xpcshell test that we have.
And then it's going to display a summary at the end.
Now as you can imagine, we have a lot of these types of tests.
So I'm not going to wait for the whole thing.
But I'm just going to show you the scrolling output here, you can see some TEST-PASSes that show up here.
And you are not seeing any TEST-FAILs.
So this is an example of one of the tests that run every time you do a check-in.
I'm just going to cancel that.
Now a lot of times you don't want to run the whole thing, because that takes a long time.
And you may be only changing a certain part of the code.
Like let's say we're working on the OSFile module.
The one that we just used.
And we want to run all the tests for that module, because we made a change in it.
Then you can just run mach xpcshell-test and then you just specify the path of where you were changing stuff.
So that would be toolkit/components/osfile
You can go a little bit deeper, but I'm just going to stay there, because it'll recursively go through it.
So I'll hit enter.
And this is going to take a little bit, maybe a couple minutes, so I'm just going to pause it [the video].
OK so it's done running, and you can see down here in the summary it says Passed 20, failed 0, TODO 0, retired 0.
Now I showed you how to run every xpcshell test, a whole directory of xpcshell tests.
And the last thing I wan to show you in this video is how to run a single XPCShell test.
So you can just specify it the exact same way as you did before for the directory, but then you actually append the actual filename that you want to run.
So I'm just going to locate a filename here.
Let's say test_creationDate.js
So let's say I made a change to just the creation date and I want to run that test.
Then I just hit enter.
And you can see that the 1 test passed right there, failed 0.
So that's all I wanted to show you for this video.
In the next video I'll show you how to create an XPCShell test.
And I'll also go over the different test types in subsequent videos as well.
Subtitles by the Amara.org community