3 <script type=
"text/javascript" src=
"webrtc_test_utilities.js"></script>
4 <script type=
"text/javascript">
6 return document
.getElementById(id
);
9 var gLocalStream
= null;
11 setAllEventsOccuredHandler(function() {
13 document
.title
= 'OK';
14 sendValueToTest(document
.title
);
17 function sendValueToTest(value
) {
18 window
.domAutomationController
.setAutomationId(0);
19 window
.domAutomationController
.send(value
);
22 function getSources() {
23 MediaStreamTrack
.getSources(function(devices
) {
24 document
.title
= 'Sources Available';
25 sendValueToTest(JSON
.stringify(devices
));
29 // Creates a MediaStream and renders it locally. When the video is detected to
30 // be rolling, the title is changed and the stream should be stopped.
31 function getUserMediaAndStop(constraints
) {
32 document
.title
= 'Calling GetUserMedia';
33 navigator
.webkitGetUserMedia(
35 function(stream
) { displayAndDetectVideo(stream
, stopVideoTrack
); },
39 // Creates a MediaStream and renders it locally. When the video is detected to
40 // be rolling, the title should be changed and the stream is let roll for a
41 // number |waitTimeInSeconds| and then it should be stopped.
42 function getUserMediaAndWaitAndStop(constraints
, waitTimeInSeconds
) {
43 navigator
.webkitGetUserMedia(
46 displayAndDetectVideo(
49 waitAndStopVideoTrack(waitTimeInSeconds
);
55 function getUserMediaAndAnalyseAndStop(constraints
) {
56 navigator
.webkitGetUserMedia(
57 constraints
, displayDetectAndAnalyzeVideo
, failedCallback
);
60 // This test that a MediaStream can be cloned and that the clone can
62 function getUserMediaAndClone() {
63 navigator
.webkitGetUserMedia({video
: true, audio
: true},
64 createAndRenderClone
, failedCallback
);
67 function failedCallback(error
) {
68 document
.title
= 'GetUserMedia call failed with code ' + error
.code
;
69 sendValueToTest(document
.title
);
72 function plugStreamIntoLocalView(stream
) {
73 gLocalStream
= stream
;
74 var localStreamUrl
= URL
.createObjectURL(stream
);
75 $('local-view').src
= localStreamUrl
;
78 function displayAndDetectVideo(stream
, callback
) {
79 plugStreamIntoLocalView(stream
);
80 document
.title
= 'Waiting for video...';
81 detectVideoPlaying('local-view', callback
);
84 function displayDetectAndAnalyzeVideo(stream
) {
85 plugStreamIntoLocalView(stream
);
89 function createAndRenderClone(stream
) {
90 gLocalStream
= stream
;
91 // TODO(perkj): --use-fake-device-for-media-stream do not currently
92 // work with audio devices and not all bots has a microphone.
93 new_stream
= new webkitMediaStream();
94 new_stream
.addTrack(stream
.getVideoTracks()[0]);
95 expectEquals(new_stream
.getVideoTracks().length
, 1);
96 if (stream
.getAudioTracks().length
> 0) {
97 new_stream
.addTrack(stream
.getAudioTracks()[0]);
98 expectEquals(new_stream
.getAudioTracks().length
, 1);
99 new_stream
.removeTrack(new_stream
.getAudioTracks()[0]);
100 expectEquals(new_stream
.getAudioTracks().length
, 0);
103 var newStreamUrl
= URL
.createObjectURL(new_stream
);
104 $('local-view').src
= newStreamUrl
;
105 waitForVideo('local-view');
108 function stopVideoTrack() {
109 gLocalStream
.getVideoTracks()[0].stop();
110 waitForVideoToStop('local-view');
113 function waitAndStopVideoTrack(waitTimeInSeconds
) {
114 document
.title
= 'Running...';
115 setTimeout(stopVideoTrack
, waitTimeInSeconds
* 1000);
118 function analyzeVideo() {
119 document
.title
= 'Waiting for video...';
121 detectAspectRatio(function(aspectRatio
) {
122 document
.title
= aspectRatio
;
132 <td>Local Preview
</td>
135 <td><video width=
"320" height=
"240" id=
"local-view"
136 autoplay=
"autoplay"></video></td>
137 <!-- Canvases are named after their corresponding video elements. -->
138 <td><canvas width=
"320" height=
"240" id=
"local-view-canvas"
139 style=
"display:none"></canvas></td>