Bug 879717 - Part 2: Test that drawing a video element to canvas never throws. r=roc, a=lmandel
authorAndreas Pehrson <pehrsons@gmail.com>
Mon, 06 Oct 2014 11:22:55 +0200
changeset 249325 05abbe4ec215b53b98d6aadbd8821c303cce9b74
parent 249324 1112988e90ac6631ee487f590155df4ad53450a2
child 249326 c98d9fcee9348ee57aba72edb34fd81b1969c8ec
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, lmandel
bugs879717
milestone37.0a2
Bug 879717 - Part 2: Test that drawing a video element to canvas never throws. r=roc, a=lmandel
dom/media/test/mochitest.ini
dom/media/test/test_bug879717.html
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -327,16 +327,17 @@ skip-if = (toolkit == 'android' && proce
 skip-if = (toolkit == 'android' && processor == 'x86') #x86 only bug 914439
 [test_bug495300.html]
 skip-if = (toolkit == 'android' && processor == 'x86') #x86 only bug 914439
 [test_bug654550.html]
 [test_bug686942.html]
 skip-if = (toolkit == 'android' && processor == 'x86') #x86 only bug 914439
 [test_bug726904.html]
 [test_bug874897.html]
+[test_bug879717.html]
 [test_bug883173.html]
 [test_bug895091.html]
 [test_bug895305.html]
 [test_bug919265.html]
 [test_bug957847.html]
 [test_bug1018933.html]
 [test_bug1113600.html]
 [test_can_play_type.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/test/test_bug879717.html
@@ -0,0 +1,119 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for bug 879717, check that a video element can be drawn into a canvas at various states of playback</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+  <script type="text/javascript" src="manifest.js"></script>
+</head>
+<body>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+var manager = new MediaTestManager;
+
+var canvas = document.createElement('canvas');
+document.body.appendChild(canvas);
+
+var checkDrawImage = function(eventName, videoElement) {
+  var exception = null;
+  var exceptionName = "nothing";
+  try {
+    var ctx = canvas.getContext('2d');
+    ctx.drawImage(videoElement, 0, 0, canvas.width, canvas.height);
+  } catch (e) {
+    exception = e;
+    exceptionName = e.name;
+  }
+  ok(exception === null,
+    "drawImage shouldn't throw an exception on " + eventName +
+    " of " + videoElement.testName + ", got " + exceptionName);
+};
+
+var checkDrawImageEventHandler = function(ev) {
+  checkDrawImage(ev.type, ev.target);
+};
+var startTest = function(media, token) {
+  manager.started(token);
+
+  // File playback
+  var v1 = document.createElement("video");
+  v1.autoplay = true;
+
+  // Captured file playback
+  var v2 = document.createElement("video");
+  v2.autoplay = true;
+
+  // Stream playback
+  var v3 = document.createElement("video");
+  v3.autoplay = true;
+
+  v1.gotLoadeddata = false;
+  v2.gotLoadeddata = false;
+  v3.gotLoadeddata = false;
+
+  v1.testName = "v1 (" + media.name + ")";
+  v2.testName = "v2 (Captured " + media.name + ")";
+  v3.testName = "v3 (Stream of " + media.name + ")";
+
+  checkDrawImage("beforeplay", v1);
+  checkDrawImage("beforeplay", v2);
+  checkDrawImage("beforeplay", v3);
+
+  v1.onloadedmetadata = checkDrawImageEventHandler;
+  v2.onloadedmetadata = checkDrawImageEventHandler;
+  v3.onloadedmetadata = checkDrawImageEventHandler;
+
+  v1.onplay = checkDrawImageEventHandler;
+  v2.onplay = checkDrawImageEventHandler;
+  v3.onplay = checkDrawImageEventHandler;
+
+  v1.onplaying = checkDrawImageEventHandler;
+  v2.onplaying = checkDrawImageEventHandler;
+  v3.onplaying = checkDrawImageEventHandler;
+
+  var onloadeddata = function(ev) {
+    ev.target.gotLoadeddata = true;
+    checkDrawImageEventHandler(ev);
+  };
+
+  v1.onloadeddata = onloadeddata;
+  v2.onloadeddata = onloadeddata;
+  v3.onloadeddata = onloadeddata;
+
+  var checkFinished = function() {
+    if (!v1.testFinished || !v2.testFinished || !v3.testFinished) {
+      return;
+    }
+
+    ok(v1.gotLoadeddata, v1.testName + " should have gotten the 'loadeddata' event callback");
+    ok(v2.gotLoadeddata, v2.testName + " should have gotten the 'loadeddata' event callback");
+    ok(v3.gotLoadeddata, v3.testName + " should have gotten the 'loadeddata' event callback");
+
+    manager.finished(token);
+  };
+
+  var onended = function(ev) {
+    checkDrawImageEventHandler(ev);
+    removeNodeAndSource(ev.target);
+    ev.target.testFinished = true;
+    checkFinished();
+  };
+
+  v1.onended = onended;
+  v2.onended = onended;
+  v3.onended = onended;
+
+  document.body.appendChild(v1);
+  document.body.appendChild(v2);
+  document.body.appendChild(v3);
+
+  v1.src = media.name;
+  v2.src = media.name;
+  v3.mozSrcObject = v2.mozCaptureStreamUntilEnded();
+}
+
+manager.runTests(getPlayableVideos(gSmallTests), startTest);
+</script>
+</pre>
+</body>
+</html>