Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 2c4a34a

Browse files
committed
Merge pull request #1 from webrtc/addBarebones
Add grunt, package info etc
2 parents 878c6f3 + 3a35dcb commit 2c4a34a

File tree

9 files changed

+272
-1
lines changed

9 files changed

+272
-1
lines changed

.eslintrc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"rules": {
3+
"array-bracket-spacing": 2,
4+
"block-spacing": [2, "never"],
5+
"brace-style": [2, "1tbs", { "allowSingleLine": false }],
6+
"camelcase": [2, {"properties": "always"}],
7+
"curly": 2,
8+
"default-case": 2,
9+
"dot-notation": 2,
10+
"eqeqeq": 2,
11+
"indent": [
12+
2,
13+
2,
14+
{"SwitchCase": 1}
15+
],
16+
"key-spacing": [2, {"beforeColon": false, "afterColon": true}],
17+
"max-len": [2, 80, 2, {"ignoreUrls": true}],
18+
"new-cap": 2,
19+
"no-console": 0,
20+
"no-else-return": 2,
21+
"no-eval": 2,
22+
"no-multi-spaces": 2,
23+
"no-multiple-empty-lines": [2, {"max": 2}],
24+
"no-shadow": 2,
25+
"no-trailing-spaces": 2,
26+
"no-unused-expressions": 2,
27+
"no-unused-vars": [2, {"args": "none"}],
28+
"object-curly-spacing": [2, "never"],
29+
"padded-blocks": [2, "never"],
30+
"quotes": [
31+
2,
32+
"single"
33+
],
34+
"semi": [
35+
2,
36+
"always"
37+
],
38+
"space-after-keywords": 2,
39+
"space-before-blocks": 2,
40+
"space-before-function-paren": [2, "never"],
41+
"spaced-comment": 2,
42+
"valid-typeof": 2
43+
},
44+
"extends": "eslint:recommended",
45+
"globals": {}
46+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
node_modules/
3+
*~

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- 4.1
5+
6+
script:
7+
- npm install
8+
- grunt

Gruntfile.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
/* globals module */
4+
5+
module.exports = function(grunt) {
6+
// configure project
7+
grunt.initConfig({
8+
// make node configurations available
9+
pkg: grunt.file.readJSON('package.json'),
10+
eslint: {
11+
options: {
12+
configFile: '.eslintrc'
13+
},
14+
target: ['src/**/*.js', 'main.js']
15+
},
16+
githooks: {
17+
all: {
18+
'pre-commit': 'eslint'
19+
}
20+
}
21+
});
22+
// enable plugins
23+
grunt.loadNpmTasks('grunt-eslint');
24+
grunt.loadNpmTasks('grunt-githooks');
25+
26+
// set default tasks to run when grunt is called without parameters
27+
grunt.registerTask('default', ['eslint']);
28+
};

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
1-
# utilities
1+
# WebRTC utilities #
22
Contains shared utilities, support tools and frameworks for the other WebRTC sub repositories.
3+
4+
## Install using npm ##
5+
´´´
6+
npm install webrtc-utilities --save-dev
7+
´´´
8+
9+
## SeleniumLib ##
10+
src/selenium-lib.js contains all that is needed to build a selenium webdriver driver for Chrome and Firefox (whatever is set in the env $BROWSER variable).
11+
It is used using require() in node.
12+
13+
## run-tests ##
14+
A bash shell script that helps travis-multirunner to download and install Chrome and Firefox browser from stable, beta and unstable channels.
15+
16+
## Development ##
17+
Add new utilities under the src folder and add them to the main.js file in the project root with the appropriate module.export set.
18+
19+
Detailed information on developing in the [webrtc](https://github.com/webrtc) github repositories can be found in the [WebRTC GitHub repo developer's guide](https://docs.google.com/document/d/1tn1t6LW2ffzGuYTK3366w1fhTkkzsSvHsBnOHoDfRzY/edit?pli=1#heading=h.e3366rrgmkdk).

main.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3+
*
4+
* Use of this source code is governed by a BSD-style license
5+
* that can be found in the LICENSE file in the root of the source
6+
* tree.
7+
*/
8+
/* eslint-env node */
9+
10+
'use strict';
11+
12+
// Add all modules to be exported here.
13+
var seleniumLib = require('./src/selenium/selenium-lib.js');
14+
15+
module.export = {
16+
seleniumLib: seleniumLib
17+
};

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "webrtc-utilities",
3+
"version": "0.0.1",
4+
"author": "The WebRTC project authors (https://www.webrtc.org/)",
5+
"description": "WebRTC test framework utilities.",
6+
"license": "BSD-3-Clause",
7+
"main": "main.js",
8+
"repository": {
9+
"type": "git",
10+
"url": "https://github.com/webrtc/utilities.git"
11+
},
12+
"dependencies": {
13+
"chromedriver": "^2.16.0",
14+
"selenium-webdriver": "^2.48.0",
15+
"tape": "^4.0.0",
16+
"testling": "^1.7.1",
17+
"travis-multirunner": "^3.0.0"
18+
},
19+
"scripts": {
20+
"postinstall": "grunt githooks"
21+
},
22+
"devDependencies": {
23+
"grunt": "^0.4.5",
24+
"grunt-cli": ">=0.1.9",
25+
"grunt-eslint": "^17.2.0",
26+
"grunt-githooks": "^0.3.1"
27+
}
28+
}

src/selenium/run-tests

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
#
3+
# Run testling with a default set of parameters
4+
#
5+
BINDIR=./browsers/bin
6+
export BROWSER=${BROWSER-chrome}
7+
export BVER=${BVER-stable}
8+
BROWSERBIN=$BINDIR/$BROWSER-$BVER
9+
if [ ! -x $BROWSERBIN ]; then
10+
echo "Installing browser"
11+
./node_modules/travis-multirunner/setup.sh
12+
fi
13+
echo "Starting browser"
14+
PATH=$PATH:./node_modules/.bin
15+
16+
node test/run-tests.js

src/selenium/selenium-lib.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3+
*
4+
* Use of this source code is governed by a BSD-style license
5+
* that can be found in the LICENSE file in the root of the source
6+
* tree.
7+
*/
8+
/* eslint-env node */
9+
10+
'use strict';
11+
12+
// https://code.google.com/p/selenium/wiki/WebDriverJs
13+
var webdriver = require('selenium-webdriver');
14+
var chrome = require('selenium-webdriver/chrome');
15+
var firefox = require('selenium-webdriver/firefox');
16+
var fs = require('fs');
17+
18+
var sharedDriver = null;
19+
20+
function getBrowserVersion() {
21+
var browser = process.env.BROWSER;
22+
var browserChannel = process.env.BVER;
23+
var symlink = './browsers/bin/' + browser + '-' + browserChannel + '/';
24+
var symPath = fs.readlink(symlink);
25+
26+
// Browser reg expressions and position to look for the milestone version.
27+
var chromeExp = '/Chrom(e|ium)\/([0-9]+)\./';
28+
var firefoxExp = '/Firefox\/([0-9]+)\./';
29+
var chromePos = 2;
30+
var firefoxPos = 1;
31+
32+
var browserVersion = function(path, expr, pos) {
33+
var match = path.match(expr);
34+
return match && match.length >= pos && parseInt(match[pos], 10);
35+
};
36+
37+
switch (browser) {
38+
case 'chrome':
39+
return browserVersion(symPath, chromeExp, chromePos);
40+
case 'firefox':
41+
return browserVersion(symPath, firefoxExp, firefoxPos);
42+
default:
43+
return 'non supported browser.';
44+
}
45+
}
46+
47+
function buildDriver() {
48+
if (sharedDriver) {
49+
return sharedDriver;
50+
}
51+
// Firefox options.
52+
// http://selenium.googlecode.com/git/docs/api/javascript/module_selenium-webdriver_firefox.html
53+
var profile = new firefox.Profile();
54+
profile.setPreference('media.navigator.streams.fake', true);
55+
// This enables device labels for enumerateDevices when using fake devices.
56+
profile.setPreference('media.navigator.permission.disabled', true);
57+
// Currently the FF webdriver extension is not signed and FF 41 no longer
58+
// allows unsigned extensions by default.
59+
// TODO: Remove this once FF no longer allow turning this off and the
60+
// selenium team starts making a signed FF webdriver extension.
61+
// https://github.com/SeleniumHQ/selenium/issues/901.
62+
profile.setPreference('xpinstall.signatures.required', false);
63+
64+
var firefoxOptions = new firefox.Options()
65+
.setProfile(profile)
66+
.setBinary('node_modules/.bin/start-firefox');
67+
68+
// Chrome options.
69+
// http://selenium.googlecode.com/git/docs/api/javascript/module_selenium-webdriver_chrome_class_Options.html#addArguments
70+
var chromeOptions = new chrome.Options()
71+
.setChromeBinaryPath('node_modules/.bin/start-chrome')
72+
.addArguments('allow-file-access-from-files')
73+
.addArguments('use-fake-device-for-media-stream')
74+
.addArguments('use-fake-ui-for-media-stream');
75+
76+
// Only enable this for Chrome >= 49.
77+
if (process.env.BROWSER === 'chrome' && getBrowserVersion >= '49') {
78+
chromeOptions.addArguments('--enable-experimental-web-platform-features');
79+
}
80+
81+
sharedDriver = new webdriver.Builder()
82+
.forBrowser(process.env.BROWSER)
83+
.setFirefoxOptions(firefoxOptions)
84+
.setChromeOptions(chromeOptions)
85+
.build();
86+
87+
// Set global executeAsyncScript() timeout (default is 0) to allow async
88+
// callbacks to be caught in tests.
89+
sharedDriver.manage().timeouts().setScriptTimeout(2000);
90+
91+
return sharedDriver;
92+
}
93+
94+
// A helper function to query stats from a PeerConnection.
95+
function getStats(driver, peerConnection) {
96+
// Execute getStats on peerconnection named `peerConnection`.
97+
driver.manage().timeouts().setScriptTimeout(1000);
98+
return driver.executeAsyncScript(
99+
'var callback = arguments[arguments.length - 1];' +
100+
peerConnection + '.getStats(null).then(function(report) {' +
101+
' callback(report);' +
102+
'});');
103+
}
104+
105+
module.exports = {
106+
buildDriver: buildDriver,
107+
getStats: getStats
108+
};

0 commit comments

Comments
 (0)