зеркало из 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:
Родитель
41df7a6715
Коммит
16fe01f1fd
|
@ -1631,6 +1631,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.
|
||||
bool IsVideoDecodingSuspended() const;
|
||||
|
||||
// Synchronously, return the next video frame and mark the element unable to
|
||||
// participate in decode suspending.
|
||||
//
|
||||
|
|
|
@ -434,9 +434,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(
|
||||
|
@ -459,6 +461,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;
|
||||
|
|
|
@ -204,13 +204,14 @@ partial interface HTMLMediaElement {
|
|||
};
|
||||
|
||||
/*
|
||||
* This is an API for simulating visibility changes to help debug and write
|
||||
* These APIs are testing only, they are used to simulate visibility changes to help debug and write
|
||||
* tests about suspend-video-decoding.
|
||||
*
|
||||
* - SetVisible() is for simulating visibility changes.
|
||||
* - HasSuspendTaint() is for querying that the element's decoder cannot suspend
|
||||
* video decoding because it has been tainted by an operation, such as
|
||||
* drawImage().
|
||||
* - isVideoDecodingSuspended() is used to know whether video decoding has suspended.
|
||||
*/
|
||||
partial interface HTMLMediaElement {
|
||||
[Pref="media.test.video-suspend"]
|
||||
|
@ -218,6 +219,9 @@ partial interface HTMLMediaElement {
|
|||
|
||||
[Pref="media.test.video-suspend"]
|
||||
boolean hasSuspendTaint();
|
||||
|
||||
[ChromeOnly]
|
||||
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: -1000%;
|
||||
}
|
||||
.outside-right {
|
||||
position: absolute;
|
||||
right: -1000%;
|
||||
}
|
||||
.outside-top {
|
||||
position: absolute;
|
||||
top: -1000%;
|
||||
}
|
||||
.outside-bottom {
|
||||
position: absolute;
|
||||
bottom: -1000%;
|
||||
}
|
||||
</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>
|
Загрузка…
Ссылка в новой задаче