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>
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) {
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;
34 const stream = element.mozCaptureStreamUntilEnded();
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) {
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);
56 ok(false, `Caught error: ${e}`);
58 manager.finished(token);
62 manager.runTests(gTrackTests, startTest);