From 83ed115b8ccd5391f05319518eec9b5eafb9b30d Mon Sep 17 00:00:00 2001 From: rwldrn Date: Thu, 16 Dec 2010 16:56:06 -0500 Subject: [PATCH] [#228] Remove Track Event; index integrity tests --- popcorn.js | 29 ++++++++++++++--- test/popcorn.unit.js | 77 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 100 insertions(+), 6 deletions(-) diff --git a/popcorn.js b/popcorn.js index 70d27bd..ac8e9a0 100644 --- a/popcorn.js +++ b/popcorn.js @@ -455,6 +455,7 @@ var trackLen = obj.data.trackEvents.byStart.length, historyLen = obj.data.history.length, + indexWasAt = 0, byStart = [], byEnd = [], history = []; @@ -468,13 +469,33 @@ byEnd.push( obj.data.trackEvents.byEnd[i] ); } - // Filter for the trackevent to remove - if ( o._id && o._id !== trackId ) { - byStart.push( obj.data.trackEvents.byStart[i] ); - byEnd.push( obj.data.trackEvents.byEnd[i] ); + // Filter for user track events (vs system track events) + if ( o._id ) { + + // Filter for the trackevent to remove + if ( o._id !== trackId ) { + byStart.push( obj.data.trackEvents.byStart[i] ); + byEnd.push( obj.data.trackEvents.byEnd[i] ); + } + + // Capture the position of the track being removed. + if ( o._id === trackId ) { + indexAt = i; + } } }); + + // Update + if ( indexWasAt <= obj.data.trackEvents.startIndex ) { + obj.data.trackEvents.startIndex--; + } + + if ( indexWasAt <= obj.data.trackEvents.endIndex ) { + obj.data.trackEvents.endIndex--; + } + + obj.data.trackEvents.byStart = byStart; obj.data.trackEvents.byEnd = byEnd; diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 3db982f..1f9ddc3 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -665,7 +665,8 @@ module("Popcorn TrackEvents"); test("Functions", function () { // TODO: break this into sep. units per function - + expect(19); + var popped = Popcorn("#video"), ffTrackId, rwTrackId, rw2TrackId, rw3TrackId, historyRef, trackEvents; @@ -755,7 +756,6 @@ test("Functions", function () { end: 10 }); - rw3TrackId = popped.getLastTrackEventId(); equals( popped.data.history.length, 3, "3 TrackEvents in history index - after new track added "); @@ -768,10 +768,83 @@ test("Functions", function () { equals( trackEvents.length, 3, "3 user created trackEvents returned by popped.getTrackEvents()" ) + + +}); + +test("Index Integrity", function () { + + stop(); + + var popped = Popcorn("#video"), trackLen; + + popped.currentTime(0).pause(); + + Popcorn.plugin("ff", function () { + return { + start: function () { + var div = document.createElement('div'); + div.id = "index-test"; + div.innerHTML = "foo"; + + document.body.appendChild(div); + }, + end: function () { + document.getElementById('index-test').parentNode.removeChild(document.getElementById('index-test')); + } + }; + }); + + popped.ff({ + id: "removeable-track-event", + start: 1, + end: 3 + }); + + equals(popped.data.trackEvents.endIndex, 0, "popped.data.trackEvents.endIndex is 0"); + equals(popped.data.trackEvents.startIndex, 0, "popped.data.trackEvents.startIndex is 0"); + equals(popped.data.trackEvents.byStart.length, 3, "popped.data.trackEvents.byStart.length is 3 - before play" ); + + + popped.listen("timeupdate", function () { + + if ( this.roundTime() >= 5 ) { + + this.pause(); + + equals(popped.data.trackEvents.byStart.length, 3, "popped.data.trackEvents.byStart.length is 3 - after play, before removeTrackEvent" ); + + equals(popped.data.trackEvents.endIndex, 2, "popped.data.trackEvents.endIndex is 2 - after play, before removeTrackEvent"); + equals(popped.data.trackEvents.startIndex, 2, "popped.data.trackEvents.startIndex is 2 - after play, before removeTrackEvent"); + + + this.removeTrackEvent("removeable-track-event"); + + equals(popped.data.trackEvents.byStart.length, 2, "popped.data.trackEvents.byStart.length is 2 - after removeTrackEvent" ); + equals(popped.data.trackEvents.endIndex, 1, "popped.data.trackEvents.endIndex is 1 - after removeTrackEvent"); + equals(popped.data.trackEvents.startIndex, 1, "popped.data.trackEvents.startIndex is 1 - after removeTrackEvent"); + + this.listen("timeupdate", function () { + + if ( this.roundTime() >= 4 ) { + + this.pause(); + start(); + + } + }); + + this.currentTime(0).play(); + } + + }); + + popped.play(); }); + module("Popcorn XHR"); test("Basic", function () { -- 2.43.0