Get foreground tab on Android
[chromium-blink-merge.git] / content / test / data / media / getusermedia.html
blob6fbe5e502afbf15edec0f7cee8a7a4e870cf3e8c
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 });
16 // This test that a MediaStream can be created and a local preview
17 // rendered.
18 function getUserMedia(constraints) {
19 navigator.webkitGetUserMedia(constraints,
20 displayAndWaitForVideoToStartAndStop, failedCallback);
23 function getUserMediaWithAnalysis(constraints) {
24 navigator.webkitGetUserMedia(
25 constraints, displayAndWaitForAndAnalyzeVideo, failedCallback);
28 // This test that a MediaStream can be cloned and that the clone can
29 // be rendered.
30 function getUserMediaAndClone() {
31 navigator.webkitGetUserMedia({video: true, audio: true},
32 createAndRenderClone, failedCallback);
35 function failedCallback(error) {
36 document.title = 'GetUserMedia call failed with code ' + error.code;
39 function displayAndWaitForVideoToStartAndStop(stream) {
40 gLocalStream = stream;
41 var localStreamUrl = webkitURL.createObjectURL(stream);
42 $('local-view').src = localStreamUrl;
43 document.title = 'Waiting for video...';
44 // Wait for video to play, then stop the track and wait for video to stop
45 // playing.
46 detectVideoPlaying('local-view', stopVideoTrack);
49 function displayAndWaitForAndAnalyzeVideo(stream) {
50 gLocalStream = stream;
51 var localStreamUrl = webkitURL.createObjectURL(stream);
52 $('local-view').src = localStreamUrl;
53 analyzeVideo();
56 function createAndRenderClone(stream) {
57 gLocalStream = stream;
58 // TODO(perkj): --use-fake-device-for-media-stream do not currently
59 // work with audio devices and not all bots has a microphone.
60 new_stream = new webkitMediaStream();
61 new_stream.addTrack(stream.getVideoTracks()[0]);
62 expectEquals(new_stream.getVideoTracks().length, 1);
63 if (stream.getAudioTracks().length > 0) {
64 new_stream.addTrack(stream.getAudioTracks()[0]);
65 expectEquals(new_stream.getAudioTracks().length, 1);
66 new_stream.removeTrack(new_stream.getAudioTracks()[0]);
67 expectEquals(new_stream.getAudioTracks().length, 0);
70 var newStreamUrl = webkitURL.createObjectURL(new_stream);
71 $('local-view').src = newStreamUrl;
72 waitForVideo('local-view');
75 function stopVideoTrack() {
76 gLocalStream.getVideoTracks()[0].stop();
77 waitForVideoToStop('local-view');
80 function analyzeVideo() {
81 document.title = 'Waiting for video...';
82 addExpectedEvent();
83 detectAspectRatio(function(aspectRatio) {
84 document.title = aspectRatio;
85 eventOccured();
86 });
89 </script>
90 </head>
91 <body>
92 <table border="0">
93 <tr>
94 <td>Local Preview</td>
95 </tr>
96 <tr>
97 <td><video width="320" height="240" id="local-view"
98 autoplay="autoplay"></video></td>
99 <!-- Canvases are named after their corresponding video elements. -->
100 <td><canvas width="320" height="240" id="local-view-canvas"
101 style="display:none"></canvas></td>
102 </tr>
103 </table>
104 </body>
105 </html>