Bug 1577505 - Don't assume media element's canplay task runs immediately. r=jib
authorAndreas Pehrson <apehrson@mozilla.com>
Wed, 13 Nov 2019 14:02:58 +0000
changeset 501742 e333a13aa5f6f658c334e4553664b8df4adb5b7a
parent 501741 7db3af2ab4045e73695595aafb07857ed05b26fc
child 501743 be6ff7053ebe1e620a8a57af13bb6b6c11aab4a0
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
bugs1577505
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 1577505 - Don't assume media element's canplay task runs immediately. r=jib Differential Revision: https://phabricator.services.mozilla.com/D52808
testing/web-platform/tests/mediacapture-streams/MediaStream-MediaElement-srcObject.https.html
--- a/testing/web-platform/tests/mediacapture-streams/MediaStream-MediaElement-srcObject.https.html
+++ b/testing/web-platform/tests/mediacapture-streams/MediaStream-MediaElement-srcObject.https.html
@@ -295,22 +295,32 @@ promise_test(async t => {
     assert_unreached("No timeupdate until potentially playing");
 
   vid.play();
 
   await new Promise(r => t.step_timeout(r, 1000));
   assert_equals(vid.readyState, vid.HAVE_NOTHING,
     "Video dimensions not known yet");
 
+  const start = performance.now();
   ctx.fillStyle = "green";
   ctx.fillRect(0, 0, canvas.width, canvas.height);
 
   // Wait for, and check, potentially playing
   await new Promise(r => vid.oncanplay = r);
-  assert_equals(vid.currentTime, 0, "currentTime has not advanced yet");
+  const canplayDuration = (performance.now() - start) / 1000;
+  // "canplay" was just dispatched from a task queued when the element became
+  // potentially playing. currentTime may not have progressed more than the time
+  // it took from becoming potentially playing to starting the
+  // canplay-dispatching task. Though the media clock and the js clock may be
+  // different, so we take double this duration, or 100ms, whichever is greater,
+  // as a safety margin.
+  const margin = Math.max(0.1, canplayDuration * 2);
+  assert_between_inclusive(vid.currentTime, 0, margin,
+    "currentTime has not advanced more than twice it took to dispatch canplay");
   assert_false(vid.paused, "Media element is not paused");
   assert_false(vid.ended, "Media element is not ended");
   assert_equals(vid.error, null,
     "Media element playback has not stopped due to errors");
   assert_greater_than(vid.readyState, vid.HAVE_CURRENT_DATA,
     "Media element playback is not blocked");
   // Unclear how to check for "paused for user interaction" and "paused for
   // in-band content".