summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/test_getUserMedia_bug1223696.html
blob: 6af7b69d70ac77e230e0c0fb3c0fb840c1880e27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
  <script type="application/javascript" src="/tests/dom/canvas/test/captureStream_common.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
  "use strict";

  createHTML({
    title: "Testing that removeTrack+addTrack of video tracks still render the correct track in a media element",
    bug: "1223696",
    visible: true
  });

  runTest(async function() {
    const stream = await getUserMedia({audio:true, video: true});
    info("Test addTrack()ing a video track to an audio-only gUM stream");

    const video = createMediaElement("video", "test_video_track");
    video.srcObject = stream;
    video.play();

    await haveEvent(video, "loadeddata", wait(5000, new Error("Timeout")));
    info("loadeddata");

    const removedTrack = stream.getVideoTracks()[0];
    stream.removeTrack(removedTrack);

    const h = new CaptureStreamTestHelper2D();
    const emitter = new VideoFrameEmitter(h.grey, h.grey);
    emitter.start();

    stream.addTrack(emitter.stream().getVideoTracks()[0]);

    checkMediaStreamContains(stream, [stream.getAudioTracks()[0],
                                      emitter.stream().getVideoTracks()[0]]);

    await h.pixelMustBecome(video, h.grey, {
      threshold: 5,
      infoString: "The canvas track should be rendered by the media element",
    });

    emitter.stop();
    for (const t of [removedTrack, ...stream.getAudioTracks()]) {
      t.stop();
    }
  });
</script>
</pre>
</body>
</html>