4 https://bugzilla.mozilla.org/show_bug.cgi?id=478957
7 <title>Test for Bug
478957</title>
8 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
10 <script type=
"text/javascript" src=
"manifest.js"></script>
13 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=478957">Mozilla Bug
478957</a>
15 <div id=
"content" style=
"display: none">
19 <div id=
"log" style=
"font-size: small;"></div>
22 <script type=
"application/javascript">
24 /** Test for Bug
478957 **/
26 // Tests whether we leak events and state change info when loading stuff from local files from a webserver.
28 var manager = new MediaTestManager;
30 var gEventTypes = [ 'loadstart', 'progress', 'suspend', 'abort', 'error', 'emptied', 'stalled', 'play', 'pause', 'loadedmetadata', 'loadeddata', 'waiting', 'playing', 'canplay', 'canplaythrough', 'seeking', 'seeked', 'timeupdate', 'ended', 'ratechange', 'durationchange', 'volumechange' ];
32 var gExpectedEvents = ['loadstart', 'error'];
34 function createTestArray() {
36 var tmpVid = document.createElement(
"video");
38 return makeInfoLeakTests().then(infoLeakTests =
> {
39 for (var testNum=
0; testNum < infoLeakTests.length; testNum++) {
40 var test = infoLeakTests[testNum];
41 if (!tmpVid.canPlayType(test.type)) {
57 var l = document.getElementById('log');
58 l.innerHTML += msg +
"<br>";
62 log(
"finish: " + v.name);
63 clearInterval(v.checkStateInterval);
65 for (var i=
0; i
<gEventTypes.length; i++) {
66 v.removeEventListener(gEventTypes[i], listener);
68 removeNodeAndSource(v);
70 manager.finished(v.token);
74 function listener(evt) {
76 log(filename(v.name) + ': got ' + evt.type);
78 // On slow machines like B2G emulator, progress timer could time out before
79 // receiving any HTTP notification. We will ignore the 'stalled' event to
81 if (evt.type == 'stalled') {
85 ok(v.eventNum < gExpectedEvents.length, filename(v.name) +
" Too many events received");
86 var expected = (v.eventNum < gExpectedEvents.length) ? gExpectedEvents[v.eventNum] :
"NoEvent";
87 is(evt.type, expected, filename(v.name) +
" Events received in wrong order");
89 if (v.eventNum == gExpectedEvents.length) {
90 // In one second, move onto the next test. This give a chance for any
91 // other events to come in. Note: we don't expect any events to come
92 // in, unless we've leaked some info, and
1 second should be enough time
93 // for the leak to show up.
94 setTimeout(function() {finish(v);},
1000);
98 function createMedia(type, src, token) {
99 var tag = getMajorMimeType(type);
100 var v = document.createElement(tag);
101 for (var i=
0; i
<gEventTypes.length; i++) {
102 v.addEventListener(gEventTypes[i], listener);
104 v.preload =
"metadata";
107 document.body.appendChild(v);
112 v.checkStateInterval = setInterval(function(){checkState(v);},
1);
116 // Define our own ok() and is() functions. The mochitest ones take ages constructing the log
117 // of all the passes, so only report failures.
118 function test_ok(b, msg) {
120 log(
"FAILED test_ok: " + msg);
125 function test_is(a, b, msg) {
127 log(
"FAILED test_is: " + msg);
132 function filename(uri) {
133 return uri.substr(uri.lastIndexOf(
"/")+
1);
136 function checkState(v) {
137 test_ok(v.networkState <= HTMLMediaElement.NETWORK_LOADING ||
138 v.networkState == HTMLMediaElement.NETWORK_NO_SOURCE,
139 "NetworkState of " + v.networkState +
" was leaked.");
140 test_ok(v.readyState == HTMLMediaElement.HAVE_NOTHING,
141 "Ready state of " + v.readyState +
" was leaked");
142 test_is(v.seeking, false,
"Seeking leaked");
143 test_is(v.currentTime,
0,
"Leaked currentTime");
144 test_ok(isNaN(v.duration),
"Leaked duration");
145 test_is(v.paused, true,
"Paused leaked");
146 test_is(v.ended, false,
"Ended leaked");
147 test_is(v.autoplay, false,
"Autoplay leaked");
148 test_is(v.controls, false,
"Controls leaked");
149 test_is(v.muted, false,
"muted leaked");
150 test_ok(v.error==null || v.error.code==MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED,
151 "Error code should not exist or be SRC_NOT_SUPPORTED. v.error=" +
152 (v.error ? v.error.code :
"null"));
153 test_ok(filename(v.currentSrc) == filename(v.name) ||
154 v.networkState == HTMLMediaElement.NETWORK_NO_SOURCE,
155 "currentSrc should match candidate uri, if we've got a valid source");
159 function startTest(test, token) {
160 manager.started(token);
161 log(
"Testing: " + test.type +
" @ " + test.name);
162 createMedia(test.type, test.name, token);
165 SimpleTest.waitForExplicitFinish();
166 createTestArray().then(testArray =
> {
167 manager.runTests(testArray, startTest);