Bug 1135170 - Fix up racey test_seek-1.html. rpending=mattwoodrow
authorBobby Holley <bobbyholley@gmail.com>
Thu, 05 Mar 2015 11:09:35 -0800
changeset 232374 dbe3c38fc4c65bc4efc67d5f618cef98e7e20810
parent 232373 995c97c870a23d6d9e7942d1669ddc4317d3dcb1
child 232375 a8cc15fc214575d0672c56e53cb1263076b95293
push id56528
push userbobbyholley@gmail.com
push dateSat, 07 Mar 2015 03:18:56 +0000
treeherdermozilla-inbound@cb5ec48a3391 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1135170
milestone39.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 1135170 - Fix up racey test_seek-1.html. rpending=mattwoodrow The use of play() and pause() in the test is hugely problematic for short video files and slow/laggy platforms. In particular, if playback has ended by the time that we fire the 'seeked' event listener, then the ensuing play() will put us back into seeking mode (seeking to 0), making the test fail.
dom/media/test/manifest.js
dom/media/test/test_seek-1.html
--- a/dom/media/test/manifest.js
+++ b/dom/media/test/manifest.js
@@ -732,16 +732,29 @@ function removeNodeAndSource(n) {
   // reset |mozSrcObject| first since it takes precedence over |src|.
   n.mozSrcObject = null;
   n.src = "";
   while (n.firstChild) {
     n.removeChild(n.firstChild);
   }
 }
 
+function once(target, name, cb) {
+  var p = new Promise(function(resolve, reject) {
+    target.addEventListener(name, function() {
+      target.removeEventListener(name, cb);
+      resolve();
+    });
+  });
+  if (cb) {
+    p.then(cb);
+  }
+  return p;
+}
+
 // Number of tests to run in parallel.
 var PARALLEL_TESTS = 2;
 
 // When true, we'll loop forever on whatever test we run. Use this to debug
 // intermittent test failures.
 const DEBUG_TEST_LOOP_FOREVER = false;
 
 // Manages a run of media tests. Runs them in chunks in order to limit
--- a/dom/media/test/test_seek-1.html
+++ b/dom/media/test/test_seek-1.html
@@ -22,72 +22,62 @@ function test_seek1(v, seekTime, is, ok,
 var startPassed = false;
 var endPassed = false;
 var seekFlagStart = false;
 var seekFlagEnd = false;
 var readonly = true;
 var completed = false;
 
 function startTest() {
-  if (completed)
-    return;
+  ok(!completed, "Should not be completed yet");
   ok(!v.seeking, "seeking should default to false");
   try {
     v.seeking = true;
     readonly = v.seeking === false;
   }
   catch(e) {
     readonly = "threw exception: " + e;
   }
   is(readonly, true, "seeking should be readonly");
 
-  v.play();
-  v.currentTime=seekTime;
+  v.currentTime = seekTime;
   seekFlagStart = v.seeking;
 }
 
 function seekStarted() {
-  if (completed)
-    return;
-  ok(v.currentTime >= seekTime - 0.1,
+  ok(!completed, "should not be completed yet");
+  ok(Math.abs(v.currentTime - seekTime) < 0.1,
      "Video currentTime should be around " + seekTime + ": " + v.currentTime + " (seeking)");
-  v.pause();
   startPassed = true;
 }
 
 function seekEnded() {
-  if (completed)
-    return;
-
-  var t = v.currentTime;
-  // Since we were playing, and we only paused asynchronously, we can't be
-  // sure that we paused before the seek finished, so we may have played
-  // ahead arbitrarily far.
-  ok(t >= seekTime - 0.1, "Video currentTime should be around " + seekTime + ": " + t + " (seeked)");
-  v.play();
+  ok(!completed, "shuld not be completed yet");
+  ok(Math.abs(v.currentTime - seekTime) < 0.1,
+     "Video currentTime should be around " + seekTime + ": " + v.currentTime + " (seeked)");
   endPassed = true;
   seekFlagEnd = v.seeking;
+  v.play();
 }
 
 function playbackEnded() {
-  if (completed)
-    return;
+  ok(!completed, "should not be completed yet");
 
   completed = true;
   ok(startPassed, "seeking event");
   ok(endPassed, "seeked event");
   ok(seekFlagStart, "seeking flag on start should be true");
   ok(!seekFlagEnd, "seeking flag on end should be false");
   finish();
 }
 
-v.addEventListener("ended", playbackEnded, false);
-v.addEventListener("loadedmetadata", startTest, false);
-v.addEventListener("seeking", seekStarted, false);
-v.addEventListener("seeked", seekEnded, false);
+once(v, "ended", playbackEnded);
+once(v, "loadedmetadata", startTest);
+once(v, "seeking", seekStarted);
+once(v, "seeked", seekEnded);
 
 }
 
 manager.runTests(createTestArray(), startTest);
 
 </script>
 </pre>
 </body>