summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/speculation-rules/prerender/resources/media-autoplay-attribute.html
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/speculation-rules/prerender/resources/media-autoplay-attribute.html')
-rw-r--r--testing/web-platform/tests/speculation-rules/prerender/resources/media-autoplay-attribute.html40
1 files changed, 40 insertions, 0 deletions
diff --git a/testing/web-platform/tests/speculation-rules/prerender/resources/media-autoplay-attribute.html b/testing/web-platform/tests/speculation-rules/prerender/resources/media-autoplay-attribute.html
new file mode 100644
index 0000000000..ebef5b725d
--- /dev/null
+++ b/testing/web-platform/tests/speculation-rules/prerender/resources/media-autoplay-attribute.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/speculation-rules/prerender/resources/utils.js"></script>
+<script src="/speculation-rules/prerender/resources/deferred-promise-utils.js"></script>
+<audio id="audio" autoplay loop></audio>
+<video id="video" autoplay type="video/mp4"></video>
+<script>
+const params = new URLSearchParams(location.search);
+// The main test page (restriction-media-auto-play-attribute.html) loads the
+// initiator page, then the initiator page will prerender itself with the
+// `prerendering` parameter.
+const isPrerendering = params.has('prerendering');
+
+if (!isPrerendering) {
+ loadInitiatorPage();
+} else {
+ const mediaType = params.get('type');
+ const media = document.getElementById(mediaType);
+ media.src = "./bear-av1-opus.mp4";
+
+ const prerenderEventCollector = new PrerenderEventCollector();
+ const promise = new Promise((resolve, reject) => {
+ media.onloadedmetadata = () => {
+ prerenderEventCollector.addEvent(
+ 'fired loadedmetadata event after prerendering is activated');
+ resolve();
+ };
+ media.onloadstart = () => {
+ // Wait some time to give the test a chance to load the data and fail the
+ // test.
+ setTimeout(() => {
+ prerenderEventCollector.start(promise, 'Autoplay');
+ }, 100);
+ };
+ media.onerror = reject;
+ });
+
+}
+</script>