Adding the ability to test on Chrome for Android.

use "android-chrome" as type in rtcbot running command.
Example: node test.js android-chrome

R=andresp@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/20329004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7102 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
houssainy@google.com
2014-09-08 13:01:40 +00:00
parent 37c39f3784
commit 9600519147
2 changed files with 40 additions and 4 deletions

View File

@@ -22,6 +22,7 @@ access its exposed API. Details are in botmanager.js.
<bot_type> — the type of the running bot. For example: <bot_type> — the type of the running bot. For example:
- chrome: chrome on host machine. - chrome: chrome on host machine.
- android: android device. Details in "Android" Section. - android: android device. Details in "Android" Section.
- android-chrome: chrome on android device. Details in "Android" Section.
== Example on how to install nodejs == == Example on how to install nodejs ==
$ cd /work/tools/ $ cd /work/tools/
@@ -35,5 +36,6 @@ Before running test with Android one MUST forward the device port 8080 to the
host machine. That is easy to achieve with chrome port forwarding tools. host machine. That is easy to achieve with chrome port forwarding tools.
- Visit chrome://inspect/devices on the host machine. - Visit chrome://inspect/devices on the host machine.
- Configure and enable port forwarding 8080 -> localhost:8080 - Configure and enable port forwarding 8080 -> localhost:8080
- Leave chrome running in the background on your Android device till - Open chrome on you Android device before running test, and leave it
the test is done. running until the end of test.
- Run your test.

View File

@@ -26,10 +26,12 @@ BotManager = function () {
this.webSocketServer_ = null; this.webSocketServer_ = null;
this.bots_ = []; this.bots_ = [];
this.pendingConnections_ = []; this.pendingConnections_ = [];
this.androidDeviceManager_ = new AndroidDeviceManager();
} }
BotManager.BotTypes = { BotManager.BotTypes = {
CHROME : 'chrome', CHROME : 'chrome',
ANDROID_CHROME : 'android-chrome',
}; };
BotManager.prototype = { BotManager.prototype = {
@@ -37,6 +39,9 @@ BotManager.prototype = {
switch(botType) { switch(botType) {
case BotManager.BotTypes.CHROME: case BotManager.BotTypes.CHROME:
return new BrowserBot(name, callback); return new BrowserBot(name, callback);
case BotManager.BotTypes.ANDROID_CHROME:
return new AndroidChromeBot(name, this.androidDeviceManager_,
callback);
default: default:
console.log('Error: Type ' + botType + ' not supported by rtc-Bot!'); console.log('Error: Type ' + botType + ' not supported by rtc-Bot!');
process.exit(1); process.exit(1);
@@ -129,6 +134,35 @@ BrowserBot.prototype = {
__proto__: Bot.prototype __proto__: Bot.prototype
} }
// AndroidChromeBot spawns a process to open
// "http://localhost:8080/bot/browser/" on chrome for Android.
AndroidChromeBot = function (name, androidDeviceManager, callback) {
Bot.call(this, name, callback);
androidDeviceManager.getNewDevice(function (serialNumber) {
this.serialNumber_ = serialNumber;
this.spawnBotProcess_();
}.bind(this));
}
AndroidChromeBot.prototype = {
spawnBotProcess_: function () {
this.log('Spawning Android device with serial ' + this.serialNumber_);
var runChrome = 'adb -s ' + this.serialNumber_ + ' shell am start ' +
'-n com.android.chrome/com.google.android.apps.chrome.Main ' +
'-d http://localhost:8080/bot/';
child.exec(runChrome, function (error, stdout, stderr) {
if (error) {
this.log(error);
process.exit(1);
}
this.log('Opening Chrome for Android...');
this.log(stdout);
}.bind(this));
},
__proto__: Bot.prototype
}
AndroidDeviceManager = function () { AndroidDeviceManager = function () {
this.connectedDevices_ = []; this.connectedDevices_ = [];
} }
@@ -156,13 +190,13 @@ AndroidDeviceManager.prototype = {
child.exec('adb devices' , function (error, stdout, stderr) { child.exec('adb devices' , function (error, stdout, stderr) {
var devices = []; var devices = [];
if (error || stderr) { if (error || stderr) {
console.log('' + (error || stderr)); console.log(error || stderr);
} }
if (stdout) { if (stdout) {
// The first line is "List of devices attached" // The first line is "List of devices attached"
// and the following lines: // and the following lines:
// <serial number> <device/emulator> // <serial number> <device/emulator>
var tempList = ('' + stdout).split("\n").slice(1); var tempList = stdout.split("\n").slice(1);
for (var i = 0; i < tempList.length; i++) { for (var i = 0; i < tempList.length; i++) {
if (tempList[i] == "") { if (tempList[i] == "") {
continue; continue;