mirror of
https://github.com/videojs/video.js.git
synced 2025-01-13 10:32:26 +02:00
Removed swf creation from tests
- Broke out RTMP tests into their own file. - Cleaned up the currentTime test to not create the swf - Cleaned up the flash dispose test - Cleaned up formatting for additional flash tests --skip-ci
This commit is contained in:
parent
ffe7c32899
commit
05b6bb2ae4
50
test/unit/tech/flash-rtmp.test.js
Normal file
50
test/unit/tech/flash-rtmp.test.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import Flash from '../../../src/js/tech/flash.js';
|
||||||
|
|
||||||
|
q.module('Flash RTMP');
|
||||||
|
|
||||||
|
var streamToPartsAndBack = function(url) {
|
||||||
|
var parts = Flash.streamToParts(url);
|
||||||
|
return Flash.streamFromParts(parts.connection, parts.stream);
|
||||||
|
};
|
||||||
|
|
||||||
|
test('test using both streamToParts and streamFromParts', function() {
|
||||||
|
ok('rtmp://myurl.com/&isthis' === streamToPartsAndBack('rtmp://myurl.com/isthis'));
|
||||||
|
ok('rtmp://myurl.com/&isthis' === streamToPartsAndBack('rtmp://myurl.com/&isthis'));
|
||||||
|
ok('rtmp://myurl.com/isthis/&andthis' === streamToPartsAndBack('rtmp://myurl.com/isthis/andthis'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('test streamToParts', function() {
|
||||||
|
var parts = Flash.streamToParts('http://myurl.com/streaming&/is/fun');
|
||||||
|
ok(parts.connection === 'http://myurl.com/streaming');
|
||||||
|
ok(parts.stream === '/is/fun');
|
||||||
|
|
||||||
|
parts = Flash.streamToParts('http://myurl.com/&streaming&/is/fun');
|
||||||
|
ok(parts.connection === 'http://myurl.com/');
|
||||||
|
ok(parts.stream === 'streaming&/is/fun');
|
||||||
|
|
||||||
|
parts = Flash.streamToParts('http://myurl.com/streaming/is/fun');
|
||||||
|
ok(parts.connection === 'http://myurl.com/streaming/is/');
|
||||||
|
ok(parts.stream === 'fun');
|
||||||
|
|
||||||
|
parts = Flash.streamToParts('whatisgoingonhere');
|
||||||
|
ok(parts.connection === 'whatisgoingonhere');
|
||||||
|
ok(parts.stream === '');
|
||||||
|
|
||||||
|
parts = Flash.streamToParts();
|
||||||
|
ok(parts.connection === '');
|
||||||
|
ok(parts.stream === '');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('test isStreamingSrc', function() {
|
||||||
|
var isStreamingSrc = Flash.isStreamingSrc;
|
||||||
|
ok(isStreamingSrc('rtmp://streaming.is/fun'));
|
||||||
|
ok(isStreamingSrc('rtmps://streaming.is/fun'));
|
||||||
|
ok(isStreamingSrc('rtmpe://streaming.is/fun'));
|
||||||
|
ok(isStreamingSrc('rtmpt://streaming.is/fun'));
|
||||||
|
// test invalid protocols
|
||||||
|
ok(!isStreamingSrc('rtmp:streaming.is/fun'));
|
||||||
|
ok(!isStreamingSrc('rtmpz://streaming.is/fun'));
|
||||||
|
ok(!isStreamingSrc('http://streaming.is/fun'));
|
||||||
|
ok(!isStreamingSrc('https://streaming.is/fun'));
|
||||||
|
ok(!isStreamingSrc('file://streaming.is/fun'));
|
||||||
|
});
|
@ -1,68 +1,12 @@
|
|||||||
import Flash from '../../../src/js/tech/flash.js';
|
import Flash from '../../../src/js/tech/flash.js';
|
||||||
import document from 'global/document';
|
import document from 'global/document';
|
||||||
|
|
||||||
let tech;
|
q.module('Flash');
|
||||||
|
|
||||||
q.module('Flash', {
|
test('Flash.canPlaySource', function() {
|
||||||
setup() {
|
|
||||||
tech = new Flash({});
|
|
||||||
},
|
|
||||||
teardown() {
|
|
||||||
tech.dispose();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var streamToPartsAndBack = function(url) {
|
|
||||||
var parts = Flash.streamToParts(url);
|
|
||||||
return Flash.streamFromParts(parts.connection, parts.stream);
|
|
||||||
};
|
|
||||||
|
|
||||||
test('test using both streamToParts and streamFromParts', function() {
|
|
||||||
ok('rtmp://myurl.com/&isthis' === streamToPartsAndBack('rtmp://myurl.com/isthis'));
|
|
||||||
ok('rtmp://myurl.com/&isthis' === streamToPartsAndBack('rtmp://myurl.com/&isthis'));
|
|
||||||
ok('rtmp://myurl.com/isthis/&andthis' === streamToPartsAndBack('rtmp://myurl.com/isthis/andthis'));
|
|
||||||
});
|
|
||||||
|
|
||||||
test('test streamToParts', function() {
|
|
||||||
var parts = Flash.streamToParts('http://myurl.com/streaming&/is/fun');
|
|
||||||
ok(parts.connection === 'http://myurl.com/streaming');
|
|
||||||
ok(parts.stream === '/is/fun');
|
|
||||||
|
|
||||||
parts = Flash.streamToParts('http://myurl.com/&streaming&/is/fun');
|
|
||||||
ok(parts.connection === 'http://myurl.com/');
|
|
||||||
ok(parts.stream === 'streaming&/is/fun');
|
|
||||||
|
|
||||||
parts = Flash.streamToParts('http://myurl.com/streaming/is/fun');
|
|
||||||
ok(parts.connection === 'http://myurl.com/streaming/is/');
|
|
||||||
ok(parts.stream === 'fun');
|
|
||||||
|
|
||||||
parts = Flash.streamToParts('whatisgoingonhere');
|
|
||||||
ok(parts.connection === 'whatisgoingonhere');
|
|
||||||
ok(parts.stream === '');
|
|
||||||
|
|
||||||
parts = Flash.streamToParts();
|
|
||||||
ok(parts.connection === '');
|
|
||||||
ok(parts.stream === '');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('test isStreamingSrc', function() {
|
|
||||||
var isStreamingSrc = Flash.isStreamingSrc;
|
|
||||||
ok(isStreamingSrc('rtmp://streaming.is/fun'));
|
|
||||||
ok(isStreamingSrc('rtmps://streaming.is/fun'));
|
|
||||||
ok(isStreamingSrc('rtmpe://streaming.is/fun'));
|
|
||||||
ok(isStreamingSrc('rtmpt://streaming.is/fun'));
|
|
||||||
// test invalid protocols
|
|
||||||
ok(!isStreamingSrc('rtmp:streaming.is/fun'));
|
|
||||||
ok(!isStreamingSrc('rtmpz://streaming.is/fun'));
|
|
||||||
ok(!isStreamingSrc('http://streaming.is/fun'));
|
|
||||||
ok(!isStreamingSrc('https://streaming.is/fun'));
|
|
||||||
ok(!isStreamingSrc('file://streaming.is/fun'));
|
|
||||||
});
|
|
||||||
|
|
||||||
test('test canPlaySource', function() {
|
|
||||||
var canPlaySource = Flash.canPlaySource;
|
var canPlaySource = Flash.canPlaySource;
|
||||||
|
|
||||||
// supported
|
// Supported
|
||||||
ok(canPlaySource({ type: 'video/mp4; codecs=avc1.42E01E,mp4a.40.2' }), 'codecs supported');
|
ok(canPlaySource({ type: 'video/mp4; codecs=avc1.42E01E,mp4a.40.2' }), 'codecs supported');
|
||||||
ok(canPlaySource({ type: 'video/mp4' }), 'video/mp4 supported');
|
ok(canPlaySource({ type: 'video/mp4' }), 'video/mp4 supported');
|
||||||
ok(canPlaySource({ type: 'video/x-flv' }), 'video/x-flv supported');
|
ok(canPlaySource({ type: 'video/x-flv' }), 'video/x-flv supported');
|
||||||
@ -70,109 +14,97 @@ test('test canPlaySource', function() {
|
|||||||
ok(canPlaySource({ type: 'video/m4v' }), 'video/m4v supported');
|
ok(canPlaySource({ type: 'video/m4v' }), 'video/m4v supported');
|
||||||
ok(canPlaySource({ type: 'VIDEO/FLV' }), 'capitalized mime type');
|
ok(canPlaySource({ type: 'VIDEO/FLV' }), 'capitalized mime type');
|
||||||
|
|
||||||
// not supported
|
// Not supported
|
||||||
ok(!canPlaySource({ type: 'video/webm; codecs="vp8, vorbis"' }));
|
ok(!canPlaySource({ type: 'video/webm; codecs="vp8, vorbis"' }));
|
||||||
ok(!canPlaySource({ type: 'video/webm' }));
|
ok(!canPlaySource({ type: 'video/webm' }));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('currentTime is the seek target during seeking', function() {
|
test('currentTime', function() {
|
||||||
var noop = function() {},
|
let getCurrentTime = Flash.prototype.currentTime;
|
||||||
seeking = false,
|
let setCurrentTime = Flash.prototype.setCurrentTime;
|
||||||
parentEl = document.createElement('div'),
|
let seeking = false;
|
||||||
tech = new Flash({
|
let setPropVal;
|
||||||
id: noop,
|
let getPropVal;
|
||||||
bufferedPercent: noop,
|
let result;
|
||||||
on: noop,
|
|
||||||
trigger: noop,
|
|
||||||
ready: noop,
|
|
||||||
addChild: noop,
|
|
||||||
options_: {},
|
|
||||||
// This complexity is needed because of the VTT.js loading
|
|
||||||
// It'd be great if we can find a better solution for that
|
|
||||||
options: function(){ return {}; },
|
|
||||||
el: function(){
|
|
||||||
return {
|
|
||||||
appendChild: noop
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
'parentEl': parentEl
|
|
||||||
}),
|
|
||||||
currentTime;
|
|
||||||
|
|
||||||
tech.el().vjs_setProperty = function(property, value) {
|
// Mock out a Flash instance to avoid creating the swf object
|
||||||
if (property === 'currentTime') {
|
let mockFlash = {
|
||||||
currentTime = value;
|
el_: {
|
||||||
}
|
vjs_setProperty: function(prop, val){
|
||||||
};
|
setPropVal = val;
|
||||||
tech.el().vjs_getProperty = function(name) {
|
},
|
||||||
if (name === 'currentTime') {
|
vjs_getProperty: function(){
|
||||||
return currentTime;
|
return getPropVal;
|
||||||
} else if (name === 'seeking') {
|
}
|
||||||
|
},
|
||||||
|
seeking: function(){
|
||||||
return seeking;
|
return seeking;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
currentTime = 3;
|
// Test the currentTime getter
|
||||||
strictEqual(3, tech.currentTime(), 'currentTime is retreived from the SWF');
|
getPropVal = 3;
|
||||||
|
result = getCurrentTime.call(mockFlash);
|
||||||
|
equal(result, 3, 'currentTime is retreived from the swf element');
|
||||||
|
|
||||||
tech['setCurrentTime'](7);
|
// Test the currentTime setter
|
||||||
|
setCurrentTime.call(mockFlash, 10);
|
||||||
|
equal(setPropVal, 10, 'currentTime is set on the swf element');
|
||||||
|
|
||||||
|
// Test current time while seeking
|
||||||
|
setCurrentTime.call(mockFlash, 20);
|
||||||
seeking = true;
|
seeking = true;
|
||||||
strictEqual(7, tech.currentTime(), 'during seeks the target time is returned');
|
result = getCurrentTime.call(mockFlash);
|
||||||
|
equal(result, 20, 'currentTime is retrieved from the lastSeekTarget while seeking');
|
||||||
|
notEqual(result, getPropVal, 'currentTime is not retrieved from the element while seeking');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('dispose removes the object element even before ready fires', function() {
|
test('dispose removes the object element even before ready fires', function() {
|
||||||
var noop = function() {},
|
// This test appears to test bad functionaly that was fixed
|
||||||
parentEl = document.createElement('div'),
|
// so it's debateable whether or not it's useful
|
||||||
tech = new Flash({
|
let dispose = Flash.prototype.dispose;
|
||||||
id: noop,
|
let mockFlash = {};
|
||||||
on: noop,
|
let noop = function(){};
|
||||||
off: noop,
|
|
||||||
trigger: noop,
|
|
||||||
ready: noop,
|
|
||||||
addChild: noop,
|
|
||||||
options: function(){ return {}; },
|
|
||||||
options_: {}
|
|
||||||
}, {
|
|
||||||
'parentEl': parentEl
|
|
||||||
});
|
|
||||||
|
|
||||||
tech.dispose();
|
// Mock required functions for dispose
|
||||||
strictEqual(tech.el(), null, 'tech el is null');
|
mockFlash.off = noop;
|
||||||
strictEqual(parentEl.children.length, 0, 'parent el is empty');
|
mockFlash.trigger = noop;
|
||||||
|
mockFlash.el_ = {};
|
||||||
|
|
||||||
|
dispose.call(mockFlash);
|
||||||
|
strictEqual(mockFlash.el_, null, 'swf el is nulled');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('ready triggering before and after disposing the tech', function() {
|
test('ready triggering before and after disposing the tech', function() {
|
||||||
var checkReady, fixtureDiv, playerDiv, techEl;
|
let checkReady = sinon.stub(Flash, 'checkReady');
|
||||||
|
let fixtureDiv = document.getElementById('qunit-fixture');
|
||||||
checkReady = sinon.stub(Flash, 'checkReady');
|
let playerDiv = document.createElement('div');
|
||||||
|
let techEl = document.createElement('div');
|
||||||
fixtureDiv = document.getElementById('qunit-fixture');
|
|
||||||
playerDiv = document.createElement('div');
|
|
||||||
techEl = document.createElement('div');
|
|
||||||
|
|
||||||
|
techEl.id = 'foo1234';
|
||||||
playerDiv.appendChild(techEl);
|
playerDiv.appendChild(techEl);
|
||||||
fixtureDiv.appendChild(playerDiv);
|
fixtureDiv.appendChild(playerDiv);
|
||||||
|
|
||||||
techEl.id = 'foo1234';
|
// Mock the swf element
|
||||||
|
|
||||||
techEl.tech = {
|
techEl.tech = {
|
||||||
el() { return techEl; }
|
el: function() {
|
||||||
|
return techEl;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
playerDiv['player'] = {
|
playerDiv.player = {
|
||||||
tech: techEl.tech
|
tech: techEl.tech
|
||||||
};
|
};
|
||||||
|
|
||||||
Flash['onReady'](techEl.id);
|
Flash.onReady(techEl.id);
|
||||||
ok(checkReady.called, 'checkReady should be called before the tech is disposed');
|
ok(checkReady.called, 'checkReady should be called before the tech is disposed');
|
||||||
|
|
||||||
// remove the tech el from the player div to simulate being disposed
|
// remove the tech el from the player div to simulate being disposed
|
||||||
playerDiv.removeChild(techEl);
|
playerDiv.removeChild(techEl);
|
||||||
Flash['onReady'](techEl.id);
|
Flash.onReady(techEl.id);
|
||||||
ok(!checkReady.calledTwice, 'checkReady should not be called after the tech is disposed');
|
ok(!checkReady.calledTwice, 'checkReady should not be called after the tech is disposed');
|
||||||
|
|
||||||
Flash['checkReady'].restore();
|
Flash.checkReady.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should have the source handler interface', function() {
|
test('should have the source handler interface', function() {
|
||||||
@ -180,34 +112,32 @@ test('should have the source handler interface', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('canHandleSource should be able to work with src objects without a type', function () {
|
test('canHandleSource should be able to work with src objects without a type', function () {
|
||||||
var canHandleSource = Flash.nativeSourceHandler.canHandleSource;
|
let canHandleSource = Flash.nativeSourceHandler.canHandleSource;
|
||||||
equal('maybe', canHandleSource({src: 'test.video.mp4'}), 'should guess that it is a mp4 video');
|
|
||||||
equal('maybe', canHandleSource({src: 'test.video.m4v'}), 'should guess that it is a m4v video');
|
equal('maybe', canHandleSource({ src: 'test.video.mp4' }), 'should guess that it is a mp4 video');
|
||||||
equal('maybe', canHandleSource({src: 'test.video.flv'}), 'should guess that it is a flash video');
|
equal('maybe', canHandleSource({ src: 'test.video.m4v' }), 'should guess that it is a m4v video');
|
||||||
equal('', canHandleSource({src: 'test.video.wgg'}), 'should return empty string if it can not play the video');
|
equal('maybe', canHandleSource({ src: 'test.video.flv' }), 'should guess that it is a flash video');
|
||||||
|
equal('', canHandleSource({ src: 'test.video.wgg' }), 'should return empty string if it can not play the video');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('seekable should be for the length of the loaded video', function() {
|
test('seekable', function() {
|
||||||
let duration = 23;
|
let seekable = Flash.prototype.seekable;
|
||||||
|
let result;
|
||||||
// mock out duration
|
let mockFlash = {
|
||||||
tech.el().vjs_getProperty = function(name) {
|
duration: function() {
|
||||||
if (name === 'duration') {
|
return this.duration_;
|
||||||
return duration;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
equal(tech.seekable().length, 1, 'seekable is non-empty');
|
|
||||||
equal(tech.seekable().start(0), 0, 'starts at zero');
|
|
||||||
equal(tech.seekable().end(0), duration, 'ends at the duration');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('seekable should be empty if no video is loaded', function() {
|
|
||||||
// mock out duration
|
|
||||||
tech.el().vjs_getProperty = function(name) {
|
|
||||||
if (name === 'duration') {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
equal(tech.seekable().length, 0, 'seekable is empty');
|
// Test a normal duration
|
||||||
|
mockFlash.duration_ = 23;
|
||||||
|
result = seekable.call(mockFlash);
|
||||||
|
equal(result.length, 1, 'seekable is non-empty');
|
||||||
|
equal(result.start(0), 0, 'starts at zero');
|
||||||
|
equal(result.end(0), mockFlash.duration_, 'ends at the duration');
|
||||||
|
|
||||||
|
// Test a zero duration
|
||||||
|
mockFlash.duration_ = 0;
|
||||||
|
result = seekable.call(mockFlash);
|
||||||
|
equal(result.length, mockFlash.duration_, 'seekable is empty with a zero duration');
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user