Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only call source handler dispose once on the same source handler #3343

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/js/tech/tech.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ Tech.withSourceHandlers = function(_Tech){
this.off(this.el_, 'loadstart', _Tech.prototype.firstLoadStartListener_);
this.off(this.el_, 'loadstart', _Tech.prototype.successiveLoadStartListener_);
this.sourceHandler_.dispose();
this.sourceHandler_ = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not much to argue about here.

LGTM!

}
};

Expand Down
79 changes: 79 additions & 0 deletions test/unit/tech/tech.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,82 @@ test('Tech#setSource clears currentSource_ after repeated loadstart', function()
equal(tech.currentSource_, null, 'Current source is still null');

});

test('setSource after tech dispose should dispose source handler once', function(){
let MyTech = extendFn(Tech);
Tech.withSourceHandlers(MyTech);

let disposeCount = 0;
let handler = {
dispose() {
disposeCount++;
}
};

MyTech.registerSourceHandler({
canPlayType: function() {
return true;
},
canHandleSource: function() {
return true;
},
handleSource: function(source, tech, options) {
return handler;
}
});

let tech = new MyTech();
tech.setSource('test');

equal(disposeCount, 0, 'did not call sourceHandler_ dispose for initial dispose');
tech.dispose();
ok(!tech.sourceHandler_, 'sourceHandler should be unset');
equal(disposeCount, 1, 'called the source handler dispose');

// this would normally be done above tech on src after dispose
tech.el_ = tech.createEl();

tech.setSource('test');
equal(disposeCount, 1, 'did not dispose after initial setSource');

tech.setSource('test');
equal(disposeCount, 2, 'did dispose on second setSource');

});

test('setSource after previous setSource should dispose source handler once', function(){
let MyTech = extendFn(Tech);
Tech.withSourceHandlers(MyTech);

let disposeCount = 0;
let handler = {
dispose() {
disposeCount++;
}
};

MyTech.registerSourceHandler({
canPlayType: function() {
return true;
},
canHandleSource: function() {
return true;
},
handleSource: function(source, tech, options) {
return handler;
}
});

let tech = new MyTech();

tech.setSource('test');
equal(disposeCount, 0, 'did not call dispose for initial setSource');

tech.setSource('test');
equal(disposeCount, 1, 'did dispose for second setSource');

tech.setSource('test');
equal(disposeCount, 2, 'did dispose for third setSource');

});