Permalink
Browse files

test: verify null-checks with player and control bar children set to …

…false (#5670)
  • Loading branch information...
BrandonOCasey authored and gkatsev committed Dec 11, 2018
1 parent 70a71ae commit 13b42ad05d41b21ac3674d86c76560c9f285d0d4

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -56,7 +56,7 @@ class LoadProgressBar extends Component {
update(event) {
const liveTracker = this.player_.liveTracker;
const buffered = this.player_.buffered();
const duration = liveTracker.isLive() ? liveTracker.seekableEnd() : this.player_.duration();
const duration = (liveTracker && liveTracker.isLive()) ? liveTracker.seekableEnd() : this.player_.duration();
const bufferedEnd = this.player_.bufferedEnd();
const children = this.partEls_;
const controlTextPercentage = this.$('.vjs-control-text-loaded-percentage');
@@ -52,7 +52,9 @@ class SeekBar extends Slider {
this.on(this.player_, 'timeupdate', this.update);
this.on(this.player_, 'ended', this.handleEnded);
this.on(this.player_, 'durationchange', this.update);
this.on(this.player_.liveTracker, 'liveedgechange', this.update);
if (this.player_.liveTracker) {
this.on(this.player_.liveTracker, 'liveedgechange', this.update);
}

// when playing, let's ensure we smoothly update the play progress bar
// via an interval
@@ -69,7 +71,7 @@ class SeekBar extends Slider {
});

this.on(this.player_, ['ended', 'pause', 'waiting'], (e) => {
if (this.player_.liveTracker.isLive() && e.type !== 'ended') {
if (this.player_.liveTracker && this.player_.liveTracker.isLive() && e.type !== 'ended') {
return;
}

@@ -109,11 +111,11 @@ class SeekBar extends Slider {
const liveTracker = this.player_.liveTracker;
let duration = this.player_.duration();

if (liveTracker.isLive()) {
if (liveTracker && liveTracker.isLive()) {
duration = this.player_.liveTracker.liveCurrentTime();
}

if (liveTracker.seekableEnd() === Infinity) {
if (liveTracker && liveTracker.seekableEnd() === Infinity) {
this.disable();
} else {
this.enable();
@@ -194,7 +196,7 @@ class SeekBar extends Slider {
let percent;
const liveTracker = this.player_.liveTracker;

if (liveTracker.isLive()) {
if (liveTracker && liveTracker.isLive()) {
percent = (currentTime - liveTracker.seekableStart()) / liveTracker.liveWindow();

// prevent the percent from changing at the live edge
@@ -247,7 +249,7 @@ class SeekBar extends Slider {
const distance = this.calculateDistance(event);
const liveTracker = this.player_.liveTracker;

if (!liveTracker.isLive()) {
if (!liveTracker || !liveTracker.isLive()) {
newTime = distance * this.player_.duration();

// Don't let video end while scrubbing.
@@ -112,7 +112,7 @@ class TimeTooltip extends Component {
let content;
const duration = this.player_.duration();

if (this.player_.liveTracker.isLive()) {
if (this.player_.liveTracker && this.player_.liveTracker.isLive()) {
const liveWindow = this.player_.liveTracker.liveWindow();
const secondsBehind = liveWindow - (seekBarPoint * liveWindow);

@@ -25,7 +25,10 @@ class SeekToLive extends Button {
super(player, options);

this.updateLiveEdgeStatus();
this.on(this.player_.liveTracker, 'liveedgechange', this.updateLiveEdgeStatus);

if (this.player_.liveTracker) {
this.on(this.player_.liveTracker, 'liveedgechange', this.updateLiveEdgeStatus);
}
}

/**
@@ -60,10 +63,11 @@ class SeekToLive extends Button {
* or not
*/
updateLiveEdgeStatus(e) {
if (this.player_.liveTracker.behindLiveEdge()) {
this.removeClass('vjs-at-live-edge');
} else {
// default to live edge
if (!this.player_.liveTracker || this.player_.liveTracker.atLiveEdge()) {
this.addClass('vjs-at-live-edge');
} else {
this.removeClass('vjs-at-live-edge');
}
}

@@ -80,7 +84,9 @@ class SeekToLive extends Button {
* Dispose of the element and stop tracking
*/
dispose() {
this.off(this.player_.liveTracker, 'liveedgechange', this.updateLiveEdgeStatus);
if (this.player_.liveTracker) {
this.off(this.player_.liveTracker, 'liveedgechange', this.updateLiveEdgeStatus);
}
this.contentEl_ = null;
this.circleEl_ = null;

@@ -2289,7 +2289,7 @@ class Player extends Component {

if (seconds === Infinity) {
this.addClass('vjs-live');
if (this.options_.liveui) {
if (this.options_.liveui && this.player_.liveTracker) {
this.addClass('vjs-liveui');
}
} else {
@@ -6,6 +6,7 @@ import PlayToggle from '../../src/js/control-bar/play-toggle.js';
import PlaybackRateMenuButton from '../../src/js/control-bar/playback-rate-menu/playback-rate-menu-button.js';
import Slider from '../../src/js/slider/slider.js';
import FullscreenToggle from '../../src/js/control-bar/fullscreen-toggle.js';
import ControlBar from '../../src/js/control-bar/control-bar.js';
import TestHelpers from './test-helpers.js';
import document from 'global/document';
import sinon from 'sinon';
@@ -256,3 +257,36 @@ QUnit.test('Muting with MuteToggle should set ARIA value of VolumeBar to 0', fun

player.dispose();
});

QUnit.test('controlbar children to false individually, does not cause an assertion', function(assert) {
const defaultChildren = ControlBar.prototype.options_.children;

defaultChildren.forEach((childName) => {
const options = {controlBar: {}};

options.controlBar[childName] = false;

const player = TestHelpers.makePlayer(options);

this.clock.tick(1000);
player.triggerReady();
player.dispose();
assert.ok(true, `${childName}: false. did not cause an assertion`);
});
});

QUnit.test('all controlbar children to false, does not cause an assertion', function(assert) {
const defaultChildren = ControlBar.prototype.options_.children;
const options = {controlBar: {}};

defaultChildren.forEach((childName) => {
options.controlBar[childName] = false;
});

const player = TestHelpers.makePlayer(options);

this.clock.tick(1000);
player.triggerReady();
player.dispose();
assert.ok(true, 'did not cause an assertion');
});
@@ -1991,3 +1991,38 @@ QUnit.test('source options are retained', function(assert) {

assert.equal(player.currentSource().sourceOption, 'someOption', 'source option retained');
});

QUnit.test('setting children to false individually, does not cause an assertion', function(assert) {
const defaultChildren = Player.prototype.options_.children;

defaultChildren.forEach((childName) => {
const options = {};

options[childName] = false;

const player = TestHelpers.makePlayer(options);

this.clock.tick(1000);

player.triggerReady();
player.dispose();
assert.ok(true, `${childName}: false. did not cause an assertion`);
});
});

QUnit.test('setting all children to false, does not cause an assertion', function(assert) {
const defaultChildren = Player.prototype.options_.children;
const options = {};

defaultChildren.forEach((childName) => {
options[childName] = false;
});

const player = TestHelpers.makePlayer(options);

this.clock.tick(1000);
player.triggerReady();

player.dispose();
assert.ok(true, 'did not cause an assertion');
});

0 comments on commit 13b42ad

Please sign in to comment.