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/webrtc@7102 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/tools/rtcbot/README b/tools/rtcbot/README
index 927d377..8b5bab1 100644
--- a/tools/rtcbot/README
+++ b/tools/rtcbot/README
@@ -22,6 +22,7 @@
  <bot_type> — 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 @@
 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/tools/rtcbot/botmanager.js b/tools/rtcbot/botmanager.js
index e8f8b9b..76e50b4 100644
--- a/tools/rtcbot/botmanager.js
+++ b/tools/rtcbot/botmanager.js
@@ -26,10 +26,12 @@
   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 @@
     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 @@
   __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 @@
     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:
         // <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++) {
           if (tempList[i] == "") {
             continue;