Bug 1345403 part 3 - Test element becomes tainted by DrawImage; r=jwwang,smaug
authorKaku Kuo <kaku@mozilla.com>
Wed, 08 Mar 2017 20:22:05 +0800
changeset 395505 7f9def21c5b721cbd9967b009a7bfd27a1a83707
parent 395504 99e3488b1ea4ed83a5b2233f2eb08defb6025cd4
child 395506 850a10a1e44fa6c8bd60d44e6735f26eb3f638b7
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang, smaug
bugs1345403
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1345403 part 3 - Test element becomes tainted by DrawImage; r=jwwang,smaug MozReview-Commit-ID: 9Txz4FbFtPe
dom/html/HTMLMediaElement.cpp
dom/html/HTMLMediaElement.h
dom/media/test/mochitest.ini
dom/media/test/test_background_video_no_suspend_disabled.html
dom/media/test/test_background_video_no_suspend_short_vid.html
dom/media/test/test_background_video_suspend.html
dom/media/test/test_background_video_suspend_ends.html
dom/media/test/test_background_video_tainted_by_drawimage.html
dom/webidl/HTMLMediaElement.webidl
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -1542,16 +1542,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
@@ -612,18 +612,22 @@ public:
   void GetMozDebugReaderData(nsAString& aString);
 
   // Returns a promise which will be resolved after collecting debugging
   // data from decoder/reader/MDSM. Used for debugging purposes.
   already_AddRefed<Promise> MozRequestDebugInfo(ErrorResult& aRv);
 
   void MozDumpDebugInfo();
 
+  // For use by mochitests. Enabling pref "media.test.video-suspend"
   void SetVisible(bool aVisible);
 
+  // For use by mochitests. Enabling pref "media.test.video-suspend"
+  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
@@ -1123,22 +1123,25 @@ tags = webvtt
 skip-if = toolkit == 'android' # android(bug 1232305)
 [test_can_play_type_wave.html]
 skip-if = android_version == '15' || android_version == '17' # android(bug 1232305)
 [test_fragment_noplay.html]
 skip-if = android_version == '15' || android_version == '17' # android(bug 1232305)
 [test_fragment_play.html]
 skip-if = android_version == '15' || android_version == '17' # bug 1335520, bug 1209318, android(bug 1232305)
 
+[test_background_video_no_suspend_disabled.html]
+skip-if = toolkit == 'android' # android(bug 1304480)
+tags = suspend
+[test_background_video_no_suspend_short_vid.html]
+skip-if = toolkit == 'android' # android(bug 1304480)
+tags = suspend
 [test_background_video_suspend.html]
 skip-if = toolkit == 'android' # android(bug 1304480)
 tags = suspend
 [test_background_video_suspend_ends.html]
 skip-if = toolkit == 'android' # bug 1295884, android(bug 1304480, bug 1232305)
 tags = suspend
-[test_background_video_no_suspend_short_vid.html]
-skip-if = toolkit == 'android' # android(bug 1304480)
-tags = suspend
-[test_background_video_no_suspend_disabled.html]
-skip-if = toolkit == 'android' # android(bug 1304480)
+[test_background_video_tainted_by_drawimage.html]
+skip-if = toolkit == 'android' # bug 1346705
 tags = suspend
 [test_temporary_file_blob_video_plays.html]
 skip-if = toolkit == 'android' # android(bug 1232305)
--- 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);
 
--- 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);
--- a/dom/media/test/test_background_video_suspend.html
+++ b/dom/media/test/test_background_video_suspend.html
@@ -16,17 +16,17 @@ function testDelay(v, start, min) {
   let end = performance.now();
   let delay = end - start;
   ok(delay > min, `${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", MIN_DELAY ]
   ],
   tests: gDecodeSuspendTests,
   runTest: (test, token) => {
     let v = appendVideoToDoc(test.name, token);
--- 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,58 @@
+<!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 type="text/javascript">
+"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) => {
+    ok(true, `${test.name}`);
+    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>
\ No newline at end of file
--- a/dom/webidl/HTMLMediaElement.webidl
+++ b/dom/webidl/HTMLMediaElement.webidl
@@ -211,13 +211,21 @@ partial interface HTMLMediaElement {
 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.
+ *
+ * - 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().
  */
 partial interface HTMLMediaElement {
-  [Pref="media.test.setVisible"]
+  [Pref="media.test.video-suspend"]
   void setVisible(boolean aVisible);
-};
+
+  [Pref="media.test.video-suspend"]
+  boolean hasSuspendTaint();
+};
\ No newline at end of file