358ec163 by Gary Katsevman

Add a test for removing event handlers

1 parent 89601c9c
...@@ -1199,6 +1199,60 @@ test('disposes the playlist loader', function() { ...@@ -1199,6 +1199,60 @@ test('disposes the playlist loader', function() {
1199 strictEqual(disposes, 1, 'disposed playlist loader'); 1199 strictEqual(disposes, 1, 'disposed playlist loader');
1200 }); 1200 });
1201 1201
1202 test('remove event handlers on dispose', function() {
1203 var player,
1204 handlers = [],
1205 timeupdateOff = 0,
1206 waitingOff = 0,
1207 oldOff,
1208 type,
1209 handler,
1210 i;
1211
1212 player = createPlayer();
1213 player.src({
1214 src: 'manifest/master.m3u8',
1215 type: 'application/vnd.apple.mpegurl'
1216 });
1217
1218 oldOff = player.off;
1219 player.off = function(type, handler) {
1220 handlers.push([type, handler]);
1221
1222 if (type === 'timeupdate') {
1223 timeupdateOff++;
1224 } else if (type === 'waiting') {
1225 waitingOff++;
1226 }
1227
1228 oldOff.call(player, type, handler);
1229 };
1230
1231 player.dispose();
1232
1233 equal(timeupdateOff, 2, 'both fillBuffer and drainBuffer handlers were removed');
1234 equal(waitingOff, 1, 'drainBuffer handler was removed');
1235
1236 for (i = 0; i < handlers.length; i++) {
1237 type = handlers[i][0];
1238 handler = handlers[i][1];
1239
1240 if (handler === player.hls.fillBuffer) {
1241 equal(type, 'timeupdate', 'fillBuffer\'s timeupdate handler was removed');
1242 } else if (handler === player.hls.drainBuffer) {
1243 if (type === 'timeupdate') {
1244 ok(type, 'drainBuffer\'s timeupdate handler was removed');
1245 } else if (type === 'waiting') {
1246 ok(type, 'drainBuffer\'s waiting handler was removed');
1247 } else {
1248 ok(false, 'drainBuffer handler was removed that wasn\'t timeupdate or waiting');
1249 }
1250 }
1251 }
1252
1253 player.off = oldOff;
1254 });
1255
1202 test('aborts the source buffer on disposal', function() { 1256 test('aborts the source buffer on disposal', function() {
1203 var aborts = 0, player; 1257 var aborts = 0, player;
1204 player = createPlayer(); 1258 player = createPlayer();
......