2013-02-09 01:25:33 +03:00
|
|
|
module('Lib');
|
2012-12-11 03:40:12 +03:00
|
|
|
|
2013-01-11 00:06:12 +03:00
|
|
|
test('should create an element', function(){
|
|
|
|
var div = vjs.createEl();
|
2013-02-09 01:25:33 +03:00
|
|
|
var span = vjs.createEl('span', { 'data-test': 'asdf', innerHTML:'fdsa' });
|
2013-01-11 00:06:12 +03:00
|
|
|
ok(div.nodeName === 'DIV');
|
|
|
|
ok(span.nodeName === 'SPAN');
|
|
|
|
ok(span['data-test'] === 'asdf');
|
2013-02-09 01:25:33 +03:00
|
|
|
ok(span.innerHTML === 'fdsa');
|
2013-01-11 00:06:12 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should make a string start with an uppercase letter', function(){
|
2013-02-09 01:25:33 +03:00
|
|
|
var foo = vjs.capitalize('bar');
|
2013-01-11 00:06:12 +03:00
|
|
|
ok(foo === 'Bar');
|
|
|
|
});
|
2012-12-11 03:40:12 +03:00
|
|
|
|
2013-01-11 00:06:12 +03:00
|
|
|
test('should loop through each property on an object', function(){
|
|
|
|
var asdf = {
|
|
|
|
a: 1,
|
|
|
|
b: 2,
|
|
|
|
'c': 3
|
2013-02-09 01:25:33 +03:00
|
|
|
};
|
2012-12-11 03:40:12 +03:00
|
|
|
|
2013-01-11 00:06:12 +03:00
|
|
|
// Add 3 to each value
|
2013-01-26 04:36:40 +03:00
|
|
|
vjs.obj.each(asdf, function(key, value){
|
2013-01-11 00:06:12 +03:00
|
|
|
asdf[key] = value + 3;
|
|
|
|
});
|
|
|
|
|
2013-02-09 01:25:33 +03:00
|
|
|
deepEqual(asdf,{a:4,b:5,'c':6});
|
2012-12-11 03:40:12 +03:00
|
|
|
});
|
|
|
|
|
2013-01-26 04:36:40 +03:00
|
|
|
test('should copy an object', function(){
|
|
|
|
var asdf = {
|
|
|
|
a: 1,
|
|
|
|
b: 2,
|
|
|
|
'c': 3
|
2013-02-09 01:25:33 +03:00
|
|
|
};
|
2013-01-26 04:36:40 +03:00
|
|
|
|
|
|
|
var fdsa = vjs.obj.copy(asdf);
|
|
|
|
|
2013-02-09 01:25:33 +03:00
|
|
|
deepEqual(asdf,fdsa);
|
2013-01-26 04:36:40 +03:00
|
|
|
});
|
|
|
|
|
2013-04-09 02:23:41 +03:00
|
|
|
test('should check if an object is plain', function(){
|
|
|
|
var empty = {};
|
|
|
|
ok(vjs.obj.isPlain(empty) === true, 'Empty object is plain');
|
|
|
|
|
|
|
|
var node = document.createElement('div');
|
|
|
|
ok(vjs.obj.isPlain(node) === false, 'DOM node is not plain');
|
|
|
|
|
|
|
|
var fn = function(){};
|
|
|
|
ok(vjs.obj.isPlain(fn) === false, 'Function is not plain');
|
|
|
|
});
|
|
|
|
|
2013-01-11 00:06:12 +03:00
|
|
|
test('should add context to a function', function(){
|
|
|
|
var newContext = { test: 'obj'};
|
|
|
|
var asdf = function(){
|
|
|
|
ok(this === newContext);
|
2013-02-09 01:25:33 +03:00
|
|
|
};
|
2013-01-11 00:06:12 +03:00
|
|
|
var fdsa = vjs.bind(newContext, asdf);
|
|
|
|
|
|
|
|
fdsa();
|
2012-12-11 03:40:12 +03:00
|
|
|
});
|
|
|
|
|
2013-01-11 00:06:12 +03:00
|
|
|
test('should add and remove a class name on an element', function(){
|
|
|
|
var el = document.createElement('div');
|
2013-02-09 01:25:33 +03:00
|
|
|
vjs.addClass(el, 'test-class');
|
2013-01-11 00:06:12 +03:00
|
|
|
ok(el.className === 'test-class', 'class added');
|
2013-02-09 01:25:33 +03:00
|
|
|
vjs.addClass(el, 'test-class');
|
2013-01-11 00:06:12 +03:00
|
|
|
ok(el.className === 'test-class', 'same class not duplicated');
|
2013-02-09 01:25:33 +03:00
|
|
|
vjs.addClass(el, 'test-class2');
|
2013-01-11 00:06:12 +03:00
|
|
|
ok(el.className === 'test-class test-class2', 'added second class');
|
2013-02-09 01:25:33 +03:00
|
|
|
vjs.removeClass(el, 'test-class');
|
2013-01-11 00:06:12 +03:00
|
|
|
ok(el.className === 'test-class2', 'removed first class');
|
|
|
|
});
|
2012-12-11 03:40:12 +03:00
|
|
|
|
2013-01-11 00:06:12 +03:00
|
|
|
test('should get and remove data from an element', function(){
|
|
|
|
var el = document.createElement('div');
|
|
|
|
var data = vjs.getData(el);
|
|
|
|
var id = el[vjs.expando];
|
|
|
|
|
|
|
|
ok(typeof data === 'object', 'data object created');
|
|
|
|
|
|
|
|
// Add data
|
|
|
|
var testData = { asdf: 'fdsa' };
|
|
|
|
data.test = testData;
|
|
|
|
ok(vjs.getData(el).test === testData, 'data added');
|
|
|
|
|
|
|
|
// Remove all data
|
|
|
|
vjs.removeData(el);
|
|
|
|
|
2013-02-09 01:25:33 +03:00
|
|
|
ok(!vjs.cache[id], 'cached item nulled');
|
|
|
|
ok(el[vjs.expando] === null || el[vjs.expando] === undefined, 'element data id removed');
|
2012-12-11 03:40:12 +03:00
|
|
|
});
|
|
|
|
|
2013-01-11 00:06:12 +03:00
|
|
|
test('should read tag attributes from elements, including HTML5 in all browsers', function(){
|
|
|
|
var tags = '<video id="vid1" controls autoplay loop muted preload="none" src="http://google.com" poster="http://www2.videojs.com/img/video-js-html5-video-player.png" data-test="asdf" data-empty-string=""></video>';
|
|
|
|
tags += '<video id="vid2">';
|
|
|
|
// Not putting source and track inside video element because
|
|
|
|
// oldIE needs the HTML5 shim to read tags inside HTML5 tags.
|
|
|
|
// Still may not work in oldIE.
|
|
|
|
tags += '<source id="source" src="http://google.com" type="video/mp4" media="fdsa" title="test" >';
|
|
|
|
tags += '<track id="track" default src="http://google.com" kind="captions" srclang="en" label="testlabel" title="test" >';
|
2013-04-13 02:51:04 +03:00
|
|
|
tags += '</video>';
|
|
|
|
|
|
|
|
document.getElementById('qunit-fixture').innerHTML += tags;
|
2013-01-11 00:06:12 +03:00
|
|
|
|
|
|
|
var vid1Vals = vjs.getAttributeValues(document.getElementById('vid1'));
|
|
|
|
var vid2Vals = vjs.getAttributeValues(document.getElementById('vid2'));
|
|
|
|
var sourceVals = vjs.getAttributeValues(document.getElementById('source'));
|
|
|
|
var trackVals = vjs.getAttributeValues(document.getElementById('track'));
|
|
|
|
|
2013-02-09 01:25:33 +03:00
|
|
|
deepEqual(vid1Vals, { 'autoplay': true, 'controls': true, 'data-test': 'asdf', 'data-empty-string': '', 'id': 'vid1', 'loop': true, 'muted': true, 'poster': 'http://www2.videojs.com/img/video-js-html5-video-player.png', 'preload': 'none', 'src': 'http://google.com' });
|
|
|
|
deepEqual(vid2Vals, { 'id': 'vid2' });
|
|
|
|
deepEqual(sourceVals, {'title': 'test', 'media': 'fdsa', 'type': 'video/mp4', 'src': 'http://google.com', 'id': 'source' });
|
|
|
|
deepEqual(trackVals, { 'default': true, /* IE no likey default key */ 'id': 'track', 'kind': 'captions', 'label': 'testlabel', 'src': 'http://google.com', 'srclang': 'en', 'title': 'test' });
|
2013-01-11 00:06:12 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should get the right style values for an element', function(){
|
2012-12-11 03:40:12 +03:00
|
|
|
var el = document.createElement('div');
|
2013-01-11 00:06:12 +03:00
|
|
|
var container = document.createElement('div');
|
2013-02-09 01:25:33 +03:00
|
|
|
var fixture = document.getElementById('qunit-fixture');
|
2013-01-11 00:06:12 +03:00
|
|
|
|
|
|
|
container.appendChild(el);
|
|
|
|
fixture.appendChild(container);
|
|
|
|
|
2013-02-09 01:25:33 +03:00
|
|
|
container.style.width = '1000px';
|
|
|
|
container.style.height = '1000px';
|
2012-12-11 03:40:12 +03:00
|
|
|
|
2013-02-09 01:25:33 +03:00
|
|
|
el.style.height = '100%';
|
|
|
|
el.style.width = '123px';
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2013-08-23 21:16:53 +03:00
|
|
|
// integer px values may get translated int very-close floats in Chrome/OS X
|
|
|
|
// so round the dimensions to ignore this
|
|
|
|
equal(Math.round(parseFloat(vjs.getComputedDimension(el, 'height'))), 1000, 'the computed height is equal');
|
|
|
|
equal(Math.round(parseFloat(vjs.getComputedDimension(el, 'width'))), 123, 'the computed width is equal');
|
2012-12-11 03:40:12 +03:00
|
|
|
});
|
|
|
|
|
2013-01-11 00:06:12 +03:00
|
|
|
test('should insert an element first in another', function(){
|
|
|
|
var el1 = document.createElement('div');
|
|
|
|
var el2 = document.createElement('div');
|
|
|
|
var parent = document.createElement('div');
|
|
|
|
|
2013-02-09 01:25:33 +03:00
|
|
|
vjs.insertFirst(el1, parent);
|
2013-01-11 00:06:12 +03:00
|
|
|
ok(parent.firstChild === el1, 'inserts first into empty parent');
|
|
|
|
|
2013-02-09 01:25:33 +03:00
|
|
|
vjs.insertFirst(el2, parent);
|
2013-01-11 00:06:12 +03:00
|
|
|
ok(parent.firstChild === el2, 'inserts first into parent with child');
|
2012-12-11 03:40:12 +03:00
|
|
|
});
|
|
|
|
|
2013-01-11 00:06:12 +03:00
|
|
|
test('should return the element with the ID', function(){
|
|
|
|
var el1 = document.createElement('div');
|
|
|
|
var el2 = document.createElement('div');
|
|
|
|
var fixture = document.getElementById('qunit-fixture');
|
|
|
|
|
|
|
|
fixture.appendChild(el1);
|
|
|
|
fixture.appendChild(el2);
|
|
|
|
|
|
|
|
el1.id = 'test_id1';
|
|
|
|
el2.id = 'test_id2';
|
|
|
|
|
2013-02-09 01:25:33 +03:00
|
|
|
ok(vjs.el('test_id1') === el1, 'found element for ID');
|
|
|
|
ok(vjs.el('#test_id2') === el2, 'found element for CSS ID');
|
2012-12-11 03:40:12 +03:00
|
|
|
});
|
|
|
|
|
2013-01-11 00:06:12 +03:00
|
|
|
test('should trim whitespace from a string', function(){
|
|
|
|
ok(vjs.trim(' asdf asdf asdf \t\n\r') === 'asdf asdf asdf');
|
2012-12-11 03:40:12 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should round a number', function(){
|
2013-01-11 00:06:12 +03:00
|
|
|
ok(vjs.round(1.01) === 1);
|
|
|
|
ok(vjs.round(1.5) === 2);
|
|
|
|
ok(vjs.round(1.55, 2) === 1.55);
|
|
|
|
ok(vjs.round(10.551, 2) === 10.55);
|
2012-12-11 03:40:12 +03:00
|
|
|
});
|
|
|
|
|
2013-01-11 00:06:12 +03:00
|
|
|
test('should format time as a string', function(){
|
2013-02-09 01:25:33 +03:00
|
|
|
ok(vjs.formatTime(1) === '0:01');
|
|
|
|
ok(vjs.formatTime(10) === '0:10');
|
|
|
|
ok(vjs.formatTime(60) === '1:00');
|
|
|
|
ok(vjs.formatTime(600) === '10:00');
|
|
|
|
ok(vjs.formatTime(3600) === '1:00:00');
|
|
|
|
ok(vjs.formatTime(36000) === '10:00:00');
|
|
|
|
ok(vjs.formatTime(360000) === '100:00:00');
|
2013-01-11 00:06:12 +03:00
|
|
|
|
|
|
|
// Using guide should provide extra leading zeros
|
2013-02-09 01:25:33 +03:00
|
|
|
ok(vjs.formatTime(1,1) === '0:01');
|
|
|
|
ok(vjs.formatTime(1,10) === '0:01');
|
|
|
|
ok(vjs.formatTime(1,60) === '0:01');
|
|
|
|
ok(vjs.formatTime(1,600) === '00:01');
|
|
|
|
ok(vjs.formatTime(1,3600) === '0:00:01');
|
2013-01-11 00:06:12 +03:00
|
|
|
// Don't do extra leading zeros for hours
|
2013-02-09 01:25:33 +03:00
|
|
|
ok(vjs.formatTime(1,36000) === '0:00:01');
|
|
|
|
ok(vjs.formatTime(1,360000) === '0:00:01');
|
2012-12-11 03:40:12 +03:00
|
|
|
});
|
|
|
|
|
2013-08-27 02:13:54 +03:00
|
|
|
test('should format invalid times as dashes', function(){
|
|
|
|
equal(vjs.formatTime(Infinity, 90), '-:-');
|
|
|
|
equal(vjs.formatTime(NaN), '-:-');
|
2013-08-27 02:23:33 +03:00
|
|
|
// equal(vjs.formatTime(NaN, 216000), '-:--:--');
|
2013-08-27 02:13:54 +03:00
|
|
|
equal(vjs.formatTime(10, Infinity), '0:00:10');
|
|
|
|
equal(vjs.formatTime(90, NaN), '1:30');
|
|
|
|
});
|
|
|
|
|
2012-12-11 03:40:12 +03:00
|
|
|
test('should create a fake timerange', function(){
|
2013-01-11 00:06:12 +03:00
|
|
|
var tr = vjs.createTimeRange(0, 10);
|
2012-12-11 03:40:12 +03:00
|
|
|
ok(tr.start() === 0);
|
2013-01-11 00:06:12 +03:00
|
|
|
ok(tr.end() === 10);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should get an absolute URL', function(){
|
|
|
|
// Errors on compiled tests that don't use unit.html. Need a better solution.
|
|
|
|
// ok(vjs.getAbsoluteURL('unit.html') === window.location.href);
|
2013-02-09 01:25:33 +03:00
|
|
|
ok(vjs.getAbsoluteURL('http://asdf.com') === 'http://asdf.com');
|
|
|
|
ok(vjs.getAbsoluteURL('https://asdf.com/index.html') === 'https://asdf.com/index.html');
|
2013-01-01 02:25:56 +03:00
|
|
|
});
|
2013-05-01 19:03:10 +03:00
|
|
|
|
|
|
|
test('vjs.findPosition should find top and left position', function() {
|
|
|
|
var d = document.createElement('div'),
|
|
|
|
position = vjs.findPosition(d);
|
2013-05-01 20:02:05 +03:00
|
|
|
d.style.top = '10px';
|
|
|
|
d.style.left = '20px';
|
|
|
|
d.style.position = 'absolute';
|
2013-05-01 19:03:10 +03:00
|
|
|
|
2013-05-01 20:02:05 +03:00
|
|
|
deepEqual(position, {left: 0, top: 0}, 'If element isn\'t in the DOM, we should get zeros');
|
2013-05-01 19:03:10 +03:00
|
|
|
|
|
|
|
document.body.appendChild(d);
|
|
|
|
position = vjs.findPosition(d);
|
2013-05-01 20:02:05 +03:00
|
|
|
deepEqual(position, {left: 20, top: 10}, 'The position was not correct');
|
2013-05-01 19:03:10 +03:00
|
|
|
|
|
|
|
d.getBoundingClientRect = null;
|
|
|
|
position = vjs.findPosition(d);
|
2013-05-01 20:02:05 +03:00
|
|
|
deepEqual(position, {left: 0, top: 0}, 'If there is no gBCR, we should get zeros');
|
|
|
|
});
|