// Potential Future automation // https://github.com/mcrmfc/qunit_sauce_runner // http://saucelabs.com/blog/index.php/2011/06/javascript-unit-testing-with-jellyfish-and-ondemand/ // https://github.com/admc/jellyfish/blob/master/test/fun/jfqunit.js function createVideoTag(id){ var tagCode, tag, attrs; tagCode = ''; tag = document.createElement("video"); tag.id = "vid1"; tag.controls = true; tag.className = "video-js vjs-default-skin"; tag.preload = "auto"; tag.width = "640"; tag.height = "264"; tag.poster = "http://video-js.zencoder.com/oceans-clip.png"; source1 = document.createElement("source"); source1.src = "http://video-js.zencoder.com/oceans-clip.mp4"; source1.type = "video/mp4"; tag.appendChild(source1); source2 = document.createElement("source"); source2.src = "http://video-js.zencoder.com/oceans-clip.webm"; source2.type = "video/webm"; tag.appendChild(source2); source3 = document.createElement("source"); source3.src = "http://video-js.zencoder.com/oceans-clip.ogv"; source3.type = "video/ogg"; tag.appendChild(source3); return tag; } function playerSetup(){ _V_.el("player_box").appendChild(createVideoTag()) var vid = document.getElementById("vid1"); this.player = _V_(vid); stop(); this.player.ready(_V_.proxy(this, function(){ start(); })); } function playerTeardown(){ stop(); _V_("vid1").destroy(); // document.body.removeChild(document.getElementById("vid1")); delete this.player; setTimeout(function(){ start(); }, 500); } module("Video.js setup", { setup: playerSetup, teardown: playerTeardown }); test("Player Set Up", function() { ok(this.player); }); /* Methods ================================================================================ */ module("API Methods", { setup: playerSetup, teardown: playerTeardown }); function failOnEnded() { this.player.one("ended", _V_.proxy(this, function(){ start(); })); } // Play Method test("Play", 1, function() { stop(); this.player.one("playing", _V_.proxy(this, function(){ ok(true); start(); })); this.player.play(); failOnEnded.call(this); }); // Pause Method test("Pause", 1, function() { stop(); // Flash doesn't currently like calling pause immediately after 'playing'. this.player.one("timeupdate", _V_.proxy(this, function(){ this.player.pause(); })); this.player.addEvent("pause", _V_.proxy(this, function(){ ok(true); start(); })); this.player.play(); }); // Paused Method test("Paused", 2, function() { stop(); this.player.one("timeupdate", _V_.proxy(this, function(){ equal(this.player.paused(), false); this.player.pause(); })); this.player.addEvent("pause", _V_.proxy(this, function(){ equal(this.player.paused(), true); start(); })); this.player.play(); }); test("currentTime()", 1, function() { stop(); // 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(){ this.player.addEvent("timeupdate", _V_.proxy(this, function(){ if (this.player.currentTime() > 0) { ok(true, "Time is greater than 0."); start(); } else { // tries++; } // if (tries >= 3) { // start(); // } })); })); this.player.play(); }); 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); // })); // }); // 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); })); this.player.one("seeked", _V_.proxy(this, function(){ _V_.log("seeked", this.player.currentTime()) ok(this.player.currentTime() > 1, "Time is greater than 1."); this.player.one("seeked", _V_.proxy(this, function(){ _V_.log("seeked2", this.player.currentTime()) ok(this.player.currentTime() <= 1, "Time is less than 1."); start(); })); this.player.currentTime(0); })); 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(); // // })); // // })); // // // })); }); /* Events ================================================================================ */ module("API Events", { setup: playerSetup, teardown: playerTeardown }); var playEventList = [] // Test all playback events test("Initial Events", 12, function() { stop(); // Give 30 seconds to run then fail. var events = [ // "loadstart" // Called during setup "play", "playing", "durationchange", "loadedmetadata", "loadeddata", "loadedalldata", "progress", "timeupdate", "canplay", "canplaythrough", "pause", "ended" ]; // Add an event listener for each event type. for (var i=0, l=events.length; i