-
Notifications
You must be signed in to change notification settings - Fork 1
Bug 923816 - Initial firefox launcher executable #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
5aee111
f7fa0b9
3b1b1ce
b4c967b
e5056bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| node_modules | ||
| firefox |
| 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 |
| 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 | ||
|
|
||
| .PHONY: test | ||
| test: node_modules | ||
| ./node_modules/.bin/mocha $(shell find . -name "*_test.js") | ||
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: a "n" is missing |
||
|
|
||
| $EXEC --exec /path/to/firefox/folder $URL | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about using |
||
| ``` | ||
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
| ); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| throw new Error('no public node interface'); |
| 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" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about |
||
| }, | ||
| "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" | ||
| } | ||
| } | ||
| 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(); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| }); |
| 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> |
| 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'); | ||
| }()); |
| 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'; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --require test/helper | ||
| --ui tdd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use: