diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp
index 4462ef1d756c..f92121ae1086 100644
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -1645,11 +1645,10 @@ HTMLMediaElement::MozDumpDebugInfo()
void
HTMLMediaElement::SetVisible(bool aVisible)
{
- if (!mDecoder) {
- return;
+ mForcedHidden = !aVisible;
+ if (mDecoder) {
+ mDecoder->SetForcedHidden(!aVisible);
}
-
- mDecoder->SetForcedHidden(!aVisible);
}
already_AddRefed
@@ -3880,6 +3879,7 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed& aNo
mFirstFrameLoaded(false),
mDefaultPlaybackStartPosition(0.0),
mHasSuspendTaint(false),
+ mForcedHidden(false),
mMediaTracksConstructed(false),
mVisibilityState(Visibility::UNTRACKED),
mErrorSink(new ErrorSink(this)),
@@ -7331,6 +7331,9 @@ HTMLMediaElement::SetDecoder(MediaDecoder* aDecoder)
}
mDecoder = aDecoder;
DDLINKCHILD("decoder", mDecoder.get());
+ if (mDecoder && mForcedHidden) {
+ mDecoder->SetForcedHidden(mForcedHidden);
+ }
}
float
diff --git a/dom/html/HTMLMediaElement.h b/dom/html/HTMLMediaElement.h
index 7f75aab11327..0cecc1243660 100644
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -1821,6 +1821,10 @@ private:
// participate in video decoder suspending.
bool mHasSuspendTaint;
+ // True if media element has been forced into being considered 'hidden'.
+ // For use by mochitests. Enabling pref "media.test.video-suspend"
+ bool mForcedHidden;
+
// True if audio tracks and video tracks are constructed and added into the
// track list, false if all tracks are removed from the track list.
bool mMediaTracksConstructed;
diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp
index d73bfdbea90b..1ded2b283474 100644
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -3080,6 +3080,11 @@ void MediaDecoderStateMachine::SetVideoDecodeModeInternal(VideoDecodeMode aMode)
{
MOZ_ASSERT(OnTaskQueue());
+ LOG("SetVideoDecodeModeInternal(), VideoDecodeMode=(%s->%s), mVideoDecodeSuspended=%c",
+ mVideoDecodeMode == VideoDecodeMode::Normal ? "Normal" : "Suspend",
+ aMode == VideoDecodeMode::Normal ? "Normal" : "Suspend",
+ mVideoDecodeSuspended ? 'T' : 'F');
+
// Should not suspend decoding if we don't turn on the pref.
if (!MediaPrefs::MDSMSuspendBackgroundVideoEnabled() &&
aMode == VideoDecodeMode::Suspend) {
@@ -3092,11 +3097,6 @@ void MediaDecoderStateMachine::SetVideoDecodeModeInternal(VideoDecodeMode aMode)
return;
}
- LOG("SetVideoDecodeModeInternal(), VideoDecodeMode=(%s->%s), mVideoDecodeSuspended=%c",
- mVideoDecodeMode == VideoDecodeMode::Normal ? "Normal" : "Suspend",
- aMode == VideoDecodeMode::Normal ? "Normal" : "Suspend",
- mVideoDecodeSuspended ? 'T' : 'F');
-
// Set new video decode mode.
mVideoDecodeMode = aMode;