mirror of
https://github.com/videojs/video.js.git
synced 2024-12-27 02:43:45 +02:00
Updated tests to include unit and integration tests.
This commit is contained in:
parent
b4b4d55767
commit
e07f9172fa
12
.jshintrc
Normal file
12
.jshintrc
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"validthis": true,
|
||||
"laxcomma" : true,
|
||||
"laxbreak" : true,
|
||||
"browser" : true,
|
||||
"eqnull" : true,
|
||||
"debug" : true,
|
||||
"devel" : true,
|
||||
"boss" : true,
|
||||
"expr" : true,
|
||||
"asi" : true
|
||||
}
|
42
test/integration.html
Normal file
42
test/integration.html
Normal file
@ -0,0 +1,42 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Video.js Test Suite</title>
|
||||
|
||||
<!-- QUnit -->
|
||||
<link rel="stylesheet" href="vendor/qunit/qunit/qunit.css" />
|
||||
<script src="vendor/qunit/qunit/qunit.js"></script>
|
||||
|
||||
<!-- Video.js CSS -->
|
||||
<link rel="stylesheet" href="../design/video-js.css" type="text/css">
|
||||
|
||||
<!-- Video.js JavaScript -->
|
||||
<script src='../src/core.js'></script>
|
||||
<script src='../src/lib.js'></script>
|
||||
<script src='../src/component.js'></script>
|
||||
<script src='../src/controls.js'></script>
|
||||
<script src='../src/events.js'></script>
|
||||
<script src='../src/json.js'></script>
|
||||
<script src='../src/player.js'></script>
|
||||
<script src='../src/tech.js'></script>
|
||||
<script src='../src/tracks.js'></script>
|
||||
|
||||
<script src='../tech/html5/html5.js'></script>
|
||||
<script src='../tech/flash/flash.js'></script>
|
||||
|
||||
<script src='../src/setup.js'></script>
|
||||
|
||||
<!-- Integration Tests -->
|
||||
<script src="integration/test.js"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<h1 id="qunit-header">Bootstrap Plugin Test Suite</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture"></div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -43,7 +43,7 @@ function createVideoTag(id){
|
||||
|
||||
function playerSetup(){
|
||||
|
||||
_V_.el("player_box").appendChild(createVideoTag())
|
||||
_V_.el("qunit-fixture").appendChild(createVideoTag())
|
||||
|
||||
var vid = document.getElementById("vid1");
|
||||
this.player = _V_(vid);
|
||||
@ -137,107 +137,107 @@ test("Paused", 2, function() {
|
||||
this.player.play();
|
||||
});
|
||||
|
||||
test("currentTime()", 1, function() {
|
||||
stop();
|
||||
// test("currentTime()", 1, function() {
|
||||
// stop();
|
||||
|
||||
// Try for 3 time updates, sometimes it updates at 0 seconds.
|
||||
// var tries = 0;
|
||||
// // Try for 3 time updates, sometimes it updates at 0 seconds.
|
||||
// // var tries = 0;
|
||||
|
||||
// Can't rely on just time update because it's faked for Flash.
|
||||
this.player.one("loadeddata", _V_.proxy(this, function(){
|
||||
// // Can't rely on just time update because it's faked for Flash.
|
||||
// this.player.one("loadeddata", _V_.proxy(this, function(){
|
||||
|
||||
this.player.addEvent("timeupdate", _V_.proxy(this, function(){
|
||||
// this.player.addEvent("timeupdate", _V_.proxy(this, function(){
|
||||
|
||||
if (this.player.currentTime() > 0) {
|
||||
ok(true, "Time is greater than 0.");
|
||||
start();
|
||||
} else {
|
||||
// tries++;
|
||||
}
|
||||
// if (this.player.currentTime() > 0) {
|
||||
// ok(true, "Time is greater than 0.");
|
||||
// start();
|
||||
// } else {
|
||||
// // tries++;
|
||||
// }
|
||||
|
||||
// if (tries >= 3) {
|
||||
// start();
|
||||
// }
|
||||
}));
|
||||
// // if (tries >= 3) {
|
||||
// // start();
|
||||
// // }
|
||||
// }));
|
||||
|
||||
}));
|
||||
// }));
|
||||
|
||||
this.player.play();
|
||||
});
|
||||
// this.player.play();
|
||||
// });
|
||||
|
||||
|
||||
test("currentTime(seconds)", 2, function() {
|
||||
stop();
|
||||
// test("currentTime(seconds)", 2, function() {
|
||||
// stop();
|
||||
|
||||
// var afterPlayback = _V_.proxy(this, function(){
|
||||
// this.player.currentTime(this.player.duration() / 2);
|
||||
//
|
||||
// this.player.addEvent("timeupdate", _V_.proxy(this, function(){
|
||||
// ok(this.player.currentTime() > 0, "Time is greater than 0.");
|
||||
//
|
||||
// this.player.pause();
|
||||
//
|
||||
// this.player.addEvent("timeupdate", _V_.proxy(this, function(){
|
||||
// ok(this.player.currentTime() == 0, "Time is 0.");
|
||||
// start();
|
||||
// }));
|
||||
//
|
||||
// this.player.currentTime(0);
|
||||
// }));
|
||||
// });
|
||||
// // var afterPlayback = _V_.proxy(this, function(){
|
||||
// // this.player.currentTime(this.player.duration() / 2);
|
||||
// //
|
||||
// // this.player.addEvent("timeupdate", _V_.proxy(this, function(){
|
||||
// // ok(this.player.currentTime() > 0, "Time is greater than 0.");
|
||||
// //
|
||||
// // this.player.pause();
|
||||
// //
|
||||
// // this.player.addEvent("timeupdate", _V_.proxy(this, function(){
|
||||
// // ok(this.player.currentTime() == 0, "Time is 0.");
|
||||
// // start();
|
||||
// // }));
|
||||
// //
|
||||
// // this.player.currentTime(0);
|
||||
// // }));
|
||||
// // });
|
||||
|
||||
// Wait for Source to be ready.
|
||||
this.player.one("loadeddata", _V_.proxy(this, function(){
|
||||
// // Wait for Source to be ready.
|
||||
// this.player.one("loadeddata", _V_.proxy(this, function(){
|
||||
|
||||
_V_.log("loadeddata", this.player);
|
||||
this.player.currentTime(this.player.duration() - 1);
|
||||
// _V_.log("loadeddata", this.player);
|
||||
// this.player.currentTime(this.player.duration() - 1);
|
||||
|
||||
}));
|
||||
// }));
|
||||
|
||||
this.player.one("seeked", _V_.proxy(this, function(){
|
||||
// this.player.one("seeked", _V_.proxy(this, function(){
|
||||
|
||||
_V_.log("seeked", this.player.currentTime())
|
||||
ok(this.player.currentTime() > 1, "Time is greater than 1.");
|
||||
// _V_.log("seeked", this.player.currentTime())
|
||||
// ok(this.player.currentTime() > 1, "Time is greater than 1.");
|
||||
|
||||
this.player.one("seeked", _V_.proxy(this, function(){
|
||||
// this.player.one("seeked", _V_.proxy(this, function(){
|
||||
|
||||
_V_.log("seeked2", this.player.currentTime())
|
||||
// _V_.log("seeked2", this.player.currentTime())
|
||||
|
||||
ok(this.player.currentTime() <= 1, "Time is less than 1.");
|
||||
start();
|
||||
// ok(this.player.currentTime() <= 1, "Time is less than 1.");
|
||||
// start();
|
||||
|
||||
}));
|
||||
// }));
|
||||
|
||||
this.player.currentTime(0);
|
||||
// this.player.currentTime(0);
|
||||
|
||||
}));
|
||||
// }));
|
||||
|
||||
|
||||
this.player.play();
|
||||
// this.player.play();
|
||||
|
||||
// this.player.one("timeupdate", _V_.proxy(this, function(){
|
||||
//
|
||||
// this.player.currentTime(this.player.duration() / 2);
|
||||
//
|
||||
// this.player.one("timeupdate", _V_.proxy(this, function(){
|
||||
// ok(this.player.currentTime() > 0, "Time is greater than 0.");
|
||||
//
|
||||
// this.player.pause();
|
||||
// this.player.currentTime(0);
|
||||
//
|
||||
// this.player.one("timeupdate", _V_.proxy(this, function(){
|
||||
//
|
||||
// ok(this.player.currentTime() == 0, "Time is 0.");
|
||||
// start();
|
||||
//
|
||||
// }));
|
||||
//
|
||||
// }));
|
||||
//
|
||||
//
|
||||
// }));
|
||||
// // this.player.one("timeupdate", _V_.proxy(this, function(){
|
||||
// //
|
||||
// // this.player.currentTime(this.player.duration() / 2);
|
||||
// //
|
||||
// // this.player.one("timeupdate", _V_.proxy(this, function(){
|
||||
// // ok(this.player.currentTime() > 0, "Time is greater than 0.");
|
||||
// //
|
||||
// // this.player.pause();
|
||||
// // this.player.currentTime(0);
|
||||
// //
|
||||
// // this.player.one("timeupdate", _V_.proxy(this, function(){
|
||||
// //
|
||||
// // ok(this.player.currentTime() == 0, "Time is 0.");
|
||||
// // start();
|
||||
// //
|
||||
// // }));
|
||||
// //
|
||||
// // }));
|
||||
// //
|
||||
// //
|
||||
// // }));
|
||||
|
||||
});
|
||||
// });
|
||||
|
||||
/* Events
|
||||
================================================================================ */
|
@ -1,52 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>QUnit Test Suite</title>
|
||||
|
||||
<link rel="stylesheet" href="../design/video-js.css" type="text/css">
|
||||
|
||||
<!--[if IE]>
|
||||
<script src="https://getfirebug.com/firebug-lite.js" type="text/javascript" charset="utf-8"></script>
|
||||
<![endif]-->
|
||||
|
||||
<!-- Video.js Source Files -->
|
||||
<script src='../src/core.js'></script>
|
||||
<script src='../src/lib.js'></script>
|
||||
<script src='../src/component.js'></script>
|
||||
<script src='../src/controls.js'></script>
|
||||
<script src='../src/events.js'></script>
|
||||
<script src='../src/json.js'></script>
|
||||
<script src='../src/player.js'></script>
|
||||
<script src='../src/tech.js'></script>
|
||||
<script src='../src/tracks.js'></script>
|
||||
|
||||
<script src='../tech/html5/html5.js'></script>
|
||||
<script src='../tech/flash/flash.js'></script>
|
||||
|
||||
|
||||
<script src='../src/setup.js'></script>
|
||||
<!-- END Video.js Source Files -->
|
||||
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
// Easy access to test Flash over HTML5. Add ?flash to URL
|
||||
if (window.location.href.indexOf("?flash") !== -1) {
|
||||
_V_.options.techOrder = ["flash"]
|
||||
}
|
||||
</script>
|
||||
|
||||
<link rel="stylesheet" href="qunit/qunit/qunit.css" type="text/css" media="screen">
|
||||
<script type="text/javascript" src="qunit/qunit/qunit.js"></script>
|
||||
<script type="text/javascript" src="test.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">QUnit Test Suite</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture">test markup</div>
|
||||
|
||||
<div id="player_box"></div>
|
||||
</body>
|
||||
</html>
|
45
test/unit.html
Normal file
45
test/unit.html
Normal file
@ -0,0 +1,45 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Video.js Test Suite</title>
|
||||
|
||||
<!-- QUnit -->
|
||||
<link rel="stylesheet" href="vendor/qunit/qunit/qunit.css" />
|
||||
<script src="vendor/qunit/qunit/qunit.js"></script>
|
||||
|
||||
<!-- Video.js CSS -->
|
||||
<link rel="stylesheet" href="../design/video-js.css" type="text/css">
|
||||
|
||||
<!-- Video.js JavaScript -->
|
||||
<script src='../src/core.js'></script>
|
||||
<script src='../src/lib.js'></script>
|
||||
<script src='../src/component.js'></script>
|
||||
<script src='../src/controls.js'></script>
|
||||
<script src='../src/events.js'></script>
|
||||
<script src='../src/json.js'></script>
|
||||
<script src='../src/player.js'></script>
|
||||
<script src='../src/tech.js'></script>
|
||||
<script src='../src/tracks.js'></script>
|
||||
|
||||
<script src='../tech/html5/html5.js'></script>
|
||||
<script src='../tech/flash/flash.js'></script>
|
||||
|
||||
<script src='../src/setup.js'></script>
|
||||
|
||||
<!-- Unit Tests -->
|
||||
<script src="unit/component.js"></script>
|
||||
<script src="unit/controls.js"></script>
|
||||
<script src="unit/player.js"></script>
|
||||
<script src="unit/lib.js"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<h1 id="qunit-header">Bootstrap Plugin Test Suite</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture"></div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
67
test/unit/component.js
Normal file
67
test/unit/component.js
Normal file
@ -0,0 +1,67 @@
|
||||
module("Component");
|
||||
|
||||
test('should create an element', function(){
|
||||
var comp = new _V_.Component({}, {});
|
||||
|
||||
ok(comp.el.nodeName);
|
||||
});
|
||||
|
||||
test('should init child coponents from options', function(){
|
||||
var comp = new _V_.Component({}, {
|
||||
components: {
|
||||
'component': true
|
||||
}
|
||||
});
|
||||
|
||||
ok(comp.el.childNodes.length === 1);
|
||||
});
|
||||
|
||||
test('should show and hide an element', function(){
|
||||
var comp = new _V_.Component({}, {});
|
||||
|
||||
comp.hide();
|
||||
ok(comp.el.style.display === 'none');
|
||||
comp.show();
|
||||
ok(comp.el.style.display === 'block');
|
||||
});
|
||||
|
||||
test('should add and remove a CSS class', function(){
|
||||
var comp = new _V_.Component({}, {});
|
||||
|
||||
comp.addClass('test-class');
|
||||
ok(comp.el.className.indexOf('test-class') !== -1);
|
||||
comp.removeClass('test-class');
|
||||
ok(comp.el.className.indexOf('test-class') === -1);
|
||||
});
|
||||
|
||||
test('should add and remove event listeners to element', function(){
|
||||
var comp = new _V_.Component({}, {});
|
||||
|
||||
// No need to make this async because we're triggering events inline.
|
||||
// We're going to trigger the event after removing the listener,
|
||||
// So if we get extra asserts that's a problem.
|
||||
expect(1);
|
||||
|
||||
var testListener = function(){
|
||||
ok(true, 'fired event once');
|
||||
};
|
||||
|
||||
comp.on('test-event', testListener);
|
||||
comp.trigger('test-event');
|
||||
comp.off('test-event', testListener);
|
||||
comp.trigger('test-event');
|
||||
});
|
||||
|
||||
test('should trigger a listener once using one()', function(){
|
||||
var comp = new _V_.Component({}, {});
|
||||
|
||||
expect(1);
|
||||
|
||||
var testListener = function(){
|
||||
ok(true, 'fired event once');
|
||||
};
|
||||
|
||||
comp.one('test-event', testListener);
|
||||
comp.trigger('test-event');
|
||||
comp.trigger('test-event');
|
||||
});
|
1
test/unit/controls.js
vendored
Normal file
1
test/unit/controls.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
module("Controls");
|
1
test/unit/core.js
Normal file
1
test/unit/core.js
Normal file
@ -0,0 +1 @@
|
||||
module("Core");
|
1
test/unit/events.js
Normal file
1
test/unit/events.js
Normal file
@ -0,0 +1 @@
|
||||
module("Events");
|
69
test/unit/lib.js
Normal file
69
test/unit/lib.js
Normal file
@ -0,0 +1,69 @@
|
||||
module("Lib");
|
||||
|
||||
test('should merge two objects', function(){
|
||||
var obj1 = { a:1, b:2 };
|
||||
var obj2 = { b:3, c:4 };
|
||||
|
||||
_V_.merge(obj1, obj2);
|
||||
|
||||
deepEqual(obj1, {a:1,b:3,c:4} );
|
||||
});
|
||||
|
||||
test('should create an element with attributes', function(){
|
||||
var el = _V_.createElement('div', { className: 'test-class', 'data-test': 'asdf' })
|
||||
ok(el.className === 'test-class');
|
||||
ok(el.getAttribute('data-test') === 'asdf' );
|
||||
});
|
||||
|
||||
test('should insert an element first', function(){
|
||||
var el1 = document.createElement('div');
|
||||
var el2 = document.createElement('div');
|
||||
var el3 = document.createElement('div');
|
||||
|
||||
_V_.insertFirst(el2, el1);
|
||||
ok(el1.childNodes[0] === el2);
|
||||
_V_.insertFirst(el3, el1);
|
||||
ok(el1.childNodes[0] === el3);
|
||||
});
|
||||
|
||||
test('should add and remove a CSS class', function(){
|
||||
var el = document.createElement('div');
|
||||
|
||||
_V_.addClass(el, 'test-class')
|
||||
ok(el.className.indexOf('test-class') !== -1);
|
||||
_V_.removeClass(el, 'test-class')
|
||||
ok(el.className.indexOf('test-class') === -1);
|
||||
});
|
||||
|
||||
test('should format the time', function(){
|
||||
ok(_V_.formatTime(120) === "2:00");
|
||||
ok(_V_.formatTime(18121) === "5:02:01");
|
||||
});
|
||||
|
||||
test('should uppercase a word', function(){
|
||||
ok(_V_.uc('asdf') === "Asdf");
|
||||
});
|
||||
|
||||
test('should trim a string', function(){
|
||||
ok(_V_.trim(' asdf ') === "asdf");
|
||||
});
|
||||
|
||||
test('should round a number', function(){
|
||||
ok(_V_.round(1.01) === 1);
|
||||
ok(_V_.round(1.01, 1) === 1.0);
|
||||
ok(_V_.round(1.01, 2) === 1.01);
|
||||
ok(_V_.round(1.05, 1) === 1.1);
|
||||
});
|
||||
|
||||
test('should test that an object is empty', function(){
|
||||
ok(_V_.isEmpty({}) === true);
|
||||
ok(_V_.isEmpty({ asdf: 'asdf' }) === false);
|
||||
});
|
||||
|
||||
test('should create a fake timerange', function(){
|
||||
var tr = _V_.createTimeRange(0, 100);
|
||||
|
||||
ok(tr.start() === 0);
|
||||
ok(tr.end() === 100);
|
||||
ok(tr.length === 1);
|
||||
});
|
22
test/unit/player.js
Normal file
22
test/unit/player.js
Normal file
@ -0,0 +1,22 @@
|
||||
module("Player", {
|
||||
setup: function(){
|
||||
var videoTag = document.createElement('video');
|
||||
videoTag.id = 'example_1';
|
||||
videoTag.className = 'video-js vjs-default-skin';
|
||||
|
||||
var fixture = document.getElementById('qunit-fixture');
|
||||
fixture.appendChild(videoTag);
|
||||
|
||||
this.player = new _V_.Player(videoTag, {});
|
||||
},
|
||||
teardown: function(){
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
test('should create and embed a new player element', function(){
|
||||
ok(this.player.el.nodeName === 'DIV');
|
||||
ok(this.player.el.parentNode.id === 'qunit-fixture');
|
||||
ok(this.player.el.className.indexOf('video-js vjs-default-skin') !== -1);
|
||||
ok(this.player.el.id === 'example_1');
|
||||
});
|
1
test/unit/setup.js
Normal file
1
test/unit/setup.js
Normal file
@ -0,0 +1 @@
|
||||
module("Setup");
|
1
test/unit/tech.js
Normal file
1
test/unit/tech.js
Normal file
@ -0,0 +1 @@
|
||||
module("Tech");
|
1
test/unit/tracks.js
Normal file
1
test/unit/tracks.js
Normal file
@ -0,0 +1 @@
|
||||
module("Tracks");
|
Loading…
Reference in New Issue
Block a user