Skip to content
Browse files

@gkatsev cleared vttjs script handlers on dispose. Fixed tests. closes

  • Loading branch information...
1 parent 94e899f commit dbdc411dc22b9694444e9de6d6a5eabc3e2c6ba6 @gkatsev gkatsev committed
Showing with 44 additions and 16 deletions.
  1. +1 −1 CHANGELOG.md
  2. +4 −0 src/js/tech/tech.js
  3. +1 −0 test/karma.conf.js
  4. +38 −15 test/unit/tracks/text-track.test.js
View
2 CHANGELOG.md
@@ -2,7 +2,7 @@ CHANGELOG
=========
## HEAD (Unreleased)
-_(none)_
+* @gkatsev cleared vttjs script handlers on dispose. Fixed tests ([view](https://github.com/videojs/video.js/pull/3189))
--------------------
View
4 src/js/tech/tech.js
@@ -333,6 +333,10 @@ class Tech extends Component {
script.onerror = () => {
this.trigger('vttjserror');
};
+ this.on('dispose', () => {
+ script.onload = null;
+ script.onerror = null;
+ });
this.el().parentNode.appendChild(script);
window['WebVTT'] = true;
}
View
1 test/karma.conf.js
@@ -28,6 +28,7 @@ module.exports = function(config) {
browserify: {
debug: true,
+ plugin: ['proxyquireify/plugin'],
transform: [
require('babelify').configure({
sourceMapRelative: './',
View
53 test/unit/tracks/text-track.test.js
@@ -3,6 +3,9 @@ import EventTarget from '../../../src/js/event-target.js';
import TextTrack from '../../../src/js/tracks/text-track.js';
import TestHelpers from '../test-helpers.js';
import log from '../../../src/js/utils/log.js';
+import proxyquireify from 'proxyquireify';
+
+const proxyquire = proxyquireify(require);
const defaultTech = {
textTracks() {},
@@ -276,20 +279,26 @@ test('tracks are parsed if vttjs is loaded', function() {
};
};
- let xhr;
- window.xhr.onCreate = (newXhr) => xhr = newXhr;
+ // use proxyquire to stub xhr module because IE8s XDomainRequest usage
+ let xhrHandler;
+ let TextTrack = proxyquire('../../../src/js/tracks/text-track.js', {
+ xhr(options, fn) {
+ xhrHandler = fn;
+ }
+ });
let tt = new TextTrack({
tech: defaultTech,
src: 'http://example.com'
});
- xhr.respond(200, {}, 'WebVTT\n');
+ xhrHandler(null, {}, 'WEBVTT\n');
ok(parserCreated, 'WebVTT is loaded, so we can just parse');
clock.restore();
window.WebVTT = oldVTT;
+ TextTrack = proxyquire('../../../src/js/tracks/text-track.js', {});
});
test('tracks are parsed once vttjs is loaded', function() {
@@ -297,10 +306,15 @@ test('tracks are parsed once vttjs is loaded', function() {
const oldVTT = window.WebVTT;
let parserCreated = false;
- window.WebVTT = true;
+ // use proxyquire to stub xhr module because IE8s XDomainRequest usage
+ let xhrHandler;
+ let TextTrack = proxyquire('../../../src/js/tracks/text-track.js', {
+ xhr(options, fn) {
+ xhrHandler = fn;
+ }
+ });
- let xhr;
- window.xhr.onCreate = (newXhr) => xhr = newXhr;
+ window.WebVTT = true;
let testTech = new EventTarget();
testTech.textTracks = () => {};
@@ -311,7 +325,7 @@ test('tracks are parsed once vttjs is loaded', function() {
src: 'http://example.com'
});
- xhr.respond(200, {}, 'WebVTT\n');
+ xhrHandler(null, {}, 'WEBVTT\n');
ok(!parserCreated, 'WebVTT is not loaded, do not try to parse yet');
@@ -336,18 +350,28 @@ test('tracks are parsed once vttjs is loaded', function() {
clock.restore();
window.WebVTT = oldVTT;
+ TextTrack = proxyquire('../../../src/js/tracks/text-track.js', {});
});
test('stops processing if vttjs loading errored out', function() {
const clock = sinon.useFakeTimers();
- sinon.stub(log, 'error');
const oldVTT = window.WebVTT;
let parserCreated = false;
-
window.WebVTT = true;
- let xhr;
- window.xhr.onCreate = (newXhr) => xhr = newXhr;
+ // use proxyquire to stub xhr module because IE8s XDomainRequest usage
+ let xhrHandler;
+ let errorMsg;
+ let TextTrack = proxyquire('../../../src/js/tracks/text-track.js', {
+ xhr(options, fn) {
+ xhrHandler = fn;
+ },
+ '../utils/log.js': {
+ error(msg) {
+ errorMsg = msg;
+ }
+ }
+ });
let testTech = new EventTarget();
testTech.textTracks = () => {};
@@ -361,20 +385,19 @@ test('stops processing if vttjs loading errored out', function() {
src: 'http://example.com'
});
- xhr.respond(200, {}, 'WebVTT\n');
+ xhrHandler(null, {}, 'WEBVTT\n');
ok(!parserCreated, 'WebVTT is not loaded, do not try to parse yet');
testTech.trigger('vttjserror');
- let errorSpyCall = log.error.getCall(0);
let offSpyCall = testTech.off.getCall(0);
- ok(errorSpyCall.calledWithMatch('vttjs failed to load, stopping trying to process'),
+ ok(/^vttjs failed to load, stopping trying to process/.test(errorMsg),
'vttjs failed to load, so, we logged an error');
ok(!parserCreated, 'WebVTT is not loaded, do not try to parse yet');
ok(offSpyCall, 'tech.off was called');
clock.restore();
- log.error.restore();
window.WebVTT = oldVTT;
+ TextTrack = proxyquire('../../../src/js/tracks/text-track.js', {});
});

0 comments on commit dbdc411

Please sign in to comment.
Something went wrong with that request. Please try again.