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

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

Issue 2545553003: WebRtcStatsPerfBrowserTest added, a perf test using the new getStats (Closed)
Patch Set: Addressed nits, rebase, default initialize Created 4 years 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/BUILD.gn ('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 /** 25 /**
26 * The default video codec that should be used. 26 * The default audio codec that should be used when creating an offer.
27 * @private
28 */
29 var gDefaultAudioCodec = null;
30
31 /**
32 * The default video codec that should be used when creating an offer.
27 * @private 33 * @private
28 */ 34 */
29 var gDefaultVideoCodec = null; 35 var gDefaultVideoCodec = null;
30 36
31 /** 37 /**
32 * Flag to indicate if Opus Dtx should be enabled. 38 * Flag to indicate if Opus Dtx should be enabled.
33 * @private 39 * @private
34 */ 40 */
35 var gOpusDtx = false; 41 var gOpusDtx = false;
36 42
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 87
82 /** 88 /**
83 * Sets the flag to force Opus Dtx to be used when creating an offer. 89 * Sets the flag to force Opus Dtx to be used when creating an offer.
84 */ 90 */
85 function forceOpusDtx() { 91 function forceOpusDtx() {
86 gOpusDtx = true; 92 gOpusDtx = true;
87 returnToTest('ok-forced'); 93 returnToTest('ok-forced');
88 } 94 }
89 95
90 /** 96 /**
91 * Sets the default video codec be used when creating an offer. 97 * Sets the default audio codec to be used when creating an offer and returns
98 * "ok" to test.
99 * @param {string} audioCodec promotes the specified codec to be the default
100 * audio codec, e.g. the first one in the list on the 'm=audio' SDP offer
101 * line. |audioCodec| is the case-sensitive codec name, e.g. 'opus' or
102 * 'ISAC'.
103 */
104 function setDefaultAudioCodec(audioCodec) {
105 gDefaultAudioCodec = audioCodec;
106 returnToTest('ok');
107 }
108
109 /**
110 * Sets the default video codec to be used when creating an offer and returns
111 * "ok" to test.
92 * @param {string} videoCodec promotes the specified codec to be the default 112 * @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 113 * 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 114 * line. |videoCodec| is the case-sensitive codec name, e.g. 'VP8' or
95 * 'H264'. 115 * 'H264'.
96 */ 116 */
97 function forceVideoCodec(videoCodec) { 117 function setDefaultVideoCodec(videoCodec) {
98 gDefaultVideoCodec = videoCodec; 118 gDefaultVideoCodec = videoCodec;
99 returnToTest('ok-forced'); 119 returnToTest('ok');
100 } 120 }
101 121
102 /** 122 /**
103 * Creates a data channel with the specified label. 123 * Creates a data channel with the specified label.
104 * Returns 'ok-created' to test. 124 * Returns 'ok-created' to test.
105 */ 125 */
106 function createDataChannel(label) { 126 function createDataChannel(label) {
107 peerConnection_().createDataChannel(label); 127 peerConnection_().createDataChannel(label);
108 returnToTest('ok-created'); 128 returnToTest('ok-created');
109 } 129 }
110 130
111 /** 131 /**
112 * Asks this page to create a local offer. 132 * Asks this page to create a local offer.
113 * 133 *
114 * Returns a string on the format ok-(JSON encoded session description). 134 * Returns a string on the format ok-(JSON encoded session description).
115 * 135 *
116 * @param {!Object} constraints Any createOffer constraints. 136 * @param {!Object} constraints Any createOffer constraints.
117 */ 137 */
118 function createLocalOffer(constraints) { 138 function createLocalOffer(constraints) {
119 peerConnection_().createOffer( 139 peerConnection_().createOffer(
120 function(localOffer) { 140 function(localOffer) {
121 success('createOffer'); 141 success('createOffer');
122 142
123 setLocalDescription(peerConnection, localOffer); 143 setLocalDescription(peerConnection, localOffer);
144 if (gDefaultAudioCodec !== null) {
145 localOffer.sdp = setSdpDefaultAudioCodec(localOffer.sdp,
146 gDefaultAudioCodec);
147 }
124 if (gDefaultVideoCodec !== null) { 148 if (gDefaultVideoCodec !== null) {
125 localOffer.sdp = setSdpDefaultVideoCodec(localOffer.sdp, 149 localOffer.sdp = setSdpDefaultVideoCodec(localOffer.sdp,
126 gDefaultVideoCodec); 150 gDefaultVideoCodec);
127 } 151 }
128 if (gOpusDtx) { 152 if (gOpusDtx) {
129 localOffer.sdp = setOpusDtxEnabled(localOffer.sdp); 153 localOffer.sdp = setOpusDtxEnabled(localOffer.sdp);
130 } 154 }
131 returnToTest('ok-' + JSON.stringify(localOffer)); 155 returnToTest('ok-' + JSON.stringify(localOffer));
132 }, 156 },
133 function(error) { failure('createOffer', error); }, 157 function(error) { failure('createOffer', error); },
(...skipping 29 matching lines...) Expand all
163 if (gOpusDtx) { 187 if (gOpusDtx) {
164 answer.sdp = setOpusDtxEnabled(answer.sdp); 188 answer.sdp = setOpusDtxEnabled(answer.sdp);
165 } 189 }
166 returnToTest('ok-' + JSON.stringify(answer)); 190 returnToTest('ok-' + JSON.stringify(answer));
167 }, 191 },
168 function(error) { failure('createAnswer', error); }, 192 function(error) { failure('createAnswer', error); },
169 constraints); 193 constraints);
170 } 194 }
171 195
172 /** 196 /**
173 * Verifies that the codec previously set using forceVideoCodec() is the 197 * Verifies that the codec previously set using setDefault[Audio/Video]Codec()
174 * default video codec, e.g. the first one in the list on the 'm=video' SDP 198 * is the default audio/video codec, e.g. the first one in the list on the
175 * answer line. If this is not the case, |failure| occurs. If no codec was 199 * 'm=audio'/'m=video' SDP answer line. If this is not the case, |failure|
176 * previously set using forceVideoCodec(), this function will return 200 * occurs. If no codec was previously set using setDefault[Audio/Video]Codec(),
177 * 'ok-no-default-set'. 201 * this function will return 'ok-no-defaults-set'.
178 * 202 *
179 * @param {!string} sessionDescJson A JSON-encoded session description. 203 * @param {!string} sessionDescJson A JSON-encoded session description.
180 */ 204 */
181 function verifyDefaultVideoCodec(sessionDescJson) { 205 function verifyDefaultCodecs(sessionDescJson) {
182 var sessionDesc = parseJson_(sessionDescJson); 206 let sessionDesc = parseJson_(sessionDescJson);
183 if (gDefaultVideoCodec === null) { 207 if (!sessionDesc.type) {
184 returnToTest('ok-no-default-set'); 208 failure('verifyDefaultCodecs',
209 'Invalid session description: ' + sessionDescJson);
210 }
211 if (gDefaultAudioCodec !== null && gDefaultVideoCodec !== null) {
212 returnToTest('ok-no-defaults-set');
185 return; 213 return;
186 } 214 }
187 if (!sessionDesc.type) { 215 if (gDefaultAudioCodec !== null) {
188 failure('verifyDefaultVideoCodec', 216 let defaultAudioCodec = getSdpDefaultAudioCodec(sessionDesc.sdp);
189 'Invalid session description: ' + sessionDescJson); 217 if (defaultAudioCodec === null) {
218 failure('verifyDefaultCodecs',
219 'Could not determine default audio codec.');
220 }
221 if (gDefaultAudioCodec !== defaultAudioCodec) {
222 failure('verifyDefaultCodecs',
223 'Expected default audio codec ' + gDefaultAudioCodec +
224 ', got ' + defaultAudioCodec + '.');
225 }
190 } 226 }
191 var defaultVideoCodec = getSdpDefaultVideoCodec(sessionDesc.sdp); 227 if (gDefaultVideoCodec !== null) {
192 if (defaultVideoCodec === null) { 228 let defaultVideoCodec = getSdpDefaultVideoCodec(sessionDesc.sdp);
193 failure('verifyDefaultVideoCodec', 229 if (defaultVideoCodec === null) {
194 'Could not determine default video codec.'); 230 failure('verifyDefaultCodecs',
195 } 231 'Could not determine default video codec.');
196 if (gDefaultVideoCodec !== defaultVideoCodec) { 232 }
197 failure('verifyDefaultVideoCodec', 233 if (gDefaultVideoCodec !== defaultVideoCodec) {
198 'Expected default video codec ' + gDefaultVideoCodec + 234 failure('verifyDefaultCodecs',
199 ', got ' + defaultVideoCodec + '.'); 235 'Expected default video codec ' + gDefaultVideoCodec +
236 ', got ' + defaultVideoCodec + '.');
237 }
200 } 238 }
201 returnToTest('ok-verified'); 239 returnToTest('ok-verified');
202 } 240 }
203 241
204 /** 242 /**
205 * Asks this page to accept an answer generated by the peer in response to a 243 * Asks this page to accept an answer generated by the peer in response to a
206 * previous offer by this page 244 * previous offer by this page
207 * 245 *
208 * Returns a string ok-accepted-answer on success. 246 * Returns a string ok-accepted-answer on success.
209 * 247 *
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 function parseJson_(json) { 460 function parseJson_(json) {
423 // Escape since the \r\n in the SDP tend to get unescaped. 461 // Escape since the \r\n in the SDP tend to get unescaped.
424 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); 462 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n');
425 try { 463 try {
426 return JSON.parse(jsonWithEscapedLineBreaks); 464 return JSON.parse(jsonWithEscapedLineBreaks);
427 } catch (exception) { 465 } catch (exception) {
428 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + 466 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' +
429 exception); 467 exception);
430 } 468 }
431 } 469 }
OLDNEW
« no previous file with comments | « chrome/test/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698