]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
modifications to processing plugin, added unit tests
authorChristopher De Cairos <cadecairos@India.(none)>
Thu, 16 Jun 2011 19:20:32 +0000 (15:20 -0400)
committerChristopher De Cairos <cadecairos@India.(none)>
Thu, 16 Jun 2011 19:20:32 +0000 (15:20 -0400)
plugins/processing/popcorn.processing.html
plugins/processing/popcorn.processing.js
plugins/processing/popcorn.processing.unit.html
plugins/processing/popcorn.processing.unit.js

index 7ccb9282915ce77b513421cdbf59a379de02a1c0..c6ec6a6d3836542c3381325d3d664810eac4995f 100644 (file)
         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);
     </video>
   </div>
   <div id="processing-div" width="50%" height="50%">
-  <hr />
   </div>
   <div id="processing-div2" width="50%" height="50%">
-
   </div>
-
   </body>
 </html>
index c09b7001b575eb349ffe3561526b3180737d32c0..0a6ff6ace043ce62f9c308edd2f1b24f37be7bb0 100644 (file)
@@ -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();
               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 );
         }
         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" }
         }
       },
 
       },
 
       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 );
       }
     };
   });
index 8aff918d7f222f9688da42fcddd7ad23468697e3..ab6a43abb66cb1a77bc52f9392b2b398259a7814 100644 (file)
@@ -10,7 +10,6 @@
   <script src="popcorn.processing.unit.js"></script>
 </head>
 <body>
-  <h1 id="qunit-header"></h1>
   <h1 id="qunit-header">Popcorn processing Plug-in Demo</h1>
   <h2 id="qunit-banner"></h2>
   <div id="qunit-testrunner-toolbar"></div>
 
     </video>
   </div>
-  <!--<div id="processing-div" width="50%" height="50%">
-  <p> This is within a DIV and was created by sending a string in "sketch:</p>
-  <p> > pause at 1 and resume at 5 seconds. </p>
-  </div>
-  <div id="processing-div2" width="50%" height="50%">
-  <p> This is within a DIV and was created by sending a file in the sketch function</p>
-  <p> > pause at 5 and resume at 10 seconds. Then Pause again at 20 to 25 seconds to test multiple instructions</p>
-  </div>
-  <p> This is within a Canvas and was created by it having it's own sketch file</p>
-  <p> > pause at 10 and resume at 15 seconds. </p>
-   <canvas id="processing-canvas2" datasrc="test2.pjs" width="100" height="100"></canvas></body>
- 
-   <hr>
-   <strong> Call Function Test </strong>
-   <div id="processing-div3" width="50%" height="50%">
-  <p> This is within a DIV and was created by sending a file in the sketch function</p>
-  <p> > change square to blue at 20 seconds. </p>
-  </div>-->
+  <div id="processing-div" width="50%" height="50%"></div>
+  <div id="processing-div-2" width="50%" height="50%"></div>
+  <div id="processing-div-3" width="50%" height="50%"></div>
 </html>
index 5e5182f8ef14c13cedcc8b3fb57abff2c03dc1cc..83e63d72ff3c279d649db18a2ba7e7cfd5d2c4bf 100644 (file)
@@ -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();
+});