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

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

Issue 293123009: Cleaned up WebRTC browser test js, removed unneeded stuff. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/media/webrtc_browsertest_base.cc ('k') | chrome/test/data/webrtc/jsep01_call.js » ('j') | 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 (c) 2012 The Chromium Authors. All rights reserved. 2 * Copyright (c) 2012 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 * See http://dev.w3.org/2011/webrtc/editor/getusermedia.html for more 8 * See http://dev.w3.org/2011/webrtc/editor/getusermedia.html for more
9 * information on getUserMedia. 9 * information on getUserMedia.
10 */ 10 */
(...skipping 27 matching lines...) Expand all
38 return document.getElementById(id); 38 return document.getElementById(id);
39 }; 39 };
40 40
41 /** 41 /**
42 * This function asks permission to use the webcam and mic from the browser. It 42 * This function asks permission to use the webcam and mic from the browser. It
43 * will return ok-requested to the test. This does not mean the request was 43 * will return ok-requested to the test. This does not mean the request was
44 * approved though. The test will then have to click past the dialog that 44 * approved though. The test will then have to click past the dialog that
45 * appears in Chrome, which will run either the OK or failed callback as a 45 * appears in Chrome, which will run either the OK or failed callback as a
46 * a result. To see which callback was called, use obtainGetUserMediaResult(). 46 * a result. To see which callback was called, use obtainGetUserMediaResult().
47 * 47 *
48 * @param {string} constraints Defines what to be requested, with mandatory 48 * @param {!object} constraints Defines what to be requested, with mandatory
kjellander_chromium 2014/05/26 14:30:47 nit: Object starting with uppercase according to h
phoglund_chromium 2014/05/27 09:29:44 Done.
49 * and optional constraints defined. The contents of this parameter depends 49 * and optional constraints defined. The contents of this parameter depends
50 * on the WebRTC version. This should be JavaScript code that we eval(). 50 * on the WebRTC version.
51 */ 51 */
52 function doGetUserMedia(constraints) { 52 function doGetUserMedia(constraints) {
53 if (!getUserMedia) { 53 if (!getUserMedia) {
54 returnToTest('Browser does not support WebRTC.'); 54 returnToTest('Browser does not support WebRTC.');
55 return; 55 return;
56 } 56 }
57 try {
58 var evaluatedConstraints;
59 eval('evaluatedConstraints = ' + constraints);
60 } catch (exception) {
61 throw failTest('Not valid JavaScript expression: ' + constraints);
62 }
63 debug('Requesting doGetUserMedia: constraints: ' + constraints); 57 debug('Requesting doGetUserMedia: constraints: ' + constraints);
64 getUserMedia(evaluatedConstraints, 58 getUserMedia(constraints,
65 function(stream) { 59 function(stream) {
66 ensureGotAllExpectedStreams_(stream, constraints); 60 ensureGotAllExpectedStreams_(stream, constraints);
67 getUserMediaOkCallback_(stream); 61 getUserMediaOkCallback_(stream);
68 }, 62 },
69 getUserMediaFailedCallback_); 63 getUserMediaFailedCallback_);
70 returnToTest('ok-requested'); 64 returnToTest('ok-requested');
71 } 65 }
72 66
73 /** 67 /**
74 * Must be called after calling doGetUserMedia. 68 * Must be called after calling doGetUserMedia.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 * @return {string} Returns the current local stream - |gLocalStream|. 118 * @return {string} Returns the current local stream - |gLocalStream|.
125 */ 119 */
126 function getLocalStream() { 120 function getLocalStream() {
127 return gLocalStream; 121 return gLocalStream;
128 } 122 }
129 123
130 // Internals. 124 // Internals.
131 125
132 /** 126 /**
133 * @private 127 * @private
134 * @param {MediaStream} stream Media stream from getUserMedia. 128 * @param {!MediaStream} stream Media stream from getUserMedia.
135 * @param {String} constraints The constraints passed 129 * @param {!object} constraints The getUserMedia constraints object.
136 */ 130 */
137 function ensureGotAllExpectedStreams_(stream, constraints) { 131 function ensureGotAllExpectedStreams_(stream, constraints) {
138 var requestedVideo = /video\s*:\s*true/i; 132 if (constraints['video'] && stream.getVideoTracks().length == 0) {
139 if (requestedVideo.test(constraints) && stream.getVideoTracks().length == 0) {
140 gRequestWebcamAndMicrophoneResult = 'failed-to-get-video'; 133 gRequestWebcamAndMicrophoneResult = 'failed-to-get-video';
141 throw ('Requested video, but did not receive a video stream from ' + 134 throw ('Requested video, but did not receive a video stream from ' +
142 'getUserMedia. Perhaps the machine you are running on ' + 135 'getUserMedia. Perhaps the machine you are running on ' +
143 'does not have a webcam.'); 136 'does not have a webcam.');
144 } 137 }
145 var requestedAudio = /audio\s*:\s*true/i; 138 if (constraints['audio'] && stream.getAudioTracks().length == 0) {
146 if (requestedAudio.test(constraints) && stream.getAudioTracks().length == 0) {
147 gRequestWebcamAndMicrophoneResult = 'failed-to-get-audio'; 139 gRequestWebcamAndMicrophoneResult = 'failed-to-get-audio';
148 throw ('Requested audio, but did not receive an audio stream ' + 140 throw ('Requested audio, but did not receive an audio stream ' +
149 'from getUserMedia. Perhaps the machine you are running ' + 141 'from getUserMedia. Perhaps the machine you are running ' +
150 'on does not have audio devices.'); 142 'on does not have audio devices.');
151 } 143 }
152 } 144 }
153 145
154 /** 146 /**
155 * @private 147 * @private
156 * @param {MediaStream} stream Media stream. 148 * @param {MediaStream} stream Media stream.
(...skipping 10 matching lines...) Expand all
167 * @param {NavigatorUserMediaError} error Error containing details. 159 * @param {NavigatorUserMediaError} error Error containing details.
168 */ 160 */
169 function getUserMediaFailedCallback_(error) { 161 function getUserMediaFailedCallback_(error) {
170 // Translate from the old error to the new. Remove when rename fully deployed. 162 // Translate from the old error to the new. Remove when rename fully deployed.
171 var errorName = error.name; 163 var errorName = error.name;
172 164
173 debug('GetUserMedia FAILED: Maybe the camera is in use by another process?'); 165 debug('GetUserMedia FAILED: Maybe the camera is in use by another process?');
174 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + errorName; 166 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + errorName;
175 debug(gRequestWebcamAndMicrophoneResult); 167 debug(gRequestWebcamAndMicrophoneResult);
176 } 168 }
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc_browsertest_base.cc ('k') | chrome/test/data/webrtc/jsep01_call.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698