Bug 1929979 - Support labeled_quantity metrics in FOG r=TravisLong
[gecko.git] / dom / media / test / test_info_leak.html
blobe09b63b0319270d1d86eb2ef29deaba2ec9dfbc5
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=478957
5 -->
6 <head>
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>
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=478957">Mozilla Bug 478957</a>
14 <p id="display"></p>
15 <div id="content" style="display: none">
17 </div>
19 <div id="log" style="font-size: small;"></div>
21 <pre id="test">
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() {
35 var tests = [];
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)) {
42 continue;
45 var t = {};
46 t.name = test.src;
47 t.type = test.type;
49 tests.push(t);
51 return tests;
55 function log(msg) {
56 info(msg);
57 var l = document.getElementById('log');
58 l.innerHTML += msg + "<br>";
61 function finish(v) {
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);
71 v = null;
74 function listener(evt) {
75 var v = evt.target;
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
80 // pass the tests.
81 if (evt.type == 'stalled') {
82 return;
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");
88 v.eventNum++;
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";
105 v.src = src;
106 v.name = src;
107 document.body.appendChild(v);
108 v.eventNum = 0;
109 v.token = token;
110 setTimeout(
111 function() {
112 v.checkStateInterval = setInterval(function(){checkState(v);},1);
113 }, 0);
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) {
119 if (!b) {
120 log("FAILED test_ok: " + msg);
121 ok(b, msg);
125 function test_is(a, b, msg) {
126 if (a != b) {
127 log("FAILED test_is: " + msg);
128 is(a,b,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);
170 </script>
171 </pre>
173 </body>
174 </html>