Bug 1461877 - Test that we don't dispatch 'playing' event for blocked playbacks. r=bryce
authorChris Pearce <cpearce@mozilla.com>
Fri, 18 May 2018 11:41:28 +1200
changeset 419059 e1eb21be77ba723bba7d5ccd461eb65d074cfc35
parent 419058 000309d44abb81084276c9fa977c57aee7126053
child 419060 25513d2e78e9dbda43c84cbd1f1c1adbf17fc89a
push id34025
push userapavel@mozilla.com
push dateMon, 21 May 2018 09:46:09 +0000
treeherdermozilla-central@8850728602d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbryce
bugs1461877
milestone62.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 1461877 - Test that we don't dispatch 'playing' event for blocked playbacks. r=bryce MozReview-Commit-ID: KXfviOtqGZI
dom/media/test/file_autoplay_policy_play_before_loadedmetadata.html
--- a/dom/media/test/file_autoplay_policy_play_before_loadedmetadata.html
+++ b/dom/media/test/file_autoplay_policy_play_before_loadedmetadata.html
@@ -24,24 +24,39 @@
 
         async function testPlayBeforeLoadedMetata(testCase, parent_window) {
           info("testPlayBeforeLoadedMetata: " + testCase.resource);
 
           let element = document.createElement("video");
           element.preload = "auto";
           element.src = testCase.resource;
           document.body.appendChild(element);
+
           is(element.paused, true, testCase.resource + " - should start out paused.");
+
           let playEventFired = false;
           once(element, "play").then(() => { playEventFired = true; });
+          let playingEventFired = false;
+          once(element, "playing").then(() => { playingEventFired = true;});
           let pauseEventFired = false;
           once(element, "pause").then(() => { pauseEventFired = true; });
+
           let played = await element.play().then(() => true, () => false);
-          let msg = testCase.resource + " should " + (!testCase.shouldPlay ? "not " : "") + "play";
-          is(played, testCase.shouldPlay, msg);
+
+          // Wait for one round through the event loop. This gives any tasks
+          // inside Gecko enqueued to dispatch events a chance to run.
+          // Specifically the "playing" event, if it's erronously fired.
+          await new Promise((resolve, reject) => {
+            setTimeout(resolve, 0);
+          });
+
+          let playingEventMsg = testCase.resource + " should " + (!testCase.shouldPlay ? "not " : "") + " fire playing";
+          is(playingEventFired, testCase.shouldPlay, playingEventMsg);
+          let playMsg = testCase.resource + " should " + (!testCase.shouldPlay ? "not " : "") + "play";
+          is(played, testCase.shouldPlay, playMsg);
           is(playEventFired, true, testCase.resource + " - we should always get a play event");
           is(pauseEventFired, !testCase.shouldPlay, testCase.resource + " - if we shouldn't play, we should get a pause event");
           removeNodeAndSource(element);
         }
 
         nextWindowMessage().then(
           async (event) => {
             await testPlayBeforeLoadedMetata(event.data, event.source);