Bug 1295921 - P3: Test element becomes tainted by DrawImage. r?jwwang, smaug
MozReview-Commit-ID: AHFbNxRtJqG
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -1482,16 +1482,23 @@ HTMLMediaElement::GetCurrentImage()
if (!container) {
return nullptr;
}
AutoLockImage lockImage(container);
return lockImage.GetImage();
}
+bool
+HTMLMediaElement::HasSuspendTaint() const
+{
+ MOZ_ASSERT(!mDecoder || (mDecoder->HasSuspendTaint() == mHasSuspendTaint));
+ return mHasSuspendTaint;
+}
+
already_AddRefed<DOMMediaStream>
HTMLMediaElement::GetSrcObject() const
{
NS_ASSERTION(!mSrcAttrStream || mSrcAttrStream->GetPlaybackStream(),
"MediaStream should have been set up properly");
RefPtr<DOMMediaStream> stream = mSrcAttrStream;
return stream.forget();
}
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -600,18 +600,22 @@ public:
already_AddRefed<MediaSource> GetMozMediaSourceObject() const;
// Returns a string describing the state of the media player internal
// data. Used for debugging purposes.
void GetMozDebugReaderData(nsAString& aString);
void MozDumpDebugInfo();
+ // For use by mochitests. Enabling pref "media.test.setVisible"
void SetVisible(bool aVisible);
+ // For use by mochitests. Enabling pref "media.test.suspend-taint"
+ bool HasSuspendTaint() const;
+
// Synchronously, return the next video frame and mark the element
// unable to participate in decode suspending.
//
// This function is synchronous for cases where decoding has been suspended
// and JS needs a frame to use in, eg., nsLayoutUtils::SurfaceFromElement()
// via drawImage().
layers::Image* GetCurrentImage();
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -945,17 +945,19 @@ tags = webvtt
# The tests below contain backend-specific tests. Write backend independent
# tests rather than adding to this list.
[test_can_play_type_webm.html]
[test_can_play_type_wave.html]
[test_fragment_noplay.html]
[test_fragment_play.html]
+[test_background_video_no_suspend_disabled.html]
+tags = suspend
+[test_background_video_no_suspend_short_vid.html]
+tags = suspend
[test_background_video_suspend.html]
tags = suspend
[test_background_video_suspend_ends.html]
tags = suspend
-[test_background_video_no_suspend_short_vid.html]
-tags = suspend
-[test_background_video_no_suspend_disabled.html]
+[test_background_video_tainted_by_drawimage.html]
tags = suspend
[test_temporary_file_blob_video_plays.html]
--- a/dom/media/test/test_background_video_no_suspend_disabled.html
+++ b/dom/media/test/test_background_video_no_suspend_disabled.html
@@ -8,17 +8,17 @@
<script>
"use strict";
var manager = new MediaTestManager;
startTest({
desc: "Test Background Video Doesn't Suspend When Feature Disabled.",
prefs: [
- [ 'media.test.setVisible', true ],
+ [ 'media.test.video-suspend', true ],
[ 'media.suspend-bkgnd-video.enabled', false ],
[ 'media.suspend-bkgnd-video.delay-ms', 0 ]
],
tests: gDecodeSuspendTests,
runTest: (test, token) => {
let v = appendVideoToDoc(test.name, token);
manager.started(token);
@@ -28,9 +28,9 @@ startTest({
.then(() => {
ok(true, 'Video ended before decode was suspended');
manager.finished(token); })
.catch((e) => {
ok(false, 'Test Failed: ' + e.toString());
manager.finished(token); });
}
});
-</script>
\ No newline at end of file
+</script>
--- a/dom/media/test/test_background_video_no_suspend_short_vid.html
+++ b/dom/media/test/test_background_video_no_suspend_short_vid.html
@@ -8,17 +8,17 @@
<script>
"use strict";
var manager = new MediaTestManager;
startTest({
desc: "Test Background Video Doesn't Suspend When Timeout Is Longer Than Video.",
prefs: [
- [ 'media.test.setVisible', true ],
+ [ 'media.test.video-suspend', true ],
[ 'media.suspend-bkgnd-video.enabled', true ],
// Gizmo.mp4 is about 5.6s
[ 'media.suspend-bkgnd-video.delay-ms', 10000 ]
],
tests: gDecodeSuspendTests,
runTest: (test, token) => {
let v = appendVideoToDoc(test.name, token);
manager.started(token);
@@ -30,9 +30,9 @@ startTest({
.then(() => {
ok(true, 'Video ended before decode was suspended');
manager.finished(token); })
.catch((e) => {
ok(false, 'Test Failed: ' + e.toString());
manager.finished(token); });
}
});
-</script>
\ No newline at end of file
+</script>
--- a/dom/media/test/test_background_video_suspend.html
+++ b/dom/media/test/test_background_video_suspend.html
@@ -14,17 +14,17 @@ function testDelay(v, start, min, max) {
let end = performance.now();
let delay = end - start;
ok(delay > min && delay < max, `${v.token} suspended with a delay of ${delay} ms`);
}
startTest({
desc: 'Test Background Video Suspends',
prefs: [
- [ "media.test.setVisible", true ],
+ [ "media.test.video-suspend", true ],
[ "media.suspend-bkgnd-video.enabled", true ],
// User a short delay to ensure video decode suspend happens before end
// of video.
[ "media.suspend-bkgnd-video.delay-ms", 100 ]
],
tests: gDecodeSuspendTests,
runTest: (test, token) => {
let v = appendVideoToDoc(test.name, token);
@@ -40,9 +40,9 @@ startTest({
})
.then(() => waitUntilEnded(v))
.then(() => {
removeNodeAndSource(v);
manager.finished(token);
});
}
});
-</script>
\ No newline at end of file
+</script>
--- a/dom/media/test/test_background_video_suspend_ends.html
+++ b/dom/media/test/test_background_video_suspend_ends.html
@@ -8,17 +8,17 @@
<script type="text/javascript">
"use strict";
var manager = new MediaTestManager;
startTest({
desc: "Test Background Suspended Video Fires 'ended' Event",
prefs: [
- [ "media.test.setVisible", true ],
+ [ "media.test.video-suspend", true ],
[ "media.suspend-bkgnd-video.enabled", true ],
// User a short delay to ensure video decode suspend happens before end
// of video.
[ "media.suspend-bkgnd-video.delay-ms", 1000 ]
],
tests: gDecodeSuspendTests,
runTest: (test, token) => {
let v = appendVideoToDoc(test.name, token);
new file mode 100644
--- /dev/null
+++ b/dom/media/test/test_background_video_tainted_by_drawimage.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Test Background Video Is Tainted By drawImage</title>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<script src="manifest.js"></script>
+<script src="background_video.js"></script>
+<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
+<script>
+"use strict";
+
+var manager = new MediaTestManager;
+
+function drawVideoToCanvas(v) {
+ let w = v.width,
+ h = v.height,
+ c = document.createElement('canvas');
+ c.width = w;
+ c.height = h;
+ document.body.appendChild(c);
+
+ let gfx = c.getContext('2d');
+ if (!gfx) {
+ throw Error("Unable to obtain context '2d' from canvas");
+ }
+
+ gfx.drawImage(v, 0, 0, w, h);
+}
+
+startTest({
+ desc: 'Test Background Video Is Tainted By drawImage',
+ prefs: [
+ [ "media.test.video-suspend", true ],
+ [ "media.suspend-bkgnd-video.enabled", true ],
+ [ "media.suspend-bkgnd-video.delay-ms", 1000 ]
+ ],
+ tests: gDecodeSuspendTests,
+ runTest: (test, token) => {
+ let v = appendVideoToDoc(test.name, token);
+ manager.started(token);
+
+ waitUntilPlaying(v)
+ .then(() => {
+ drawVideoToCanvas(v);
+ ok(v.hasSuspendTaint(), "Video is tainted after drawing to canvas");
+ return checkVideoDoesntSuspend(v);
+ })
+ .then(() => {
+ ok(true, 'Video ended before decode was suspended');
+ manager.finished(token);
+ })
+ .catch((e) => {
+ ok(false, 'Test failed: ' + e.toString());
+ manager.finished(token);
+ });
+ }
+});
+</script>
--- a/dom/webidl/HTMLMediaElement.webidl
+++ b/dom/webidl/HTMLMediaElement.webidl
@@ -210,15 +210,22 @@ partial interface HTMLMediaElement {
* event and an "ended" event.
*/
partial interface HTMLMediaElement {
[Throws, Pref="media.seekToNextFrame.enabled"]
Promise<void> seekToNextFrame();
};
/*
- * This is an API for simulating visibility changes to help debug and write
- * tests about suspend-video-decoding.
+ * This is an API 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 can
+ suspend video decoding because it has been tainted by an
+ operation, such as drawImage().
*/
partial interface HTMLMediaElement {
- [Pref="media.test.setVisible"]
+ [Pref="media.test.video-suspend"]
void setVisible(boolean aVisible);
+
+ [Pref="media.test.video-suspend"]
+ boolean hasSuspendTaint();
};