Bug 1715415 - part3 : modify test. r=chunmin

Differential Revision: https://phabricator.services.mozilla.com/D117957
This commit is contained in:
alwu 2021-07-08 21:28:48 +00:00
Родитель 0f80f824b2
Коммит c6966d640a
2 изменённых файлов: 35 добавлений и 2 удалений

Просмотреть файл

@ -62,6 +62,12 @@ add_task(async function triggerDefaultActionHandler() {
info(`default action handler should pause media`);
await checkOrWaitUntilMediaPauses(tab, { videoId });
const controller = tab.linkedBrowser.browsingContext.mediaController;
ok(
!controller.isActive,
`controller should be deactivated after receiving stop`
);
info(`remove tab`);
await tab.close();
}
@ -115,8 +121,16 @@ add_task(
await waitUntilActionHandlerIsTriggered(tab, action, frameId);
info(`start media from main frame so iframe would become inactive`);
// When action is `play`, controller is already playing, because above
// code won't pause media. So we need to wait for the active session
// changed to ensure the following tests can be executed on the right
// browsing context.
let waitForControllerStatusChanged =
action == "play"
? waitUntilActiveMediaSessionChanged()
: ensureControllerIsPlaying(tab.controller);
await Promise.all([
waitUntilActiveMediaSessionChanged(),
waitForControllerStatusChanged,
startMedia(tab, { videoId }),
]);
@ -392,3 +406,17 @@ function loadIframe(tab, iframeId, url) {
function waitUntilActiveMediaSessionChanged() {
return BrowserUtils.promiseObserved("active-media-session-changed");
}
function ensureControllerIsPlaying(controller) {
return new Promise(r => {
if (controller.isPlaying) {
r();
return;
}
controller.onplaybackstatechange = () => {
if (controller.isPlaying) {
r();
}
};
});
}

Просмотреть файл

@ -64,7 +64,12 @@ window.onmessage = async event => {
}
const action = event.data.action;
window.triggeredActionHandler[action] = new Promise(r => {
navigator.mediaSession.setActionHandler(action, () => {
navigator.mediaSession.setActionHandler(action, async () => {
if (action == "stop" || action == "pause") {
video.pause();
} else if (action == "play") {
await video.play();
}
r();
});
});