зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1715415 - part3 : modify test. r=chunmin
Differential Revision: https://phabricator.services.mozilla.com/D117957
This commit is contained in:
Родитель
0f80f824b2
Коммит
c6966d640a
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче