summaryrefslogtreecommitdiffstats
path: root/dom/media/tests/mochitest/test_peerConnection_capturedVideo.html
blob: 27bcc9a52ac259776fbb77b5130d18295a1cf2ac (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="pc.js"></script>
  <script type="text/javascript" src="../../test/manifest.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript;version=1.8">
var manager = new MediaTestManager;

createHTML({
  bug: "1081409",
  title: "Captured video-only over peer connection",
  visible: true
}).then(() => new Promise(resolve => {
  manager.runTests(getPlayableVideos(gLongerTests), startTest);
  manager.onFinished = () => {
    // Tear down before SimpleTest.finish.
    if ("nsINetworkInterfaceListService" in SpecialPowers.Ci) {
      getNetworkUtils().tearDownNetwork();
    }
    resolve();
  };
}))
.catch(e => ok(false, "Unexpected " + e + ":\n" + e.stack));

// Run tests in sequence for log readability.
PARALLEL_TESTS = 1;

function startTest(media, token) {
  manager.started(token);
  var video = document.createElement('video');
  video.id = "id_" + media.name;
  video.width = 160;
  video.height = 120;
  video.muted = true;
  video.loop = true;
  video.preload = "metadata";
  video.src = "../../test/" + media.name;

  document.getElementById("content").appendChild(video);

  var test;
  new Promise((resolve, reject) => {
    video.onloadedmetadata = resolve;
    video.onerror = () => reject(video.error);
  })
  .then(() => {
    video.onerror = () => ok(false, media.name + " failed in playback (code=" +
                             video.error.code + "). Stream should be OK. " +
                             "Continuing test.");
    return runNetworkTest(() => {
      var stream = video.mozCaptureStream();
      test = new PeerConnectionTest({ config_local: { label_suffix: media.name },
                                      config_remote: { label_suffix: media.name } });
      test.setOfferOptions({ offerToReceiveVideo: false,
                             offerToReceiveAudio: false });
      var hasVideo = stream.getVideoTracks().length > 0;
      var hasAudio = stream.getAudioTracks().length > 0;
      test.setMediaConstraints([{ video: hasVideo, audio: hasAudio }], []);
      test.chain.replace("PC_LOCAL_GUM", [
        function PC_LOCAL_CAPTUREVIDEO(test) {
          test.pcLocal.attachLocalStream(stream);
          video.play();
        }
      ]);
      return test.chain.execute();
    });
  })
  // Handle both MediaErrors (with the `code` attribute) and other errors.
  .catch(e => ok(false, "Error (" + e + ")" +
                        (e.code ? " (code=" + e.code + ")" : "") +
                        " in test for " + media.name +
                        (e.stack ? ":\n" + e.stack : "")))
  .then(() => test && test.close())
  .then(() => {
    removeNodeAndSource(video);
    manager.finished(token);
  })
  .catch(e => ok(false, "Error (" + e + ") during shutdown."));
};

</script>
</pre>
</body>
</html>