summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_not_reset_playbackRate_when_removing_nonloaded_media_from_document.html
diff options
context:
space:
mode:
Diffstat (limited to 'dom/media/test/test_not_reset_playbackRate_when_removing_nonloaded_media_from_document.html')
-rw-r--r--dom/media/test/test_not_reset_playbackRate_when_removing_nonloaded_media_from_document.html46
1 files changed, 46 insertions, 0 deletions
diff --git a/dom/media/test/test_not_reset_playbackRate_when_removing_nonloaded_media_from_document.html b/dom/media/test/test_not_reset_playbackRate_when_removing_nonloaded_media_from_document.html
new file mode 100644
index 0000000000..f1b8cc8b15
--- /dev/null
+++ b/dom/media/test/test_not_reset_playbackRate_when_removing_nonloaded_media_from_document.html
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Do not reset playback rate when removing non-loaded media from a document</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script src="manifest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<script class="testbody" type="text/javascript">
+/**
+ * When removing media from a document, it should only trigger internal pause,
+ * instead of the pause method, which would trigger loading process and reset
+ * the media's playback rate for non-loaded media.
+ */
+async function startTest() {
+ info(`create a media and append it to a document`);
+ const audio = document.createElement("audio");
+ document.body.appendChild(audio);
+
+ info(`change audio's playbackRate and remove it from a document`);
+ const expectedRate = 0.1;
+ audio.playbackRate = expectedRate;
+ await once(audio, "ratechange");
+ is(audio.playbackRate, expectedRate,
+ `${audio.playbackRate} is equal to ${expectedRate}`);
+ audio.remove();
+
+ info(`queue a macrotask to check if the playback rate is still unchanged`);
+ setTimeout(() => {
+ // If we unexpectedly reset the playback rate, it would happen in a
+ // microtask when removing media from a document [1] (Await a stable state),
+ // which would always be run before the macrotask.
+ // [1] https://html.spec.whatwg.org/#playing-the-media-resource:remove-an-element-from-a-document
+ is(audio.playbackRate, expectedRate,
+ `${audio.playbackRate} is equal to ${expectedRate}`);
+ SimpleTest.finish();
+ }, 0);
+}
+
+SimpleTest.waitForExplicitFinish();
+onload = startTest;
+
+</script>
+</body>
+</html>