--- a/dom/media/mediasource/test/.eslintrc.js
+++ b/dom/media/mediasource/test/.eslintrc.js
@@ -14,16 +14,17 @@ module.exports = {
"loadSegment": false,
"must_not_reject": false,
"must_not_throw": false,
"must_reject": false,
"must_throw": false,
"once": false,
"range": false,
"runWithMSE": false,
+ "wait": false,
"waitUntilTime": false
},
// Use const/let instead of var for tighter scoping, avoiding redeclaration
"rules": {
"array-bracket-spacing": ["error", "never"],
"no-var": "error",
"prefer-const": "error"
}
--- a/dom/media/mediasource/test/mediasource.js
+++ b/dom/media/mediasource/test/mediasource.js
@@ -30,32 +30,27 @@ async function runWithMSE(testFunction)
try {
await testFunction(ms, el);
} catch (e) {
ok(false, `${testFunction.name} failed with error ${e.name}`);
throw e;
}
}
-async function fetchWithXHR(uri, onLoadFunction) {
- let result = await new Promise(resolve => {
+async function fetchWithXHR(uri) {
+ return new Promise(resolve => {
const xhr = new XMLHttpRequest();
xhr.open("GET", uri, true);
xhr.responseType = "arraybuffer";
xhr.addEventListener("load", function() {
is(xhr.status, 200, "fetchWithXHR load uri='" + uri + "' status=" + xhr.status);
resolve(xhr.response);
});
xhr.send();
});
-
- if (onLoadFunction) {
- result = await onLoadFunction(result);
- }
- return result;
}
function range(start, end) {
const rv = [];
for (let i = start; i < end; ++i) {
rv.push(i);
}
return rv;
@@ -84,25 +79,23 @@ async function must_reject(f, msg, error
if (error === true) {
ok(false, `Please provide name of expected error! Got ${e.name}: ${e.message}.`);
} else if (e.name != error) {
throw e;
}
}
}
+const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
+
const must_not_throw = (f, msg) => must_throw(f, msg, false);
const must_not_reject = (f, msg) => must_reject(f, msg, false);
-async function once(target, name, cb) {
- let result = await new Promise(r => target.addEventListener(name, r, {once: true}));
- if (cb) {
- result = await cb();
- }
- return result;
+async function once(target, name) {
+ return new Promise(r => target.addEventListener(name, r, {once: true}));
}
function timeRangeToString(r) {
let str = "TimeRanges: ";
for (let i = 0; i < r.length; i++) {
str += "[" + r.start(i) + ", " + r.end(i) + ")";
}
return str;
--- a/dom/media/mediasource/test/test_AppendPartialInitSegment.html
+++ b/dom/media/mediasource/test/test_AppendPartialInitSegment.html
@@ -7,39 +7,37 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
-runWithMSE(function(ms, v) {
- ms.addEventListener("sourceopen", function() {
- const sb = ms.addSourceBuffer("video/webm");
+runWithMSE(async (ms, v) => {
+ await once(ms, "sourceopen");
+ const sb = ms.addSourceBuffer("video/webm");
- fetchWithXHR("seek.webm", async function(arrayBuffer) {
- // init segment is total 236 bytes.
- info("- append partial init segment -");
- sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 100));
+ const arrayBuffer = await fetchWithXHR("seek.webm");
+ // init segment is total 236 bytes.
+ info("- append partial init segment -");
+ sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 100));
- info("- wait for updateend -");
- await once(sb, "updateend");
+ info("- wait for updateend -");
+ await once(sb, "updateend");
- info("- append remaining init segment -");
- sb.appendBuffer(new Uint8Array(arrayBuffer, 100, 136));
+ info("- append remaining init segment -");
+ sb.appendBuffer(new Uint8Array(arrayBuffer, 100, 136));
- info("- wait for metadata -");
- await once(v, "loadedmetadata");
- is(v.videoWidth, 320, "videoWidth has correct initial value");
- is(v.videoHeight, 240, "videoHeight has correct initial value");
+ info("- wait for metadata -");
+ await once(v, "loadedmetadata");
+ is(v.videoWidth, 320, "videoWidth has correct initial value");
+ is(v.videoHeight, 240, "videoHeight has correct initial value");
- info("- wait for updateend -");
- await once(sb, "updateend");
- SimpleTest.finish();
- });
- });
+ info("- wait for updateend -");
+ await once(sb, "updateend");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/mediasource/test/test_AutoRevocation.html
+++ b/dom/media/mediasource/test/test_AutoRevocation.html
@@ -12,22 +12,22 @@
SimpleTest.waitForExplicitFinish();
runWithMSE(function() {
const ms = new MediaSource();
const o = URL.createObjectURL(ms);
const v = document.createElement("video");
- v.addEventListener("error", function(e) {
+ v.addEventListener("error", () => {
ok(true, "ObjectURL should be auto-revoked");
SimpleTest.finish();
});
- v.addEventListener("stalled", function(e) {
+ v.addEventListener("stalled", () => {
ok(false, "If auto-revocation is gone, please turn on TODOs in browser_mediaSourceURL.js");
SimpleTest.finish();
});
setTimeout(function() {
v.src = o;
v.preload = "auto";
document.body.appendChild(v);
--- a/dom/media/mediasource/test/test_BufferedSeek.html
+++ b/dom/media/mediasource/test/test_BufferedSeek.html
@@ -7,42 +7,38 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
-runWithMSE(function(ms, v) {
- ms.addEventListener("sourceopen", function() {
- const sb = ms.addSourceBuffer("video/webm");
+runWithMSE(async (ms, v) => {
+ await once(ms, "sourceopen");
+ const sb = ms.addSourceBuffer("video/webm");
- fetchWithXHR("seek.webm", function(arrayBuffer) {
- sb.appendBuffer(new Uint8Array(arrayBuffer));
- });
+ sb.appendBuffer(new Uint8Array(await fetchWithXHR("seek.webm")));
- const target = 2;
+ const target = 2;
- v.addEventListener("loadedmetadata", function() {
- ok(true, "received loadedmetadata");
- v.currentTime = target;
- });
+ v.addEventListener("loadedmetadata", () => {
+ ok(true, "received loadedmetadata");
+ v.currentTime = target;
+ });
- let wasSeeking = false;
+ let wasSeeking = false;
- v.addEventListener("seeking", function() {
- wasSeeking = true;
- is(v.currentTime, target, "Video currentTime at target");
- });
+ v.addEventListener("seeking", () => {
+ wasSeeking = true;
+ is(v.currentTime, target, "Video currentTime at target");
+ });
- v.addEventListener("seeked", function() {
- ok(wasSeeking, "Received expected seeking and seeked events");
- is(v.currentTime, target, "Video currentTime at target");
- SimpleTest.finish();
- });
- });
+ await once(v, "seeked");
+ ok(wasSeeking, "Received expected seeking and seeked events");
+ is(v.currentTime, target, "Video currentTime at target");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/mediasource/test/test_BufferedSeek_mp4.html
+++ b/dom/media/mediasource/test/test_BufferedSeek_mp4.html
@@ -7,42 +7,37 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
-runWithMSE(function(ms, v) {
- ms.addEventListener("sourceopen", function() {
- const sb = ms.addSourceBuffer("video/mp4");
+runWithMSE(async (ms, v) => {
+ await once(ms, "sourceopen");
+ const sb = ms.addSourceBuffer("video/mp4");
+
+ sb.appendBuffer(new Uint8Array(await fetchWithXHR("bipbop/bipbop2s.mp4")));
- fetchWithXHR("bipbop/bipbop2s.mp4", function(arrayBuffer) {
- sb.appendBuffer(new Uint8Array(arrayBuffer));
- });
+ const target = 1.3;
- const target = 1.3;
+ await once(v, "loadedmetadata");
+ ok(true, "received loadedmetadata");
+ v.currentTime = target;
- v.addEventListener("loadedmetadata", function() {
- ok(true, "received loadedmetadata");
- v.currentTime = target;
- });
-
- let wasSeeking = false;
+ let wasSeeking = false;
- v.addEventListener("seeking", function() {
- wasSeeking = true;
- is(v.currentTime, target, "Video currentTime at target");
- });
+ v.addEventListener("seeking", () => {
+ wasSeeking = true;
+ is(v.currentTime, target, "Video currentTime at target");
+ });
- v.addEventListener("seeked", function() {
- ok(wasSeeking, "Received expected seeking and seeked events");
- is(v.currentTime, target, "Video currentTime at target");
- SimpleTest.finish();
- });
- });
+ await once(v, "seeked");
+ ok(wasSeeking, "Received expected seeking and seeked events");
+ is(v.currentTime, target, "Video currentTime at target");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/mediasource/test/test_ChangeType.html
+++ b/dom/media/mediasource/test/test_ChangeType.html
@@ -31,17 +31,17 @@ runWithMSE(function(ms, el) {
ok(true, "Receive a sourceopen event");
const videosb = ms.addSourceBuffer("video/mp4");
if (typeof videosb.changeType === "undefined") {
info("changeType API is not available");
}
- el.addEventListener("error", function(e) {
+ el.addEventListener("error", e => {
ok(false, "should not fire '" + e.type + "' event");
SimpleTest.finish();
});
is(el.readyState, el.HAVE_NOTHING, "readyState is HAVE_NOTHING");
const loadedmetadataPromises = [];
loadedmetadataPromises.push(fetchAndLoad(videosb, "bipbop/bipbop", ["init"], ".mp4"));
loadedmetadataPromises.push(once(el, "loadedmetadata"));
Promise.all(loadedmetadataPromises)
--- a/dom/media/mediasource/test/test_EndOfStream.html
+++ b/dom/media/mediasource/test/test_EndOfStream.html
@@ -7,44 +7,23 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
-runWithMSE(function() {
- const ms = new MediaSource();
-
- const v = document.createElement("video");
- v.src = URL.createObjectURL(ms);
- document.body.appendChild(v);
-
- ms.addEventListener("sourceopen", function() {
- const sb = ms.addSourceBuffer("video/webm");
+runWithMSE(async (ms, v) => {
+ await once(ms, "sourceopen");
+ const sb = ms.addSourceBuffer("video/webm");
- fetchWithXHR("seek.webm", function(arrayBuffer) {
- sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 88966));
- let count = 0;
- sb.addEventListener("updateend", function() {
- ++count;
- if (count == 1) {
- setTimeout(function() {
- let fail = false;
- try {
- ms.endOfStream();
- } catch (e) {
- fail = true;
- }
- ok(!fail, "MediaSource.endOfStream succeeded");
- SimpleTest.finish();
- }, 0);
- }
- });
- });
- });
+ sb.appendBuffer(new Uint8Array(await fetchWithXHR("seek.webm"), 0, 88966));
+ await once(sb, "updateend");
+ await wait(0);
+ must_not_throw(() => ms.endOfStream(), "MediaSource.endOfStream succeeded");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/mediasource/test/test_EndOfStream_mp4.html
+++ b/dom/media/mediasource/test/test_EndOfStream_mp4.html
@@ -7,44 +7,23 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
-runWithMSE(function() {
- const ms = new MediaSource();
-
- const v = document.createElement("video");
- v.src = URL.createObjectURL(ms);
- document.body.appendChild(v);
-
- ms.addEventListener("sourceopen", function() {
- const sb = ms.addSourceBuffer("video/mp4");
+runWithMSE(async (ms, v) => {
+ await once(ms, "sourceopen");
+ const sb = ms.addSourceBuffer("video/mp4");
- fetchWithXHR("bipbop/bipbop2s.mp4", function(arrayBuffer) {
- sb.appendBuffer(new Uint8Array(arrayBuffer));
- let count = 0;
- sb.addEventListener("updateend", function() {
- ++count;
- if (count == 1) {
- setTimeout(function() {
- let fail = false;
- try {
- ms.endOfStream();
- } catch (e) {
- fail = true;
- }
- ok(!fail, "MediaSource.endOfStream succeeded");
- SimpleTest.finish();
- }, 0);
- }
- });
- });
- });
+ sb.appendBuffer(new Uint8Array(await fetchWithXHR("bipbop/bipbop2s.mp4")));
+ await once(sb, "updateend");
+ await wait(0);
+ must_not_throw(() => ms.endOfStream(), "MediaSource.endOfStream succeeded");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/mediasource/test/test_FrameSelection_mp4.html
+++ b/dom/media/mediasource/test/test_FrameSelection_mp4.html
@@ -16,17 +16,17 @@ SimpleTest.waitForExplicitFinish();
runWithMSE(async (ms, v) => {
await once(ms, "sourceopen");
ok(true, "Receive a sourceopen event");
ms.addEventListener("sourceopen", () => ok(false, "No more sourceopen"));
const sb = ms.addSourceBuffer("video/mp4");
ok(sb, "Create a SourceBuffer");
logEvents(v);
- sb.addEventListener("error", function(e) {
+ sb.addEventListener("error", e => {
ok(false, `should not fire ${e.type} event`);
SimpleTest.finish();
});
await fetchAndLoad(sb, "bipbop/bipbop", ["init"], ".mp4");
const p = once(v, "loadeddata");
await fetchAndLoad(sb, "bipbop/bipbop", range(1, 3), ".m4s");
await p;
is(sb.buffered.length, 1, "continuous range");
--- a/dom/media/mediasource/test/test_HaveMetadataUnbufferedSeek.html
+++ b/dom/media/mediasource/test/test_HaveMetadataUnbufferedSeek.html
@@ -7,40 +7,32 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
-runWithMSE(function(ms, v) {
- ms.addEventListener("sourceopen", function() {
- const sb = ms.addSourceBuffer("video/webm");
+runWithMSE(async (ms, v) => {
+ await once(ms, "sourceopen");
+ const sb = ms.addSourceBuffer("video/webm");
- fetchWithXHR("seek.webm", function(arrayBuffer) {
- sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 67833));
- });
+ const arrayBuffer = await fetchWithXHR("seek.webm");
+ sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 67833));
- const target = 2;
+ const target = 2;
- v.addEventListener("loadeddata", function() {
- ok(v.readyState >= v.HAVE_CURRENT_DATA, "readyState is >= CURRENT_DATA");
- v.currentTime = target;
- }, {once: true});
+ await once(v, "loadeddata");
+ ok(v.readyState >= v.HAVE_CURRENT_DATA, "readyState is >= CURRENT_DATA");
+ v.currentTime = target;
- v.addEventListener("seeking", function() {
- is(v.readyState, v.HAVE_METADATA, "readyState is HAVE_METADATA");
- fetchWithXHR("seek.webm", function(arrayBuffer) {
- sb.appendBuffer(new Uint8Array(arrayBuffer, 67833));
- });
- });
-
- v.addEventListener("seeked", function() {
- SimpleTest.finish();
- });
- });
+ await once(v, "seeking");
+ is(v.readyState, v.HAVE_METADATA, "readyState is HAVE_METADATA");
+ sb.appendBuffer(new Uint8Array(await fetchWithXHR("seek.webm"), 67833));
+ await once(v, "seeked");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/mediasource/test/test_HaveMetadataUnbufferedSeek_mp4.html
+++ b/dom/media/mediasource/test/test_HaveMetadataUnbufferedSeek_mp4.html
@@ -7,45 +7,36 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
-runWithMSE(function(ms, v) {
- ms.addEventListener("sourceopen", function() {
- const sb = ms.addSourceBuffer("video/mp4");
+runWithMSE(async (ms, v) => {
+ await once(ms, "sourceopen");
+ const sb = ms.addSourceBuffer("video/mp4");
- fetchWithXHR("bipbop/bipbop2s.mp4", function(arrayBuffer) {
- // 25819 is the offset of the first media segment's end
- sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 25819));
- });
+ const arrayBuffer = await fetchWithXHR("bipbop/bipbop2s.mp4");
+ // 25819 is the offset of the first media segment's end
+ sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 25819));
- const target = 1.3;
-
- v.addEventListener("loadeddata", function() {
- ok(v.readyState >= v.HAVE_CURRENT_DATA, "readyState is >= CURRENT_DATA");
- v.currentTime = target;
- }, {once: true});
+ const target = 1.3;
- v.addEventListener("seeking", function() {
- is(v.readyState, v.HAVE_METADATA, "readyState is HAVE_METADATA");
- fetchWithXHR("bipbop/bipbop2s.mp4", function(arrayBuffer) {
- // 25819 is the offset of the first media segment's end
- sb.addEventListener("updateend", function() {
- ms.endOfStream();
- });
- sb.appendBuffer(new Uint8Array(arrayBuffer, 25819));
- });
- });
+ await once(v, "loadeddata");
+ ok(v.readyState >= v.HAVE_CURRENT_DATA, "readyState is >= CURRENT_DATA");
+ v.currentTime = target;
- v.addEventListener("seeked", function() {
- SimpleTest.finish();
- });
- });
+ await once(v, "seeking");
+ is(v.readyState, v.HAVE_METADATA);
+ // 25819 is the offset of the first media segment's end
+ sb.appendBuffer(new Uint8Array(arrayBuffer, 25819));
+ await once(sb, "updateend");
+ ms.endOfStream();
+ await once(v, "seeked");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/mediasource/test/test_LoadedDataFired_mp4.html
+++ b/dom/media/mediasource/test/test_LoadedDataFired_mp4.html
@@ -9,22 +9,22 @@
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
runWithMSE(async (ms, el) => {
el.controls = true;
- el.addEventListener("loadeddata", function() {
+ el.addEventListener("loadeddata", () => {
ok(el.buffered.length > 0, "data is buffered");
is(el.buffered.start(0), 0, "must fire loadeddata when data has been loaded");
is(el.currentTime, 0, "must fire loadeddata at start");
});
- el.addEventListener("playing", function() {
+ el.addEventListener("playing", () => {
ok(el.buffered.length > 0, "data is buffered");
is(el.buffered.start(0), 0, "must fire playing when data has been loaded");
ok(el.currentTime >= 0, "must have started playback");
});
await once(ms, "sourceopen");
ok(true, "Receive a sourceopen event");
const videosb = ms.addSourceBuffer("video/mp4");
is(el.readyState, el.HAVE_NOTHING, "readyState is HAVE_NOTHING");
--- a/dom/media/mediasource/test/test_LoadedMetadataFired.html
+++ b/dom/media/mediasource/test/test_LoadedMetadataFired.html
@@ -7,31 +7,25 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
-runWithMSE(function(ms, v) {
- ms.addEventListener("sourceopen", function() {
- const sb = ms.addSourceBuffer("video/webm");
+runWithMSE(async (ms, v) => {
+ await once(ms, "sourceopen");
+ const sb = ms.addSourceBuffer("video/webm");
- v.addEventListener("loadedmetadata", function() {
- ok(true, "Got loadedmetadata event");
- is(v.videoWidth, 320, "videoWidth has correct initial value");
- is(v.videoHeight, 240, "videoHeight has correct initial value");
- SimpleTest.finish();
- });
-
- fetchWithXHR("seek.webm", function(arrayBuffer) {
- sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 318));
- v.play();
- });
- });
-
+ sb.appendBuffer(new Uint8Array(await fetchWithXHR("seek.webm"), 0, 318));
+ v.play();
+ await once(v, "loadedmetadata");
+ ok(true, "Got loadedmetadata event");
+ is(v.videoWidth, 320, "videoWidth has correct initial value");
+ is(v.videoHeight, 240, "videoHeight has correct initial value");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/mediasource/test/test_LoadedMetadataFired_mp4.html
+++ b/dom/media/mediasource/test/test_LoadedMetadataFired_mp4.html
@@ -7,31 +7,25 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
-runWithMSE(function(ms, v) {
- ms.addEventListener("sourceopen", function() {
- const sb = ms.addSourceBuffer("video/mp4");
+runWithMSE(async (ms, v) => {
+ await once(ms, "sourceopen");
+ const sb = ms.addSourceBuffer("video/mp4");
- v.addEventListener("loadedmetadata", function() {
- ok(true, "Got loadedmetadata event");
- is(v.videoWidth, 400, "videoWidth has correct initial value");
- is(v.videoHeight, 300, "videoHeight has correct initial value");
- SimpleTest.finish();
- });
-
- fetchWithXHR("bipbop/bipbop2s.mp4", function(arrayBuffer) {
- sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 1395));
- v.play();
- });
- });
-
+ sb.appendBuffer(new Uint8Array(await fetchWithXHR("bipbop/bipbop2s.mp4"), 0, 1395));
+ v.play();
+ await once(v, "loadedmetadata");
+ ok(true, "Got loadedmetadata event");
+ is(v.videoWidth, 400, "videoWidth has correct initial value");
+ is(v.videoHeight, 300, "videoHeight has correct initial value");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/mediasource/test/test_MediaSource.html
+++ b/dom/media/mediasource/test/test_MediaSource.html
@@ -7,104 +7,86 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
-runWithMSE(function() {
+runWithMSE(async (ms, v) => {
SimpleTest.doesThrow(() => new SourceBuffer, "new SourceBuffer should fail");
SimpleTest.doesThrow(() => new SourceBufferList, "new SourceBufferList direct should fail");
- const 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");
// Wrapper creation, tests for leaks.
SpecialPowers.wrap(ms);
// Set an expando to force wrapper creation, tests for leaks.
ms.foo = null;
- const o = URL.createObjectURL(ms);
- ok(o, "Create an objectURL from the MediaSource");
-
- const v = document.createElement("video");
- v.preload = "auto";
- v.src = o;
- document.body.appendChild(v);
+ ok(URL.createObjectURL(ms), "Create an objectURL from the MediaSource");
let loadedmetadataCount = 0;
let updatestartCount = 0;
let updateendCount = 0;
let updateCount = 0;
ok(MediaSource.isTypeSupported("video/webm; codecs=vp8"), "VP8 MSE is always supported");
- ok(MediaSource.isTypeSupported("audio/webm", "Audio MSE is always supported"));
+ ok(MediaSource.isTypeSupported("audio/webm"), "Audio MSE is always supported");
- ms.addEventListener("sourceopen", function() {
- ok(true, "Receive a sourceopen event");
- is(ms.readyState, "open", "MediaSource must be in open state after sourceopen");
- const 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");
- is(ms.activeSourceBuffers.length, 0, "MediaSource.activeSourceBuffers is expected length");
-
-
- fetchWithXHR("seek.webm", function(arrayBuffer) {
- sb.appendBuffer(new Uint8Array(arrayBuffer));
- is(sb.updating, true, "SourceBuffer.updating is expected value after appendBuffer");
- });
+ await once(ms, "sourceopen");
+ ok(true, "Receive a sourceopen event");
+ is(ms.readyState, "open", "MediaSource must be in open state after sourceopen");
+ const 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");
+ is(ms.activeSourceBuffers.length, 0, "MediaSource.activeSourceBuffers is expected length");
- sb.addEventListener("update", function() {
- is(sb.updating, false, "SourceBuffer.updating is expected value in update event");
- updateCount++;
- /* Ensure that we endOfStream on the first update event only as endOfStream can
- raise more if the duration of the last buffered range and the intial duration
- differ. See bug 1065207 */
- if (updateCount == 1) {
- ms.endOfStream();
- }
- });
+ sb.appendBuffer(new Uint8Array(await fetchWithXHR("seek.webm")));
+ is(sb.updating, true, "SourceBuffer.updating is expected value after appendBuffer");
- sb.addEventListener("updatestart", function() {
- updatestartCount++;
- });
-
- sb.addEventListener("updateend", function() {
- is(ms.activeSourceBuffers[0], sb, "SourceBuffer in active list matches our SourceBuffer");
- is(sb.updating, false, "SourceBuffer.updating is expected value in updateend event");
- updateendCount++;
- v.play();
- });
+ sb.addEventListener("update", () => {
+ is(sb.updating, false, "SourceBuffer.updating is expected value in update event");
+ updateCount++;
+ /* Ensure that we endOfStream on the first update event only as endOfStream can
+ raise more if the duration of the last buffered range and the intial duration
+ differ. See bug 1065207 */
+ if (updateCount == 1) {
+ ms.endOfStream();
+ }
});
- ms.addEventListener("sourceended", function() {
+ sb.addEventListener("updatestart", () => updatestartCount++);
+
+ sb.addEventListener("updateend", () => {
+ is(ms.activeSourceBuffers[0], sb, "SourceBuffer in active list matches our SourceBuffer");
+ is(sb.updating, false, "SourceBuffer.updating is expected value in updateend event");
+ updateendCount++;
+ v.play();
+ });
+
+ ms.addEventListener("sourceended", () => {
ok(true, "Receive a sourceended event");
is(ms.readyState, "ended", "MediaSource must be in ended state after sourceended");
});
- v.addEventListener("loadedmetadata", function() {
- loadedmetadataCount++;
- });
+ v.addEventListener("loadedmetadata", () => loadedmetadataCount++);
- v.addEventListener("ended", function() {
- // XXX: Duration should be exactly 4.0, see bug 1065207.
- ok(Math.abs(v.duration - 4) <= 0.002, "Video has correct duration");
- ok(Math.abs(v.currentTime - 4) <= 0.002, "Video has played to end");
- // XXX: 2 update events can be received dueto duration differences, see bug 1065207.
- ok(updateCount == 1 || updateCount == 2, "update event received");
- ok(updateendCount == 1 || updateendCount == 2, "updateend event received");
- ok(updatestartCount == 1 || updatestartCount == 2, "updatestart event received");
- is(loadedmetadataCount, 1, "loadedmetadata event received");
- v.remove();
- SimpleTest.finish();
- });
+ await once(v, "ended");
+ // XXX: Duration should be exactly 4.0, see bug 1065207.
+ ok(Math.abs(v.duration - 4) <= 0.002, "Video has correct duration");
+ ok(Math.abs(v.currentTime - 4) <= 0.002, "Video has played to end");
+ // XXX: 2 update events can be received dueto duration differences, see bug 1065207.
+ ok(updateCount == 1 || updateCount == 2, "update event received");
+ ok(updateendCount == 1 || updateendCount == 2, "updateend event received");
+ ok(updatestartCount == 1 || updatestartCount == 2, "updatestart event received");
+ is(loadedmetadataCount, 1, "loadedmetadata event received");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/mediasource/test/test_MediaSource_mp4.html
+++ b/dom/media/mediasource/test/test_MediaSource_mp4.html
@@ -7,102 +7,84 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
-runWithMSE(function() {
+runWithMSE(async (ms, v) => {
SimpleTest.doesThrow(() => new SourceBuffer, "new SourceBuffer should fail");
SimpleTest.doesThrow(() => new SourceBufferList, "new SourceBufferList direct should fail");
- const 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");
// Wrapper creation, tests for leaks.
SpecialPowers.wrap(ms);
// Set an expando to force wrapper creation, tests for leaks.
ms.foo = null;
- const o = URL.createObjectURL(ms);
- ok(o, "Create an objectURL from the MediaSource");
-
- const v = document.createElement("video");
- v.preload = "auto";
- v.src = o;
- document.body.appendChild(v);
+ ok(URL.createObjectURL(ms), "Create an objectURL from the MediaSource");
let loadedmetadataCount = 0;
let updatestartCount = 0;
let updateendCount = 0;
let updateCount = 0;
- ms.addEventListener("sourceopen", function() {
- ok(true, "Receive a sourceopen event");
- is(ms.readyState, "open", "MediaSource must be in open state after sourceopen");
- const sb = ms.addSourceBuffer("video/mp4");
- 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");
- is(ms.activeSourceBuffers.length, 0, "MediaSource.activeSourceBuffers is expected length");
-
-
- fetchWithXHR("bipbop/bipbop2s.mp4", function(arrayBuffer) {
- sb.appendBuffer(new Uint8Array(arrayBuffer));
- is(sb.updating, true, "SourceBuffer.updating is expected value after appendBuffer");
- });
+ await once(ms, "sourceopen");
+ ok(true, "Receive a sourceopen event");
+ is(ms.readyState, "open", "MediaSource must be in open state after sourceopen");
+ const sb = ms.addSourceBuffer("video/mp4");
+ 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");
+ is(ms.activeSourceBuffers.length, 0, "MediaSource.activeSourceBuffers is expected length");
- sb.addEventListener("update", function() {
- is(sb.updating, false, "SourceBuffer.updating is expected value in update event");
- updateCount++;
- /* Ensure that we endOfStream on the first update event only as endOfStream can
- raise more if the duration of the last buffered range and the intial duration
- differ. See bug 1065207 */
- if (updateCount == 1) {
- ms.endOfStream();
- }
- });
+ sb.appendBuffer(new Uint8Array(await fetchWithXHR("bipbop/bipbop2s.mp4")));
+ is(sb.updating, true, "SourceBuffer.updating is expected value after appendBuffer");
- sb.addEventListener("updatestart", function() {
- updatestartCount++;
- });
-
- sb.addEventListener("updateend", function() {
- is(ms.activeSourceBuffers[0], sb, "SourceBuffer in active list matches our SourceBuffer");
- is(sb.updating, false, "SourceBuffer.updating is expected value in updateend event");
- updateendCount++;
- v.play();
- });
+ sb.addEventListener("update", () => {
+ is(sb.updating, false, "SourceBuffer.updating is expected value in update event");
+ updateCount++;
+ /* Ensure that we endOfStream on the first update event only as endOfStream can
+ raise more if the duration of the last buffered range and the intial duration
+ differ. See bug 1065207 */
+ if (updateCount == 1) {
+ ms.endOfStream();
+ }
});
- ms.addEventListener("sourceended", function() {
+ sb.addEventListener("updatestart", () => updatestartCount++);
+
+ sb.addEventListener("updateend", () => {
+ is(ms.activeSourceBuffers[0], sb, "SourceBuffer in active list matches our SourceBuffer");
+ is(sb.updating, false, "SourceBuffer.updating is expected value in updateend event");
+ updateendCount++;
+ v.play();
+ });
+
+ ms.addEventListener("sourceended", () => {
ok(true, "Receive a sourceended event");
is(ms.readyState, "ended", "MediaSource must be in ended state after sourceended");
});
- v.addEventListener("loadedmetadata", function() {
- loadedmetadataCount++;
- });
+ v.addEventListener("loadedmetadata", () => loadedmetadataCount++);
- v.addEventListener("ended", function() {
- // The bipbop video doesn't start at 0. The old MSE code adjust the
- // timestamps and ignore the audio track. The new one doesn't.
- isfuzzy(v.duration, 1.696, 0.166, "Video has correct duration");
- isfuzzy(v.currentTime, 1.696, 0.166, "Video has correct duration");
- // XXX: 2 update events can be received dueto duration differences, see bug 1065207.
- ok(updateCount == 1 || updateCount == 2, "update event received");
- ok(updateendCount == 1 || updateendCount == 2, "updateend event received");
- ok(updatestartCount == 1 || updatestartCount == 2, "updatestart event received");
- is(loadedmetadataCount, 1, "loadedmetadata event received");
- v.remove();
- SimpleTest.finish();
- });
+ await once(v, "ended");
+ // The bipbop video doesn't start at 0. The old MSE code adjust the
+ // timestamps and ignore the audio track. The new one doesn't.
+ isfuzzy(v.duration, 1.696, 0.166, "Video has correct duration");
+ isfuzzy(v.currentTime, 1.696, 0.166, "Video has correct duration");
+ // XXX: 2 update events can be received dueto duration differences, see bug 1065207.
+ ok(updateCount == 1 || updateCount == 2, "update event received");
+ ok(updateendCount == 1 || updateendCount == 2, "updateend event received");
+ ok(updatestartCount == 1 || updatestartCount == 2, "updatestart event received");
+ is(loadedmetadataCount, 1, "loadedmetadata event received");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/mediasource/test/test_SeekableBeforeAndAfterEndOfStream.html
+++ b/dom/media/mediasource/test/test_SeekableBeforeAndAfterEndOfStream.html
@@ -7,50 +7,48 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
-runWithMSE(function(ms, v) {
- ms.addEventListener("sourceopen", function() {
- const sb = ms.addSourceBuffer("video/webm");
+runWithMSE(async (ms, v) => {
+ await once(ms, "sourceopen");
+ const sb = ms.addSourceBuffer("video/webm");
- fetchWithXHR("seek.webm", async function(arrayBuffer) {
- info("- append buffer -");
- sb.appendBuffer(new Uint8Array(arrayBuffer));
+ const arrayBuffer = await fetchWithXHR("seek.webm");
+ info("- append first buffer -");
+ sb.appendBuffer(new Uint8Array(arrayBuffer));
- info("- wait for metadata -");
- await once(v, "loadedmetadata");
+ info("- wait for metadata -");
+ await once(v, "loadedmetadata");
- info("- wait for updateend -");
- await once(sb, "updateend");
+ info("- wait for updateend -");
+ await once(sb, "updateend");
- info("- check seekable -");
- const target = 2;
- ok(v.seekable.length, "Resource is seekable");
- is(v.seekable.start(0), 0, "Seekable's start point is correct");
- is(v.seekable.end(0), ms.duration, "Seekable's end point is correct");
- ok(v.seekable.length &&
- target >= v.seekable.start(0) &&
- target < v.seekable.end(0), "Target is within seekable range");
+ info("- check seekable -");
+ const target = 2;
+ ok(v.seekable.length, "Resource is seekable");
+ is(v.seekable.start(0), 0, "Seekable's start point is correct");
+ is(v.seekable.end(0), ms.duration, "Seekable's end point is correct");
+ ok(v.seekable.length &&
+ target >= v.seekable.start(0) &&
+ target < v.seekable.end(0), "Target is within seekable range");
- info("- call end of stream -");
- ms.endOfStream();
- await once(ms, "sourceended");
+ info("- call end of stream -");
+ ms.endOfStream();
+ await once(ms, "sourceended");
- info("- check seekable -");
- ok(v.seekable.length, "Resource is seekable");
- is(v.seekable.start(0), 0, "Seekable's start point is correct");
- is(v.seekable.end(0), ms.duration, "Seekable's end point is correct");
- ok(v.seekable.length &&
- target >= v.seekable.start(0) &&
- target < v.seekable.end(0), "Target is within seekable range");
- SimpleTest.finish();
- });
- });
+ info("- check seekable -");
+ ok(v.seekable.length, "Resource is seekable");
+ is(v.seekable.start(0), 0, "Seekable's start point is correct");
+ is(v.seekable.end(0), ms.duration, "Seekable's end point is correct");
+ ok(v.seekable.length &&
+ target >= v.seekable.start(0) &&
+ target < v.seekable.end(0), "Target is within seekable range");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/mediasource/test/test_SeekableBeforeAndAfterEndOfStreamSplit.html
+++ b/dom/media/mediasource/test/test_SeekableBeforeAndAfterEndOfStreamSplit.html
@@ -7,56 +7,54 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
-runWithMSE(function(ms, v) {
- ms.addEventListener("sourceopen", function() {
- const sb = ms.addSourceBuffer("video/webm");
+runWithMSE(async (ms, v) => {
+ await once(ms, "sourceopen");
+ const sb = ms.addSourceBuffer("video/webm");
- fetchWithXHR("seek.webm", async function(arrayBuffer) {
- info("- append first buffer -");
- // 25523 is the offset of the first media segment's end
- sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 25523));
+ const arrayBuffer = await fetchWithXHR("seek.webm");
+ info("- append first buffer -");
+ // 25523 is the offset of the first media segment's end
+ sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 25523));
- info("- wait for metadata -");
- await once(v, "loadedmetadata");
+ info("- wait for metadata -");
+ await once(v, "loadedmetadata");
- info("- wait for updateend -");
- await once(sb, "updateend");
+ info("- wait for updateend -");
+ await once(sb, "updateend");
- info("- append second buffer -");
- sb.appendBuffer(new Uint8Array(arrayBuffer, 25523));
- await once(sb, "updateend");
+ info("- append second buffer -");
+ sb.appendBuffer(new Uint8Array(arrayBuffer, 25523));
+ await once(sb, "updateend");
- info("- check seekable -");
- const target = 2;
- ok(v.seekable.length, "Resource is seekable");
- is(v.seekable.start(0), 0, "Seekable's start point is correct");
- is(v.seekable.end(0), ms.duration, "Seekable's end point is correct");
- ok(v.seekable.length &&
- target >= v.seekable.start(0) &&
- target < v.seekable.end(0), "Target is within seekable range");
+ info("- check seekable -");
+ const target = 2;
+ ok(v.seekable.length, "Resource is seekable");
+ is(v.seekable.start(0), 0, "Seekable's start point is correct");
+ is(v.seekable.end(0), ms.duration, "Seekable's end point is correct");
+ ok(v.seekable.length &&
+ target >= v.seekable.start(0) &&
+ target < v.seekable.end(0), "Target is within seekable range");
- info("- call end of stream -");
- ms.endOfStream();
- await once(ms, "sourceended");
+ info("- call end of stream -");
+ ms.endOfStream();
+ await once(ms, "sourceended");
- info("- check seekable -");
- ok(v.seekable.length, "Resource is seekable");
- is(v.seekable.start(0), 0, "Seekable's start point is correct");
- is(v.seekable.end(0), ms.duration, "Seekable's end point is correct");
- ok(v.seekable.length &&
- target >= v.seekable.start(0) &&
- target < v.seekable.end(0), "Target is within seekable range");
- SimpleTest.finish();
- });
- });
+ info("- check seekable -");
+ ok(v.seekable.length, "Resource is seekable");
+ is(v.seekable.start(0), 0, "Seekable's start point is correct");
+ is(v.seekable.end(0), ms.duration, "Seekable's end point is correct");
+ ok(v.seekable.length &&
+ target >= v.seekable.start(0) &&
+ target < v.seekable.end(0), "Target is within seekable range");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/mediasource/test/test_SeekableBeforeAndAfterEndOfStreamSplit_mp4.html
+++ b/dom/media/mediasource/test/test_SeekableBeforeAndAfterEndOfStreamSplit_mp4.html
@@ -7,56 +7,54 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
-runWithMSE(function(ms, v) {
- ms.addEventListener("sourceopen", function() {
- const sb = ms.addSourceBuffer("video/mp4");
+runWithMSE(async (ms, v) => {
+ await once(ms, "sourceopen");
+ const sb = ms.addSourceBuffer("video/mp4");
- fetchWithXHR("bipbop/bipbop2s.mp4", async function(arrayBuffer) {
- info("- append first buffer -");
- // 25819 is the offset of the first media segment's end
- sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 25819));
+ const arrayBuffer = await fetchWithXHR("bipbop/bipbop2s.mp4");
+ info("- append first buffer -");
+ // 25819 is the offset of the first media segment's end
+ sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 25819));
- info("- wait for metadata -");
- await once(v, "loadedmetadata");
+ info("- wait for metadata -");
+ await once(v, "loadedmetadata");
- info("- wait for updateend -");
- await once(sb, "updateend");
+ info("- wait for updateend -");
+ await once(sb, "updateend");
- info("- append second buffer -");
- sb.appendBuffer(new Uint8Array(arrayBuffer, 25819));
- await once(sb, "updateend");
+ info("- append second buffer -");
+ sb.appendBuffer(new Uint8Array(arrayBuffer, 25819));
+ await once(sb, "updateend");
- info("- check seekable -");
- const target = 1.3;
- ok(v.seekable.length, "Resource is seekable");
- is(v.seekable.start(0), 0, "Seekable's start point is correct");
- is(v.seekable.end(0), ms.duration, "Seekable's end point is correct");
- ok(v.seekable.length &&
- target >= v.seekable.start(0) &&
- target < v.seekable.end(0), "Target is within seekable range");
+ info("- check seekable -");
+ const target = 1.3;
+ ok(v.seekable.length, "Resource is seekable");
+ is(v.seekable.start(0), 0, "Seekable's start point is correct");
+ is(v.seekable.end(0), ms.duration, "Seekable's end point is correct");
+ ok(v.seekable.length &&
+ target >= v.seekable.start(0) &&
+ target < v.seekable.end(0), "Target is within seekable range");
- info("- call end of stream -");
- ms.endOfStream();
- await once(ms, "sourceended");
+ info("- call end of stream -");
+ ms.endOfStream();
+ await once(ms, "sourceended");
- info("- check seekable -");
- ok(v.seekable.length, "Resource is seekable");
- is(v.seekable.start(0), 0, "Seekable's start point is correct");
- is(v.seekable.end(0), ms.duration, "Seekable's end point is correct");
- ok(v.seekable.length &&
- target >= v.seekable.start(0) &&
- target < v.seekable.end(0), "Target is within seekable range");
- SimpleTest.finish();
- });
- });
+ info("- check seekable -");
+ ok(v.seekable.length, "Resource is seekable");
+ is(v.seekable.start(0), 0, "Seekable's start point is correct");
+ is(v.seekable.end(0), ms.duration, "Seekable's end point is correct");
+ ok(v.seekable.length &&
+ target >= v.seekable.start(0) &&
+ target < v.seekable.end(0), "Target is within seekable range");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/mediasource/test/test_SeekableBeforeAndAfterEndOfStream_mp4.html
+++ b/dom/media/mediasource/test/test_SeekableBeforeAndAfterEndOfStream_mp4.html
@@ -7,51 +7,49 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
-runWithMSE(function(ms, v) {
- ms.addEventListener("sourceopen", function() {
- const sb = ms.addSourceBuffer("video/mp4");
+runWithMSE(async (ms, v) => {
+ await once(ms, "sourceopen");
+ const sb = ms.addSourceBuffer("video/mp4");
- fetchWithXHR("bipbop/bipbop2s.mp4", async function(arrayBuffer) {
- info("- append buffer -");
- sb.appendBuffer(new Uint8Array(arrayBuffer));
+ const arrayBuffer = await fetchWithXHR("bipbop/bipbop2s.mp4");
+ info("- append buffer -");
+ sb.appendBuffer(new Uint8Array(arrayBuffer));
- info("- wait for metadata -");
- await once(v, "loadedmetadata");
+ info("- wait for metadata -");
+ await once(v, "loadedmetadata");
- info("- wait for updateend -");
- await once(sb, "updateend");
+ info("- wait for updateend -");
+ await once(sb, "updateend");
- info("- check seekable -");
- const target = 1.3;
- ok(v.seekable.length, "Resource is seekable");
- is(v.seekable.start(0), 0, "Seekable's start point is correct");
- is(v.seekable.end(0), ms.duration, "Seekable's end point is correct");
- ok(v.seekable.length &&
- target >= v.seekable.start(0) &&
- target < v.seekable.end(0), "Target is within seekable range");
+ info("- check seekable -");
+ const target = 1.3;
+ ok(v.seekable.length, "Resource is seekable");
+ is(v.seekable.start(0), 0, "Seekable's start point is correct");
+ is(v.seekable.end(0), ms.duration, "Seekable's end point is correct");
+ ok(v.seekable.length &&
+ target >= v.seekable.start(0) &&
+ target < v.seekable.end(0), "Target is within seekable range");
- info("- call end of stream -");
- ms.endOfStream();
- await once(ms, "sourceended");
+ info("- call end of stream -");
+ ms.endOfStream();
+ await once(ms, "sourceended");
- info("- check seekable -");
- ok(v.seekable.length, "Resource is seekable");
- is(v.seekable.start(0), 0, "Seekable's start point is correct");
- is(v.seekable.end(0), ms.duration, "Seekable's end point is correct");
- ok(v.seekable.length &&
- target >= v.seekable.start(0) &&
- target < v.seekable.end(0), "Target is within seekable range");
- SimpleTest.finish();
- });
- });
+ info("- check seekable -");
+ ok(v.seekable.length, "Resource is seekable");
+ is(v.seekable.start(0), 0, "Seekable's start point is correct");
+ is(v.seekable.end(0), ms.duration, "Seekable's end point is correct");
+ ok(v.seekable.length &&
+ target >= v.seekable.start(0) &&
+ target < v.seekable.end(0), "Target is within seekable range");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/mediasource/test/test_SetModeThrows.html
+++ b/dom/media/mediasource/test/test_SetModeThrows.html
@@ -9,17 +9,17 @@
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
// MSE supports setting mode now. make sure it does not throw.
runWithMSE(function(ms, v) {
- ms.addEventListener("sourceopen", function() {
+ ms.addEventListener("sourceopen", () => {
const sb = ms.addSourceBuffer("video/webm");
sb.mode = "segments";
ok("true", "Setting to segments does not throw");
try {
sb.mode = "sequence";
ok("true", "Setting to sequence does not throw");
} catch (e) { ok(false, "Should not throw setting mode to sequence: " + e); }
--- a/dom/media/mediasource/test/test_SplitAppend.html
+++ b/dom/media/mediasource/test/test_SplitAppend.html
@@ -7,40 +7,30 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
-let updateCount = 0;
-
-runWithMSE(function(ms, v) {
- ms.addEventListener("sourceopen", function() {
- const sb = ms.addSourceBuffer("video/webm");
+runWithMSE(async (ms, v) => {
+ await once(ms, "sourceopen");
+ const sb = ms.addSourceBuffer("video/webm");
- fetchWithXHR("seek.webm", function(arrayBuffer) {
- sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 318));
- sb.addEventListener("updateend", function() {
- updateCount++;
- if (updateCount == 1) {
- sb.appendBuffer(new Uint8Array(arrayBuffer, 318));
- } else if (updateCount == 2) {
- ms.endOfStream();
- }
- });
- v.play();
- });
- });
-
- v.addEventListener("ended", function() {
- // XXX: Duration should be exactly 4.0, see bug 1065207.
- ok(Math.abs(v.duration - 4) <= 0.002, "Video has correct duration");
- ok(Math.abs(v.currentTime - 4) <= 0.002, "Video has played to end");
- SimpleTest.finish();
- });
+ const arrayBuffer = await fetchWithXHR("seek.webm");
+ sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 318));
+ v.play();
+ await once(sb, "updateend");
+ sb.appendBuffer(new Uint8Array(arrayBuffer, 318));
+ await once(sb, "updateend");
+ ms.endOfStream();
+ await once(v, "ended");
+ // XXX: Duration should be exactly 4.0, see bug 1065207.
+ ok(Math.abs(v.duration - 4) <= 0.002, "Video has correct duration");
+ ok(Math.abs(v.currentTime - 4) <= 0.002, "Video has played to end");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/mediasource/test/test_SplitAppendDelay.html
+++ b/dom/media/mediasource/test/test_SplitAppendDelay.html
@@ -8,42 +8,31 @@
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout("untriaged");
-let updateCount = 0;
-
-runWithMSE(function(ms, v) {
- ms.addEventListener("sourceopen", function() {
- const sb = ms.addSourceBuffer("video/webm");
+runWithMSE(async (ms, v) => {
+ await once(ms, "sourceopen");
+ const sb = ms.addSourceBuffer("video/webm");
- fetchWithXHR("seek.webm", function(arrayBuffer) {
- sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 318));
- sb.addEventListener("updateend", function() {
- updateCount++;
- if (updateCount == 1) {
- window.setTimeout(function() {
- sb.appendBuffer(new Uint8Array(arrayBuffer, 318));
- }, 1000);
- } else if (updateCount == 2) {
- ms.endOfStream();
- }
- });
- v.play();
- });
- });
-
- v.addEventListener("ended", function() {
- // XXX: Duration should be exactly 4.0, see bug 1065207.
- ok(Math.abs(v.duration - 4) <= 0.002, "Video has correct duration");
- ok(Math.abs(v.currentTime - 4) <= 0.002, "Video has played to end");
- SimpleTest.finish();
- });
+ const arrayBuffer = await fetchWithXHR("seek.webm");
+ sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 318));
+ v.play();
+ await once(sb, "updateend");
+ await wait(1000);
+ sb.appendBuffer(new Uint8Array(arrayBuffer, 318));
+ await once(sb, "updateend");
+ ms.endOfStream();
+ await once(v, "ended");
+ // XXX: Duration should be exactly 4.0, see bug 1065207.
+ ok(Math.abs(v.duration - 4) <= 0.002, "Video has correct duration");
+ ok(Math.abs(v.currentTime - 4) <= 0.002, "Video has played to end");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/mediasource/test/test_SplitAppendDelay_mp4.html
+++ b/dom/media/mediasource/test/test_SplitAppendDelay_mp4.html
@@ -8,43 +8,32 @@
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout("untriaged");
-let updateCount = 0;
-
-runWithMSE(function(ms, v) {
- ms.addEventListener("sourceopen", function() {
- const sb = ms.addSourceBuffer("video/mp4");
+runWithMSE(async (ms, v) => {
+ await once(ms, "sourceopen");
+ const sb = ms.addSourceBuffer("video/mp4");
- fetchWithXHR("bipbop/bipbop2s.mp4", function(arrayBuffer) {
- sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 1395));
- sb.addEventListener("updateend", function() {
- updateCount++;
- if (updateCount == 1) {
- window.setTimeout(function() {
- sb.appendBuffer(new Uint8Array(arrayBuffer, 1395));
- }, 1000);
- } else if (updateCount == 2) {
- ms.endOfStream();
- }
- });
- v.play();
- });
- });
-
- v.addEventListener("ended", function() {
- // The bipbop video doesn't start at 0. The old MSE code adjust the
- // timestamps and ignore the audio track. The new one doesn't.
- isfuzzy(v.duration, 1.696, 0.166, "Video has correct duration");
- isfuzzy(v.currentTime, 1.696, 0.166, "Video has played to end");
- SimpleTest.finish();
- });
+ const arrayBuffer = await fetchWithXHR("bipbop/bipbop2s.mp4");
+ sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 1395));
+ v.play();
+ await once(sb, "updateend");
+ await wait(1000);
+ sb.appendBuffer(new Uint8Array(arrayBuffer, 1395));
+ await once(sb, "updateend");
+ ms.endOfStream();
+ await once(v, "ended");
+ // The bipbop video doesn't start at 0. The old MSE code adjust the
+ // timestamps and ignore the audio track. The new one doesn't.
+ isfuzzy(v.duration, 1.696, 0.166, "Video has correct duration");
+ isfuzzy(v.currentTime, 1.696, 0.166, "Video has played to end");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/mediasource/test/test_SplitAppend_mp4.html
+++ b/dom/media/mediasource/test/test_SplitAppend_mp4.html
@@ -7,41 +7,32 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
-let updateCount = 0;
-
-runWithMSE(function(ms, v) {
- ms.addEventListener("sourceopen", function() {
- const sb = ms.addSourceBuffer("video/mp4");
+runWithMSE(async (ms, v) => {
+ await once(ms, "sourceopen");
+ const sb = ms.addSourceBuffer("video/mp4");
- fetchWithXHR("bipbop/bipbop2s.mp4", function(arrayBuffer) {
- sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 1395));
- sb.addEventListener("updateend", function() {
- updateCount++;
- if (updateCount == 1) {
- sb.appendBuffer(new Uint8Array(arrayBuffer, 1395));
- } else if (updateCount == 2) {
- ms.endOfStream();
- }
- });
- v.play();
- });
- });
+ const arrayBuffer = await fetchWithXHR("bipbop/bipbop2s.mp4");
+ sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 1395));
+ v.play();
+ await once(sb, "updateend");
+ sb.appendBuffer(new Uint8Array(arrayBuffer, 1395));
+ await once(sb, "updateend");
+ ms.endOfStream();
- v.addEventListener("ended", function() {
- // The bipbop video doesn't start at 0. The old MSE code adjust the
- // timestamps and ignore the audio track. The new one doesn't.
- isfuzzy(v.duration, 1.696, 0.166, "Video has correct duration");
- isfuzzy(v.currentTime, 1.696, 0.166, "Video has played to end");
- SimpleTest.finish();
- });
+ await once(v, "ended");
+ // The bipbop video doesn't start at 0. The old MSE code adjust the
+ // timestamps and ignore the audio track. The new one doesn't.
+ isfuzzy(v.duration, 1.696, 0.166, "Video has correct duration");
+ isfuzzy(v.currentTime, 1.696, 0.166, "Video has played to end");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/mediasource/test/test_WaitingOnMissingDataEnded_mp4.html
+++ b/dom/media/mediasource/test/test_WaitingOnMissingDataEnded_mp4.html
@@ -10,17 +10,17 @@
<pre id="test"><script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
runWithMSE(async (ms, el) => {
el.controls = true;
await once(ms, "sourceopen");
ok(true, "Receive a sourceopen event");
- el.addEventListener("ended", function() {
+ el.addEventListener("ended", () => {
ok(false, "ended should never fire");
SimpleTest.finish();
});
const videosb = ms.addSourceBuffer("video/mp4");
await fetchAndLoad(videosb, "bipbop/bipbop_video", ["init"], ".mp4");
await fetchAndLoad(videosb, "bipbop/bipbop_video", range(1, 5), ".m4s");
await fetchAndLoad(videosb, "bipbop/bipbop_video", range(6, 8), ".m4s");
is(el.buffered.length, 2, "discontinuous buffered range");
--- a/dom/media/mediasource/test/test_WebMTagsBeforeCluster.html
+++ b/dom/media/mediasource/test/test_WebMTagsBeforeCluster.html
@@ -9,41 +9,39 @@
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
addMSEPrefs(["media.mediasource.webm.enabled", true]);
-runWithMSE(function(ms, v) {
- ms.addEventListener("sourceopen", function() {
- const sb = ms.addSourceBuffer("video/webm");
+runWithMSE(async (ms, v) => {
+ await once(ms, "sourceopen");
+ const sb = ms.addSourceBuffer("video/webm");
- fetchWithXHR("tags_before_cluster.webm", async function(arrayBuffer) {
- info("- append buffer -");
- sb.appendBuffer(new Uint8Array(arrayBuffer));
+ const arrayBuffer = await fetchWithXHR("tags_before_cluster.webm");
+ info("- append buffer -");
+ sb.appendBuffer(new Uint8Array(arrayBuffer));
- info("- wait for metadata -");
- await once(v, "loadedmetadata");
-
- info("- wait for updateend -");
- await once(sb, "updateend");
+ info("- wait for metadata -");
+ await once(v, "loadedmetadata");
- info("- call end of stream -");
- ms.endOfStream();
- await once(ms, "sourceended");
+ info("- wait for updateend -");
+ await once(sb, "updateend");
- info("- check buffered range -");
- is(sb.buffered.length, 1, "buffered range is not empty.");
+ info("- call end of stream -");
+ ms.endOfStream();
+ await once(ms, "sourceended");
- info("- video is playing -");
- v.play();
- await once(v, "timeupdate");
- SimpleTest.finish();
- });
- });
+ info("- check buffered range -");
+ is(sb.buffered.length, 1, "buffered range is not empty.");
+
+ info("- video is playing -");
+ v.play();
+ await once(v, "timeupdate");
+ SimpleTest.finish();
});
</script>
</pre>
</body>
</html>