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>Media test: media selection</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 | <script type="application/javascript" src="manifest.js"></script> |
michael@0 | 8 | </head> |
michael@0 | 9 | <body> |
michael@0 | 10 | <pre id="test"> |
michael@0 | 11 | <script class="testbody" type="text/javascript"> |
michael@0 | 12 | var manager = new MediaTestManager; |
michael@0 | 13 | |
michael@0 | 14 | function maketest(attach_media, name, type, check_metadata) { |
michael@0 | 15 | return function (token) { |
michael@0 | 16 | var e = document.createElement('video'); |
michael@0 | 17 | e.preload = "metadata"; |
michael@0 | 18 | manager.started(token); |
michael@0 | 19 | var errorRun = false; |
michael@0 | 20 | if (check_metadata) { |
michael@0 | 21 | e.addEventListener('loadedmetadata', function () { |
michael@0 | 22 | ok(e.readyState >= HTMLMediaElement.HAVE_METADATA, |
michael@0 | 23 | 'test ' + token + ' readyState ' + e.readyState + ' expected >= ' + HTMLMediaElement.HAVE_METADATA); |
michael@0 | 24 | is(e.currentSrc.substring(e.currentSrc.length - name.length), name, 'test ' + token); |
michael@0 | 25 | // The load can go idle due to cache size limits |
michael@0 | 26 | ok(e.networkState >= HTMLMediaElement.NETWORK_IDLE, |
michael@0 | 27 | 'test ' + token + ' networkState = ' + e.networkState + ' expected >= ' + HTMLMediaElement.NETWORK_IDLE); |
michael@0 | 28 | check_metadata(e); |
michael@0 | 29 | e.parentNode.removeChild(e); |
michael@0 | 30 | manager.finished(token); |
michael@0 | 31 | }, false); |
michael@0 | 32 | } else { |
michael@0 | 33 | e.addEventListener('error', function(event) { |
michael@0 | 34 | is(errorRun, false, "error handler should run once only!"); |
michael@0 | 35 | errorRun = true; |
michael@0 | 36 | is(e.readyState, HTMLMediaElement.HAVE_NOTHING, |
michael@0 | 37 | 'test ' + token + ' readyState should be HAVE_NOTHING when load fails.'); |
michael@0 | 38 | e.parentNode.removeChild(e); |
michael@0 | 39 | manager.finished(token); |
michael@0 | 40 | }, true); |
michael@0 | 41 | } |
michael@0 | 42 | attach_media(e, name, type); |
michael@0 | 43 | } |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | function set_src(element, name, type) { |
michael@0 | 47 | element.src = name; |
michael@0 | 48 | document.body.appendChild(element); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | function add_source(element, name, type) { |
michael@0 | 52 | do_add_source(element, name, type); |
michael@0 | 53 | document.body.appendChild(element); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | function do_add_source(element, name, type) { |
michael@0 | 57 | var source = document.createElement('source'); |
michael@0 | 58 | if (type) { |
michael@0 | 59 | source.type = type; |
michael@0 | 60 | } |
michael@0 | 61 | source.src = name; |
michael@0 | 62 | element.appendChild(source); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | function add_sources_last(element, name, type) { |
michael@0 | 66 | do_add_source(element, name, 'unsupported/type'); |
michael@0 | 67 | do_add_source(element, name, type); |
michael@0 | 68 | document.body.appendChild(element); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | function add_sources_first(element, name, type) { |
michael@0 | 72 | do_add_source(element, name, type); |
michael@0 | 73 | do_add_source(element, name, 'unsupported/type'); |
michael@0 | 74 | document.body.appendChild(element); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | function late_add_sources_last(element, name, type) { |
michael@0 | 78 | document.body.appendChild(element); |
michael@0 | 79 | do_add_source(element, name, 'unsupported/type'); |
michael@0 | 80 | do_add_source(element, name, type); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | function late_add_sources_first(element, name, type) { |
michael@0 | 84 | document.body.appendChild(element); |
michael@0 | 85 | do_add_source(element, name, type); |
michael@0 | 86 | do_add_source(element, name, 'unsupported/type'); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | var nextTest = 0; |
michael@0 | 90 | var subtests = [ |
michael@0 | 91 | maketest(add_source, 'unknown.raw', 'bogus/type', null) |
michael@0 | 92 | ]; |
michael@0 | 93 | |
michael@0 | 94 | var tmpVid = document.createElement('video'); |
michael@0 | 95 | |
michael@0 | 96 | for (var i = 0; i < gSmallTests.length; ++i) { |
michael@0 | 97 | var test = gSmallTests[i]; |
michael@0 | 98 | var src = test.name; |
michael@0 | 99 | var type = test.type; |
michael@0 | 100 | |
michael@0 | 101 | if (!tmpVid.canPlayType(type)) |
michael@0 | 102 | continue; |
michael@0 | 103 | |
michael@0 | 104 | // The following nested function hack is to ensure that 'test' is correctly |
michael@0 | 105 | // captured in the closure and we don't end up getting the value 'test' |
michael@0 | 106 | // had in the last iteration of the loop. I blame Brendan. |
michael@0 | 107 | var check = function(test) { return function (e) { |
michael@0 | 108 | checkMetadata(test.name, e, test); |
michael@0 | 109 | }}(test); |
michael@0 | 110 | |
michael@0 | 111 | var otherType = type.match(/^video\//) ? "audio/x-wav" : "video/ogg"; |
michael@0 | 112 | subtests.push(maketest(set_src, src, null, check), |
michael@0 | 113 | maketest(add_source, src, null, check), |
michael@0 | 114 | maketest(add_source, src, type, check), |
michael@0 | 115 | maketest(add_sources_last, src, null, check), |
michael@0 | 116 | maketest(add_sources_first, src, type, check), |
michael@0 | 117 | |
michael@0 | 118 | // type hint matches a decoder, actual type matches different decoder |
michael@0 | 119 | maketest(add_source, src, otherType, check), |
michael@0 | 120 | maketest(add_source, 'unknown.raw', type, null), |
michael@0 | 121 | |
michael@0 | 122 | // should not start loading, type excludes it from media candiate list |
michael@0 | 123 | maketest(add_source, src, 'bogus/type', null), |
michael@0 | 124 | |
michael@0 | 125 | // element doesn't notice source children attached later, needs bug 462455 fixed |
michael@0 | 126 | maketest(late_add_sources_last, src, type, check), |
michael@0 | 127 | maketest(late_add_sources_first, src, type, check)); |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | function startTest(test, token) { |
michael@0 | 131 | test(token); |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | manager.runTests(subtests, startTest); |
michael@0 | 135 | |
michael@0 | 136 | </script> |
michael@0 | 137 | </pre> |
michael@0 | 138 | </body> |
michael@0 | 139 | </html> |