author Andreas Pehrson <>
Fri, 23 Nov 2018 15:01:01 +0000
changeset 507044 7964b0b2f8363fbf1e5d3cdcc50b1d279987f1e9
parent 466523 8709ce7f1de1104c7a872c79ee8f0625dc5b504f
permissions -rw-r--r--
Bug 1423241 - Ensure audio loads after video to make drawImage happy. r=jib filed to cover this case in the spec. Differential Revision:

  <script type="application/javascript" src="/tests/dom/canvas/test/captureStream_common.js"></script>
  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
<pre id="test">

  bug: "1259788",
  title: "Test CaptureStream video content on HTMLMediaElement playing a gUM MediaStream",
  visible: true

var gUMVideoElement;
var captureStreamElement;

const pausedTimeout = 1000;
let h;

runTest(async () => {
  try {
    await pushPrefs(
      // This test expects fake video devices, as it expects captured frames to
      // shift over time, which is not currently provided by loopback devices
      ['media.video_loopback_dev', ''],
      ['media.navigator.streams.fake', true]);

    let stream = await getUserMedia({video: true});
    h = new VideoStreamHelper();
    gUMVideoElement =
      createMediaElement("video", "gUMVideo");
    gUMVideoElement.srcObject = stream;;

    captureStreamElement =
      createMediaElement("video", "captureStream");
    captureStreamElement.srcObject = gUMVideoElement.mozCaptureStream();;

    await h.checkVideoPlaying(captureStreamElement);

    // Adding a dummy audio track to the stream will keep a consuming media
    // element from ending.
    // We could also solve it by repeatedly play()ing or autoplay, but then we
    // wouldn't be sure the media element stopped rendering video because it
    // went to the ended state or because there were no frames for the track.
    let osc = createOscillatorStream(new AudioContext(), 1000);

    info("Video flowing. Pausing.");
    await h.checkVideoPaused(captureStreamElement, { time: pausedTimeout });

    info("Video stopped flowing. Playing.");;
    await h.checkVideoPlaying(captureStreamElement);

    info("Video flowing. Removing source.");
    stream = gUMVideoElement.srcObject;
    gUMVideoElement.srcObject = null;
    await h.checkVideoPaused(captureStreamElement, { time: pausedTimeout });

    info("Video stopped flowing. Setting source.");
    gUMVideoElement.srcObject = stream;
    await h.checkVideoPlaying(captureStreamElement);

    info("Video flowing. Changing source by track manipulation. Remove first.");
    let track = gUMVideoElement.srcObject.getTracks()[0];
    await h.checkVideoPaused(captureStreamElement, { time: pausedTimeout });

    info("Video paused. Changing source by track manipulation. Add first.");
    await h.checkVideoPlaying(captureStreamElement);

    gUMVideoElement.srcObject.getTracks().forEach(t => t.stop());
    ok(true, "Test passed.");
  } catch (e) {
    ok(false, "Test failed: " + e + (e.stack ? "\n" + e.stack : ""));