Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: chrome/test/data/webrtc/peerconnection.js

Issue 2195293002: Revert of Adds a WebRTC browser_test with opus dtx enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/data/webrtc/munge_sdp.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /**
2 * Copyright 2014 The Chromium Authors. All rights reserved. 2 * Copyright 2014 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 /** 7 /**
8 * The one and only peer connection in this page. 8 * The one and only peer connection in this page.
9 * @private 9 * @private
10 */ 10 */
11 var gPeerConnection = null; 11 var gPeerConnection = null;
12 12
13 /** 13 /**
14 * This stores ICE candidates generated on this side. 14 * This stores ICE candidates generated on this side.
15 * @private 15 * @private
16 */ 16 */
17 var gIceCandidates = []; 17 var gIceCandidates = [];
18 18
19 /** 19 /**
20 * Keeps track of whether we have seen crypto information in the SDP. 20 * Keeps track of whether we have seen crypto information in the SDP.
21 * @private 21 * @private
22 */ 22 */
23 var gHasSeenCryptoInSdp = 'no-crypto-seen'; 23 var gHasSeenCryptoInSdp = 'no-crypto-seen';
24 24
25 /**
26 * The default video codec that should be used.
27 * @private
28 */
29 var gDefaultVideoCodec = null;
30
31 /**
32 * Flag to indicate if Opus Dtx should be enabled.
33 * @private
34 */
35 var gOpusDtx = false;
36
37 // Public interface to tests. These are expected to be called with 25 // Public interface to tests. These are expected to be called with
38 // ExecuteJavascript invocations from the browser tests and will return answers 26 // ExecuteJavascript invocations from the browser tests and will return answers
39 // through the DOM automation controller. 27 // through the DOM automation controller.
40 28
41 /** 29 /**
42 * Creates a peer connection. Must be called before most other public functions 30 * Creates a peer connection. Must be called before most other public functions
43 * in this file. Alternatively, see |preparePeerConnectionWithCertificate|. 31 * in this file. Alternatively, see |preparePeerConnectionWithCertificate|.
44 * @param {Object} keygenAlgorithm Unless null, this is an |AlgorithmIdentifier| 32 * @param {Object} keygenAlgorithm Unless null, this is an |AlgorithmIdentifier|
45 * to be used as parameter to |RTCPeerConnection.generateCertificate|. The 33 * to be used as parameter to |RTCPeerConnection.generateCertificate|. The
46 * resulting certificate will be used by the peer connection. If null, a default 34 * resulting certificate will be used by the peer connection. If null, a default
(...skipping 26 matching lines...) Expand all
73 */ 61 */
74 function preparePeerConnectionWithCertificate(certificate) { 62 function preparePeerConnectionWithCertificate(certificate) {
75 if (gPeerConnection !== null) 63 if (gPeerConnection !== null)
76 throw failTest('Creating peer connection, but we already have one.'); 64 throw failTest('Creating peer connection, but we already have one.');
77 gPeerConnection = createPeerConnection_( 65 gPeerConnection = createPeerConnection_(
78 {iceServers:[], certificates:[certificate]}); 66 {iceServers:[], certificates:[certificate]});
79 returnToTest('ok-peerconnection-created'); 67 returnToTest('ok-peerconnection-created');
80 } 68 }
81 69
82 /** 70 /**
83 * Sets the flag to force Opus Dtx to be used when creating an offer.
84 */
85 function forceOpusDtx() {
86 gOpusDtx = true;
87 returnToTest('ok-forced');
88 }
89
90 /**
91 * Sets the default video codec be used when creating an offer.
92 * @param {string} videoCodec promotes the specified codec to be the default
93 * video codec, e.g. the first one in the list on the 'm=video' SDP offer
94 * line. |videoCodec| is the case-sensitive codec name, e.g. 'VP8' or
95 * 'H264'.
96 */
97 function forceVideoCodec(videoCodec) {
98 gDefaultVideoCodec = videoCodec;
99 returnToTest('ok-forced');
100 }
101
102 /**
103 * Asks this page to create a local offer. 71 * Asks this page to create a local offer.
104 * 72 *
105 * Returns a string on the format ok-(JSON encoded session description). 73 * Returns a string on the format ok-(JSON encoded session description).
106 * 74 *
107 * @param {!Object} constraints Any createOffer constraints. 75 * @param {!Object} constraints Any createOffer constraints.
76 * @param {string} videoCodec If not null, promotes the specified codec to be
77 * the default video codec, e.g. the first one in the list on the 'm=video'
78 * SDP offer line. |videoCodec| is the case-sensitive codec name, e.g.
79 * 'VP8' or 'H264'.
108 */ 80 */
109 function createLocalOffer(constraints) { 81 function createLocalOffer(constraints, videoCodec = null) {
110 peerConnection_().createOffer( 82 peerConnection_().createOffer(
111 function(localOffer) { 83 function(localOffer) {
112 success('createOffer'); 84 success('createOffer');
113 85
114 setLocalDescription(peerConnection, localOffer); 86 setLocalDescription(peerConnection, localOffer);
115 if (gDefaultVideoCodec !== null) { 87 if (videoCodec !== null)
116 localOffer.sdp = setSdpDefaultVideoCodec(localOffer.sdp, 88 localOffer.sdp = setSdpDefaultVideoCodec(localOffer.sdp, videoCodec);
117 gDefaultVideoCodec); 89
118 }
119 if (gOpusDtx) {
120 localOffer.sdp = setOpusDtxEnabled(localOffer.sdp);
121 }
122 returnToTest('ok-' + JSON.stringify(localOffer)); 90 returnToTest('ok-' + JSON.stringify(localOffer));
123 }, 91 },
124 function(error) { failure('createOffer', error); }, 92 function(error) { failure('createOffer', error); },
125 constraints); 93 constraints);
126 } 94 }
127 95
128 /** 96 /**
129 * Asks this page to accept an offer and generate an answer. 97 * Asks this page to accept an offer and generate an answer.
130 * 98 *
131 * Returns a string on the format ok-(JSON encoded session description). 99 * Returns a string on the format ok-(JSON encoded session description).
(...skipping 12 matching lines...) Expand all
144 var sessionDescription = new RTCSessionDescription(offer); 112 var sessionDescription = new RTCSessionDescription(offer);
145 peerConnection_().setRemoteDescription( 113 peerConnection_().setRemoteDescription(
146 sessionDescription, 114 sessionDescription,
147 function() { success('setRemoteDescription'); }, 115 function() { success('setRemoteDescription'); },
148 function(error) { failure('setRemoteDescription', error); }); 116 function(error) { failure('setRemoteDescription', error); });
149 117
150 peerConnection_().createAnswer( 118 peerConnection_().createAnswer(
151 function(answer) { 119 function(answer) {
152 success('createAnswer'); 120 success('createAnswer');
153 setLocalDescription(peerConnection, answer); 121 setLocalDescription(peerConnection, answer);
154 if (gOpusDtx) {
155 answer.sdp = setOpusDtxEnabled(answer.sdp);
156 }
157 returnToTest('ok-' + JSON.stringify(answer)); 122 returnToTest('ok-' + JSON.stringify(answer));
158 }, 123 },
159 function(error) { failure('createAnswer', error); }, 124 function(error) { failure('createAnswer', error); },
160 constraints); 125 constraints);
161 } 126 }
162 127
163 /** 128 /**
164 * Verifies that the codec previously set using forceVideoCodec() is the 129 * Verifies that the specified codec is the default video codec, e.g. the first
165 * default video codec, e.g. the first one in the list on the 'm=video' SDP 130 * one in the list on the 'm=video' SDP answer line. If this is not the case,
166 * answer line. If this is not the case, |failure| occurs. If no codec was 131 * |failure| occurs.
167 * previously set using forceVideoCodec(), this function will return
168 * 'ok-no-default-set'.
169 * 132 *
170 * @param {!string} sessionDescJson A JSON-encoded session description. 133 * @param {!string} sessionDescJson A JSON-encoded session description.
134 * @param {!string} expectedVideoCodec The case-sensitive codec name, e.g.
135 * 'VP8' or 'H264'.
171 */ 136 */
172 function verifyDefaultVideoCodec(sessionDescJson) { 137 function verifyDefaultVideoCodec(sessionDescJson, expectedVideoCodec) {
173 var sessionDesc = parseJson_(sessionDescJson); 138 var sessionDesc = parseJson_(sessionDescJson);
174 var defaultVideoCodec = getSdpDefaultVideoCodec(sessionDesc.sdp);
175 if (gDefaultVideoCodec === null) {
176 returnToTest('ok-no-default-set');
177 return;
178 }
179 if (!sessionDesc.type) { 139 if (!sessionDesc.type) {
180 failure('verifyDefaultVideoCodec', 140 failure('verifyDefaultVideoCodec',
181 'Invalid session description: ' + sessionDescJson); 141 'Invalid session description: ' + sessionDescJson);
182 } 142 }
183 var defaultVideoCodec = getSdpDefaultVideoCodec(sessionDesc.sdp); 143 var defaultVideoCodec = getSdpDefaultVideoCodec(sessionDesc.sdp);
184 if (defaultVideoCodec === null) { 144 if (defaultVideoCodec === null) {
185 failure('verifyDefaultVideoCodec', 145 failure('verifyDefaultVideoCodec',
186 'Could not determine default video codec.'); 146 'Could not determine default video codec.');
187 } 147 }
188 if (gDefaultVideoCodec !== defaultVideoCodec) { 148 if (expectedVideoCodec !== defaultVideoCodec) {
189 failure('verifyDefaultVideoCodec', 149 failure('verifyDefaultVideoCodec',
190 'Expected default video codec ' + gDefaultVideoCodec + 150 'Expected default video codec ' + expectedVideoCodec +
191 ', got ' + defaultVideoCodec + '.'); 151 ', got ' + defaultVideoCodec + '.');
192 } 152 }
193 returnToTest('ok-verified'); 153 returnToTest('ok-verified');
194 } 154 }
195 155
196 /** 156 /**
197 * Asks this page to accept an answer generated by the peer in response to a 157 * Asks this page to accept an answer generated by the peer in response to a
198 * previous offer by this page 158 * previous offer by this page
199 * 159 *
200 * Returns a string ok-accepted-answer on success. 160 * Returns a string ok-accepted-answer on success.
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 function parseJson_(json) { 349 function parseJson_(json) {
390 // Escape since the \r\n in the SDP tend to get unescaped. 350 // Escape since the \r\n in the SDP tend to get unescaped.
391 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); 351 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n');
392 try { 352 try {
393 return JSON.parse(jsonWithEscapedLineBreaks); 353 return JSON.parse(jsonWithEscapedLineBreaks);
394 } catch (exception) { 354 } catch (exception) {
395 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + 355 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' +
396 exception); 356 exception);
397 } 357 }
398 } 358 }
OLDNEW
« no previous file with comments | « chrome/test/data/webrtc/munge_sdp.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698