Bug 879717 - Part 2. Test that drawing a video element to canvas

From 5be50c1d6131a58d8a06dcaa0dfca8156ef71273 Mon Sep 17 00:00:00 2001
 never throws. r=roc
---
 dom/media/test/mochitest.ini       |   1 +
 dom/media/test/test_bug879717.html | 119 +++++++++++++++++++++++++++++++++++++
 2 files changed, 120 insertions(+)
 create mode 100644 dom/media/test/test_bug879717.html
This commit is contained in:
Andreas Pehrson 2014-10-06 11:22:55 +02:00
parent 7c09df35ce
commit 9fa2cc3ffe
2 changed files with 120 additions and 0 deletions

View File

@ -332,6 +332,7 @@ skip-if = (toolkit == 'android' && processor == 'x86') #x86 only bug 914439
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]

View File

@ -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>