From: Christopher De Cairos Date: Thu, 16 Jun 2011 19:20:32 +0000 (-0400) Subject: modifications to processing plugin, added unit tests X-Git-Tag: v0.7^2~31^2~7 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=7e7c956ab29848128953a1aa0c34daf3c00330d8;p=popcorn-js.git modifications to processing plugin, added unit tests --- diff --git a/plugins/processing/popcorn.processing.html b/plugins/processing/popcorn.processing.html index 7ccb928..c6ec6a6 100644 --- a/plugins/processing/popcorn.processing.html +++ b/plugins/processing/popcorn.processing.html @@ -14,19 +14,22 @@ start: 2, end: 10, target: 'processing-div', - sketch: 'test.pjs' + sketch: 'test.pjs', + noPause: true } ) .processing({ start: 10, end: 15, target: 'processing-div2', - sketch: 'test2.pjs' + sketch: 'test2.pjs', + noPause: false } ) .processing({ start: 15, end: 20, sketch: 'test.pjs', target: 'processing-div2', + noPause: true } ) window.popped = p; }, false); @@ -55,11 +58,8 @@
-
-
- diff --git a/plugins/processing/popcorn.processing.js b/plugins/processing/popcorn.processing.js index c09b700..0a6ff6a 100644 --- a/plugins/processing/popcorn.processing.js +++ b/plugins/processing/popcorn.processing.js @@ -20,7 +20,7 @@ } } else { setTimeout ( function() { - toggle.call ( this, on, options ); + toggle.call( this, on, options ); }, 10 ); } }, @@ -60,8 +60,7 @@ }); initProcessing = function() { - if ( codeReady && window.Processing ) { - options.pjsInstance = new Processing( options.canvas, processingCode ); + var addListeners = function() { popcorn.listen( "pause", function () { if ( options.canvas.style.display === "inline" ) { options.pjsInstance.noLoop(); @@ -72,7 +71,13 @@ options.pjsInstance.loop(); } }); + }; + + if ( codeReady && window.Processing ) { + options.pjsInstance = new Processing( options.canvas, processingCode ); + !options.noPause && addListeners(); options.isReady = true; + options.isLooping = false; } else { setTimeout ( initProcessing, 10 ); } @@ -91,10 +96,9 @@ options: { start : { elem: "input", type: "text", label: "In" }, end : { elem: "input", type: "text", label: "Out" }, - control : { elem: "input", type: "text", label: "Control" }, target : { elem: "input", type: "text", label: "Target" }, sketch : { elem: "input", type: "text", label: "Sketch" }, - func : { elem: "input", type: "text", label: "Function" } + noPause : { elem: "select", options: [ "TRUE", "FALSE" ], label: "No Loop" } } }, @@ -114,11 +118,11 @@ }, start: function( event, options ) { - toggle.call ( this, true, options ); + toggle.call( this, true, options ); }, end: function( event, options ) { - toggle.call ( this, false, options ); + toggle.call( this, false, options ); } }; }); diff --git a/plugins/processing/popcorn.processing.unit.html b/plugins/processing/popcorn.processing.unit.html index 8aff918..ab6a43a 100644 --- a/plugins/processing/popcorn.processing.unit.html +++ b/plugins/processing/popcorn.processing.unit.html @@ -10,7 +10,6 @@ -

Popcorn processing Plug-in Demo

@@ -35,22 +34,7 @@ - +
+
+
diff --git a/plugins/processing/popcorn.processing.unit.js b/plugins/processing/popcorn.processing.unit.js index 5e5182f..83e63d7 100644 --- a/plugins/processing/popcorn.processing.unit.js +++ b/plugins/processing/popcorn.processing.unit.js @@ -1 +1,93 @@ -//TODO: Write tests .. >.< +test( "Processing plugin tests", function() { + var popped = Popcorn( "#video" ), + expects = 18, + count = 0, + processingDiv = document.getElementById( "processing-div" ), + processingDiv2= document.getElementById( "processing-div-2" ), + processingDiv3= document.getElementById( "processing-div-3" ), + canvases = []; + + expect( expects ); + + function plus() { + if ( ++count === expects ) { + start(); + } + } + + stop(); + + ok( "processing" in popped, "processing is a method of the popped instance" ); + plus(); + + equals( processingDiv.innerHTML, "", "'processing-div' is empty" ); + plus(); + + equals( processingDiv2.innerHTML, "", "'processing-div-2' is empty" ); + plus(); + + equals( processingDiv3.innerHTML, "", "'processing-div-3' is empty" ); + plus(); + + popped.processing({ + start: 0, + end: 3, + target: "processing-div", + sketch: "test.pjs" + }) + .processing({ + start: 4, + end: 7, + target: "processing-div-2", + sketch: "test2.pjs" + }) + .processing({ + start: 4, + end: 7, + target: "processing-div-3", + sketch: "test.pjs" + }) + .exec( 1.5, function() { + equals( processingDiv.children[ 0 ].style.display, "inline", "canvas '" + processingDiv.children[ 0 ].id + "' is displayed" ); + plus(); + //TODO: David Humphrey has written code that allows for listening to events on Processing instances. when + // it lands In the next processing release we'll be able to detect if a processing instance is looping or not. + // this is required in order to test the noPause functionality (automatically) + }) + .exec( 5, function() { + equals( processingDiv.children[ 0 ].style.display, "none", "canvas '" + processingDiv.children[ 0 ].id + "' is hidden" ); + plus(); + equals( processingDiv2.children[ 0 ].style.display, "inline", "canvas '" + processingDiv.children[ 0 ].id + "' is displayed" ); + plus(); + equals( processingDiv3.children[ 0 ].style.display, "inline", "canvas '" + processingDiv.children[ 0 ].id + "' is displayed" ); + plus(); + }).exec( 7.5, function() { + equals( processingDiv.children[ 0 ].style.display, "none", "canvas '" + processingDiv.children[ 0 ].id + "' is hidden" ); + plus(); + equals( processingDiv2.children[ 0 ].style.display, "none", "canvas '" + processingDiv.children[ 0 ].id + "' is hidden" ); + plus(); + equals( processingDiv3.children[ 0 ].style.display, "none", "canvas '" + processingDiv.children[ 0 ].id + "' is hidden" ); + plus(); + }); + + //check that three canvases were created + canvases = document.getElementsByTagName( "canvas" ); + equals( canvases.length, 3, "Three canvases are present" ); + plus(); + + Popcorn.forEach( canvases, function( ctx ) { + var idCount = 0, i = -1, len = canvases.length; + for ( ; ++i < len; ){ + if ( ctx.id === canvases[ i ].id ) { + idCount++; + } + } + equals( idCount, 1, ctx.id + " is a unique canvas id" ); + plus(); + + equals( ctx.style.display, "none", ctx.id + " is hidden initially" ); + plus(); + }); + + popped.play(); +});