зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1511235 - part2 : add test. r=jya,baku
Add new webidl method for testing only and a test. Differential Revision: https://phabricator.services.mozilla.com/D13805 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
7b4432b505
Коммит
aba79e9edc
|
@ -1630,6 +1630,10 @@ void HTMLMediaElement::SetVisible(bool aVisible) {
|
|||
}
|
||||
}
|
||||
|
||||
bool HTMLMediaElement::IsVideoDecodingSuspended() const {
|
||||
return mDecoder && mDecoder->IsVideoDecodingSuspended();
|
||||
}
|
||||
|
||||
already_AddRefed<layers::Image> HTMLMediaElement::GetCurrentImage() {
|
||||
MarkAsTainted();
|
||||
|
||||
|
|
|
@ -560,6 +560,9 @@ class HTMLMediaElement : public nsGenericHTMLElement,
|
|||
// For use by mochitests. Enabling pref "media.test.video-suspend"
|
||||
bool HasSuspendTaint() const;
|
||||
|
||||
// For use by mochitests. Enabling pref "media.test.video-suspend"
|
||||
bool IsVideoDecodingSuspended() const;
|
||||
|
||||
// Synchronously, return the next video frame and mark the element unable to
|
||||
// participate in decode suspending.
|
||||
//
|
||||
|
|
|
@ -435,9 +435,11 @@ void MediaDecoder::OnPlaybackEvent(MediaPlaybackEvent&& aEvent) {
|
|||
break;
|
||||
case MediaPlaybackEvent::EnterVideoSuspend:
|
||||
GetOwner()->DispatchAsyncEvent(NS_LITERAL_STRING("mozentervideosuspend"));
|
||||
mIsVideoDecodingSuspended = true;
|
||||
break;
|
||||
case MediaPlaybackEvent::ExitVideoSuspend:
|
||||
GetOwner()->DispatchAsyncEvent(NS_LITERAL_STRING("mozexitvideosuspend"));
|
||||
mIsVideoDecodingSuspended = false;
|
||||
break;
|
||||
case MediaPlaybackEvent::StartVideoSuspendTimer:
|
||||
GetOwner()->DispatchAsyncEvent(
|
||||
|
@ -460,6 +462,10 @@ void MediaDecoder::OnPlaybackEvent(MediaPlaybackEvent&& aEvent) {
|
|||
}
|
||||
}
|
||||
|
||||
bool MediaDecoder::IsVideoDecodingSuspended() const {
|
||||
return mIsVideoDecodingSuspended;
|
||||
}
|
||||
|
||||
void MediaDecoder::OnPlaybackErrorEvent(const MediaResult& aError) {
|
||||
DecodeError(aError);
|
||||
}
|
||||
|
|
|
@ -312,6 +312,8 @@ class MediaDecoder : public DecoderDoctorLifeLogger<MediaDecoder> {
|
|||
|
||||
void SetIsBackgroundVideoDecodingAllowed(bool aAllowed);
|
||||
|
||||
bool IsVideoDecodingSuspended() const;
|
||||
|
||||
/******
|
||||
* The following methods must only be called on the main
|
||||
* thread.
|
||||
|
@ -578,6 +580,9 @@ class MediaDecoder : public DecoderDoctorLifeLogger<MediaDecoder> {
|
|||
MediaEventListener mOnDecodeWarning;
|
||||
MediaEventListener mOnNextFrameStatus;
|
||||
|
||||
// True if we have suspended video decoding.
|
||||
bool mIsVideoDecodingSuspended = false;
|
||||
|
||||
protected:
|
||||
// PlaybackRate and pitch preservation status we should start at.
|
||||
double mPlaybackRate;
|
||||
|
|
|
@ -218,6 +218,10 @@ partial interface HTMLMediaElement {
|
|||
|
||||
[Pref="media.test.video-suspend"]
|
||||
boolean hasSuspendTaint();
|
||||
|
||||
[ChromeOnly]
|
||||
// This one is used for testing only
|
||||
readonly attribute boolean isVideoDecodingSuspended;
|
||||
};
|
||||
|
||||
/* Audio Output Devices API */
|
||||
|
|
|
@ -103,6 +103,10 @@ uses-unsafe-cpows = true
|
|||
[browser_isSynthetic.js]
|
||||
[browser_keyevents_during_autoscrolling.js]
|
||||
[browser_label_textlink.js]
|
||||
[browser_suspend_videos_outside_viewport.js]
|
||||
support-files =
|
||||
file_outside_viewport_videos.html
|
||||
gizmo.mp4
|
||||
[browser_mediaPlayback.js]
|
||||
tags = audiochannel
|
||||
[browser_mediaPlayback_mute.js]
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* This test is used to ensure we suspend video decoding if video is not in the
|
||||
* viewport.
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const PAGE = "https://example.com/browser/toolkit/content/tests/browser/file_outside_viewport_videos.html";
|
||||
|
||||
async function test_suspend_video_decoding() {
|
||||
let videos = content.document.getElementsByTagName("video");
|
||||
for (let video of videos) {
|
||||
info(`- start video on the ${video.id} side and outside the viewport -`);
|
||||
await video.play();
|
||||
ok(true, `video started playing`);
|
||||
ok(video.isVideoDecodingSuspended, `video decoding is suspended`);
|
||||
}
|
||||
}
|
||||
|
||||
add_task(async function setup_test_preference() {
|
||||
await SpecialPowers.pushPrefEnv({"set": [
|
||||
["media.suspend-bkgnd-video.enabled", true],
|
||||
["media.suspend-bkgnd-video.delay-ms", 0],
|
||||
]});
|
||||
});
|
||||
|
||||
add_task(async function start_test() {
|
||||
await BrowserTestUtils.withNewTab({
|
||||
gBrowser,
|
||||
url: PAGE,
|
||||
}, async browser => {
|
||||
await ContentTask.spawn(browser, null, test_suspend_video_decoding);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,41 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>outside viewport videos</title>
|
||||
<style>
|
||||
/**
|
||||
* These CSS would move elements to the far left/right/top/bottom where user
|
||||
* can not see elements in the viewport if user doesn't scroll the page.
|
||||
*/
|
||||
.outside-left {
|
||||
position: absolute;
|
||||
left: -200%;
|
||||
}
|
||||
.outside-right {
|
||||
position: absolute;
|
||||
right: -200%;
|
||||
}
|
||||
.outside-top {
|
||||
position: absolute;
|
||||
top: -200%;
|
||||
}
|
||||
.outside-bottom {
|
||||
position: absolute;
|
||||
bottom: -200%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="outside-left">
|
||||
<video id="left" src="gizmo.mp4">
|
||||
</div>
|
||||
<div class="outside-right">
|
||||
<video id="right" src="gizmo.mp4">
|
||||
</div>
|
||||
<div class="outside-top">
|
||||
<video id="top" src="gizmo.mp4">
|
||||
</div>
|
||||
<div class="outside-bottom">
|
||||
<video id="bottom" src="gizmo.mp4">
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче