blob: 6518c20e019d78a123a5bd430b6ae1d11dad3ba3 [file] [log] [blame]
houssainy@google.com07ca9492014-09-22 13:52:39 +00001// Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
2//
3// Use of this source code is governed by a BSD-style license
4// that can be found in the LICENSE file in the root of the source
5// tree. An additional intellectual property rights grant can be found
6// in the file PATENTS. All contributing project authors may
7// be found in the AUTHORS file in the root of the source tree.
8//
9// A unidirectional video and audio flowing test from bot 1 to bot 2.
houssainy@google.comd0bb5862014-09-30 15:20:15 +000010// The test succeeds after collecting stats for 10 seconds from both bots
11// and then write these stats to a file.
houssainy@google.com07ca9492014-09-22 13:52:39 +000012//
13// Note: the source of the video and audio stream is getUserMedia().
andresp@webrtc.org458c2c32014-10-16 07:36:37 +000014function testOneWayVideo(test, bot1, bot2) {
houssainy@google.comd0bb5862014-09-30 15:20:15 +000015 var report = test.createStatisticsReport("webrtc_video_streaming");
16
houssainy@google.com07ca9492014-09-22 13:52:39 +000017 test.wait([
18 createPeerConnection.bind(bot1),
19 createPeerConnection.bind(bot2) ],
20 onPeerConnectionCreated);
21
22 function createPeerConnection(done) {
houssainy@google.com33820592014-10-22 17:17:15 +000023 test.createTurnConfig(onTurnConfig.bind(this), test.fail);
houssainy@google.com0371a372014-10-17 16:43:50 +000024
25 function onTurnConfig(config) {
houssainy@google.com3e2f8ff2014-10-15 15:01:11 +000026 this.createPeerConnection(config, done, test.fail);
houssainy@google.com0371a372014-10-17 16:43:50 +000027 };
houssainy@google.com07ca9492014-09-22 13:52:39 +000028 }
29
andresp@webrtc.org458c2c32014-10-16 07:36:37 +000030 function onPeerConnectionCreated(pc1, pc2) {
houssainy@google.com07ca9492014-09-22 13:52:39 +000031 test.log("RTC Peers created.");
houssainy@google.com07ca9492014-09-22 13:52:39 +000032 pc1.addEventListener('addstream', test.fail);
33 pc2.addEventListener('addstream', onAddStream);
34 pc1.addEventListener('icecandidate', onIceCandidate.bind(pc2));
35 pc2.addEventListener('icecandidate', onIceCandidate.bind(pc1));
36
37 bot1.getUserMedia({video:true, audio:true}, onUserMediaSuccess, test.fail);
38
39 function onUserMediaSuccess(stream) {
40 test.log("User has granted access to local media.");
41 pc1.addStream(stream);
42 bot1.showStream(stream.id, true, true);
43
andresp@webrtc.org458c2c32014-10-16 07:36:37 +000044 createOfferAndAnswer(pc1, pc2);
houssainy@google.com07ca9492014-09-22 13:52:39 +000045 }
46 }
47
48 function onAddStream(event) {
49 test.log("On Add stream.");
50 bot2.showStream(event.stream.id, true, false);
51 }
52
53 function onIceCandidate(event) {
andresp@webrtc.org458c2c32014-10-16 07:36:37 +000054 if(event.candidate) {
houssainy@google.com07ca9492014-09-22 13:52:39 +000055 test.log(event.candidate.candidate);
56 this.addIceCandidate(event.candidate,
57 onAddIceCandidateSuccess, test.fail);
andresp@webrtc.org458c2c32014-10-16 07:36:37 +000058 }
houssainy@google.com07ca9492014-09-22 13:52:39 +000059
60 function onAddIceCandidateSuccess() {
61 test.log("Candidate added successfully");
andresp@webrtc.org458c2c32014-10-16 07:36:37 +000062 }
houssainy@google.com07ca9492014-09-22 13:52:39 +000063 }
64
andresp@webrtc.org458c2c32014-10-16 07:36:37 +000065 function createOfferAndAnswer(pc1, pc2) {
houssainy@google.com07ca9492014-09-22 13:52:39 +000066 test.log("Creating offer.");
67 pc1.createOffer(gotOffer, test.fail);
68
69 function gotOffer(offer) {
70 test.log("Got offer");
71 pc1.setLocalDescription(offer, onSetSessionDescriptionSuccess, test.fail);
72 pc2.setRemoteDescription(offer, onSetSessionDescriptionSuccess,
73 test.fail);
74 test.log("Creating answer");
75 pc2.createAnswer(gotAnswer, test.fail);
76 }
77
78 function gotAnswer(answer) {
79 test.log("Got answer");
80 pc2.setLocalDescription(answer, onSetSessionDescriptionSuccess,
81 test.fail);
82 pc1.setRemoteDescription(answer, onSetSessionDescriptionSuccess,
83 test.fail);
houssainy@google.comd0bb5862014-09-30 15:20:15 +000084 collectStats();
houssainy@google.com07ca9492014-09-22 13:52:39 +000085 }
86
87 function onSetSessionDescriptionSuccess() {
88 test.log("Set session description success.");
89 }
houssainy@google.comd0bb5862014-09-30 15:20:15 +000090
91 function collectStats() {
92 report.collectStatsFromPeerConnection("bot1", pc1);
93 report.collectStatsFromPeerConnection("bot2", pc2);
94
95 setTimeout(function() {
96 report.finish(test.done);
97 }, 10000);
98 }
houssainy@google.com07ca9492014-09-22 13:52:39 +000099 }
100}
101
houssainy@google.comc221db62014-10-17 09:13:43 +0000102registerBotTest('testOneWayVideo/chrome-chrome',
andresp@webrtc.org458c2c32014-10-16 07:36:37 +0000103 testOneWayVideo, ['chrome', 'chrome']);