Bug 1172394 - Modernize test_streams_element_capture_reset.html. r=jib
☠☠ backed out by 7272d77d4e80 ☠ ☠
authorAndreas Pehrson <apehrson@mozilla.com>
Wed, 13 Nov 2019 08:56:12 +0000
changeset 501789 c3bd415507e8bd658b1fe760da997015b098af3e
parent 501788 1c45b135318d8cb519b8d58af72ab864fe6bfd62
child 501790 7e7baa73e1efeacd1d19dc95e3f79133d796daf4
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs1172394
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1172394 - Modernize test_streams_element_capture_reset.html. r=jib Differential Revision: https://phabricator.services.mozilla.com/D52044
dom/media/test/test_streams_element_capture_reset.html
--- a/dom/media/test/test_streams_element_capture_reset.html
+++ b/dom/media/test/test_streams_element_capture_reset.html
@@ -1,134 +1,130 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <title>Test that reloading and seeking in a media element that's being captured doesn't crash</title>
   <script 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>
+  <script src="manifest.js"></script>
 </head>
 <body>
 <video id="v"></video>
 <video id="vout"></video>
 <video id="vout_untilended"></video>
 <pre id="test">
-<script class="testbody" type="text/javascript">
-SimpleTest.waitForExplicitFinish();
-
-var v = document.getElementById('v');
-var vout = document.getElementById('vout');
-var vout_untilended = document.getElementById('vout_untilended');
+<script>
+const v = document.getElementById('v');
+const vout = document.getElementById('vout');
+const vout_untilended = document.getElementById('vout_untilended');
 
 function dumpEvent(event) {
-  var video = event.target;
-  info(video.name + " GOT EVENT " + event.type +
-       " currentTime=" + video.currentTime +
-       " paused=" + video.paused +
-       " ended=" + video.ended +
-       " readyState=" + video.readyState);
+  const video = event.target;
+  info(
+    `${video.name}:${video.id} GOT EVENT ${event.type} ` +
+    `currentTime=${video.currentTime} paused=${video.paused} ` +
+    `ended=${video.ended} readyState=${video.readyState}`
+  );
 }
 
-var events = ["timeupdate", "seeking", "seeked", "ended", "playing", "pause"];
-for (var i = 0; i < events.length; ++i) {
-  v.addEventListener(events[i], dumpEvent);
+function unexpected(event) {
+  ok(false, `${event.type} event received on ${event.target.id} unexpectedly`);
+};
+
+const events = ["timeupdate", "seeking", "seeked", "ended", "playing", "pause"];
+for (const e of events) {
+  v.addEventListener(e, dumpEvent);
+  vout.addEventListener(e, dumpEvent);
+  vout_untilended.addEventListener(e, dumpEvent);
 }
 
 function isWithinEps(a, b, msg) {
   ok(Math.abs(a - b) < 0.01,
      "Got " + a + ", expected " + b + "; " + msg);
 }
 
 function isGreaterThanOrEqualEps(a, b, msg) {
   ok(a >= b - 0.01,
      "Got " + a + ", expected at least " + b + "; " + msg);
 }
 
-function startTest(test) {
-  var seekTime = test.duration/2;
-
-  function endedAfterReplay() {
-    isGreaterThanOrEqualEps(v.currentTime, test.duration, "checking v.currentTime at third 'ended' event");
-    isGreaterThanOrEqualEps(vout.currentTime, (test.duration - seekTime) + test.duration*2,
-	            "checking vout.currentTime after seeking, playing through and reloading");
-    SimpleTest.finish();
-  };
-
-  function endedAfterSeek() {
-    isGreaterThanOrEqualEps(v.currentTime, test.duration, "checking v.currentTime at second 'ended' event");
-    isGreaterThanOrEqualEps(vout.currentTime, (test.duration - seekTime) + test.duration,
-                "checking vout.currentTime after seeking and playing through again");
-    v.removeEventListener("ended", endedAfterSeek);
-    v.addEventListener("ended", endedAfterReplay);
-    v.src = test.name + "?1";
-    v.play();
-  };
+async function startTest(test) {
+  const seekTime = test.duration/2;
 
-  function seeked() {
-    isGreaterThanOrEqualEps(v.currentTime, seekTime, "Finished seeking");
-    isGreaterThanOrEqualEps(vout.currentTime, test.duration,
-                "checking vout.currentTime has not changed after seeking");
-    v.removeEventListener("seeked", seeked);
-    function dontPlayAgain() {
-      ok(false, "vout_untilended should not play again");
-    }
-    vout_untilended.addEventListener("playing", dontPlayAgain);
-    vout_untilended.addEventListener("ended", dontPlayAgain);
-    v.addEventListener("ended", endedAfterSeek);
-    v.play();
-  };
-
-  function ended() {
-    // Don't compare current time until both v and vout_untilended are ended,
-    // otherwise, current time could be smaller than the duration.
-    if (!v.ended || !vout_untilended.ended) {
-      return;
-    }
-
-    isGreaterThanOrEqualEps(vout.currentTime, test.duration, "checking vout.currentTime at first 'ended' event");
-    isGreaterThanOrEqualEps(v.currentTime, test.duration, "checking v.currentTime at first 'ended' event");
-    is(vout.ended, false, "checking vout has not ended");
-    is(vout_untilended.ended, true, "checking vout_untilended has actually ended");
-
-    v.removeEventListener("ended", ended);
-    vout_untilended.removeEventListener("ended", ended);
-
-    v.pause();
-    v.currentTime = seekTime;
-    v.addEventListener("seeked", seeked);
-  };
-
-  v.addEventListener("ended", ended);
-  vout_untilended.addEventListener("ended", ended);
-
-  function checkNoEnded() {
-    ok(false, "ended event received unexpectedly");
-  };
-
-  vout.addEventListener("ended", checkNoEnded);
+  vout.onended = unexpected;
 
   v.src = test.name;
   v.name = test.name;
+  vout.name = test.name;
+  vout_untilended.name = test.name;
   v.preload = "metadata";
+  await new Promise(r => v.onloadedmetadata = r);
+
+  vout.srcObject = v.mozCaptureStream();
+  vout.play();
+
+  vout_untilended.srcObject = v.mozCaptureStreamUntilEnded();
+  vout_untilended.play();
 
-  function loadedmetadata() {
-    vout.srcObject = v.mozCaptureStream();
-    vout.play();
+  v.play();
+
+  await Promise.all([
+    new Promise(r => v.onended = r),
+    new Promise(r => vout_untilended.onended = r),
+  ]);
+
+  isGreaterThanOrEqualEps(vout.currentTime, test.duration,
+    "checking vout.currentTime at first 'ended' event");
+  isGreaterThanOrEqualEps(v.currentTime, test.duration,
+    "checking v.currentTime at first 'ended' event");
+  ok(!vout.ended, "checking vout has not ended");
+  ok(vout_untilended.ended, "checking vout_untilended has actually ended");
 
-    vout_untilended.srcObject = v.mozCaptureStreamUntilEnded();
-    vout_untilended.play();
+  v.pause();
+  v.currentTime = seekTime;
+  await new Promise(r => v.onseeked = r);
+
+  isGreaterThanOrEqualEps(v.currentTime, seekTime, "Finished seeking");
+  isGreaterThanOrEqualEps(vout.currentTime, test.duration,
+    "checking vout.currentTime has not changed after seeking");
+
+  vout_untilended.onplaying = unexpected;
+  vout_untilended.onended = unexpected;
+  v.play();
+
+  await new Promise(r => v.onended = r);
 
-    v.play();
-  };
+  isGreaterThanOrEqualEps(v.currentTime, test.duration,
+    "checking v.currentTime at second 'ended' event");
+  isGreaterThanOrEqualEps(vout.currentTime,
+    (test.duration - seekTime) + test.duration,
+    "checking vout.currentTime after seeking and playing through again");
+  v.src = test.name + "?1";
+  v.play();
 
-  v.addEventListener("loadedmetadata", loadedmetadata, {once: true});
+  await new Promise(r => v.onended = r);
+
+  isGreaterThanOrEqualEps(v.currentTime, test.duration,
+    "checking v.currentTime at third 'ended' event");
+  isGreaterThanOrEqualEps(vout.currentTime,
+    (test.duration - seekTime) + test.duration*2,
+    "checking vout.currentTime after seeking, playing through and reloading");
 }
 
-var testVideo = getPlayableVideo(gSmallTests);
-if (testVideo) {
-  startTest(testVideo);
-} else {
-  todo(false, "No playable video");
-}
+(async () => {
+  SimpleTest.waitForExplicitFinish();
+  try {
+    const testVideo = getPlayableVideo(gSmallTests);
+    if (testVideo) {
+      await startTest(testVideo);
+    } else {
+      todo(false, "No playable video");
+    }
+  } catch(e) {
+    ok(false, `Error: ${e}`);
+  } finally {
+    SimpleTest.finish();
+  }
+})();
 </script>
 </pre>
 </body>
 </html>