]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#207] Enforce reserved function names;
authorRick Waldron <waldron.rick@gmail.com>
Wed, 8 Dec 2010 20:51:30 +0000 (15:51 -0500)
committerRick Waldron <waldron.rick@gmail.com>
Wed, 8 Dec 2010 20:51:30 +0000 (15:51 -0500)
popcorn.js
test/popcorn.unit.js

index 05de7c171600d0a4e4facefdcb81468aa404943f..ff96db8938c6406923ad77b3998864ccd1d73560 100644 (file)
     Popcorn.p[key] = Popcorn.events.fn[key];
   });  
   
+  Popcorn.protect = {
+    natives: "load play pause currentTime playbackRate mute volume duration".toLowerCase().split(/\s+/)
+  };
+  
   //  Plugins are registered 
   Popcorn.registry = [];
   //  An interface for extending Popcorn 
   //  with plugin functionality
   Popcorn.plugin = function( name, definition ) {
 
+    if ( Popcorn.protect.natives.indexOf( name.toLowerCase() ) >= 0 ) {
+      Popcorn.error("'" + name + "' is a protected function name");
+      return;
+    }
+
     //  Provides some sugar, but ultimately extends
     //  the definition into Popcorn.p 
     
index c565953484302fa241069ce7065f308e3761f5db..76d52b2a5c9e116d5c5bf8596d322fb24c8b9bf5 100644 (file)
@@ -55,6 +55,15 @@ test("Utility", function () {
 });
 
 
+test("Protected", function () {
+  
+  expect(1);
+  //  TODO: comprehensive tests for these utilities
+  
+  ok( !!Popcorn.protect , "Popcorn.protect exists");
+  
+  
+});
 
 
 
@@ -478,14 +487,32 @@ test("Plugin API", function () {
   });    
 });
 
+test("Protected Names", function () {
+  
+  //QUnit.reset();
+  
+  expect(8);
+
+  var popped = Popcorn("#video");
+
+  $.each( "load play pause currentTime playbackRate mute volume duration".split(/\s+/), function (k, name) {
+    try {
 
+      Popcorn.plugin( name, {});
+    }   catch (e) {
 
+      ok( name, "Attempting to overwrite '" + name + "' threw an exception " );
+
+    };
+  });
+});
 
 
 
+/*
 test("Events Extended", function () {
   
-  //QUnit.reset();
+  QUnit.reset();
   
   // needs expectation
 
@@ -493,7 +520,7 @@ test("Events Extended", function () {
       expects = 11, 
       count = 0;
 
-  //expect(expects);
+  expect(expects);
   // not in full use
   function plus(){ 
     if ( ++count == expects ) start(); 
@@ -504,6 +531,7 @@ test("Events Extended", function () {
   
   Popcorn.plugin("extendedEvents", (function () {
   
+    var fired = [];
 
     var pluginObj = {
 
@@ -518,9 +546,17 @@ test("Events Extended", function () {
     $.each( Setup.events, function ( k, type ) {
       
       pluginObj[type]  = function (event, opts) {
-        ok( true, type + " fired!" );
+      
+        if ( fired.indexOf(type) === -1 ) {
+          fired.push(type);
+          
+          ok( true, type + " fired" );
+          
+          plus();
         
-        plus();
+        
+          
+        }
       };
     
     });
@@ -542,9 +578,14 @@ test("Events Extended", function () {
   
   popped.currentTime(19).play();
   
-  
-});
+  $.each( Setup.events, function ( k, type ) {
+    
+    popped.trigger(type);
+      
+  });
 
+});
+*/
 
 /*
 module("Popcorn Video Object")