d78cee51 by Gary Katsevman

Change event handler test to be more generic

1 parent f6291590
......@@ -1185,56 +1185,35 @@ test('disposes the playlist loader', function() {
test('remove event handlers on dispose', function() {
var
player,
handlers = [],
timeupdateOff = 0,
waitingOff = 0,
oldOff,
type,
handler,
i;
onhandlers = 0,
offhandlers = 0,
oldOn,
oldOff;
player = createPlayer();
player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
oldOn = player.on;
oldOff = player.off;
player.on = function(type, handler) {
onhandlers++;
oldOn.call(player, type, handler);
};
player.off = function(type, handler) {
handlers.push([type, handler]);
if (type === 'timeupdate') {
timeupdateOff++;
} else if (type === 'waiting') {
waitingOff++;
}
offhandlers++;
oldOff.call(player, type, handler);
};
player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
openMediaSource(player);
player.hls.playlists.trigger('loadedmetadata');
player.dispose();
equal(timeupdateOff, 2, 'both fillBuffer and drainBuffer handlers were removed');
equal(waitingOff, 1, 'drainBuffer handler was removed');
for (i = 0; i < handlers.length; i++) {
type = handlers[i][0];
handler = handlers[i][1];
if (handler === player.hls.fillBuffer) {
equal(type, 'timeupdate', 'fillBuffer\'s timeupdate handler was removed');
} else if (handler === player.hls.drainBuffer) {
if (type === 'timeupdate') {
ok(type, 'drainBuffer\'s timeupdate handler was removed');
} else if (type === 'waiting') {
ok(type, 'drainBuffer\'s waiting handler was removed');
} else {
ok(false, 'drainBuffer handler was removed that wasn\'t timeupdate or waiting');
}
}
}
equal(offhandlers, onhandlers, 'the amount of on and off handlers is the same');
player.off = oldOff;
player.on = oldOn;
});
test('aborts the source buffer on disposal', function() {
......