diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/media/test/test_streams_element_capture.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/media/test/test_streams_element_capture.html')
-rw-r--r-- | dom/media/test/test_streams_element_capture.html | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/dom/media/test/test_streams_element_capture.html b/dom/media/test/test_streams_element_capture.html new file mode 100644 index 000000000..5e30a3ce4 --- /dev/null +++ b/dom/media/test/test_streams_element_capture.html @@ -0,0 +1,98 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Test that a MediaStream captured from one element plays back in another</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"> +SimpleTest.waitForExplicitFinish(); + +// longer timeout for slow platforms +if (isSlowPlatform()) { + SimpleTest.requestLongerTimeout(3); + SimpleTest.requestCompleteLog(); +} + +function checkDrawImage(vout) { + var canvas = document.createElement("canvas"); + var ctx = canvas.getContext("2d"); + ctx.drawImage(vout, 0, 0); + var imgData = ctx.getImageData(0, 0, 1, 1); + is(imgData.data[3], 255, "Check video frame pixel has been drawn"); +} + +function isGreaterThanOrEqualEps(a, b, msg) { + ok(a >= b - 0.01, + "Got " + a + ", expected at least " + b + "; " + msg); +} + +function startTest(test) { + var v = document.createElement('video'); + var vout = document.createElement('video'); + + v.src = test.name; + var stream; + + var checkEnded = function() { + is(stream.currentTime, vout.currentTime, test.name + " stream final currentTime"); + if (test.duration) { + isGreaterThanOrEqualEps(vout.currentTime, test.duration, + test.name + " current time at end"); + } + is(vout.readyState, vout.HAVE_CURRENT_DATA, test.name + " checking readyState"); + ok(vout.ended, test.name + " checking playback has ended"); + if (test.type.match(/^video/)) { + checkDrawImage(vout); + } + vout.parentNode.removeChild(vout); + removeNodeAndSource(v); + SimpleTest.finish(); + }; + vout.addEventListener("ended", checkEnded, false); + + document.body.appendChild(vout); + + var onloadedmetadata = function (ev) { + stream = v.mozCaptureStreamUntilEnded(); + is(stream.currentTime, 0, test.name + " stream initial currentTime"); + vout.srcObject = stream; + is(vout.srcObject, stream, test.name + " set output element .srcObject correctly"); + v.play(); + vout.play(); + } + + v.preload = 'metadata'; + v.addEventListener('loadedmetadata', onloadedmetadata, false); + + // Log events for debugging. + var events = ["suspend", "play", "canplay", "canplaythrough", "loadstart", "loadedmetadata", + "loadeddata", "playing", "ended", "error", "stalled", "emptied", "abort", + "waiting", "pause"]; + function logEvent(e) { + Log(e.target.name, "got " + e.type); + } + events.forEach(function(e) { + v.addEventListener(e, logEvent, false); + vout.addEventListener(e, logEvent, false); + }); + +} + +// We only test one playable video because for some of the audio files +// --- small-shot.mp3.mp4 and small-shot.m4a --- GStreamer doesn't decode +// as much data as indicated by the duration, causing this test to fail on +// Linux. See bug 1084185. +var testVideo = getPlayableVideo(gSmallTests); +if (testVideo) { + startTest(testVideo); +} else { + todo(false, "No playable video"); +} +</script> +</pre> +</body> +</html> |