Bug 1394702 - rewrite test_seek_out_of_range.html to be more robust. r=kaku
authorJW Wang <jwwang@mozilla.com>
Tue, 09 Jan 2018 17:35:07 +0800
changeset 450288 1b13a12e07ac595f6d8dbea4c115ccc10f45475a
parent 450287 02b1c192fe2f1838328030042efde94610719645
child 450289 760107333833656db6c6b8706da966047e1874f2
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskaku
bugs1394702
milestone59.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 1394702 - rewrite test_seek_out_of_range.html to be more robust. r=kaku See comment 20 for the root cause. We wait for both 'seeked' and 'ended' events to fire to make sure playback has reached the end before calling play(). MozReview-Commit-ID: 55NEmqyDuSI
dom/media/test/test_seek_out_of_range.html
--- a/dom/media/test/test_seek_out_of_range.html
+++ b/dom/media/test/test_seek_out_of_range.html
@@ -13,70 +13,40 @@
 if (navigator.platform.startsWith("Win")) {
   SimpleTest.expectAssertions(0, 10);
 }
 
 var manager = new MediaTestManager;
 
 // Test if the ended event works correctly.
 
-function startTest(e) {
-  var v = e.target;
-  checkMetadata(v._name, v, v._test);
-  is(v._loadedMetadata, false, "Should only receive one loadedmetadata event for " + v._name);
-  v._loadedMetadata = true;
-  v.currentTime = 3.0 * v.duration;
-}
-
-function playbackEnded(e) {
-  var v = e.target;
-  // We should have dispatched an ended event when we seeked to the end of
-  // media, but we want the ended event which dispatches once playback has
-  // completed after the seek to the beginning.
-  if (!v._played)
-    return;
-  ok(v.ended, "Checking ended set after seeking to EOF and playing for " + v._name);
-  ok(!v._finished, "Should only hit the end once for " + v._name);
-  v._finished = true;
-  removeNodeAndSource(v);
-  manager.finished(v.token);
-}
-
-function endSeek(e) {
-  var v = e.target;
-  if (v._seeked)
-    return;
-  v._seeked = true;
-  ok(Math.abs(v.duration - v.currentTime) < 0.1,
-     "Should be at end of media for " + v._name + " t=" + v.currentTime + " d=" + v.duration);
-  v.play();
-}
-
-function playing(e) {
-  e.target._played = true;
-}
-
-function initTest(test, token) {
+async function initTest(test, token) {
   var type = getMajorMimeType(test.type);
   var v = document.createElement(type);
   v.preload = "auto";
   v.token = token;
   manager.started(token);
   v.src = test.name;
   v._name = test.name;
-  v._finished = false;
-  v._test = test;
-  v._loadedMetadata = false;
-  v._seeked = false;
-  v._played = false;
-  v.addEventListener("loadedmetadata", startTest);
-  v.addEventListener("playing", playing);
-  v.addEventListener("seeked", endSeek);
-  v.addEventListener("ended", playbackEnded);
   document.body.appendChild(v);
+
+  await once(v, "loadedmetadata");
+  info(`${v._name}: seeking to the end of the media.`);
+  v.currentTime = 3.0 * v.duration;
+  // Wait for 'seeked' and 'ended' to be fired.
+  await Promise.all([once(v, "seeked"), once(v, "ended")]);
+  // Check currentTime is near the end of the media.
+  ok(Math.abs(v.duration - v.currentTime) < 0.1,
+     "Should be at end of media for " + v._name + " t=" + v.currentTime + " d=" + v.duration);
+  // Call play() to start playback from the beginning.
+  v.play();
+  await once(v, "ended");
+  ok(v.ended, "Checking ended set after seeking to EOF and playing for " + v._name);
+  removeNodeAndSource(v);
+  manager.finished(v.token);
 }
 
 manager.runTests(gSmallTests, initTest);
 
 </script>
 </pre>
 </body>
 </html>