Backed out changeset ddccd40117a0 (bug 1853271) for causing bug 1854769. CLOSED TREE
[gecko.git] / dom / media / test / test_streams_tracks.html
blob845bc36ca35cc9c94832f94581b969c052f2227f
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>Test MediaStreamTrack interfaces</title>
5 <script src="/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
7 <script type="text/javascript" src="manifest.js"></script>
8 </head>
9 <body>
10 <pre id="test">
11 <script class="testbody" type="text/javascript">
12 const manager = new MediaTestManager;
14 function testTracks(tracks, hasTrack, kind, src) {
15 is(tracks.length, hasTrack ? 1 : 0, `Correct ${kind} track count for ${src}`);
16 for (const track of tracks) {
17 is(track.readyState, "live", `Track ${track.id} should still be live`);
18 is(track.kind, kind, `Correct track kind for track ${track.id} of ${src}`);
19 ok(/\{........-....-....-....-............\}/.test(track.id),
20 `id ${track.id} for ${track.kind} track of ${src} has correct form`);
24 async function startTest(test, token) {
25 try {
26 info(`Starting test of ${test.name}`);
27 const element = document.createElement("video");
29 element.token = token;
30 manager.started(token);
32 element.src = test.name;
33 element.test = test;
34 const stream = element.mozCaptureStreamUntilEnded();
36 element.play();
38 await new Promise(r => element.onloadedmetadata = r);
40 testTracks(stream.getAudioTracks(), test.hasAudio, "audio", test.name);
41 testTracks(stream.getVideoTracks(), test.hasVideo, "video", test.name);
42 const tracks = stream.getTracks();
44 await new Promise(r => element.onended = r);
46 for (let i = 0; i < tracks.length; ++i) {
47 await Promise.race(
48 tracks.map(t => new Promise(r => t.onended = r))
50 await new Promise(r => stream.onremovetrack = r);
53 testTracks(stream.getAudioTracks(), false, "audio", test.name);
54 testTracks(stream.getVideoTracks(), false, "video", test.name);
55 } catch(e) {
56 ok(false, `Caught error: ${e}`);
57 } finally {
58 manager.finished(token);
62 manager.runTests(gTrackTests, startTest);
63 </script>
64 </pre>
65 </body>
66 </html>