summaryrefslogtreecommitdiffstats
path: root/dom/media/tests/mochitest/test_getUserMedia_loadedmetadata.html
blob: d6efac46505b3a113f81265afed155272e538ba0 (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
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
  createHTML({
    title: "getUserMedia in media element should have video dimensions on loadedmetadata",
    bug: "1240478"
  });
  /**
   * Tests that assigning a stream to a media element results in the
   * "loadedmetadata" event without having to play() the media element.
   *
   * Also makes sure that the video size has been set on "loadedmetadata".
   */
  runTest(function () {
    var v = document.createElement("video");
    document.body.appendChild(v);
    v.preload = "metadata";

    var constraints = {video: true, audio: true};
    return getUserMedia(constraints).then(stream => new Promise(resolve => {
      v.srcObject = stream;
      v.onloadedmetadata = () => {
        isnot(v.videoWidth, 0, "videoWidth shall be set on 'loadedmetadata'");
        isnot(v.videoHeight, 0, "videoHeight shall be set on 'loadedmetadata'");
        resolve();
      };
    })
    .then(() => stream.getTracks().forEach(t => t.stop())));
  });

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