зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1621166 - part3 : make 'playMedia' and 'pauseMedia' as general utils functions. r=MeFisto94
There are several tests using similar methods of playing/pausing media, and we should make them as util functions to share the same code. Differential Revision: https://phabricator.services.mozilla.com/D67382 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
7db6ce8171
Коммит
1ca8d55a56
|
@ -17,7 +17,7 @@ add_task(async function setupTestingPref() {
|
|||
add_task(async function testPlayPauseAndStop() {
|
||||
info(`open page and start media`);
|
||||
const tab = await createTabAndLoad(PAGE);
|
||||
await playMedia(tab);
|
||||
await playMedia(tab, testVideoId);
|
||||
|
||||
info(`pressing 'pause' key`);
|
||||
ChromeUtils.generateMediaControlKeysTestEvent("pause");
|
||||
|
@ -38,7 +38,7 @@ add_task(async function testPlayPauseAndStop() {
|
|||
add_task(async function testPlayPause() {
|
||||
info(`open page and start media`);
|
||||
const tab = await createTabAndLoad(PAGE);
|
||||
await playMedia(tab);
|
||||
await playMedia(tab, testVideoId);
|
||||
|
||||
info(`pressing 'playPause' key, media should stop`);
|
||||
ChromeUtils.generateMediaControlKeysTestEvent("playPause");
|
||||
|
@ -68,21 +68,3 @@ function waitUntilPlaybackStops(tab) {
|
|||
waitUntilMainMediaControllerPlaybackChanged(),
|
||||
]);
|
||||
}
|
||||
|
||||
function playMedia(tab) {
|
||||
const playPromise = SpecialPowers.spawn(
|
||||
tab.linkedBrowser,
|
||||
[testVideoId],
|
||||
Id => {
|
||||
const video = content.document.getElementById(Id);
|
||||
if (!video) {
|
||||
ok(false, `can't get the media element!`);
|
||||
}
|
||||
return video.play();
|
||||
}
|
||||
);
|
||||
return Promise.all([
|
||||
playPromise,
|
||||
waitUntilMainMediaControllerPlaybackChanged(),
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ add_task(async function testDefaultMetadataForPageWithoutMediaSession() {
|
|||
const tab = await createTabAndLoad(PAGE_NON_AUTOPLAY);
|
||||
|
||||
info(`start media`);
|
||||
await playMedia(tab);
|
||||
await playMedia(tab, testVideoId);
|
||||
|
||||
info(`should use default metadata because of lacking of media session`);
|
||||
await isUsingDefaultMetadata(tab);
|
||||
|
@ -56,7 +56,7 @@ add_task(async function testDefaultMetadataForPageUsingEmptyMetadata() {
|
|||
const tab = await createTabAndLoad(PAGE_NON_AUTOPLAY);
|
||||
|
||||
info(`start media`);
|
||||
await playMedia(tab);
|
||||
await playMedia(tab, testVideoId);
|
||||
|
||||
info(`create empty media metadata`);
|
||||
await setMediaMetadata(tab, {
|
||||
|
@ -78,7 +78,7 @@ add_task(async function testDefaultMetadataForPageUsingNullMetadata() {
|
|||
const tab = await createTabAndLoad(PAGE_NON_AUTOPLAY);
|
||||
|
||||
info(`start media`);
|
||||
await playMedia(tab);
|
||||
await playMedia(tab, testVideoId);
|
||||
|
||||
info(`create empty media metadata`);
|
||||
await setNullMediaMetadata(tab);
|
||||
|
@ -95,7 +95,7 @@ add_task(async function testMetadataWithEmptyTitleAndArtwork() {
|
|||
const tab = await createTabAndLoad(PAGE_NON_AUTOPLAY);
|
||||
|
||||
info(`start media`);
|
||||
await playMedia(tab);
|
||||
await playMedia(tab, testVideoId);
|
||||
|
||||
info(`create media metadata with empty title and artwork`);
|
||||
await setMediaMetadata(tab, {
|
||||
|
@ -117,7 +117,7 @@ add_task(async function testMetadataWithoutTitleAndArtwork() {
|
|||
const tab = await createTabAndLoad(PAGE_NON_AUTOPLAY);
|
||||
|
||||
info(`start media`);
|
||||
await playMedia(tab);
|
||||
await playMedia(tab, testVideoId);
|
||||
|
||||
info(`create media metadata with empty title and artwork`);
|
||||
await setMediaMetadata(tab, {
|
||||
|
@ -142,7 +142,7 @@ add_task(async function testMetadataInPrivateBrowsing() {
|
|||
const tab = await createTabAndLoad(PAGE_NON_AUTOPLAY, privateWindow);
|
||||
|
||||
info(`start media`);
|
||||
await playMedia(tab);
|
||||
await playMedia(tab, testVideoId);
|
||||
|
||||
info(`set metadata`);
|
||||
let metadata = {
|
||||
|
@ -168,7 +168,7 @@ add_task(async function testSetMetadataFromMediaSessionAPI() {
|
|||
const tab = await createTabAndLoad(PAGE_NON_AUTOPLAY);
|
||||
|
||||
info(`start media`);
|
||||
await playMedia(tab);
|
||||
await playMedia(tab, testVideoId);
|
||||
|
||||
info(`set metadata`);
|
||||
let metadata = {
|
||||
|
@ -223,10 +223,10 @@ add_task(async function testSetMetadataAfterMediaPaused() {
|
|||
const tab = await createTabAndLoad(PAGE_NON_AUTOPLAY);
|
||||
|
||||
info(`start media in order to let this tab be controlled`);
|
||||
await playMedia(tab);
|
||||
await playMedia(tab, testVideoId);
|
||||
|
||||
info(`pause media`);
|
||||
await pauseMedia(tab);
|
||||
await pauseMedia(tab, testVideoId);
|
||||
|
||||
info(`set metadata after media is paused`);
|
||||
let metadata = {
|
||||
|
@ -249,7 +249,7 @@ add_task(async function testSetMetadataAmongMultipleTabs() {
|
|||
const tab1 = await createTabAndLoad(PAGE_NON_AUTOPLAY);
|
||||
|
||||
info(`start media in tab1`);
|
||||
await playMedia(tab1);
|
||||
await playMedia(tab1, testVideoId);
|
||||
|
||||
info(`set metadata for tab1`);
|
||||
let metadata = {
|
||||
|
@ -276,7 +276,7 @@ add_task(async function testSetMetadataAmongMultipleTabs() {
|
|||
await setMediaMetadata(tab2, metadata);
|
||||
|
||||
info(`start media in tab2`);
|
||||
await playMedia(tab2);
|
||||
await playMedia(tab2, testVideoId);
|
||||
|
||||
info(`current active metadata should become metadata from tab2`);
|
||||
await isCurrentMetadataEqualTo(metadata);
|
||||
|
@ -305,7 +305,7 @@ add_task(async function testMetadataAfterTabNavigation() {
|
|||
const tab = await createTabAndLoad(PAGE_NON_AUTOPLAY);
|
||||
|
||||
info(`start media`);
|
||||
await playMedia(tab);
|
||||
await playMedia(tab, testVideoId);
|
||||
|
||||
info(`set metadata`);
|
||||
let metadata = {
|
||||
|
@ -335,32 +335,6 @@ add_task(async function testMetadataAfterTabNavigation() {
|
|||
/**
|
||||
* The following are helper functions.
|
||||
*/
|
||||
function playMedia(tab) {
|
||||
const playPromise = SpecialPowers.spawn(
|
||||
tab.linkedBrowser,
|
||||
[testVideoId],
|
||||
Id => {
|
||||
const video = content.document.getElementById(Id);
|
||||
if (!video) {
|
||||
ok(false, `can't get the media element!`);
|
||||
}
|
||||
return video.play();
|
||||
}
|
||||
);
|
||||
return Promise.all([playPromise, waitUntilMainMediaControllerChanged()]);
|
||||
}
|
||||
|
||||
function pauseMedia(tab) {
|
||||
return SpecialPowers.spawn(tab.linkedBrowser, [testVideoId], Id => {
|
||||
const video = content.document.getElementById(Id);
|
||||
if (!video) {
|
||||
ok(false, `can't get the media element!`);
|
||||
}
|
||||
ok(!video.paused, `video is playing before calling pause`);
|
||||
video.pause();
|
||||
});
|
||||
}
|
||||
|
||||
async function isUsingDefaultMetadata(tab, options = {}) {
|
||||
let metadata = ChromeUtils.getCurrentActiveMediaMetadata();
|
||||
if (options.isPrivateBrowsing) {
|
||||
|
|
|
@ -85,9 +85,9 @@ add_task(async function testBothGuessedAndDeclaredPlaybackState() {
|
|||
*/
|
||||
function setGuessedPlaybackState(tab, state) {
|
||||
if (state == "playing") {
|
||||
return playMedia(tab);
|
||||
return playMedia(tab, testVideoId);
|
||||
} else if (state == "paused") {
|
||||
return pauseMedia(tab);
|
||||
return pauseMedia(tab, testVideoId);
|
||||
}
|
||||
// We won't set the state `stopped`, which would only happen if no any media
|
||||
// has ever been started in the page.
|
||||
|
@ -95,43 +95,6 @@ function setGuessedPlaybackState(tab, state) {
|
|||
return Promise.resolve();
|
||||
}
|
||||
|
||||
function playMedia(tab) {
|
||||
const playPromise = SpecialPowers.spawn(
|
||||
tab.linkedBrowser,
|
||||
[testVideoId],
|
||||
Id => {
|
||||
const video = content.document.getElementById(Id);
|
||||
if (!video) {
|
||||
ok(false, `can't get the media element!`);
|
||||
}
|
||||
return video.play();
|
||||
}
|
||||
);
|
||||
return Promise.all([
|
||||
playPromise,
|
||||
waitUntilMainMediaControllerPlaybackChanged(),
|
||||
]);
|
||||
}
|
||||
|
||||
function pauseMedia(tab) {
|
||||
const spawnPromise = SpecialPowers.spawn(
|
||||
tab.linkedBrowser,
|
||||
[testVideoId],
|
||||
Id => {
|
||||
const video = content.document.getElementById(Id);
|
||||
if (!video) {
|
||||
ok(false, `can't get the media element!`);
|
||||
}
|
||||
ok(!video.paused, `video is playing before calling pause`);
|
||||
video.pause();
|
||||
}
|
||||
);
|
||||
return Promise.all([
|
||||
spawnPromise,
|
||||
waitUntilMainMediaControllerPlaybackChanged(),
|
||||
]);
|
||||
}
|
||||
|
||||
function isActualPlaybackStateEqualTo(tab, expectedState) {
|
||||
const currentState = ChromeUtils.getCurrentMediaSessionPlaybackState();
|
||||
is(
|
||||
|
|
|
@ -18,6 +18,67 @@ async function createTabAndLoad(url, inputWindow = null) {
|
|||
return tab;
|
||||
}
|
||||
|
||||
/**
|
||||
* Play the specific media and wait until it plays successfully and the main
|
||||
* controller has been updated.
|
||||
*
|
||||
* @param {tab} tab
|
||||
* The tab that contains the media which we would play
|
||||
* @param {string} elementId
|
||||
* The element Id of the media which we would play
|
||||
* @return {Promise}
|
||||
* Resolve when the media has been starting playing and the main
|
||||
* controller has been updated.
|
||||
*/
|
||||
function playMedia(tab, elementId) {
|
||||
const playPromise = SpecialPowers.spawn(
|
||||
tab.linkedBrowser,
|
||||
[elementId],
|
||||
Id => {
|
||||
const video = content.document.getElementById(Id);
|
||||
if (!video) {
|
||||
ok(false, `can't get the media element!`);
|
||||
}
|
||||
return video.play();
|
||||
}
|
||||
);
|
||||
return Promise.all([
|
||||
playPromise,
|
||||
waitUntilMainMediaControllerPlaybackChanged(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pause the specific media and wait until it pauses successfully and the main
|
||||
* controller has been updated.
|
||||
*
|
||||
* @param {tab} tab
|
||||
* The tab that contains the media which we would pause
|
||||
* @param {string} elementId
|
||||
* The element Id of the media which we would pause
|
||||
* @return {Promise}
|
||||
* Resolve when the media has been paused and the main controller has
|
||||
* been updated.
|
||||
*/
|
||||
function pauseMedia(tab, elementId) {
|
||||
const pausePromise = SpecialPowers.spawn(
|
||||
tab.linkedBrowser,
|
||||
[elementId],
|
||||
Id => {
|
||||
const video = content.document.getElementById(Id);
|
||||
if (!video) {
|
||||
ok(false, `can't get the media element!`);
|
||||
}
|
||||
ok(!video.paused, `video is playing before calling pause`);
|
||||
video.pause();
|
||||
}
|
||||
);
|
||||
return Promise.all([
|
||||
pausePromise,
|
||||
waitUntilMainMediaControllerPlaybackChanged(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a promise that resolves when the specific media starts playing.
|
||||
*
|
||||
|
|
Загрузка…
Ссылка в новой задаче