2015-03-28 07:59:21 +02:00
|
|
|
/**
|
|
|
|
* These tests run on the minified, window.videojs and ensure the needed
|
|
|
|
* APIs still exist
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function(){
|
2015-03-26 06:43:41 +02:00
|
|
|
|
2015-04-29 23:36:20 +02:00
|
|
|
q.module('Player API');
|
2013-03-05 23:39:43 +03:00
|
|
|
|
2015-03-28 07:59:21 +02:00
|
|
|
test('videojs should exist on the window', function() {
|
|
|
|
ok(window.videojs, 'videojs exists on the window');
|
|
|
|
});
|
|
|
|
|
2013-06-24 22:47:47 +03:00
|
|
|
test('should be able to access expected player API methods', function() {
|
2015-03-28 07:59:21 +02:00
|
|
|
var player = videojs.getComponent('Player').prototype;
|
2013-06-24 22:47:47 +03:00
|
|
|
|
|
|
|
// Native HTML5 Methods
|
2013-12-10 03:16:09 +03:00
|
|
|
ok(player.error, 'error exists');
|
2013-06-24 22:47:47 +03:00
|
|
|
ok(player.src, 'src exists');
|
2013-12-10 03:16:09 +03:00
|
|
|
ok(player.currentSrc, 'currentSrc exists');
|
|
|
|
ok(player.buffered, 'buffered exists');
|
|
|
|
ok(player.load, 'load exists');
|
|
|
|
ok(player.seeking, 'seeking exists');
|
2013-06-24 22:47:47 +03:00
|
|
|
ok(player.currentTime, 'currentTime exists');
|
|
|
|
ok(player.duration, 'duration exists');
|
2013-12-10 03:16:09 +03:00
|
|
|
ok(player.paused, 'paused exists');
|
|
|
|
ok(player.ended, 'ended exists');
|
|
|
|
ok(player.autoplay, 'autoplay exists');
|
|
|
|
ok(player.loop, 'loop exists');
|
|
|
|
ok(player.play , 'play exists');
|
|
|
|
ok(player.pause , 'pause exists');
|
|
|
|
ok(player.controls, 'controls exists');
|
2013-06-24 22:47:47 +03:00
|
|
|
ok(player.volume, 'volume exists');
|
|
|
|
ok(player.muted, 'muted exists');
|
|
|
|
ok(player.width, 'width exists');
|
|
|
|
ok(player.height, 'height exists');
|
2013-12-10 03:16:09 +03:00
|
|
|
ok(player.poster, 'poster exists');
|
|
|
|
ok(player.textTracks, 'textTracks exists');
|
2014-05-16 00:46:28 +03:00
|
|
|
ok(player.requestFullscreen, 'requestFullscreen exists');
|
|
|
|
ok(player.exitFullscreen, 'exitFullscreen exists');
|
2014-05-14 00:02:02 +03:00
|
|
|
ok(player.playbackRate, 'playbackRate exists');
|
2015-02-13 01:26:32 +02:00
|
|
|
ok(player.networkState, 'networkState exists');
|
|
|
|
ok(player.readyState, 'readyState exists');
|
2013-06-24 22:47:47 +03:00
|
|
|
|
2013-12-10 03:16:09 +03:00
|
|
|
// Unsupported Native HTML5 Methods
|
|
|
|
// ok(player.canPlayType, 'canPlayType exists');
|
|
|
|
// ok(player.startTime, 'startTime exists');
|
|
|
|
// ok(player.defaultPlaybackRate, 'defaultPlaybackRate exists');
|
|
|
|
// ok(player.playbackRate, 'playbackRate exists');
|
|
|
|
// ok(player.played, 'played exists');
|
|
|
|
// ok(player.seekable, 'seekable exists');
|
|
|
|
// ok(player.videoWidth, 'videoWidth exists');
|
|
|
|
// ok(player.videoHeight, 'videoHeight exists');
|
|
|
|
|
|
|
|
// Additional player methods
|
|
|
|
ok(player.bufferedPercent, 'bufferedPercent exists');
|
|
|
|
ok(player.reportUserActivity, 'reportUserActivity exists');
|
|
|
|
ok(player.userActive, 'userActive exists');
|
|
|
|
ok(player.usingNativeControls, 'usingNativeControls exists');
|
2014-05-16 00:46:28 +03:00
|
|
|
ok(player.isFullscreen, 'isFullscreen exists');
|
2013-12-10 03:16:09 +03:00
|
|
|
|
2015-02-14 01:18:07 +02:00
|
|
|
// TextTrack methods
|
|
|
|
ok(player.textTracks, 'textTracks exists');
|
2015-12-08 18:24:51 +02:00
|
|
|
ok(player.remoteTextTrackEls, 'remoteTextTrackEls exists');
|
2015-02-14 01:18:07 +02:00
|
|
|
ok(player.remoteTextTracks, 'remoteTextTracks exists');
|
|
|
|
ok(player.addTextTrack, 'addTextTrack exists');
|
|
|
|
ok(player.addRemoteTextTrack, 'addRemoteTextTrack exists');
|
|
|
|
ok(player.removeRemoteTextTrack, 'removeRemoteTextTrack exists');
|
|
|
|
|
2014-09-06 00:19:30 +03:00
|
|
|
// Deprecated methods that should still exist
|
|
|
|
ok(player.requestFullScreen, 'requestFullScreen exists');
|
|
|
|
ok(player.isFullScreen, 'isFullScreen exists');
|
|
|
|
ok(player.cancelFullScreen, 'cancelFullScreen exists');
|
2013-06-24 22:47:47 +03:00
|
|
|
});
|
2013-03-05 23:39:43 +03:00
|
|
|
|
2013-12-19 04:53:43 +03:00
|
|
|
test('should be able to access expected component API methods', function() {
|
2015-04-14 22:08:32 +02:00
|
|
|
var Component = videojs.getComponent('Component');
|
|
|
|
var comp = new Component({ id: function(){ return 1; }, reportUserActivity: function(){} });
|
2013-12-19 04:53:43 +03:00
|
|
|
|
|
|
|
// Component methods
|
|
|
|
ok(comp.player, 'player exists');
|
|
|
|
ok(comp.options, 'options exists');
|
|
|
|
ok(comp.init, 'init exists');
|
|
|
|
ok(comp.dispose, 'dispose exists');
|
|
|
|
ok(comp.createEl, 'createEl exists');
|
|
|
|
ok(comp.contentEl, 'contentEl exists');
|
|
|
|
ok(comp.el, 'el exists');
|
|
|
|
ok(comp.addChild, 'addChild exists');
|
|
|
|
ok(comp.getChild, 'getChild exists');
|
|
|
|
ok(comp.getChildById, 'getChildById exists');
|
|
|
|
ok(comp.children, 'children exists');
|
|
|
|
ok(comp.initChildren, 'initChildren exists');
|
|
|
|
ok(comp.removeChild, 'removeChild exists');
|
|
|
|
ok(comp.on, 'on exists');
|
|
|
|
ok(comp.off, 'off exists');
|
|
|
|
ok(comp.one, 'one exists');
|
|
|
|
ok(comp.trigger, 'trigger exists');
|
|
|
|
ok(comp.triggerReady, 'triggerReady exists');
|
|
|
|
ok(comp.show, 'show exists');
|
|
|
|
ok(comp.hide, 'hide exists');
|
|
|
|
ok(comp.width, 'width exists');
|
|
|
|
ok(comp.height, 'height exists');
|
|
|
|
ok(comp.dimensions, 'dimensions exists');
|
|
|
|
ok(comp.ready, 'ready exists');
|
|
|
|
ok(comp.addClass, 'addClass exists');
|
|
|
|
ok(comp.removeClass, 'removeClass exists');
|
|
|
|
ok(comp.buildCSSClass, 'buildCSSClass exists');
|
2014-12-03 21:31:39 +02:00
|
|
|
ok(comp.setInterval, 'setInterval exists');
|
|
|
|
ok(comp.clearInterval, 'clearInterval exists');
|
|
|
|
ok(comp.setTimeout, 'setTimeout exists');
|
|
|
|
ok(comp.clearTimeout, 'clearTimeout exists');
|
2013-12-19 04:53:43 +03:00
|
|
|
});
|
|
|
|
|
2014-03-06 03:08:49 +03:00
|
|
|
test('should be able to access expected MediaTech API methods', function() {
|
2015-04-14 22:08:32 +02:00
|
|
|
var media = videojs.getComponent('Tech');
|
2015-03-26 06:43:41 +02:00
|
|
|
var mediaProto = media.prototype;
|
|
|
|
var html5 = videojs.getComponent('Html5');
|
|
|
|
var html5Proto = html5.prototype;
|
|
|
|
var flash = videojs.getComponent('Flash');
|
|
|
|
var flashProto = flash.prototype;
|
2014-03-06 03:08:49 +03:00
|
|
|
|
2015-01-13 00:28:22 +02:00
|
|
|
ok(mediaProto.setPoster, 'setPoster should exist on the Media tech');
|
2014-03-06 03:08:49 +03:00
|
|
|
ok(html5Proto.setPoster, 'setPoster should exist on the HTML5 tech');
|
|
|
|
ok(flashProto.setPoster, 'setPoster should exist on the Flash tech');
|
2014-03-27 23:24:03 +03:00
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
ok(html5.patchCanPlayType, 'patchCanPlayType should exist for HTML5');
|
|
|
|
ok(html5.unpatchCanPlayType, 'unpatchCanPlayType should exist for HTML5');
|
2014-03-28 00:25:58 +03:00
|
|
|
|
2015-01-13 00:28:22 +02:00
|
|
|
// Source Handler Functions
|
|
|
|
ok(media.withSourceHandlers, 'withSourceHandlers should exist for Media Tech');
|
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
ok(html5.canPlaySource, 'canPlaySource should exist for HTML5');
|
|
|
|
ok(html5.registerSourceHandler, 'registerSourceHandler should exist for Html5');
|
|
|
|
ok(html5.selectSourceHandler, 'selectSourceHandler should exist for Html5');
|
|
|
|
ok(html5.prototype.setSource, 'setSource should exist for Html5');
|
|
|
|
ok(html5.prototype.disposeSourceHandler, 'disposeSourceHandler should exist for Html5');
|
|
|
|
|
|
|
|
ok(flash.canPlaySource, 'canPlaySource should exist for Flash');
|
|
|
|
ok(flash.registerSourceHandler, 'registerSourceHandler should exist for Flash');
|
|
|
|
ok(flash.selectSourceHandler, 'selectSourceHandler should exist for Flash');
|
|
|
|
ok(flash.prototype.setSource, 'setSource should exist for Flash');
|
|
|
|
ok(flash.prototype.disposeSourceHandler, 'disposeSourceHandler should exist for Flash');
|
2014-03-06 03:08:49 +03:00
|
|
|
});
|
|
|
|
|
2013-03-05 23:39:43 +03:00
|
|
|
test('should export ready api call to public', function() {
|
2015-03-28 07:59:21 +02:00
|
|
|
var videoTag = testHelperMakeTag();
|
2013-03-05 23:39:43 +03:00
|
|
|
|
|
|
|
var fixture = document.getElementById('qunit-fixture');
|
|
|
|
fixture.appendChild(videoTag);
|
|
|
|
|
2013-05-09 19:23:32 +03:00
|
|
|
var player = videojs('example_1');
|
2013-03-05 23:39:43 +03:00
|
|
|
ok(player.ready !== undefined, 'ready callback is defined');
|
|
|
|
player.dispose();
|
|
|
|
});
|
2013-03-06 00:23:01 +03:00
|
|
|
|
2013-08-23 21:15:58 +03:00
|
|
|
test('should export useful components to the public', function () {
|
2015-05-17 00:59:46 +02:00
|
|
|
ok(videojs.browser.TOUCH_ENABLED !== undefined, 'Touch detection should be public');
|
2015-03-26 06:43:41 +02:00
|
|
|
ok(videojs.getComponent('ControlBar'), 'ControlBar should be public');
|
|
|
|
ok(videojs.getComponent('Button'), 'Button should be public');
|
|
|
|
ok(videojs.getComponent('PlayToggle'), 'PlayToggle should be public');
|
|
|
|
ok(videojs.getComponent('FullscreenToggle'), 'FullscreenToggle should be public');
|
|
|
|
ok(videojs.getComponent('BigPlayButton'), 'BigPlayButton should be public');
|
|
|
|
ok(videojs.getComponent('LoadingSpinner'), 'LoadingSpinner should be public');
|
|
|
|
ok(videojs.getComponent('CurrentTimeDisplay'), 'CurrentTimeDisplay should be public');
|
|
|
|
ok(videojs.getComponent('DurationDisplay'), 'DurationDisplay should be public');
|
|
|
|
ok(videojs.getComponent('TimeDivider'), 'TimeDivider should be public');
|
|
|
|
ok(videojs.getComponent('RemainingTimeDisplay'), 'RemainingTimeDisplay should be public');
|
|
|
|
ok(videojs.getComponent('Slider'), 'Slider should be public');
|
|
|
|
ok(videojs.getComponent('ProgressControl'), 'ProgressControl should be public');
|
|
|
|
ok(videojs.getComponent('SeekBar'), 'SeekBar should be public');
|
|
|
|
ok(videojs.getComponent('LoadProgressBar'), 'LoadProgressBar should be public');
|
|
|
|
ok(videojs.getComponent('PlayProgressBar'), 'PlayProgressBar should be public');
|
|
|
|
ok(videojs.getComponent('VolumeControl'), 'VolumeControl should be public');
|
|
|
|
ok(videojs.getComponent('VolumeBar'), 'VolumeBar should be public');
|
|
|
|
ok(videojs.getComponent('VolumeLevel'), 'VolumeLevel should be public');
|
|
|
|
ok(videojs.getComponent('VolumeMenuButton'), 'VolumeMenuButton should be public');
|
|
|
|
ok(videojs.getComponent('MuteToggle'), 'MuteToggle should be public');
|
|
|
|
ok(videojs.getComponent('PosterImage'), 'PosterImage should be public');
|
|
|
|
ok(videojs.getComponent('Menu'), 'Menu should be public');
|
|
|
|
ok(videojs.getComponent('MenuItem'), 'MenuItem should be public');
|
|
|
|
ok(videojs.getComponent('MenuButton'), 'MenuButton should be public');
|
|
|
|
ok(videojs.getComponent('PlaybackRateMenuButton'), 'PlaybackRateMenuButton should be public');
|
|
|
|
|
|
|
|
ok(videojs.getComponent('CaptionSettingsMenuItem'), 'CaptionSettingsMenuItem should be public');
|
|
|
|
ok(videojs.getComponent('OffTextTrackMenuItem'), 'OffTextTrackMenuItem should be public');
|
|
|
|
ok(videojs.getComponent('TextTrackMenuItem'), 'TextTrackMenuItem should be public');
|
|
|
|
ok(videojs.getComponent('TextTrackDisplay'), 'TextTrackDisplay should be public');
|
|
|
|
ok(videojs.getComponent('TextTrackButton'), 'TextTrackButton should be public');
|
|
|
|
ok(videojs.getComponent('CaptionsButton'), 'CaptionsButton should be public');
|
|
|
|
ok(videojs.getComponent('SubtitlesButton'), 'SubtitlesButton should be public');
|
|
|
|
ok(videojs.getComponent('ChaptersButton'), 'ChaptersButton should be public');
|
|
|
|
ok(videojs.getComponent('ChaptersTrackMenuItem'), 'ChaptersTrackMenuItem should be public');
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-05-04 01:12:38 +02:00
|
|
|
ok(videojs.mergeOptions, 'mergeOptions should be public');
|
2013-08-23 21:15:58 +03:00
|
|
|
});
|
|
|
|
|
2013-03-06 00:23:01 +03:00
|
|
|
test('should be able to initialize player twice on the same tag using string reference', function() {
|
2015-03-28 07:59:21 +02:00
|
|
|
var videoTag = testHelperMakeTag();
|
2013-03-06 00:23:01 +03:00
|
|
|
var id = videoTag.id;
|
|
|
|
|
|
|
|
var fixture = document.getElementById('qunit-fixture');
|
|
|
|
fixture.appendChild(videoTag);
|
|
|
|
|
2013-05-09 19:23:32 +03:00
|
|
|
var player = videojs('example_1');
|
2013-03-06 00:23:01 +03:00
|
|
|
player.dispose();
|
|
|
|
ok(!document.getElementById(id), 'element is removed');
|
|
|
|
|
2015-03-28 07:59:21 +02:00
|
|
|
videoTag = testHelperMakeTag();
|
2013-03-06 00:23:01 +03:00
|
|
|
fixture.appendChild(videoTag);
|
|
|
|
|
2013-05-09 19:23:32 +03:00
|
|
|
player = videojs('example_1');
|
2013-03-06 00:23:01 +03:00
|
|
|
player.dispose();
|
|
|
|
});
|
2013-06-03 23:19:46 +03:00
|
|
|
|
2015-05-17 00:59:46 +02:00
|
|
|
test('videojs.getPlayers() should be available after minification', function() {
|
2015-03-28 07:59:21 +02:00
|
|
|
var videoTag = testHelperMakeTag();
|
2013-06-05 20:27:38 +03:00
|
|
|
var id = videoTag.id;
|
|
|
|
|
|
|
|
var fixture = document.getElementById('qunit-fixture');
|
|
|
|
fixture.appendChild(videoTag);
|
|
|
|
|
|
|
|
var player = videojs(id);
|
2015-05-17 00:59:46 +02:00
|
|
|
ok(videojs.getPlayers()[id] === player, 'videojs.getPlayers() is available');
|
2013-06-05 20:27:38 +03:00
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
});
|
2013-11-26 23:46:20 +03:00
|
|
|
|
2014-09-04 20:13:58 +03:00
|
|
|
test('component can be subclassed externally', function(){
|
2015-03-26 06:43:41 +02:00
|
|
|
var Component = videojs.getComponent('Component');
|
|
|
|
var ControlBar = videojs.getComponent('ControlBar');
|
|
|
|
|
2015-09-22 17:19:04 +02:00
|
|
|
var player = new (videojs.extend(Component, {
|
2014-09-04 20:13:58 +03:00
|
|
|
reportUserActivity: function(){},
|
2015-02-14 01:18:07 +02:00
|
|
|
textTracks: function(){ return {
|
|
|
|
addEventListener: Function.prototype,
|
|
|
|
removeEventListener: Function.prototype
|
|
|
|
};
|
|
|
|
}
|
2014-09-04 20:13:58 +03:00
|
|
|
}))({
|
|
|
|
id: function(){},
|
|
|
|
reportUserActivity: function(){}
|
|
|
|
});
|
2015-03-26 06:43:41 +02:00
|
|
|
|
|
|
|
ok(new ControlBar(player), 'created a control bar without throwing');
|
2014-09-04 20:13:58 +03:00
|
|
|
});
|
2015-03-28 07:59:21 +02:00
|
|
|
|
|
|
|
function testHelperMakeTag(){
|
|
|
|
var videoTag = document.createElement('video');
|
|
|
|
videoTag.id = 'example_1';
|
|
|
|
videoTag.className = 'video-js vjs-default-skin';
|
|
|
|
return videoTag;
|
|
|
|
}
|
|
|
|
|
2015-04-28 20:50:09 +02:00
|
|
|
test('should extend Component', function(){
|
|
|
|
var Component = videojs.getComponent('Component');
|
2015-09-22 17:19:04 +02:00
|
|
|
var MyComponent = videojs.extend(Component, {
|
2015-04-28 20:50:09 +02:00
|
|
|
constructor: function() {
|
|
|
|
this.bar = true;
|
|
|
|
},
|
|
|
|
foo: function() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var myComponent = new MyComponent();
|
|
|
|
ok(myComponent instanceof Component, 'creates an instance of Component');
|
|
|
|
ok(myComponent instanceof MyComponent, 'creates an instance of MyComponent');
|
|
|
|
ok(myComponent.bar, 'the constructor function is used');
|
|
|
|
ok(myComponent.foo(), 'instance methods are applied');
|
|
|
|
|
2015-09-22 17:19:04 +02:00
|
|
|
var NoMethods = videojs.extend(Component);
|
2015-04-28 20:50:09 +02:00
|
|
|
var noMethods = new NoMethods({});
|
|
|
|
ok(noMethods.on, 'should extend component with no methods or constructor');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
})();
|