Truly independent web browser
Tests/LibWeb: Rework HTMLMediaElement-gc-during-load to use gcAsync()
Zaggy102478fad054c932
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex bc722400b7a..6b7a7b2a7d6 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -138,6 +138,7 @@ Text/input/wpt-import/xhr/send-usp.any.htmlCrash/HTML/media-element-load-with-pending-source-buffer-append.htmlText/input/HTML/HTMLMediaElement-bodyless-response.htmlText/input/HTML/HTMLMediaElement-failed-range-response-after-metadata.html+Text/input/HTML/HTMLMediaElement-gc-during-load.htmlText/input/HTML/HTMLMediaElement-preload-metadata-suspends-download.htmlText/input/HTML/HTMLMediaElement-seek-past-fetched-data-after-network-error.htmlCrash/HTML/video-track-switch-during-seek.htmldiff --git a/Tests/LibWeb/Text/input/HTML/HTMLMediaElement-gc-during-load.html b/Tests/LibWeb/Text/input/HTML/HTMLMediaElement-gc-during-load.htmlindex 0ce7b1df32a..775833b0aaf 100644--- a/Tests/LibWeb/Text/input/HTML/HTMLMediaElement-gc-during-load.html+++ b/Tests/LibWeb/Text/input/HTML/HTMLMediaElement-gc-during-load.html@@ -1,22 +1,31 @@<!DOCTYPE html><script src="../include.js"></script><script>- asyncTest(done => {- {- let video = document.createElement("video");- video.src = "file:///nonexistent-media-file.webm";- video.addEventListener("error", () => {- println("error event fired");- done();- });- }+ // A media element that nothing else references must stay alive while its fetch is ongoing, so that it can still fire+ // the events of its load.- // Queue a task to GC after all pending tasks have run.- // If the element is not kept alive by the ongoing fetch of its- // src, then the error event will never fire, and this test will- // time out.- requestIdleCallback(() => {- internals.gc();+ // This is not done in the async test function, whose suspended frame could keep the element alive.+ function startLoadingUnreferencedVideo(url, onError) {+ const video = document.createElement("video");+ video.src = url;+ video.addEventListener("error", onError);+ }++ asyncTest(async done => {+ const server = httpTestServer();+ const token = `gc-during-load-${crypto.randomUUID()}`;+ const mediaURL = await server.createEcho("GET", `/${token}.webm`, { status: 404, wait_for_unblock: token });+ const unblockURL = new URL(`/unblock/${token}`, mediaURL);+ unblockURL.hostname = uniqueLocalhostHostname("gc-during-load-unblock");++ startLoadingUnreferencedVideo(mediaURL, () => {+ println("error event fired");+ done();});++ // Collect garbage while the response is held back, so that only the fetch can keep the element alive.+ await server.waitForRequest(mediaURL);+ await internals.gcAsync();+ await fetch(unblockURL);});</script>