зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1654045 - part4 : add a test to ensure we would stop controlling media when it reaches to the end. r=chunmin
Differential Revision: https://phabricator.services.mozilla.com/D85231
This commit is contained in:
Родитель
408ccb2310
Коммит
c7563ad7c8
|
@ -10,6 +10,7 @@ support-files =
|
|||
file_muted_autoplay.html
|
||||
file_non_autoplay.html
|
||||
file_non_eligible_media.html
|
||||
file_non_looping_media.html
|
||||
head.js
|
||||
../../test/gizmo.mp4
|
||||
../../test/gizmo-noaudio.webm
|
||||
|
@ -31,4 +32,5 @@ support-files =
|
|||
[browser_media_control_seekto.js]
|
||||
[browser_media_control_supported_keys.js]
|
||||
[browser_media_control_stop_timer.js]
|
||||
[browser_stop_control_after_media_reaches_to_end.js]
|
||||
[browser_resume_latest_paused_media.js]
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
/* eslint-disable no-undef */
|
||||
const PAGE_URL =
|
||||
"https://example.com/browser/dom/media/mediacontrol/tests/file_non_looping_media.html";
|
||||
|
||||
/**
|
||||
* This test is used to ensure that we would stop controlling media after it
|
||||
* reaches to the end.
|
||||
*/
|
||||
add_task(async function testControlShouldStopAfterMediaReachesToTheEnd() {
|
||||
info(`open media page and play media until the end`);
|
||||
const tab = await createTabAndLoad(PAGE_URL);
|
||||
await Promise.all([
|
||||
checkIfMediaControllerBecomeInactiveAfterMediaEnds(tab),
|
||||
playMediaUntilItReachesToTheEnd(tab),
|
||||
]);
|
||||
|
||||
info(`remove tab`);
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
/**
|
||||
* The following are helper functions.
|
||||
*/
|
||||
function checkIfMediaControllerBecomeInactiveAfterMediaEnds(tab) {
|
||||
return new Promise(r => {
|
||||
let activeChangedNums = 0;
|
||||
const controller = tab.linkedBrowser.browsingContext.mediaController;
|
||||
controller.onactivated = () => {
|
||||
is(
|
||||
++activeChangedNums,
|
||||
1,
|
||||
`Receive ${activeChangedNums} times 'onactivechange'`
|
||||
);
|
||||
ok(controller.isActive, "controller should be active");
|
||||
ok(controller.isAudible, "controller should be audible");
|
||||
ok(controller.isPlaying, "controller should be playing");
|
||||
};
|
||||
controller.ondeactivated = () => {
|
||||
is(
|
||||
++activeChangedNums,
|
||||
2,
|
||||
`Receive ${activeChangedNums} times 'onactivechange'`
|
||||
);
|
||||
ok(!controller.isActive, "controller should be inactive");
|
||||
ok(!controller.isAudible, "controller should be inaudible");
|
||||
ok(!controller.isPlaying, "controller should be paused");
|
||||
r();
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function playMediaUntilItReachesToTheEnd(tab) {
|
||||
return SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
|
||||
const video = content.document.getElementById("video");
|
||||
if (!video) {
|
||||
ok(false, "can't get video");
|
||||
}
|
||||
|
||||
if (video.readyState < video.HAVE_METADATA) {
|
||||
info(`load media to get its duration`);
|
||||
video.load();
|
||||
await new Promise(r => (video.loadedmetadata = r));
|
||||
}
|
||||
|
||||
info(`adjust the start position to faster reach to the end`);
|
||||
ok(video.duration > 1.0, "video's duration is larger than 1.0s");
|
||||
video.currentTime = video.duration - 1.0;
|
||||
|
||||
info(`play ${video.id} video`);
|
||||
video.play();
|
||||
await new Promise(r => (video.onended = r));
|
||||
});
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Non looping media page</title>
|
||||
</head>
|
||||
<body>
|
||||
<video id="video" src="gizmo.mp4"></video>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче