summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_streams_srcObject.html
blob: a5a4205cd302659837a6963655193a5fa7c1aa16 (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Test interactions of src and srcObject</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  <script type="text/javascript" src="manifest.js"></script>
</head>
<body onload="doTests()">
<audio id="a1"></audio>
<audio id="a2"></audio>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();

var doTest = srcObject => new Promise(resolve => {
  var a = document.getElementById('a1');
  a.src = getPlayableAudio(gSmallTests).name;
  var b = new Audio();

  var newSrc = a.src + "?2";
  b.src = newSrc;
  is(b[srcObject], null, "Initial srcObject is null");
  var stream = a.mozCaptureStream();
  b[srcObject] = stream;
  is(b[srcObject], stream, "Stream set correctly");
  try {
    b[srcObject] = "invalid";
    ok(false, "Setting srcObject to an invalid value should throw.");
  } catch (e) {
    ok(e instanceof TypeError, "Exception should be a TypeError");
  }
  is(b[srcObject], stream, "Stream not set to invalid value");
  is(b.src, newSrc, "src attribute not affected by setting srcObject");
  var step = 0;
  b.addEventListener("loadedmetadata", function() {
    if (step == 0) {
      is(b.currentSrc, "", "currentSrc set to empty string while playing srcObject");
      b[srcObject] = null;
      is(b[srcObject], null, "Stream set to null");
      // The resource selection algorithm will run again and choose b.src
    } else if (step == 1) {
      is(b.currentSrc, b.src, "currentSrc set to src now that srcObject is null");
      resolve();
    }
    ++step;
  });
  a.play();
  b.play();
});

// TODO: remove prefixed version soon (1183495).

var doTests = () => doTest("srcObject").then(() => doTest("mozSrcObject"))
  .catch(e => ok(false, "Unexpected error: " + e))
  .then(() => SimpleTest.finish())
  .catch(e => ok(false, "Coding error: " + e));

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