Selecting bot_type changed to be specified in the test file
Selecting bot_type changed to be specified in the test file instead of
specify it in the running command.
Now we can write test for rtcBot that run one bot on chrome for android
and the other bot on chrome for desktop.
R=andresp@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/23069004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7458 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/tools/rtcbot/README b/webrtc/tools/rtcbot/README
index 8b5bab1..72f9f63 100644
--- a/webrtc/tools/rtcbot/README
+++ b/webrtc/tools/rtcbot/README
@@ -17,12 +17,7 @@
== How to run the test ==
$ cd trunk/webrtc/tool/rtcbot
$ npm install express browserify ws websocket-stream dnode
- $ node test.js <bot_type> <test_file_path>
-
- <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.
+ $ node test.js <test_file_path>
== Example on how to install nodejs ==
$ cd /work/tools/
@@ -31,6 +26,12 @@
$ nvm install 0.10
$ nvm use 0.10
+== Supported Bot Types ==
+ - "chrome": chrome on host machine.
+ - "android-chrome": chrome on android device. Details in "Android" Section.
+
+ * Bot type is specified for each spawned bot in the test file.
+
== Android ==
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.
diff --git a/webrtc/tools/rtcbot/bot/browser/bot.js b/webrtc/tools/rtcbot/bot/browser/bot.js
index 808d88a..f278d89 100644
--- a/webrtc/tools/rtcbot/bot/browser/bot.js
+++ b/webrtc/tools/rtcbot/bot/browser/bot.js
@@ -25,10 +25,10 @@
}
}
-function createPeerConnection(doneCallback, failCallback) {
+function createPeerConnection(config, doneCallback, failCallback) {
console.log("Creating peer connection");
var obj = {};
- var pc = new webkitRTCPeerConnection(null);
+ var pc = new webkitRTCPeerConnection(config);
expose(obj, pc, "close");
expose(obj, pc, "createOffer");
@@ -113,9 +113,38 @@
return null;
};
+// Ask computeengineondemand to give us TURN server credentials and URIs.
+function asyncCreateTurnConfig(onSuccess, onError) {
+ var CEOD_URL = ('https://computeengineondemand.appspot.com/turn?' +
+ 'username=1234&key=5678');
+ var xhr = new XMLHttpRequest();
+ function onResult() {
+ if (xhr.readyState != 4)
+ return;
+
+ if (xhr.status != 200) {
+ onError('TURN request failed');
+ return;
+ }
+
+ var response = JSON.parse(xhr.responseText);
+ var iceServer = {
+ 'username': response.username,
+ 'credential': response.password,
+ 'urls': response.uris
+ };
+ onSuccess({ 'iceServers': [ iceServer ] });
+ }
+
+ xhr.onreadystatechange = onResult;
+ xhr.open('GET', CEOD_URL, true);
+ xhr.send();
+};
+
connectToServer({
ping: ping,
getUserMedia: getUserMedia,
createPeerConnection: createPeerConnection,
showStream: showStream,
+ asyncCreateTurnConfig: asyncCreateTurnConfig,
});
diff --git a/webrtc/tools/rtcbot/test.js b/webrtc/tools/rtcbot/test.js
index 785d5e8..e117398 100644
--- a/webrtc/tools/rtcbot/test.js
+++ b/webrtc/tools/rtcbot/test.js
@@ -16,11 +16,10 @@
var vm = require('vm');
var BotManager = require('./botmanager.js');
-function Test(botType) {
+function Test() {
this.timeout_ = setTimeout(
this.fail.bind(this, "Test timeout!"),
100000);
- this.botType_ = botType;
}
Test.prototype = {
@@ -67,11 +66,11 @@
}
},
- spawnBot: function (name, doneCallback) {
+ spawnBot: function (name, botType, doneCallback) {
// Lazy initialization of botmanager.
if (!this.botManager_)
this.botManager_ = new BotManager();
- this.botManager_.spawnNewBot(name, this.botType_, doneCallback);
+ this.botManager_.spawnNewBot(name, botType, doneCallback);
},
createStatisticsReport: function (outputFileName) {
@@ -137,11 +136,11 @@
},
}
-function runTest(botType, testfile) {
+function runTest(testfile) {
console.log("Running test: " + testfile);
var script = vm.createScript(fs.readFileSync(testfile), testfile);
- script.runInNewContext({ test: new Test(botType), setInterval: setInterval,
+ script.runInNewContext({ test: new Test(), setInterval: setInterval,
setTimeout: setTimeout });
}
-runTest(process.argv[2], process.argv[3]);
+runTest(process.argv[2]);
diff --git a/webrtc/tools/rtcbot/test/ping_pong.js b/webrtc/tools/rtcbot/test/ping_pong.js
index e519738..feee3bc 100644
--- a/webrtc/tools/rtcbot/test/ping_pong.js
+++ b/webrtc/tools/rtcbot/test/ping_pong.js
@@ -16,4 +16,4 @@
}
}
-test.spawnBot("alice", testPingPong);
+test.spawnBot("alice", "chrome", testPingPong);
diff --git a/webrtc/tools/rtcbot/test/simple_offer_answer.js b/webrtc/tools/rtcbot/test/simple_offer_answer.js
index 61eb0ba..e052598 100644
--- a/webrtc/tools/rtcbot/test/simple_offer_answer.js
+++ b/webrtc/tools/rtcbot/test/simple_offer_answer.js
@@ -17,7 +17,7 @@
establishCall);
function createPeerConnection(done) {
- this.createPeerConnection(done, test.fail);
+ this.createPeerConnection(null, done, test.fail);
}
function establishCall(pc1, pc2) {
@@ -49,6 +49,6 @@
test.done();
}
-test.wait( [ test.spawnBot.bind(test, "alice"),
- test.spawnBot.bind(test, "bob") ],
+test.wait( [ test.spawnBot.bind(test, "alice", "chrome"),
+ test.spawnBot.bind(test, "bob", "chrome") ],
testOfferAnswer);
diff --git a/webrtc/tools/rtcbot/test/webrtc_video_streaming.js b/webrtc/tools/rtcbot/test/webrtc_video_streaming.js
index 7b0457c..62b7056 100644
--- a/webrtc/tools/rtcbot/test/webrtc_video_streaming.js
+++ b/webrtc/tools/rtcbot/test/webrtc_video_streaming.js
@@ -24,7 +24,9 @@
onPeerConnectionCreated);
function createPeerConnection(done) {
- this.createPeerConnection(done, test.fail);
+ this.asyncCreateTurnConfig(function(config) {
+ this.createPeerConnection(config, done, test.fail);
+ }.bind(this), test.fail);
}
function onPeerConnectionCreated(peer1, peer2) {
@@ -101,6 +103,6 @@
}
}
-test.wait( [ test.spawnBot.bind(test, "alice"),
- test.spawnBot.bind(test, "bob") ],
+test.wait( [ test.spawnBot.bind(test, "alice", "chrome"),
+ test.spawnBot.bind(test, "bob", "android-chrome") ],
testVideoStreaming);