From 5b142310d4c9b050a8837f579d35e58684459cd6 Mon Sep 17 00:00:00 2001 From: Christopher De Cairos Date: Mon, 26 Sep 2011 15:15:24 -0400 Subject: [PATCH] Modified Popcorn.protect.natives to capture keys from Popcorn.p, added better tests, fixed test polluting the prototype [#738] --- popcorn.js | 11 +++++------ test/popcorn.unit.js | 29 +++++++++++++++++++---------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/popcorn.js b/popcorn.js index 9450dca..cf46c36 100644 --- a/popcorn.js +++ b/popcorn.js @@ -750,12 +750,6 @@ Popcorn.p[ key ] = Popcorn.events.fn[ key ]; }); - // Protected API methods - Popcorn.protect = { - natives: ( "load play pause currentTime playbackRate mute volume duration removePlugin roundTime trigger listen unlisten exec" + - "preload playbackRate autoplay loop controls muted buffered readyState seeking paused played seekable ended" ).toLowerCase().split( /\s+/ ) - }; - // Internal Only - Adds track events to the instance object Popcorn.addTrackEvent = function( obj, track ) { @@ -1776,6 +1770,11 @@ // alias for exec function Popcorn.p.cue = Popcorn.p.exec; + // Protected API methods + Popcorn.protect = { + natives: Object.keys( Popcorn.p ).join( "," ).toLowerCase().split( "," ) + }; + // Exposes Popcorn to global context global.Popcorn = Popcorn; diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index b975bc7..6f2fa3b 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -2497,6 +2497,7 @@ test("Remove Plugin", function() { function plus() { if ( ++count === expects ) { start(); + Popcorn.removePlugin( "cleanup" ); } } @@ -2616,26 +2617,34 @@ test("Remove Plugin", function() { }); +test( "Protected Names", function() { + var keys = Object.keys( Popcorn.p ), + len = keys.length, + count = 0, + popped = Popcorn( "#video" ); + expect( len ); -test("Protected Names", function() { - //QUnit.reset(); - - expect(8); - - var popped = Popcorn("#video"); + function plus() { + if ( ++count === len ) { + start(); + } + } - $.each( "load play pause currentTime playbackRate mute volume duration".split(/\s+/), function(k, name) { + Popcorn.forEach( keys, function( name ) { try { - Popcorn.plugin( name, {}); - } catch (e) { + Popcorn.plugin( name, {} ); + } catch ( e ) { ok( name, "Attempting to overwrite '" + name + "' threw an exception " ); - + plus(); }; }); + + stop( 5000 ); + }); test("Defaulting Empty End Values", function() { -- 2.43.0