Skip to content

Commit

Permalink
[#573] Adds protection handling for popcorn proto methods inside of r…
Browse files Browse the repository at this point in the history
…emovePlugin; 28 Unit tests
  • Loading branch information
rwaldron committed Jun 14, 2011
1 parent 6e02766 commit 6133d56
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
9 changes: 7 additions & 2 deletions popcorn.js
Expand Up @@ -642,7 +642,7 @@

// Protected API methods
Popcorn.protect = {
natives: "load play pause currentTime playbackRate mute volume duration removePlugin roundTime trigger listen unlisten".toLowerCase().split( /\s+/ )
natives: "load play pause currentTime playbackRate mute volume duration removePlugin roundTime trigger listen unlisten exec".toLowerCase().split( /\s+/ )
};

// Internal Only - Adds track events to the instance object
Expand Down Expand Up @@ -836,7 +836,7 @@
Popcorn.plugin = function( name, definition, manifest ) {

if ( Popcorn.protect.natives.indexOf( name.toLowerCase() ) >= 0 ) {
Popcorn.error("'" + name + "' is a protected function name");
Popcorn.error( "'" + name + "' is a protected function name" );
return;
}

Expand Down Expand Up @@ -956,6 +956,11 @@
name = obj;
obj = Popcorn.p;

if ( Popcorn.protect.natives.indexOf( name.toLowerCase() ) >= 0 ) {
Popcorn.error( "'" + name + "' is a protected function name" );
return;
}

var registryLen = Popcorn.registry.length,
registryIdx;

Expand Down
19 changes: 19 additions & 0 deletions test/popcorn.unit.js
Expand Up @@ -334,6 +334,25 @@ test("Protected", function () {

});

test("Protected from removal", function () {

expect( Popcorn.protect.natives.length * 2 );

Popcorn.protect.natives.forEach(function( name ) {

try {
Popcorn.plugin( name );
} catch( e ) {
ok( true, e.message + " and cannot be used as a plugin name" );
}

try {
Popcorn.removePlugin( name );
} catch( e ) {
ok( true, e.message + " and cannot be removed with this API" );
}
});
});



Expand Down

0 comments on commit 6133d56

Please sign in to comment.