From b62618fce6eb8db2605c0690d7eaf16e1d92ffc0 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 8 Dec 2010 15:51:30 -0500 Subject: [PATCH] [#207] Enforce reserved function names; --- popcorn.js | 9 ++++++++ test/popcorn.unit.js | 53 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/popcorn.js b/popcorn.js index 05de7c1..ff96db8 100644 --- a/popcorn.js +++ b/popcorn.js @@ -317,12 +317,21 @@ 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 diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index c565953..76d52b2 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -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") -- 2.43.0