diff --git a/content/media/mediasource/test/mediasource.js b/content/media/mediasource/test/mediasource.js index bca2fd2b5286..921adbef9d0a 100644 --- a/content/media/mediasource/test/mediasource.js +++ b/content/media/mediasource/test/mediasource.js @@ -1,20 +1,34 @@ // Helpers for Media Source Extensions tests function runWithMSE(testFunction) { - addLoadEvent(() => SpecialPowers.pushPrefEnv({"set": [[ "media.mediasource.enabled", true ]]}, testFunction)); + function bootstrapTest() { + var ms = new MediaSource(); + + var el = document.createElement("video"); + el.src = URL.createObjectURL(ms); + el.preload = "auto"; + + document.body.appendChild(el); + SimpleTest.registerCleanupFunction(function () { + el.parentNode.removeChild(el); + }); + + testFunction(ms, el); + } + + addLoadEvent(function () { + SpecialPowers.pushPrefEnv({"set": [[ "media.mediasource.enabled", true ]]}, + bootstrapTest); + }); } function fetchWithXHR(uri, onLoadFunction) { var xhr = new XMLHttpRequest(); xhr.open("GET", uri, true); - xhr.responseType = "blob"; - xhr.addEventListener("load", function (e) { + xhr.responseType = "arraybuffer"; + xhr.addEventListener("load", function () { is(xhr.status, 200, "fetchWithXHR load uri='" + uri + "' status=" + xhr.status); - var rdr = new FileReader(); - rdr.addEventListener("load", function (e) { - onLoadFunction(e.target.result); - }); - rdr.readAsArrayBuffer(e.target.response); + onLoadFunction(xhr.response); }); xhr.send(); }; diff --git a/content/media/mediasource/test/test_BufferedSeek.html b/content/media/mediasource/test/test_BufferedSeek.html index bb87efb56773..4f1cd1025cdc 100644 --- a/content/media/mediasource/test/test_BufferedSeek.html +++ b/content/media/mediasource/test/test_BufferedSeek.html @@ -12,14 +12,7 @@ SimpleTest.waitForExplicitFinish(); -runWithMSE(function () { - var ms = new MediaSource(); - - var v = document.createElement("video"); - v.preload = "auto"; - v.src = URL.createObjectURL(ms); - document.body.appendChild(v); - +runWithMSE(function (ms, v) { ms.addEventListener("sourceopen", function () { var sb = ms.addSourceBuffer("video/webm"); @@ -51,7 +44,6 @@ runWithMSE(function () { v.addEventListener("seeked", function () { ok(wasSeeking, "Received expected seeking and seeked events"); is(v.currentTime, target, "Video currentTime not at target"); - v.parentNode.removeChild(v); SimpleTest.finish(); }); }); diff --git a/content/media/mediasource/test/test_FrameSelection.html b/content/media/mediasource/test/test_FrameSelection.html index d441a044973a..dab987bc3b59 100644 --- a/content/media/mediasource/test/test_FrameSelection.html +++ b/content/media/mediasource/test/test_FrameSelection.html @@ -12,14 +12,7 @@ SimpleTest.waitForExplicitFinish(); -runWithMSE(function () { - var ms = new MediaSource(); - - var v = document.createElement("video"); - v.preload = "auto"; - v.src = URL.createObjectURL(ms); - document.body.appendChild(v); - +runWithMSE(function (ms, v) { ms.addEventListener("sourceopen", function () { var sb = ms.addSourceBuffer("video/webm"); @@ -66,7 +59,6 @@ runWithMSE(function () { if (target) { v.currentTime = target.currentTime; } else { - v.parentNode.removeChild(v); SimpleTest.finish(); } }); diff --git a/content/media/mediasource/test/test_SplitAppend.html b/content/media/mediasource/test/test_SplitAppend.html index 353ac50fe2e6..34070c456e8b 100644 --- a/content/media/mediasource/test/test_SplitAppend.html +++ b/content/media/mediasource/test/test_SplitAppend.html @@ -12,14 +12,7 @@ SimpleTest.waitForExplicitFinish(); -runWithMSE(function () { - var ms = new MediaSource(); - - var v = document.createElement("video"); - v.preload = "auto"; - v.src = URL.createObjectURL(ms); - document.body.appendChild(v); - +runWithMSE(function (ms, v) { ms.addEventListener("sourceopen", function () { var sb = ms.addSourceBuffer("video/webm"); @@ -41,7 +34,6 @@ runWithMSE(function () { v.addEventListener("ended", function () { is(v.duration, 4, "Video has correct duration"); is(v.currentTime, 4, "Video has played to end"); - v.parentNode.removeChild(v); SimpleTest.finish(); }); }); diff --git a/content/media/mediasource/test/test_SplitAppendDelay.html b/content/media/mediasource/test/test_SplitAppendDelay.html index 8602ee656e66..9bf26e6dc6be 100644 --- a/content/media/mediasource/test/test_SplitAppendDelay.html +++ b/content/media/mediasource/test/test_SplitAppendDelay.html @@ -12,14 +12,7 @@ SimpleTest.waitForExplicitFinish(); -runWithMSE(function () { - var ms = new MediaSource(); - - var v = document.createElement("video"); - v.preload = "auto"; - v.src = URL.createObjectURL(ms); - document.body.appendChild(v); - +runWithMSE(function (ms, v) { ms.addEventListener("sourceopen", function () { var sb = ms.addSourceBuffer("video/webm"); @@ -43,7 +36,6 @@ runWithMSE(function () { v.addEventListener("ended", function () { is(v.duration, 4, "Video has correct duration"); is(v.currentTime, 4, "Video has played to end"); - v.parentNode.removeChild(v); SimpleTest.finish(); }); });