Bug 1689741 - not controlling the real-time media via the media control. r=padenot
Differential Revision: https://phabricator.services.mozilla.com/D112668
This commit is contained in:
@@ -7635,6 +7635,11 @@ bool HTMLMediaElement::ShouldStartMediaControlKeyListener() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mSrcStream) {
|
||||
MEDIACONTROL_LOG("Not listening because media is real-time");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsBeingUsedInPictureInPictureMode()) {
|
||||
MEDIACONTROL_LOG("Start listener because of being used in PiP mode");
|
||||
return true;
|
||||
|
||||
@@ -25,6 +25,7 @@ support-files =
|
||||
[browser_audio_focus_management.js]
|
||||
[browser_control_page_with_audible_and_inaudible_media.js]
|
||||
[browser_default_action_handler.js]
|
||||
[browser_only_control_non_real_time_media.js]
|
||||
[browser_media_control_audio_focus_within_a_page.js]
|
||||
[browser_media_control_before_media_starts.js]
|
||||
[browser_media_control_captured_audio.js]
|
||||
@@ -32,7 +33,7 @@ support-files =
|
||||
[browser_media_control_keys_event.js]
|
||||
[browser_media_control_main_controller.js]
|
||||
[browser_media_control_non_eligible_media.js]
|
||||
skip-if =
|
||||
skip-if =
|
||||
verify && os == 'mac' # bug 1673509
|
||||
[browser_media_control_playback_state.js]
|
||||
[browser_media_control_position_state.js]
|
||||
@@ -40,7 +41,7 @@ skip-if =
|
||||
[browser_media_control_supported_keys.js]
|
||||
[browser_media_control_stop_timer.js]
|
||||
[browser_nosrc_and_error_media.js]
|
||||
skip-if =
|
||||
skip-if =
|
||||
verify && os == 'mac' # bug 1673509
|
||||
[browser_seek_captured_audio.js]
|
||||
[browser_stop_control_after_media_reaches_to_end.js]
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
const PAGE_URL =
|
||||
"https://example.com/browser/dom/media/mediacontrol/tests/browser/file_empty_title.html";
|
||||
|
||||
/**
|
||||
* This test is used to ensure that real-time media won't be affected by the
|
||||
* media control. Only non-real-time media would.
|
||||
*/
|
||||
add_task(async function setupTestingPref() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["media.mediacontrol.testingevents.enabled", true]],
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function testOnlyControlNonRealTimeMedia() {
|
||||
const tab = await createLoadedTabWrapper(PAGE_URL);
|
||||
const controller = tab.linkedBrowser.browsingContext.mediaController;
|
||||
await StartRealTimeMedia(tab);
|
||||
ok(
|
||||
!controller.isActive,
|
||||
"starting a real-time media won't acivate controller"
|
||||
);
|
||||
|
||||
info(`playing a non-real-time media would activate controller`);
|
||||
await Promise.all([
|
||||
new Promise(r => (controller.onactivated = r)),
|
||||
startNonRealTimeMedia(tab),
|
||||
]);
|
||||
|
||||
info(`'pause' action should only pause non-real-time media`);
|
||||
MediaControlService.generateMediaControlKey("pause");
|
||||
await new Promise(r => (controller.onplaybackstatechange = r));
|
||||
await checkIfMediaAreAffectedByMediaControl(tab);
|
||||
|
||||
info(`remove tab`);
|
||||
await tab.close();
|
||||
});
|
||||
|
||||
async function startNonRealTimeMedia(tab) {
|
||||
return SpecialPowers.spawn(tab.linkedBrowser, [], async _ => {
|
||||
let video = content.document.getElementById("video");
|
||||
if (!video) {
|
||||
ok(false, `can not get the video element!`);
|
||||
return;
|
||||
}
|
||||
await video.play();
|
||||
});
|
||||
}
|
||||
|
||||
async function StartRealTimeMedia(tab) {
|
||||
return SpecialPowers.spawn(tab.linkedBrowser, [], async _ => {
|
||||
let videoRealTime = content.document.createElement("video");
|
||||
content.document.body.appendChild(videoRealTime);
|
||||
videoRealTime.srcObject = await content.navigator.mediaDevices.getUserMedia(
|
||||
{ audio: true, fake: true }
|
||||
);
|
||||
// We want to ensure that the checking of should the media be controlled by
|
||||
// media control would be performed after the element finishes loading the
|
||||
// media stream. Using `autoplay` would trigger the play invocation only
|
||||
// after the element get enough data.
|
||||
videoRealTime.autoplay = true;
|
||||
await new Promise(r => (videoRealTime.onplaying = r));
|
||||
});
|
||||
}
|
||||
|
||||
async function checkIfMediaAreAffectedByMediaControl(tab) {
|
||||
return SpecialPowers.spawn(tab.linkedBrowser, [], async _ => {
|
||||
const vids = content.document.getElementsByTagName("video");
|
||||
for (let vid of vids) {
|
||||
if (!vid.srcObject) {
|
||||
ok(vid.paused, "non-real-time media should be paused");
|
||||
} else {
|
||||
ok(!vid.paused, "real-time media should not be affected");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user