From 96005191474b36e68ba7455c2de70d290449a7db Mon Sep 17 00:00:00 2001 From: "houssainy@google.com" Date: Mon, 8 Sep 2014 13:01:40 +0000 Subject: [PATCH] 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 --- webrtc/tools/rtcbot/README | 6 +++-- webrtc/tools/rtcbot/botmanager.js | 38 +++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/webrtc/tools/rtcbot/README b/webrtc/tools/rtcbot/README index 927d37795..8b5bab10c 100644 --- a/webrtc/tools/rtcbot/README +++ b/webrtc/tools/rtcbot/README @@ -22,6 +22,7 @@ access its exposed API. Details are in botmanager.js. — the type of the running bot. For example: - chrome: chrome on host machine. - android: android device. Details in "Android" Section. + - android-chrome: chrome on android device. Details in "Android" Section. == Example on how to install nodejs == $ 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. - Visit chrome://inspect/devices on the host machine. - Configure and enable port forwarding 8080 -> localhost:8080 - - Leave chrome running in the background on your Android device till - the test is done. \ No newline at end of file + - Open chrome on you Android device before running test, and leave it + running until the end of test. + - Run your test. diff --git a/webrtc/tools/rtcbot/botmanager.js b/webrtc/tools/rtcbot/botmanager.js index e8f8b9b2f..76e50b40b 100644 --- a/webrtc/tools/rtcbot/botmanager.js +++ b/webrtc/tools/rtcbot/botmanager.js @@ -26,10 +26,12 @@ BotManager = function () { this.webSocketServer_ = null; this.bots_ = []; this.pendingConnections_ = []; + this.androidDeviceManager_ = new AndroidDeviceManager(); } BotManager.BotTypes = { CHROME : 'chrome', + ANDROID_CHROME : 'android-chrome', }; BotManager.prototype = { @@ -37,6 +39,9 @@ BotManager.prototype = { switch(botType) { case BotManager.BotTypes.CHROME: return new BrowserBot(name, callback); + case BotManager.BotTypes.ANDROID_CHROME: + return new AndroidChromeBot(name, this.androidDeviceManager_, + callback); default: console.log('Error: Type ' + botType + ' not supported by rtc-Bot!'); process.exit(1); @@ -129,6 +134,35 @@ BrowserBot.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 () { this.connectedDevices_ = []; } @@ -156,13 +190,13 @@ AndroidDeviceManager.prototype = { child.exec('adb devices' , function (error, stdout, stderr) { var devices = []; if (error || stderr) { - console.log('' + (error || stderr)); + console.log(error || stderr); } if (stdout) { // The first line is "List of devices attached" // and the following lines: // - var tempList = ('' + stdout).split("\n").slice(1); + var tempList = stdout.split("\n").slice(1); for (var i = 0; i < tempList.length; i++) { if (tempList[i] == "") { continue;