Bug 1346120 part 6 - Test drawImage gets a non-single-color image from suspended video; r=jwwang
authorKaku Kuo <kaku@mozilla.com>
Thu, 09 Mar 2017 17:37:32 +0800
changeset 347412 e924204de04084739434958143a0b7e9a78cbd23
parent 347411 b1ce928cbeebdc8d2bfcc83d9e29b2bdc9bbfaa4
child 347413 c1880dccfde597ff54f0dea2028f8d56d8231a89
push id31496
push usercbook@mozilla.com
push dateTue, 14 Mar 2017 13:21:57 +0000
treeherdermozilla-central@9a26ed658fdc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang
bugs1346120
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 1346120 part 6 - Test drawImage gets a non-single-color image from suspended video; r=jwwang Once part 4 is applied, a suspend video element won't be rendered anymore, so that the video element keeps the last decoded-frame. By this way, drawing a suspended video element to a canvas should get something that is not single-color. MozReview-Commit-ID: J6dsZIvtO
dom/media/test/mochitest.ini
dom/media/test/test_background_video_drawimage_with_suspended_video.html
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -1144,10 +1144,14 @@ tags = suspend
 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_tainted_by_drawimage.html]
 skip-if = toolkit == 'android' # bug 1346705
 tags = suspend
+[test_background_video_drawimage_with_suspended_video.html]
+skip-if = toolkit == 'android' # bug 1346705
+tags = suspend
+
 [test_temporary_file_blob_video_plays.html]
 skip-if = toolkit == 'android' # android(bug 1232305)
new file mode 100644
--- /dev/null
+++ b/dom/media/test/test_background_video_drawimage_with_suspended_video.html
@@ -0,0 +1,78 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Test Background Video Displays Video Frame via drawImage When Suspended</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"/>
+<style>
+video, canvas {
+  border: 1px solid black;
+}
+</style>
+<script type="text/javascript">
+"use strict";
+
+var manager = new MediaTestManager;
+
+function drawVideoToCanvas(v) {
+  console.log('drawVideoToCanvas');
+  let w = v.width,
+      h = v.height,
+      c = document.createElement('canvas');
+  c.width = 4;
+  c.height = 4;
+  c.style.width = 64;
+  c.style.height = 64;
+  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, 4, 4);
+  let imageData = gfx.getImageData(0, 0, 4, 4);
+  let pixels = imageData.data;
+
+  // Check that pixels aren't all the same colour.
+  // Implements by checking against rgb of the first pixel.
+  let rr = pixels[0],
+      gg = pixels[1],
+      bb = pixels[2],
+      allSame = true;
+
+  for (let i = 0; i < 4*4; i++) {
+    let r = pixels[4*i+0];
+    let g = pixels[4*i+1];
+    let b = pixels[4*i+2];
+    if (r != rr || g != gg || b != bb) {
+      allSame = false;
+      break;
+    }
+  }
+
+  ok(!allSame, "Pixels aren't all the same color");
+}
+
+startTest({
+  desc: 'Test Background Video Displays Video Frame via drawImage When Suspended',
+  prefs: [
+    [ "media.test.video-suspend", true ],
+    [ "media.suspend-bkgnd-video.enabled", true ],
+    [ "media.suspend-bkgnd-video.delay-ms", 500 ]
+  ],
+  tests: gDecodeSuspendTests,
+  runTest: (test, token) => {
+    let v = appendVideoToDoc(test.name, token);
+    manager.started(token);
+
+    waitUntilPlaying(v)
+      .then(() => testVideoSuspendsWhenHidden(v))
+      .then(() => {
+        drawVideoToCanvas(v);
+        manager.finished(token);
+      });
+  }
+});
+</script>
\ No newline at end of file