Bug 1642590 - part2 : add test. r=bryce
authoralwu <alwu@mozilla.com>
Wed, 17 Jun 2020 20:50:08 +0000
changeset 536647 cb580c56e5dbfa78f01bcdaadc33ae3b99fc72e2
parent 536646 dc2606225a5c98c434c2f77960bdd0b5ea4b8ddc
child 536648 2e5e69b8c661608783666a16293a064299e0bfb4
push id119597
push useralwu@mozilla.com
push dateMon, 22 Jun 2020 21:10:42 +0000
treeherderautoland@cb580c56e5db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbryce
bugs1642590
milestone79.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 1642590 - part2 : add test. r=bryce Differential Revision: https://phabricator.services.mozilla.com/D79926
dom/media/test/mochitest.ini
dom/media/test/test_not_reset_playbackRate_when_removing_nonloaded_media_from_document.html
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -969,16 +969,17 @@ scheme=https
 [test_mixed_principals.html]
 skip-if = toolkit == 'android' # bug 1309814, android(bug 1232305)
 [test_mozHasAudio.html]
 [test_multiple_mediastreamtracks.html]
 scheme=https
 [test_networkState.html]
 [test_new_audio.html]
 [test_no_load_event.html]
+[test_not_reset_playbackRate_when_removing_nonloaded_media_from_document.html]
 [test_paused.html]
 [test_paused_after_ended.html]
 [test_play_events.html]
 [test_play_events_2.html]
 [test_play_promise_1.html]
 tags=promise-play
 [test_play_promise_2.html]
 tags=promise-play
new file mode 100644
--- /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>