Skip to content

Commit

Permalink
test: refactor tests so that players/blob urls/ and media elements ar…
Browse files Browse the repository at this point in the history
…e cleaned up (#1174)

Chrome 92 introduced a limit (75) on the number of media elements that can exist in a page at a time and we were going over that limit in our tests, causing them to fail.
  • Loading branch information
brandonocasey authored Jul 27, 2021
1 parent 464a365 commit b3d1ec0
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 102 deletions.
4 changes: 3 additions & 1 deletion test/configuration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ QUnit.module('Configuration - Options', {
this.env.restore();
videojs.Vhs.supportsNativeHls = this.old.NativeHlsSupport;

this.player.dispose();
if (this.player) {
this.player.dispose();
}
videojs.options.vhs = {};

}
Expand Down
45 changes: 29 additions & 16 deletions test/loader-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import QUnit from 'qunit';
import videojs from 'video.js';
import xhrFactory from '../src/xhr';
import Config from '../src/config';
import document from 'global/document';
import {
playlistWithDuration,
useFakeEnvironment,
Expand Down Expand Up @@ -63,8 +64,20 @@ export const LoaderCommonHooks = {
this.syncController = new SyncController();
this.decrypter = new Decrypter();
this.timelineChangeController = new TimelineChangeController();

this.video = document.createElement('video');

this.setupMediaSource = (mediaSource, sourceUpdater, options) => {
return setupMediaSource(mediaSource, sourceUpdater, videojs.mergeOptions({
videoEl: this.video
}, options));
};
},
afterEach(assert) {
this.video.src = '';
this.video.removeAttribute('src');
this.video = null;

this.env.restore();
this.decrypter.terminate();
this.sourceUpdater.dispose();
Expand Down Expand Up @@ -195,7 +208,7 @@ export const LoaderCommonFactory = ({
});

QUnit.test('calling load should unpause', function(assert) {
return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
return this.setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
loader.playlist(playlistWithDuration(20));
loader.pause();

Expand Down Expand Up @@ -233,7 +246,7 @@ export const LoaderCommonFactory = ({
});

QUnit.test('regularly checks the buffer while unpaused', function(assert) {
return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
return this.setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {

loader.playlist(playlistWithDuration(90));

Expand Down Expand Up @@ -268,7 +281,7 @@ export const LoaderCommonFactory = ({
});

QUnit.test('does not check the buffer while paused', function(assert) {
return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
return this.setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
loader.playlist(playlistWithDuration(90));

loader.load();
Expand Down Expand Up @@ -296,7 +309,7 @@ export const LoaderCommonFactory = ({
const segment = testData();
const segmentBytes = segment.byteLength;

return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
return this.setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {

loader.playlist(playlistWithDuration(10));

Expand Down Expand Up @@ -459,7 +472,7 @@ export const LoaderCommonFactory = ({
progresses++;
});

return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
return this.setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {

loader.playlist(playlistWithDuration(20));
loader.load();
Expand Down Expand Up @@ -512,7 +525,7 @@ export const LoaderCommonFactory = ({

if (initSegments) {
QUnit.test('downloads init segments if specified', function(assert) {
return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_, {isVideoOnly: true}).then(() => {
return this.setupMediaSource(loader.mediaSource_, loader.sourceUpdater_, {isVideoOnly: true}).then(() => {
const playlist = playlistWithDuration(20);
const map = {
resolvedUri: 'mainInitSegment',
Expand Down Expand Up @@ -558,7 +571,7 @@ export const LoaderCommonFactory = ({
});

QUnit.test('detects init segment changes and downloads it', function(assert) {
return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_, {isVideoOnly: true}).then(() => {
return this.setupMediaSource(loader.mediaSource_, loader.sourceUpdater_, {isVideoOnly: true}).then(() => {
const playlist = playlistWithDuration(20);
const buffered = videojs.createTimeRanges();

Expand Down Expand Up @@ -665,7 +678,7 @@ export const LoaderCommonFactory = ({
});

QUnit.test('SegmentLoader.mediaIndex is adjusted when live playlist is updated', function(assert) {
return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
return this.setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {

loader.playlist(playlistWithDuration(50, {
mediaSequence: 0,
Expand Down Expand Up @@ -750,7 +763,7 @@ export const LoaderCommonFactory = ({
});
};

return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
return this.setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {

// Setting currentTime to 31 so that we start requesting at segment #3
this.currentTime = 31;
Expand Down Expand Up @@ -825,7 +838,7 @@ export const LoaderCommonFactory = ({
// only main/fmp4 segment loaders use async appends and parts/partIndex
if (usesAsyncAppends) {
QUnit.test('playlist change before any appends does not error', function(assert) {
return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
return this.setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
loader.playlist(playlistWithDuration(50, {
uri: 'bar-720.m3u8',
mediaSequence: 0,
Expand Down Expand Up @@ -855,7 +868,7 @@ export const LoaderCommonFactory = ({
});

QUnit.test('mediaIndex and partIndex are used', function(assert) {
return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
return this.setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
loader.playlist(playlistWithDuration(50, {
mediaSequence: 0,
endList: false,
Expand All @@ -874,7 +887,7 @@ export const LoaderCommonFactory = ({
});

QUnit.test('mediaIndex and partIndex survive playlist change', function(assert) {
return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
return this.setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
loader.playlist(playlistWithDuration(50, {
mediaSequence: 0,
endList: false,
Expand Down Expand Up @@ -903,7 +916,7 @@ export const LoaderCommonFactory = ({

QUnit.test('drops partIndex if playlist update drops parts', function(assert) {
loader.duration_ = () => Infinity;
return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
return this.setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
loader.playlist(playlistWithDuration(50, {
mediaSequence: 0,
endList: false,
Expand Down Expand Up @@ -1009,7 +1022,7 @@ export const LoaderCommonFactory = ({
});

QUnit.test('dispose cleans up outstanding work', function(assert) {
return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
return this.setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {

loader.playlist(playlistWithDuration(20));

Expand Down Expand Up @@ -1204,7 +1217,7 @@ export const LoaderCommonFactory = ({
QUnit.test(
'does not skip over segment if live playlist update occurs while processing',
function(assert) {
return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
return this.setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
const playlist = playlistWithDuration(40);

playlist.endList = false;
Expand Down Expand Up @@ -1271,7 +1284,7 @@ export const LoaderCommonFactory = ({
handleAppendsDone_();
};

return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
return this.setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {

const playlist = playlistWithDuration(40);

Expand Down
2 changes: 2 additions & 0 deletions test/playback-watcher.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ QUnit.test('changing sources does not break ability to skip gap at beginning of
let vhsGapSkipEvents = 0;
let hlsGapSkipEvents = 0;

this.player.dispose();

this.player = createPlayer({
html5: {
vhs: {
Expand Down
Loading

0 comments on commit b3d1ec0

Please sign in to comment.