blob: 8ebad874d15db67c90959ff526209d6b82d31988 [file] [log] [blame]
houssainy@google.comfce8f5d2014-10-22 17:24:20 +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,
10// and download a file from a server after 2 seconds of establishing
11// the call.
12//
13// The test succeeds after collecting stats for 10 seconds from both bots
14// and then write these stats to a file.
15//
16// Note: the source of the video and audio stream is getUserMedia().
17//
18// // TODO(houssainy)
19// This test is still not working properly because we still missing the
20// Cross-Origin Resource Sharing (CORS) to be able to download the file
21// from non localhost domain.
22//
23function testOneWayVideoWithDownloading(test, bot1, bot2) {
24 var report = test.createStatisticsReport("testOneWayVideoWithDownloading");
25
26 test.wait([
27 createPeerConnection.bind(bot1),
28 createPeerConnection.bind(bot2) ],
29 onPeerConnectionCreated);
30
31 function createPeerConnection(done) {
32 test.createTurnConfig(onTurnConfig.bind(this), test.fail);
33
34 function onTurnConfig(config) {
35 this.createPeerConnection(config, done, test.fail);
36 };
37 }
38
39 function onPeerConnectionCreated(pc1, pc2) {
40 test.log("RTC Peers created.");
41 pc1.addEventListener('addstream', test.fail);
42 pc2.addEventListener('addstream', onAddStream);
43 pc1.addEventListener('icecandidate', onIceCandidate.bind(pc2));
44 pc2.addEventListener('icecandidate', onIceCandidate.bind(pc1));
45
46 bot1.getUserMedia({video:true, audio:true}, onUserMediaSuccess, test.fail);
47
48 function onUserMediaSuccess(stream) {
49 test.log("User has granted access to local media.");
50 pc1.addStream(stream);
51 bot1.showStream(stream.id, true, true);
52
53 createOfferAndAnswer(pc1, pc2);
54 }
55 }
56
57 function onAddStream(event) {
58 test.log("On Add stream.");
59 bot2.showStream(event.stream.id, true, false);
60 }
61
62 function onIceCandidate(event) {
63 if(event.candidate) {
64 test.log(event.candidate.candidate);
65 this.addIceCandidate(event.candidate,
66 onAddIceCandidateSuccess, test.fail);
67 }
68
69 function onAddIceCandidateSuccess() {
70 test.log("Candidate added successfully");
71 }
72 }
73
74 function createOfferAndAnswer(pc1, pc2) {
75 test.log("Creating offer.");
76 pc1.createOffer(gotOffer, test.fail);
77
78 function gotOffer(offer) {
79 test.log("Got offer");
80 pc1.setLocalDescription(offer, onSetSessionDescriptionSuccess, test.fail);
81 pc2.setRemoteDescription(offer, onSetSessionDescriptionSuccess,
82 test.fail);
83 test.log("Creating answer");
84 pc2.createAnswer(gotAnswer, test.fail);
85 }
86
87 function gotAnswer(answer) {
88 test.log("Got answer");
89 pc2.setLocalDescription(answer, onSetSessionDescriptionSuccess,
90 test.fail);
91 pc1.setRemoteDescription(answer, onSetSessionDescriptionSuccess,
92 test.fail);
93 collectStats();
94
95 setTimeout(function() {
96 downloadFile(bot1, "bot1");
97 downloadFile(bot2, "bot2");
98 }, 2000);
99 }
100
101 function onSetSessionDescriptionSuccess() {
102 test.log("Set session description success.");
103 }
104
105 function collectStats() {
106 report.collectStatsFromPeerConnection("bot1", pc1);
107 report.collectStatsFromPeerConnection("bot2", pc2);
108
109 setTimeout(function() {
110 report.finish(test.done);
111 }, 10000);
112 }
113
114 function downloadFile(bot, name) {
115 bot.downloadFile("http://test-needs-a-file-server",
116 onDownloadSuccess.bind(null, name), test.fail);
117
118 function onDownloadSuccess(name, data) {
119 test.log( name + " downloaded " +
120 Math.round(data.length/(1024*1024)) + "MB.");
121 }
122 }
123 }
124}
125
126registerBotTest('testOneWayVideoWithDownloading/chrome-chrome',
127 testOneWayVideoWithDownloading, ['chrome', 'chrome']);