Skip to content

Commit

Permalink
Prevent non native text tracks from leaking cuechange event listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
gesinger committed Nov 25, 2015
1 parent 6bbd6f1 commit 24d7953
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/js/tech/tech.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,8 @@ class Tech extends Component {
window['WebVTT'] = true;
}

let textTracksChanges = Fn.bind(this, function() {
let updateDisplay = () => this.trigger('texttrackchange');

let updateDisplay = () => this.trigger('texttrackchange');
let textTracksChanges = () => {
updateDisplay();

for (let i = 0; i < tracks.length; i++) {
Expand All @@ -333,7 +332,7 @@ class Tech extends Component {
track.addEventListener('cuechange', updateDisplay);
}
}
});
};

tracks.addEventListener('change', textTracksChanges);

Expand Down
46 changes: 46 additions & 0 deletions test/unit/tracks/tracks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import ChaptersButton from '../../../src/js/control-bar/text-track-controls/chap
import SubtitlesButton from '../../../src/js/control-bar/text-track-controls/subtitles-button.js';
import CaptionsButton from '../../../src/js/control-bar/text-track-controls/captions-button.js';

import TextTrack from '../../../src/js/tracks/text-track.js';
import TextTrackDisplay from '../../../src/js/tracks/text-track-display.js';
import Html5 from '../../../src/js/tech/html5.js';
import Flash from '../../../src/js/tech/flash.js';
Expand Down Expand Up @@ -342,3 +343,48 @@ if (Html5.supportsNativeTextTracks()) {
emulatedTt.on('addtrack', addtrack);
});
}

test('removes cuechange event when text track is hidden for emulated tracks', function() {
let player = TestHelpers.makePlayer();
let tt = new TextTrack({
tech: player.tech_,
mode: 'showing'
});
tt.addCue({
id: '1',
startTime: 2,
endTime: 5
});
player.tech_.textTracks().addTrack_(tt);
player.tech_.emulateTextTracks();

let numTextTrackChanges = 0;
player.tech_.on('texttrackchange', function() {
numTextTrackChanges++;
});

tt.mode = 'showing';
equal(numTextTrackChanges, 1,
'texttrackchange should be called once for mode change');
tt.mode = 'showing';
equal(numTextTrackChanges, 2,
'texttrackchange should be called once for mode change');

player.tech_.currentTime = function() {
return 3;
};
player.tech_.trigger('timeupdate');
equal(numTextTrackChanges, 3,
'texttrackchange should be triggered once for the cuechange');

tt.mode = 'hidden';
equal(numTextTrackChanges, 4,
'texttrackchange should be called once for the mode change');

player.tech_.currentTime = function() {
return 7;
};
player.tech_.trigger('timeupdate');
equal(numTextTrackChanges, 4,
'texttrackchange should be not be called since mode is hidden');
});

0 comments on commit 24d7953

Please sign in to comment.