Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test whether we can create an MediaSource interface</title> |
michael@0 | 5 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 7 | </head> |
michael@0 | 8 | <body> |
michael@0 | 9 | <pre id="test"> |
michael@0 | 10 | <script class="testbody" type="text/javascript"> |
michael@0 | 11 | |
michael@0 | 12 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 13 | |
michael@0 | 14 | addLoadEvent(function() { |
michael@0 | 15 | ok(!window.MediaSource, "MediaSource should be hidden behind a pref"); |
michael@0 | 16 | var accessThrows = false; |
michael@0 | 17 | try { |
michael@0 | 18 | new MediaSource(); |
michael@0 | 19 | } catch (e) { |
michael@0 | 20 | accessThrows = true; |
michael@0 | 21 | } |
michael@0 | 22 | ok(accessThrows, "MediaSource should be hidden behind a pref"); |
michael@0 | 23 | SpecialPowers.pushPrefEnv({"set": [[ "media.mediasource.enabled", true ]]}, |
michael@0 | 24 | function () { |
michael@0 | 25 | SpecialPowers.setBoolPref("media.mediasource.enabled", true); |
michael@0 | 26 | var ms = new MediaSource(); |
michael@0 | 27 | ok(ms, "Create a MediaSource object"); |
michael@0 | 28 | ok(ms instanceof EventTarget, "MediaSource must be an EventTarget"); |
michael@0 | 29 | is(ms.readyState, "closed", "New MediaSource must be in closed state"); |
michael@0 | 30 | // Force wrapper creation, tests for leaks. |
michael@0 | 31 | ms.foo = null; |
michael@0 | 32 | var o = URL.createObjectURL(ms); |
michael@0 | 33 | ok(o, "Create an objectURL from the MediaSource"); |
michael@0 | 34 | var v = document.createElement("video"); |
michael@0 | 35 | v.preload = "auto"; |
michael@0 | 36 | document.body.appendChild(v); |
michael@0 | 37 | v.src = o; |
michael@0 | 38 | ms.addEventListener("sourceopen", function () { |
michael@0 | 39 | ok(true, "Receive a sourceopen event"); |
michael@0 | 40 | is(ms.readyState, "open", "MediaSource must be in open state after sourceopen"); |
michael@0 | 41 | var sb = ms.addSourceBuffer("video/webm"); |
michael@0 | 42 | ok(sb, "Create a SourceBuffer"); |
michael@0 | 43 | is(ms.sourceBuffers.length, 1, "MediaSource.sourceBuffers is expected length"); |
michael@0 | 44 | is(ms.sourceBuffers[0], sb, "SourceBuffer in list matches our SourceBuffer"); |
michael@0 | 45 | fetch("seek.webm", function (blob) { |
michael@0 | 46 | var r = new FileReader(); |
michael@0 | 47 | r.addEventListener("load", function (e) { |
michael@0 | 48 | sb.appendBuffer(new Uint8Array(e.target.result)); |
michael@0 | 49 | ms.endOfStream(); |
michael@0 | 50 | v.play(); |
michael@0 | 51 | }); |
michael@0 | 52 | r.readAsArrayBuffer(blob); |
michael@0 | 53 | }); |
michael@0 | 54 | }); |
michael@0 | 55 | ms.addEventListener("sourceended", function () { |
michael@0 | 56 | ok(true, "Receive a sourceended event"); |
michael@0 | 57 | is(ms.readyState, "ended", "MediaSource must be in ended state after sourceended"); |
michael@0 | 58 | }); |
michael@0 | 59 | v.addEventListener("ended", function () { |
michael@0 | 60 | is(v.duration, 4, "Video has correct duration"); |
michael@0 | 61 | v.parentNode.removeChild(v); |
michael@0 | 62 | SimpleTest.finish(); |
michael@0 | 63 | }); |
michael@0 | 64 | }); |
michael@0 | 65 | }); |
michael@0 | 66 | |
michael@0 | 67 | function fetch(src, cb) { |
michael@0 | 68 | var xhr = new XMLHttpRequest(); |
michael@0 | 69 | xhr.open("GET", src, true); |
michael@0 | 70 | xhr.responseType = "blob"; |
michael@0 | 71 | xhr.addEventListener("load", function (e) { |
michael@0 | 72 | if (xhr.status != 200) { |
michael@0 | 73 | return false; |
michael@0 | 74 | } |
michael@0 | 75 | cb(xhr.response); |
michael@0 | 76 | }); |
michael@0 | 77 | xhr.send(); |
michael@0 | 78 | }; |
michael@0 | 79 | </script> |
michael@0 | 80 | </pre> |
michael@0 | 81 | </body> |
michael@0 | 82 | </html> |