2015-05-04 01:12:38 +02:00
|
|
|
import Flash from '../../../src/js/tech/flash.js';
|
2015-03-26 06:43:41 +02:00
|
|
|
import document from 'global/document';
|
2013-08-24 01:05:04 +03:00
|
|
|
|
2015-06-08 22:42:39 +02:00
|
|
|
q.module('Flash');
|
2013-08-24 01:05:04 +03:00
|
|
|
|
2015-06-08 22:42:39 +02:00
|
|
|
test('Flash.canPlaySource', function() {
|
2015-03-11 03:01:11 +02:00
|
|
|
var canPlaySource = Flash.canPlaySource;
|
2013-10-29 21:00:54 +03:00
|
|
|
|
2015-06-08 22:42:39 +02:00
|
|
|
// Supported
|
2013-10-29 21:00:54 +03:00
|
|
|
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/x-flv' }), 'video/x-flv supported');
|
|
|
|
ok(canPlaySource({ type: 'video/flv' }), 'video/flv supported');
|
|
|
|
ok(canPlaySource({ type: 'video/m4v' }), 'video/m4v supported');
|
|
|
|
ok(canPlaySource({ type: 'VIDEO/FLV' }), 'capitalized mime type');
|
|
|
|
|
2015-06-08 22:42:39 +02:00
|
|
|
// Not supported
|
2013-10-29 21:00:54 +03:00
|
|
|
ok(!canPlaySource({ type: 'video/webm; codecs="vp8, vorbis"' }));
|
|
|
|
ok(!canPlaySource({ type: 'video/webm' }));
|
|
|
|
});
|
2014-01-24 02:13:22 +03:00
|
|
|
|
2015-06-08 22:42:39 +02:00
|
|
|
test('currentTime', function() {
|
|
|
|
let getCurrentTime = Flash.prototype.currentTime;
|
|
|
|
let setCurrentTime = Flash.prototype.setCurrentTime;
|
|
|
|
let seeking = false;
|
|
|
|
let setPropVal;
|
|
|
|
let getPropVal;
|
|
|
|
let result;
|
|
|
|
|
|
|
|
// Mock out a Flash instance to avoid creating the swf object
|
|
|
|
let mockFlash = {
|
|
|
|
el_: {
|
|
|
|
vjs_setProperty: function(prop, val){
|
|
|
|
setPropVal = val;
|
|
|
|
},
|
|
|
|
vjs_getProperty: function(){
|
|
|
|
return getPropVal;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
seeking: function(){
|
2014-01-24 02:13:22 +03:00
|
|
|
return seeking;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-08 22:42:39 +02:00
|
|
|
// Test the currentTime getter
|
|
|
|
getPropVal = 3;
|
|
|
|
result = getCurrentTime.call(mockFlash);
|
|
|
|
equal(result, 3, 'currentTime is retreived from the swf element');
|
|
|
|
|
|
|
|
// Test the currentTime setter
|
|
|
|
setCurrentTime.call(mockFlash, 10);
|
|
|
|
equal(setPropVal, 10, 'currentTime is set on the swf element');
|
2014-01-24 02:13:22 +03:00
|
|
|
|
2015-06-08 22:42:39 +02:00
|
|
|
// Test current time while seeking
|
|
|
|
setCurrentTime.call(mockFlash, 20);
|
2014-01-24 02:13:22 +03:00
|
|
|
seeking = true;
|
2015-06-08 22:42:39 +02:00
|
|
|
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');
|
2014-01-24 02:13:22 +03:00
|
|
|
});
|
2014-07-17 00:01:01 +03:00
|
|
|
|
2014-07-09 23:08:47 +03:00
|
|
|
test('dispose removes the object element even before ready fires', function() {
|
2015-06-08 22:42:39 +02:00
|
|
|
// This test appears to test bad functionaly that was fixed
|
|
|
|
// so it's debateable whether or not it's useful
|
|
|
|
let dispose = Flash.prototype.dispose;
|
|
|
|
let mockFlash = {};
|
|
|
|
let noop = function(){};
|
|
|
|
|
|
|
|
// Mock required functions for dispose
|
|
|
|
mockFlash.off = noop;
|
|
|
|
mockFlash.trigger = noop;
|
|
|
|
mockFlash.el_ = {};
|
|
|
|
|
|
|
|
dispose.call(mockFlash);
|
|
|
|
strictEqual(mockFlash.el_, null, 'swf el is nulled');
|
2014-07-09 23:08:47 +03:00
|
|
|
});
|
2014-07-29 03:27:29 +03:00
|
|
|
|
2014-07-17 00:01:01 +03:00
|
|
|
test('ready triggering before and after disposing the tech', function() {
|
2015-06-08 22:42:39 +02:00
|
|
|
let checkReady = sinon.stub(Flash, 'checkReady');
|
|
|
|
let fixtureDiv = document.getElementById('qunit-fixture');
|
|
|
|
let playerDiv = document.createElement('div');
|
|
|
|
let techEl = document.createElement('div');
|
2014-07-17 00:01:01 +03:00
|
|
|
|
2015-06-08 22:42:39 +02:00
|
|
|
techEl.id = 'foo1234';
|
2014-07-17 00:01:01 +03:00
|
|
|
playerDiv.appendChild(techEl);
|
|
|
|
fixtureDiv.appendChild(playerDiv);
|
|
|
|
|
2015-06-08 22:42:39 +02:00
|
|
|
// Mock the swf element
|
2015-05-06 20:01:52 +02:00
|
|
|
techEl.tech = {
|
2015-06-08 22:42:39 +02:00
|
|
|
el: function() {
|
|
|
|
return techEl;
|
|
|
|
}
|
2015-05-06 20:01:52 +02:00
|
|
|
};
|
|
|
|
|
2015-06-08 22:42:39 +02:00
|
|
|
playerDiv.player = {
|
2015-05-06 20:01:52 +02:00
|
|
|
tech: techEl.tech
|
2014-07-17 00:01:01 +03:00
|
|
|
};
|
|
|
|
|
2015-06-08 22:42:39 +02:00
|
|
|
Flash.onReady(techEl.id);
|
2014-07-17 00:01:01 +03:00
|
|
|
ok(checkReady.called, 'checkReady should be called before the tech is disposed');
|
|
|
|
|
|
|
|
// remove the tech el from the player div to simulate being disposed
|
|
|
|
playerDiv.removeChild(techEl);
|
2015-06-08 22:42:39 +02:00
|
|
|
Flash.onReady(techEl.id);
|
2014-07-17 00:01:01 +03:00
|
|
|
ok(!checkReady.calledTwice, 'checkReady should not be called after the tech is disposed');
|
|
|
|
|
2015-06-08 22:42:39 +02:00
|
|
|
Flash.checkReady.restore();
|
2014-07-17 00:01:01 +03:00
|
|
|
});
|
2014-12-03 00:22:34 +02:00
|
|
|
|
|
|
|
test('should have the source handler interface', function() {
|
2015-03-11 03:01:11 +02:00
|
|
|
ok(Flash.registerSourceHandler, 'has the registerSourceHandler function');
|
2014-12-03 00:22:34 +02:00
|
|
|
});
|
2015-03-24 20:52:04 +02:00
|
|
|
|
|
|
|
test('canHandleSource should be able to work with src objects without a type', function () {
|
2015-06-08 22:42:39 +02:00
|
|
|
let canHandleSource = Flash.nativeSourceHandler.canHandleSource;
|
2015-06-08 22:47:04 +02:00
|
|
|
|
2015-06-08 22:42:39 +02:00
|
|
|
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.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');
|
2015-06-08 22:47:04 +02:00
|
|
|
});
|
|
|
|
|
2015-06-08 22:42:39 +02:00
|
|
|
test('seekable', function() {
|
|
|
|
let seekable = Flash.prototype.seekable;
|
|
|
|
let result;
|
|
|
|
let mockFlash = {
|
|
|
|
duration: function() {
|
|
|
|
return this.duration_;
|
2015-06-08 22:47:04 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-08 22:42:39 +02:00
|
|
|
// 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');
|
2015-06-08 22:47:04 +02:00
|
|
|
});
|