зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1654657 - part8 : add test cases to ensure non-eligible media can be controlled when it enters fullscreen or PIP mode. r=chunmin
Differential Revision: https://phabricator.services.mozilla.com/D85640
This commit is contained in:
Родитель
31d53cc484
Коммит
9fd2c32518
|
@ -2,6 +2,13 @@
|
|||
const PAGE_NON_ELIGIBLE_MEDIA =
|
||||
"https://example.com/browser/dom/media/mediacontrol/tests/file_non_eligible_media.html";
|
||||
|
||||
// Import this in order to use `triggerPictureInPicture()`.
|
||||
/* import-globals-from ../../../../toolkit/components/pictureinpicture/tests/head.js */
|
||||
Services.scriptloader.loadSubScript(
|
||||
"chrome://mochitests/content/browser/toolkit/components/pictureinpicture/tests/head.js",
|
||||
this
|
||||
);
|
||||
|
||||
// This array contains the elements' id in `file_non_eligible_media.html`.
|
||||
const gNonEligibleElementIds = [
|
||||
"muted",
|
||||
|
@ -59,6 +66,43 @@ add_task(async function testPlayPauseAndStop() {
|
|||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Normally those media are not able to being controlled, however, once they
|
||||
* enter fullsceen or Picture-in-Picture mode, then they can be controlled.
|
||||
*/
|
||||
add_task(async function testNonEligibleMediaEnterFullscreen() {
|
||||
for (const elementId of gNonEligibleElementIds) {
|
||||
info(`- open new tab and start non eligible media ${elementId} -`);
|
||||
const tab = await createTabAndLoad(PAGE_NON_ELIGIBLE_MEDIA);
|
||||
await startNonEligibleMedia(tab, elementId);
|
||||
|
||||
info(`entering fullscreen should activate the media controller`);
|
||||
await enableFullScreen(tab, elementId);
|
||||
await checkOrWaitUntilControllerBecomeActive(tab);
|
||||
ok(true, `fullscreen ${elementId} media is able to being controlled`);
|
||||
|
||||
info(`remove tab`);
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function testNonEligibleMediaEnterPIPMode() {
|
||||
for (const elementId of gNonEligibleElementIds) {
|
||||
info(`- open new tab and start non eligible media ${elementId} -`);
|
||||
const tab = await createTabAndLoad(PAGE_NON_ELIGIBLE_MEDIA);
|
||||
await startNonEligibleMedia(tab, elementId);
|
||||
|
||||
info(`media entering PIP mode should activate the media controller`);
|
||||
const winPIP = await triggerPictureInPicture(tab.linkedBrowser, elementId);
|
||||
await checkOrWaitUntilControllerBecomeActive(tab);
|
||||
ok(true, `PIP ${elementId} media is able to being controlled`);
|
||||
|
||||
info(`remove tab`);
|
||||
await BrowserTestUtils.closeWindow(winPIP);
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* The following are helper functions.
|
||||
*/
|
||||
|
@ -130,3 +174,21 @@ function waitUntilMediaPaused(tab, elementId) {
|
|||
return new Promise(r => (video.onpaused = r));
|
||||
});
|
||||
}
|
||||
|
||||
function enableFullScreen(tab, elementId) {
|
||||
return SpecialPowers.spawn(tab.linkedBrowser, [elementId], elementId => {
|
||||
return new Promise(r => {
|
||||
const element = content.document.getElementById(elementId);
|
||||
element.requestFullscreen();
|
||||
element.onfullscreenchange = () => {
|
||||
element.onfullscreenchange = null;
|
||||
element.onfullscreenerror = null;
|
||||
r();
|
||||
};
|
||||
element.onfullscreenerror = () => {
|
||||
// Retry until the element successfully enters fullscreen.
|
||||
element.requestFullscreen();
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -305,3 +305,15 @@ function waitUntilControllerMetadataChanged() {
|
|||
function waitUntilMediaControllerAmountChanged() {
|
||||
return BrowserUtils.promiseObserved("media-controller-amount-changed");
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the media controll from given tab is active. If not, return a
|
||||
* promise and resolve it when controller become active.
|
||||
*/
|
||||
async function checkOrWaitUntilControllerBecomeActive(tab) {
|
||||
const controller = tab.linkedBrowser.browsingContext.mediaController;
|
||||
if (controller.isActive) {
|
||||
return;
|
||||
}
|
||||
await new Promise(r => (controller.onactivated = r));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче