[GStreamer][MediaStream] Handle track addition and removal
[WebKit-https.git] / LayoutTests / fast / mediastream / MediaStream-video-element-remove-track.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3     <head>
4         <script src="../../resources/js-test-pre.js"></script>
5         <script>
6             var video;
7             var mediaStream;
8
9             function logEvent(element, eventName, func)
10             {
11                 function _eventCallback(evt)
12                 {
13                     if (window.wasFinishJSTestCalled)
14                         return;
15
16                     debug(`Event <em>'${evt.type}'</em>`);
17                     if (func)
18                         func(evt);
19                 }
20                 element.addEventListener(eventName, _eventCallback, true);
21             }
22
23             function checkVideoElement()
24             {
25                 evalAndLog("video.pause()");
26
27                 debug("<br>**** check video element ****");
28                 debug("<br>**** check video tracks ****");
29                 shouldBe('video.videoTracks.length', '1');
30                 shouldBe('video.videoTracks[0].id', 'mediaStream.getVideoTracks()[0].id');
31
32                 debug("<br>**** check audio tracks ****");
33                 shouldBe('video.audioTracks.length', '1');
34                 shouldBe('video.audioTracks[0].id', 'mediaStream.getAudioTracks()[0].id');
35
36                 setTimeout(removeAudioTrack, 100);
37             }
38
39             function checkVideoElement2()
40             {
41                 debug("<br>**** check video element ****");
42                 shouldBe('video.videoWidth', 'mediaStream.getVideoTracks()[0].getSettings().width');
43                 shouldBe('video.videoHeight', 'mediaStream.getVideoTracks()[0].getSettings().height');
44
45                 debug("<br>**** check video tracks ****");
46                 shouldBe('video.videoTracks.length', '1');
47                 shouldBe('video.videoTracks[0].id', 'mediaStream.getVideoTracks()[0].id');
48                 shouldBeEqualToString('video.videoTracks[0].language', '');
49                 shouldBeEqualToString('video.videoTracks[0].kind', 'main');
50
51                 debug("<br>**** check no audio track ****");
52                 shouldBe('video.audioTracks.length', '0');
53                 shouldBe('mediaStream.getAudioTracks().length', '0');
54
55                 finishJSTest();
56             }
57
58             function canplay()
59             {
60                 debug("<br>*** start playback ****");
61                 evalAndLog("video.play()");
62                 setTimeout(checkVideoElement, 100);
63             }
64
65             function removeAudioTrack() {
66                 track = mediaStream.getAudioTracks()[0];
67                 debug("<br>**** removing audio track ****");
68                 try {
69                     mediaStream.removeTrack(track);
70                 } catch (exception) {
71                     testFailed("removeTrack threw an exception.");
72                     finishJSTest();
73                 }
74                 setTimeout(checkVideoElement2, 100);
75             }
76
77             function setupStream(stream)
78             {
79                 mediaStream = stream;
80                 testPassed('mediaDevices.getUserMedia succeeded.');
81
82                 debug("<br>**** setup video element ****");
83                 evalAndLog("video.srcObject = mediaStream");
84             }
85
86             function start()
87             {
88                 description("Tests checking removing MediaStream track applies to the video element.");
89                 video = document.querySelector('video');
90                 logEvent(video, 'canplay', canplay)
91
92                 debug("<br>**** calling mediaDevices.getUserMedia() ****");
93                 if (window.testRunner)
94                     testRunner.setUserMediaPermission(true);
95                 navigator.mediaDevices.getUserMedia( {video: true, audio: true} )
96                     .then(setupStream)
97                     .catch(function(reason) {
98                         debug(`Stream generation failed with error: ${reason}`);
99                     });
100             }
101
102             window.jsTestIsAsync = true;
103             window.successfullyParsed = true;
104         </script>
105     </head>
106     <body onload="start()">
107         <p id="description"></p>
108         <video controls  width="680" height="360"></video>
109         <div id="console"></div>
110         <script src="../../resources/js-test-post.js"></script>
111     </body>
112 </html>