From: rwldrn Date: Thu, 16 Dec 2010 20:32:13 +0000 (-0500) Subject: [#228] Remove Track Event X-Git-Tag: v0.2~40 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=a748ca02a83f0be03d6c3d40c74ebd1c70fd8823;p=popcorn-js.git [#228] Remove Track Event --- diff --git a/popcorn.js b/popcorn.js index e539d02..70d27bd 100644 --- a/popcorn.js +++ b/popcorn.js @@ -431,8 +431,9 @@ Popcorn.addTrackEvent = function( obj, track ) { - if ( "natives" in track ) { - track["_id"] = track.natives.type + Popcorn.guid(); + if ( track.natives ) { + // supports user defined track event id + track["_id"] = !track.id ? track.natives.type + Popcorn.guid() : track.id; // Push track event ids into the history obj.data.history.push( track["_id"] ); diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 9eaed11..3db982f 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -666,7 +666,7 @@ test("Functions", function () { // TODO: break this into sep. units per function - var popped = Popcorn("#video"), ffTrackId, rwTrackId, rw2TrackId, historyRef, trackEvents; + var popped = Popcorn("#video"), ffTrackId, rwTrackId, rw2TrackId, rw3TrackId, historyRef, trackEvents; Popcorn.plugin("ff", function () { @@ -749,7 +749,24 @@ test("Functions", function () { equals( trackEvents.length, 2, "2 user created trackEvents returned by popped.getTrackEvents()" ) + popped.rw({ + id: "my-track-id", + start: 3, + end: 10 + }); + + + rw3TrackId = popped.getLastTrackEventId(); + + equals( popped.data.history.length, 3, "3 TrackEvents in history index - after new track added "); + equals( popped.data.trackEvents.byStart.length, 5, "5 TrackEvents in popped.data.trackEvents.byStart - after new track added"); + equals( popped.data.trackEvents.byEnd.length, 5, "5 TrackEvents in popped.data.trackEvents.byEnd - after new track added"); + + equals( rw3TrackId, "my-track-id", "TrackEvent has user defined id"); + + trackEvents = popped.getTrackEvents(); + equals( trackEvents.length, 3, "3 user created trackEvents returned by popped.getTrackEvents()" ) });