Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
firefox
3 changes: 3 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 0.0.1
- Initial release with very basic firefox launching
- Each launch gets a clean profile
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
default: test
firefox:
mozilla-download --product firefox firefox

node_modules:
npm install

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use:

NPM_INSTALLED_PROGRAMS = node_modules/.bin/mocha
$(NPM_INSTALLED_PROGRAMS): package.json
    npm install
    touch $(NPM_INSTALLED_PROGRAMS)

test: node_modules/.bin/mocha
  ./node_modules/.bin/mocha ....

.PHONY: test
test: node_modules
./node_modules/.bin/mocha $(shell find . -name "*_test.js")
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
firefox-launcher
================
# Test Agent Firefox Launcher

test-agent firefox launcher
The intent is this module is never used directly as it is very low level
guts for launching firefox with a clean profile each time...

This should be used in conjunction with (test-agent)[https://github.com/test-agent/test-agent]

## Usage

(there is no node interface)

```sh
# if you installed with npm install -g
EXEC=test-agent-firefox-launcher
# if you installed with npm install
EXEC=./node_modules/.bin/test-aget-firefox-launcher

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: a "n" is missing


$EXEC --exec /path/to/firefox/folder $URL

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about using PROGRAM instead of EXEC ?

```
67 changes: 67 additions & 0 deletions bin/test-agent-firefox-launcher
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#! /usr/bin/env node
/**
TestAgent firefox launcher plugin executable. Handles the details of launching
the firefox instance.

Why would we have a binary that wraps the launch of other binaries???

- auto detection of exectuable firefox

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "executable"

- better control of logging
- unified? spot where we can alter how the binary is launched for firefox

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd say this should go to README.md instead of here


*/

var program = require('commander'),
mozrunner = require('mozilla-runner'),
mozprofile = require('mozilla-profile-builder'),
fs = require('fs');

program.
option(
'--exec-name <name>',
'Name of executable to launch (like b2g-bin or firefox)',
'firefox'
).
option('--exec <path>', 'Path to the firefox executable').
option('--profile <path>', 'path to base profile').
parse(process.argv);

if (!program.exec) {
console.error('must pass an --exec flag')
program.outputHelp();
process.exit(1);
}

if (!fs.existsSync(program.exec)) {
console.error(
'--exec must be a path on the file system (maybe you need to use which?)'
);
program.outputHelp();
process.exit(1);
}

// options for the run
var profileOptions = {};
var runnerOptions = { argv: program.args };

/**
Utility for managing the death of the parent (current) process.
*/
function handleFirefoxProcess(proc) {
process.once('SIGTERM', proc.kill.bind(proc));
}

mozprofile.create(profileOptions, function(err, instance) {
if (err) throw err;

// set the profile path
runnerOptions.profile = instance.path;
mozrunner.run(
program.execName,
program.exec, runnerOptions,
function(err, child) {
if (err) throw err;
handleFirefoxProcess(child);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe I don't understand everything here, but don't you want to kill the process also if you have err ?

}
);
});
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw new Error('no public node interface');
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "test-agent-firefox-launcher",
"version": "0.0.1",
"description": "Test agent firefox launcher executable",
"main": "index.js",
"scripts": {
"test": "make test"
},
"bin": {
"test-agent-firefox-launcher": "./bin/test-agent-firefox-launcher"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get what is specific to "test-agent" here, why this name ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about clean-firefox-launcher since it creates a clean profile at each invocation ?

},
"repository": {
"type": "git",
"url": "https://github.com/test-agent/firefox-launcher.git"
},
"author": "",
"license": "Apache2",
"dependencies": {
"mozilla-runner": "0.0.1",
"ws": "~0.4.31",
"commander": "~2.0.0",
"mozilla-profile-builder": "~0.3.0"
},
"devDependencies": {
"mocha": "~1.13.0",
"node-static": "~0.7.1",
"mozilla-download": "~0.2.1"
}
}
56 changes: 56 additions & 0 deletions test/bin/test-agent-firefox-launcher_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
suite('test-agent-firefox-launcher', function() {
var spawn = require('child_process').spawn,
executable = __dirname + '/../../bin/test-agent-firefox-launcher',
firefox = __dirname + '/../../firefox',
// this also spawns the server!
url = testServer(),
WebSocketServer = require('ws').Server;

function launch(args) {
var proc = spawn(executable, args);
if (process.env.DEBUG) {
proc.stdout.pipe(process.stdout);
proc.stderr.pipe(process.stderr);
}
return proc;
}

function verifyNonZeroExit(proc, done) {
proc.on('exit', function(status) {
assert(status !== 0, 'should exit process with a status other than 0');
done();
});
}

test('failure - no exec argument', function(done) {
var proc = launch();
verifyNonZeroExit(proc, done);
});

test('failure - missing firefox', function(done) {
var proc = launch(['--exec', '/iam/not/heere']);
verifyNonZeroExit(proc, done);
});

suite('success - launch', function() {
var wsServer, proc;
setup(function() {
wsServer = new WebSocketServer({ port: 60001 });
});

teardown(function() {
wsServer.close();
});

test('client connects to ws server', function(done) {
proc = launch(['--exec', firefox, url]);
wsServer.on('connection', function() {
proc.kill();
proc.on('exit', function() {
done();
});
});
});
});

});
10 changes: 10 additions & 0 deletions test/fixtures/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Head</title>
<script src="websocket.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
</body>
</html>
5 changes: 5 additions & 0 deletions test/fixtures/websocket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(function() {
// all we need to do is verify that the socket is opened that is
// enough to tell us that the plugin works....
new WebSocket('ws://localhost:60001');
}());
27 changes: 27 additions & 0 deletions test/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
global.assert = require('assert');
var TEST_PORT = 8787;

global.testServer = function() {
// reference to the sever must be at this function scope so
// suiteTeardown can actually close it.
var server;

suiteSetup(function() {
var static = require('node-static');
// root of the project
var file = new static.Server(__dirname + '/fixtures/');

server = require('http').createServer(function(request, response) {
request.addListener('end', function() {
// Serve files!
file.serve(request, response);
}).resume();
}).listen(8787);
});

suiteTeardown(function() {
server.close();
});

return 'http://localhost:' + TEST_PORT + '/index.html';
};
2 changes: 2 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--require test/helper
--ui tdd