Bug 1487143 - Properly dispatch MozAutoplayMediaBlocked event to content, r=alwu

The MozAutoplayMediaBlocked event should have its target set to the video
element, not the document.

Also, MozNoControlsBlockedVideo event has to initialized from the CustomEvent
constructor of the right window for the XBL binding to access it. I don't know
when it stopped working.

Test is added to ensure the entire UI won't break.

Differential Revision: https://phabricator.services.mozilla.com/D5801

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Timothy Guan-tin Chien 2018-09-13 21:21:11 +00:00
parent 9455e67e2c
commit 052ca9c390
4 changed files with 17 additions and 5 deletions

View File

@ -4147,7 +4147,7 @@ HTMLMediaElement::DispatchEventsWhenPlayWasNotAllowed()
}
#if defined(MOZ_WIDGET_ANDROID)
RefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(OwnerDoc(),
new AsyncEventDispatcher(this,
NS_LITERAL_STRING("MozAutoplayMediaBlocked"),
CanBubble::eYes,
ChromeOnlyDispatch::eYes);

View File

@ -186,7 +186,7 @@ var CastingApps = {
}
case "MozAutoplayMediaBlocked": {
if (this._bound && this._bound.has(aEvent.target)) {
aEvent.target.dispatchEvent(new CustomEvent("MozNoControlsBlockedVideo"));
aEvent.target.dispatchEvent(new aEvent.target.ownerGlobal.CustomEvent("MozNoControlsBlockedVideo"));
} else {
if (!this._blocked) {
this._blocked = new WeakMap;
@ -202,7 +202,7 @@ var CastingApps = {
this._bound.set(aEvent.target, true);
if (this._blocked && this._blocked.has(aEvent.target)) {
this._blocked.delete(aEvent.target);
aEvent.target.dispatchEvent(new CustomEvent("MozNoControlsBlockedVideo"));
aEvent.target.dispatchEvent(new aEvent.target.ownerGlobal.CustomEvent("MozNoControlsBlockedVideo"));
}
break;
}

View File

@ -1,5 +1,6 @@
<!DOCTYPE html>
<audio id="testAudio" src="audio.ogg" loop></audio>
<!-- autoplay blocked UI only shows up in <video>, not <audio> -->
<video id="testAudio" src="audio.ogg" loop></video>
<script type="text/javascript">
var audio = document.getElementById("testAudio");
audio.oncanplay = function() {

View File

@ -13,8 +13,11 @@
* This test is used to check whether 'MozAutoplayMediaBlocked' would be fired
* correctly when the media was blocked.
*/
"use strict";
/* globals InspectorUtils */
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/Task.jsm");
@ -40,7 +43,7 @@ add_task(async function test_MozAutoplayMediaBlocked() {
let tab = gBrowserApp.addTab(URL);
let browser = tab.browser;
const mediaBlockedPromise = promiseBrowserEvent(browser, "MozAutoplayMediaBlocked");
const mediaBlockedPromise = promiseTabEvent(browser, "MozAutoplayMediaBlocked");
info("- wait for loading tab's content -");
await promiseBrowserEvent(browser, "load");
@ -49,6 +52,14 @@ add_task(async function test_MozAutoplayMediaBlocked() {
await mediaBlockedPromise;
ok(true, "got `MozAutoplayMediaBlocked` event");
let doc = browser.contentWindow.document;
let video = doc.getElementById("testAudio");
let kids = InspectorUtils.getChildrenForNode(video, true);
let videocontrols = kids[1];
let button = doc.getAnonymousElementByAttribute(videocontrols, "anonid", "clickToPlay");
ok(!button.hidden, "Click to play button is not hidden");
info("- remove tab -");
gBrowserApp.closeTab(tab);
});