Bug 855130 - Add initial tests for MediaSource Extensions implementation. r=roc

---
 content/media/mediasource/moz.build                |   4 ++
 content/media/mediasource/test/Makefile.in         |  18 +++++
 content/media/mediasource/test/moz.build           |   4 ++
 content/media/mediasource/test/seek.webm           | Bin 0 -> 215529 bytes
 .../media/mediasource/test/test_MediaSource.html   |  79 +++++++++++++++++++++
 5 files changed, 105 insertions(+)
 create mode 100644 content/media/mediasource/test/Makefile.in
 create mode 100644 content/media/mediasource/test/moz.build
 create mode 100644 content/media/mediasource/test/seek.webm
 create mode 100644 content/media/mediasource/test/test_MediaSource.html
This commit is contained in:
Matthew Gregan 2013-07-02 15:46:49 +12:00
parent 54d3db2b8b
commit 646050b29f
5 changed files with 105 additions and 0 deletions

View File

@ -3,6 +3,10 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
PARALLEL_DIRS += [
'test'
]
MODULE = 'content'
EXPORTS += [

View File

@ -0,0 +1,18 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
DEPTH := @DEPTH@
topsrcdir := @top_srcdir@
srcdir := @srcdir@
VPATH := @srcdir@
relativesrcdir := @relativesrcdir@
include $(DEPTH)/config/autoconf.mk
MOCHITEST_FILES = \
test_MediaSource.html \
seek.webm \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,4 @@
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

Binary file not shown.

View File

@ -0,0 +1,79 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test whether we can create an MediaSource interface</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
ok(!window.MediaSource, "MediaSource should be hidden behind a pref");
var accessThrows = false;
try {
new MediaSource();
} catch (e) {
accessThrows = true;
}
ok(accessThrows, "MediaSource should be hidden behind a pref");
SpecialPowers.setBoolPref("media.mediasource.enabled", true);
var ms = new MediaSource();
ok(ms, "Create a MediaSource object");
ok(ms instanceof EventTarget, "MediaSource must be an EventTarget");
is(ms.readyState, "closed", "New MediaSource must be in closed state");
// Force wrapper creation, tests for leaks.
ms.foo = null;
var o = URL.createObjectURL(ms);
ok(o, "Create an objectURL from the MediaSource");
var v = document.createElement("video");
document.body.appendChild(v);
v.src = o;
ms.addEventListener("sourceopen", function () {
ok(true, "Receive a sourceopen event");
is(ms.readyState, "open", "MediaSource must be in open state after sourceopen");
var sb = ms.addSourceBuffer("video/webm");
ok(sb, "Create a SourceBuffer");
is(ms.sourceBuffers.length, 1, "MediaSource.sourceBuffers is expected length");
is(ms.sourceBuffers[0], sb, "SourceBuffer in list matches our SourceBuffer");
fetch("seek.webm", function (blob) {
var r = new FileReader();
r.addEventListener("load", function (e) {
sb.appendBuffer(new Uint8Array(e.target.result));
ms.endOfStream();
v.play();
});
r.readAsArrayBuffer(blob);
});
});
ms.addEventListener("sourceended", function () {
ok(true, "Receive a sourceended event");
is(ms.readyState, "ended", "MediaSource must be in ended state after sourceended");
});
v.addEventListener("playing", function () {
is(v.duration, 4, "Video has correct duration");
v.parentNode.removeChild(v);
SpecialPowers.clearUserPref("media.mediasource.enabled");
SimpleTest.finish();
});
});
function fetch(src, cb) {
var xhr = new XMLHttpRequest();
xhr.open("GET", src, true);
xhr.responseType = "blob";
xhr.addEventListener("load", function (e) {
if (xhr.status != 200) {
return false;
}
cb(xhr.response);
});
xhr.send();
};
</script>
</pre>
</body>
</html>