Change event handler test to be more generic
Showing
1 changed file
with
18 additions
and
39 deletions
... | @@ -1185,56 +1185,35 @@ test('disposes the playlist loader', function() { | ... | @@ -1185,56 +1185,35 @@ test('disposes the playlist loader', function() { |
1185 | test('remove event handlers on dispose', function() { | 1185 | test('remove event handlers on dispose', function() { |
1186 | var | 1186 | var |
1187 | player, | 1187 | player, |
1188 | handlers = [], | 1188 | onhandlers = 0, |
1189 | timeupdateOff = 0, | 1189 | offhandlers = 0, |
1190 | waitingOff = 0, | 1190 | oldOn, |
1191 | oldOff, | 1191 | oldOff; |
1192 | type, | ||
1193 | handler, | ||
1194 | i; | ||
1195 | 1192 | ||
1196 | player = createPlayer(); | 1193 | player = createPlayer(); |
1197 | player.src({ | 1194 | oldOn = player.on; |
1198 | src: 'manifest/master.m3u8', | ||
1199 | type: 'application/vnd.apple.mpegurl' | ||
1200 | }); | ||
1201 | |||
1202 | oldOff = player.off; | 1195 | oldOff = player.off; |
1196 | player.on = function(type, handler) { | ||
1197 | onhandlers++; | ||
1198 | oldOn.call(player, type, handler); | ||
1199 | }; | ||
1203 | player.off = function(type, handler) { | 1200 | player.off = function(type, handler) { |
1204 | handlers.push([type, handler]); | 1201 | offhandlers++; |
1205 | |||
1206 | if (type === 'timeupdate') { | ||
1207 | timeupdateOff++; | ||
1208 | } else if (type === 'waiting') { | ||
1209 | waitingOff++; | ||
1210 | } | ||
1211 | |||
1212 | oldOff.call(player, type, handler); | 1202 | oldOff.call(player, type, handler); |
1213 | }; | 1203 | }; |
1204 | player.src({ | ||
1205 | src: 'manifest/master.m3u8', | ||
1206 | type: 'application/vnd.apple.mpegurl' | ||
1207 | }); | ||
1208 | openMediaSource(player); | ||
1209 | player.hls.playlists.trigger('loadedmetadata'); | ||
1214 | 1210 | ||
1215 | player.dispose(); | 1211 | player.dispose(); |
1216 | 1212 | ||
1217 | equal(timeupdateOff, 2, 'both fillBuffer and drainBuffer handlers were removed'); | 1213 | equal(offhandlers, onhandlers, 'the amount of on and off handlers is the same'); |
1218 | equal(waitingOff, 1, 'drainBuffer handler was removed'); | ||
1219 | |||
1220 | for (i = 0; i < handlers.length; i++) { | ||
1221 | type = handlers[i][0]; | ||
1222 | handler = handlers[i][1]; | ||
1223 | |||
1224 | if (handler === player.hls.fillBuffer) { | ||
1225 | equal(type, 'timeupdate', 'fillBuffer\'s timeupdate handler was removed'); | ||
1226 | } else if (handler === player.hls.drainBuffer) { | ||
1227 | if (type === 'timeupdate') { | ||
1228 | ok(type, 'drainBuffer\'s timeupdate handler was removed'); | ||
1229 | } else if (type === 'waiting') { | ||
1230 | ok(type, 'drainBuffer\'s waiting handler was removed'); | ||
1231 | } else { | ||
1232 | ok(false, 'drainBuffer handler was removed that wasn\'t timeupdate or waiting'); | ||
1233 | } | ||
1234 | } | ||
1235 | } | ||
1236 | 1214 | ||
1237 | player.off = oldOff; | 1215 | player.off = oldOff; |
1216 | player.on = oldOn; | ||
1238 | }); | 1217 | }); |
1239 | 1218 | ||
1240 | test('aborts the source buffer on disposal', function() { | 1219 | test('aborts the source buffer on disposal', function() { | ... | ... |
-
Please register or sign in to post a comment