<!DOCTYPE HTML>
<html>
<head>
  <title>MSE: WebM tags element before cluster element</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="mediasource.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">

SimpleTest.waitForExplicitFinish();

addMSEPrefs(["media.mediasource.webm.enabled", true]);

runWithMSE(async (ms, v) => {
  await once(ms, "sourceopen");
  const sb = ms.addSourceBuffer("video/webm");

  const arrayBuffer = await fetchWithXHR("tags_before_cluster.webm");
  info("- append buffer -");
  sb.appendBuffer(new Uint8Array(arrayBuffer));

  info("- wait for metadata -");
  await once(v, "loadedmetadata");

  info("- wait for updateend -");
  await once(sb, "updateend");

  info("- call end of stream -");
  ms.endOfStream();
  await once(ms, "sourceended");

  info("- check buffered range -");
  is(sb.buffered.length, 1, "buffered range is not empty.");

  info("- video is playing -");
  v.play();
  await once(v, "timeupdate");
  SimpleTest.finish();
});

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