IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / test / data / media / getusermedia.html
blob92037cfb53752b854b205e66e6a1587f8776a1de
1 <html>
2 <head>
3 <script type="text/javascript" src="webrtc_test_utilities.js"></script>
4 <script type="text/javascript">
5 $ = function(id) {
6 return document.getElementById(id);
7 };
9 var gLocalStream = null;
11 setAllEventsOccuredHandler(function() {
12 gLocalStream.stop();
13 document.title = 'OK';
14 sendValueToTest(document.title);
15 });
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));
26 });
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(
34 constraints,
35 function(stream) { displayAndDetectVideo(stream, stopVideoTrack); },
36 failedCallback);
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(
44 constraints,
45 function(stream) {
46 displayAndDetectVideo(
47 stream,
48 function() {
49 waitAndStopVideoTrack(waitTimeInSeconds);
50 });
52 failedCallback);
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
61 // be rendered.
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);
86 analyzeVideo();
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...';
120 addExpectedEvent();
121 detectAspectRatio(function(aspectRatio) {
122 document.title = aspectRatio;
123 eventOccured();
127 </script>
128 </head>
129 <body>
130 <table border="0">
131 <tr>
132 <td>Local Preview</td>
133 </tr>
134 <tr>
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>
140 </tr>
141 </table>
142 </body>
143 </html>