WebKit export of https://bugs.webkit.org/show_bug.cgi?id=231945 (#31343)

diff --git a/video-rvfc/request-video-frame-callback-dom.html b/video-rvfc/request-video-frame-callback-dom.html
index 0277d72..c1804b4 100644
--- a/video-rvfc/request-video-frame-callback-dom.html
+++ b/video-rvfc/request-video-frame-callback-dom.html
@@ -13,17 +13,24 @@
   width: 320,
 }
 
-async_test(function(t) {
+promise_test(async function(t) {
+    let done;
+    const promise = new Promise(resolve => done = resolve);
+
     let video = document.createElement('video');
 
-    video.requestVideoFrameCallback(t.step_func_done());
+    video.requestVideoFrameCallback(done);
     video.src = testVideo.url;
-    video.play();
+    await video.play();
 
+    return promise;
 }, 'Test a video outside of the DOM can still use video.rVFC.');
 
 function rvfcStyleTest(applyStyle, description) {
-    async_test(function(t) {
+    promise_test(async function(t) {
+      let done;
+      const promise = new Promise(resolve => done = resolve);
+
       let video = document.createElement('video');
       document.body.appendChild(video);
       applyStyle(video);
@@ -31,12 +38,14 @@
       video.requestVideoFrameCallback(
         t.step_func( _ => {
           // Make sure we can receive more than one callback.
-          video.requestVideoFrameCallback(t.step_func_done());
+          video.requestVideoFrameCallback(done);
         })
       );
 
       video.src = testVideo.url;
-      video.play();
+      await video.play();
+
+      return promise;
     }, description);
 }
 
diff --git a/video-rvfc/request-video-frame-callback-parallel.html b/video-rvfc/request-video-frame-callback-parallel.html
index 14c5de1..682fd0a 100644
--- a/video-rvfc/request-video-frame-callback-parallel.html
+++ b/video-rvfc/request-video-frame-callback-parallel.html
@@ -7,7 +7,10 @@
 <script src="/common/media.js"></script>
 <script>
 
-async_test(function(t) {
+promise_test(async function(t) {
+    let done;
+    const promise = new Promise(resolve => done = resolve);
+
     let video = document.createElement('video');
     document.body.appendChild(video);
 
@@ -19,17 +22,22 @@
       firstMetadata = metadata;
     }));
 
-    video.requestVideoFrameCallback(t.step_func_done((time, metadata) => {
+    video.requestVideoFrameCallback(t.step_func((time, metadata) => {
       assert_equals(firstTime, time);
       assert_object_equals(firstMetadata, metadata);
+      done();
     }));
 
     video.src = getVideoURI('/media/movie_5');
     video.play();
 
+    return promise;
 }, 'Test callbacks get the same information.');
 
-async_test(function(t) {
+promise_test(async function(t) {
+    let done;
+    const promise = new Promise(resolve => done = resolve);
+
     let video = document.createElement('video');
     document.body.appendChild(video);
 
@@ -46,12 +54,12 @@
     );
 
     // NOTE: This callback should be executed last.
-    video.requestVideoFrameCallback(
-      t.step_func_done()
-    );
+    video.requestVideoFrameCallback(done);
 
     video.src = getVideoURI('/media/movie_5');
     video.play();
+
+    return promise;
 }, 'Test we can cancel callbacks from callbacks.');
 </script>
 </html>
diff --git a/video-rvfc/request-video-frame-callback-repeating.html b/video-rvfc/request-video-frame-callback-repeating.html
index e637a08..38e4aba 100644
--- a/video-rvfc/request-video-frame-callback-repeating.html
+++ b/video-rvfc/request-video-frame-callback-repeating.html
@@ -7,7 +7,10 @@
 <script src="/common/media.js"></script>
 <script>
 
-async_test(function(t) {
+promise_test(async function(t) {
+    let done;
+    const promise = new Promise(resolve => done = resolve);
+
     let video = document.createElement('video');
     document.body.appendChild(video);
 
@@ -24,18 +27,23 @@
 
       // Queue up a second callback, and make sure it's called at the same time
       // as the one we just queued up.
-      video.requestVideoFrameCallback(t.step_func_done((time) => {
+      video.requestVideoFrameCallback(t.step_func((time) => {
         assert_equals(time, secondTime, "Callbacks queued together should be called at the same time");
+        done();
       }))
 
     }));
 
     video.src = getVideoURI('/media/movie_5');
-    video.play();
+    await video.play();
 
+    return promise;
 }, 'Test new callbacks are only called on the next frame.');
 
-async_test(function(t) {
+promise_test(async function(t) {
+    let done;
+    const promise = new Promise(resolve => done = resolve);
+
     let video = document.createElement('video');
     document.body.appendChild(video);
 
@@ -64,7 +72,7 @@
       lastMetadata = metadata;
 
       if (++currentCallNumber > maxNumberOfCalls) {
-        t.done()
+        done()
       } else {
         video.requestVideoFrameCallback(t.step_func(repeatingCallback));
       }
@@ -73,8 +81,9 @@
     video.requestVideoFrameCallback(t.step_func(repeatingCallback));
 
     video.src = getVideoURI('/media/movie_5');
-    video.play();
+    await video.play();
 
+    return promise;
 }, 'Test chaining calls to video.rVFC, and verify the required parameters.');
 </script>
 </html>
diff --git a/video-rvfc/request-video-frame-callback.html b/video-rvfc/request-video-frame-callback.html
index a440414..256216e 100644
--- a/video-rvfc/request-video-frame-callback.html
+++ b/video-rvfc/request-video-frame-callback.html
@@ -18,26 +18,34 @@
   width: 320,
 }
 
-async_test(function(t) {
+promise_test(async function(t) {
+    let done;
+    const promise = new Promise(resolve => done = resolve);
+
     let video = document.createElement('video');
     document.body.appendChild(video);
 
     let id = video.requestVideoFrameCallback(
-      t.step_func_done((time, metadata) => {
+      t.step_func((time, metadata) => {
         assert_true(time > 0);
         assert_equals(metadata.height, testVideo.height);
         assert_equals(metadata.width, testVideo.width);
+        done();
       })
     );
 
     assert_true(id > 0);
 
     video.src = testVideo.url;
-    video.play();
+    await video.play();
 
+    return promise;
 }, 'Test we can register a video.rVFC callback.');
 
-async_test(function(t) {
+promise_test(async function(t) {
+    let done;
+    const promise = new Promise(resolve => done = resolve);
+
     let video = document.createElement('video');
     document.body.appendChild(video);
 
@@ -45,19 +53,24 @@
       t.step_func(video_now => {
         // Queue a call to window.rAF, and make sure it is executed within the
         // same turn of the event loop (with the same 'time' parameter).
-        window.requestAnimationFrame( t.step_func_done( window_now => {
+        window.requestAnimationFrame( t.step_func( window_now => {
           assert_equals(video_now, window_now);
+          done();
         }));
       })
     );
 
     video.src = testVideo.url;
-    video.play();
+    await video.play();
 
+    return promise;
 }, 'Test video.rVFC callbacks run before window.rAF callbacks.');
 
 
-async_test(function(t) {
+promise_test(async function(t) {
+    let done;
+    const promise = new Promise(resolve => done = resolve);
+
     let video = document.createElement('video');
     document.body.appendChild(video);
 
@@ -74,12 +87,14 @@
         // At this point, the other callback shouldn't have fired, but
         // give it some more time and really make sure it doesn't, by going
         // throught the event loop once more.
-        t.step_timeout(() => { t.done(); }, 0);
+        t.step_timeout(() => { done(); }, 0);
       })
     );
 
     video.src = testVideo.url;
-    video.play();
+    await video.play();
+
+    return promise;
 }, 'Test we can cancel a video.rVFC request.');
 
 test(function(t) {
@@ -105,6 +120,7 @@
 
 promise_test(async function(t) {
     let video = document.createElement('video');
+    video.autoplay = true;
     document.body.appendChild(video);
 
     let first_width = 0;