1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-23 02:04:34 +02:00
video.js/test/unit/tech/tech-faker.js

177 lines
3.2 KiB
JavaScript
Raw Normal View History

// Fake a media playback tech controller so that player tests
2020-12-22 21:10:53 +02:00
// can run without HTML5 which PhantomJS does not support.
Broke up Lib and Util into smaller libraries of functions Broke out bind, guid, and element data functions from Lib Separated out more dom functions in to dom.js Broke out URL functions into url.js Removed setLocalStorage since it wasn't being used Moved browser tests out of lib Moved log functions into their own file Removed trim() since it wasn't being used Moved formatTime into its own file Moved round into its own file and renamed roundFloat() Moved capitalize into its own file and renamed as toTitleCase() Moved createTimeRange into its own file Removed Lib.arr.forEach infavor of the native forEach Removed Lib.obj.create in favor of native Object.create (ES6-sham) Removed obj.each in favor of native Object.getOwnPropertyNames().forEach() Removed obj.merge and copy. Using lodash.assign instead. Replaced Lib.obj.isPlain with lodash.isPlainObject Removed Lib.obj.isArray in favor of the native Array.isArray Also removed the lib.js tests file as all tests have been moved or removed. Removed Lib.isEmpty in favor of !Object.getOwnPropertyNames().length Switched Util.mergeOptions and deepMerge to use new mergeOptions() Moved Lib.TEST_VID to Html5.TEST_VID Removed Lib references everywhere. Woo! Attempting to fix sourcemap test errors by setting grunt-browserify version Switched to object.assign from lodash.assign Removed unused 'inherits' dependency Reorganzied test files and added '.test' to file names Combined js/core.js and js/video.js Moved events.js into the utils directory
2015-05-04 01:12:38 +02:00
import Tech from '../../../src/js/tech/tech.js';
import {createTimeRanges} from '../../../src/js/utils/time.js';
/**
* @class
*/
Broke up Lib and Util into smaller libraries of functions Broke out bind, guid, and element data functions from Lib Separated out more dom functions in to dom.js Broke out URL functions into url.js Removed setLocalStorage since it wasn't being used Moved browser tests out of lib Moved log functions into their own file Removed trim() since it wasn't being used Moved formatTime into its own file Moved round into its own file and renamed roundFloat() Moved capitalize into its own file and renamed as toTitleCase() Moved createTimeRange into its own file Removed Lib.arr.forEach infavor of the native forEach Removed Lib.obj.create in favor of native Object.create (ES6-sham) Removed obj.each in favor of native Object.getOwnPropertyNames().forEach() Removed obj.merge and copy. Using lodash.assign instead. Replaced Lib.obj.isPlain with lodash.isPlainObject Removed Lib.obj.isArray in favor of the native Array.isArray Also removed the lib.js tests file as all tests have been moved or removed. Removed Lib.isEmpty in favor of !Object.getOwnPropertyNames().length Switched Util.mergeOptions and deepMerge to use new mergeOptions() Moved Lib.TEST_VID to Html5.TEST_VID Removed Lib references everywhere. Woo! Attempting to fix sourcemap test errors by setting grunt-browserify version Switched to object.assign from lodash.assign Removed unused 'inherits' dependency Reorganzied test files and added '.test' to file names Combined js/core.js and js/video.js Moved events.js into the utils directory
2015-05-04 01:12:38 +02:00
class TechFaker extends Tech {
constructor(options, handleReady) {
super(options, handleReady);
this.featuresPlaybackRate = true;
this.defaultPlaybackRate_ = 1;
this.playbackRate_ = 1;
this.currentTime_ = 0;
if (this.options_ && this.options_.sourceset) {
this.fakeSourceset();
}
if (!options || options.autoReady !== false) {
this.triggerReady();
}
}
createEl() {
const el = super.createEl('div', {
className: 'vjs-tech'
});
return el;
}
// fake a poster attribute to mimic the video element
poster() {
return this.el().poster;
}
setPoster(val) {
this.el().poster = val;
this.trigger('posterchange');
}
setControls(val) {}
setVolume(value) {
this.volume_ = value;
}
setMuted() {}
setAutoplay(v) {
if (!v) {
this.options_.autoplay = false;
}
this.options_.autoplay = true;
}
defaultPlaybackRate(value) {
if (value !== undefined) {
this.defaultPlaybackRate_ = parseFloat(value);
}
return this.defaultPlaybackRate_;
}
setPlaybackRate(value) {
const last = this.playbackRate_;
this.playbackRate_ = parseFloat(value);
if (value !== last) {
this.trigger('ratechange');
}
}
playbackRate() {
return this.playbackRate_;
}
setCurrentTime(value) {
const last = this.currentTime_;
this.currentTime_ = parseFloat(value);
if (value !== last) {
this.trigger('timeupdate');
}
}
currentTime() {
return this.currentTime_;
}
seekable() {
return createTimeRanges(0, 0);
}
seeking() {
return false;
}
setScrubbing() {}
fakeSourceset() {
this.el_.src = this.options_.sourceset;
this.el_.setAttribute('src', this.options_.sourceset);
super.triggerSourceset(this.options_.sourceset);
}
src(src) {
if (typeof src !== 'undefined' && this.options_ && this.options_.sourceset) {
this.fakeSourceset();
}
return 'movie.mp4';
}
load() {
}
currentSrc() {
return 'movie.mp4';
}
volume() {
return this.volume_ || 0;
}
muted() {
return false;
}
autoplay() {
return this.options_.autoplay || false;
}
pause() {
return false;
}
paused() {
return true;
}
loop() {
return false;
}
play() {
this.trigger('play');
}
supportsFullScreen() {
return false;
}
buffered() {
return {};
}
duration() {
return {};
}
networkState() {
return 0;
}
readyState() {
return 0;
}
controls() {
return false;
}
ended() {
return false;
}
crossOrigin() {
return null;
}
// Support everything except for "video/unsupported-format"
static isSupported() {
return true;
}
static canPlayType(type) {
return (type !== 'video/unsupported-format' ? 'maybe' : '');
}
static canPlaySource(srcObj) {
return srcObj.type !== 'video/unsupported-format';
}
}
Tech.registerTech('TechFaker', TechFaker);
Broke up Lib and Util into smaller libraries of functions Broke out bind, guid, and element data functions from Lib Separated out more dom functions in to dom.js Broke out URL functions into url.js Removed setLocalStorage since it wasn't being used Moved browser tests out of lib Moved log functions into their own file Removed trim() since it wasn't being used Moved formatTime into its own file Moved round into its own file and renamed roundFloat() Moved capitalize into its own file and renamed as toTitleCase() Moved createTimeRange into its own file Removed Lib.arr.forEach infavor of the native forEach Removed Lib.obj.create in favor of native Object.create (ES6-sham) Removed obj.each in favor of native Object.getOwnPropertyNames().forEach() Removed obj.merge and copy. Using lodash.assign instead. Replaced Lib.obj.isPlain with lodash.isPlainObject Removed Lib.obj.isArray in favor of the native Array.isArray Also removed the lib.js tests file as all tests have been moved or removed. Removed Lib.isEmpty in favor of !Object.getOwnPropertyNames().length Switched Util.mergeOptions and deepMerge to use new mergeOptions() Moved Lib.TEST_VID to Html5.TEST_VID Removed Lib references everywhere. Woo! Attempting to fix sourcemap test errors by setting grunt-browserify version Switched to object.assign from lodash.assign Removed unused 'inherits' dependency Reorganzied test files and added '.test' to file names Combined js/core.js and js/video.js Moved events.js into the utils directory
2015-05-04 01:12:38 +02:00
export default TechFaker;