mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 1621166 - part4 : add test. r=MeFisto94
Differential Revision: https://phabricator.services.mozilla.com/D67385 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
1ca8d55a56
commit
699bb58267
@ -8,6 +8,7 @@ support-files =
|
||||
../../test/gizmo.mp4
|
||||
../../test/gizmo-noaudio.webm
|
||||
../../test/gizmo-short.mp4
|
||||
!/toolkit/components/pictureinpicture/tests/head.js
|
||||
../../../../toolkit/content/tests/browser/silentAudioTrack.webm
|
||||
|
||||
[browser_audio_focus_management.js]
|
||||
@ -15,3 +16,4 @@ support-files =
|
||||
[browser_media_control_keys_event.js]
|
||||
[browser_media_control_non_eligible_media.js]
|
||||
[browser_media_control_playback_state.js]
|
||||
[browser_media_control_stop_timer.js]
|
||||
|
@ -0,0 +1,80 @@
|
||||
/* eslint-disable no-undef */
|
||||
|
||||
// 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
|
||||
);
|
||||
|
||||
const PAGE_NON_AUTOPLAY =
|
||||
"https://example.com/browser/dom/media/mediacontrol/tests/file_non_autoplay.html";
|
||||
|
||||
const testVideoId = "video";
|
||||
|
||||
add_task(async function setupTestingPref() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["media.mediacontrol.testingevents.enabled", true],
|
||||
// As `main-media-controller-playback-changed` is dispatched asynchronously, if
|
||||
// we want to receive it after pausing media, we should postpone the time of
|
||||
// triggering the stop timer. That value should be changed to 0 after landing
|
||||
// bug1620113.
|
||||
["media.mediacontrol.stopcontrol.timer.ms", 2000],
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* This test is used to check the stop timer for media element, which would stop
|
||||
* media control for the specific element when the element has been paused over
|
||||
* certain length of time. (That is controlled by the value of the pref
|
||||
* `media.mediacontrol.stopcontrol.timer.ms`) In this test, we set the pref to 0
|
||||
* which means the stop timer would be triggered after the media is paused.
|
||||
* However, if the media is being used in PIP mode, we won't start the stop
|
||||
* timer for it.
|
||||
*/
|
||||
add_task(async function testStopMediaControlAfterPausingMedia() {
|
||||
info(`open media page`);
|
||||
const tab = await createTabAndLoad(PAGE_NON_AUTOPLAY);
|
||||
|
||||
info(`start media`);
|
||||
await playMedia(tab, testVideoId);
|
||||
|
||||
info(`pause media and the stop timer would stop media control`);
|
||||
await pauseMediaAndMediaControlShouldBeStopped(tab, testVideoId);
|
||||
|
||||
info(`remove tab`);
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
add_task(async function testNotToStopMediaControlForPIPVideo() {
|
||||
info(`open media page`);
|
||||
const tab = await createTabAndLoad(PAGE_NON_AUTOPLAY);
|
||||
|
||||
info(`start media`);
|
||||
await playMedia(tab, testVideoId);
|
||||
|
||||
info(`trigger PIP mode`);
|
||||
let pipWin = await triggerPictureInPicture(tab.linkedBrowser, testVideoId);
|
||||
|
||||
info(`pause media and the stop timer would not stop media control`);
|
||||
await pauseMedia(tab, testVideoId);
|
||||
|
||||
info(`pressing 'play' key should start PIP video again`);
|
||||
await generateMediaControlKeyEvent("play");
|
||||
await checkOrWaitUntilMediaStartedPlaying(tab, testVideoId);
|
||||
|
||||
info(`remove tab`);
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
/**
|
||||
* The following is helper function.
|
||||
*/
|
||||
function pauseMediaAndMediaControlShouldBeStopped(tab, testVideoId) {
|
||||
// After pausing media, the stop timer would be triggered and stop the media
|
||||
// control, which would reset the current main media controller.
|
||||
const controllerChangedPromise = waitUntilMainMediaControllerChanged();
|
||||
return Promise.all([pauseMedia(tab, testVideoId), controllerChangedPromise]);
|
||||
}
|
@ -18,6 +18,23 @@ async function createTabAndLoad(url, inputWindow = null) {
|
||||
return tab;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a promise that resolves when generated media control keys has
|
||||
* triggered the main media controller's corresponding method and changes its
|
||||
* playback state.
|
||||
*
|
||||
* @param {string} event
|
||||
* The event name of the media control key
|
||||
* @return {Promise}
|
||||
* Resolve when the main controller receives the media control key event
|
||||
* and change its playback state.
|
||||
*/
|
||||
function generateMediaControlKeyEvent(event) {
|
||||
const playbackStateChanged = waitUntilMainMediaControllerPlaybackChanged();
|
||||
ChromeUtils.generateMediaControlKeysTestEvent(event);
|
||||
return playbackStateChanged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Play the specific media and wait until it plays successfully and the main
|
||||
* controller has been updated.
|
||||
|
Loading…
Reference in New Issue
Block a user