diff --git a/test/sync-controller.test.js b/test/sync-controller.test.js index 5b7b2b19e..3d1988c6a 100644 --- a/test/sync-controller.test.js +++ b/test/sync-controller.test.js @@ -66,6 +66,58 @@ QUnit.test('returns correct sync point for ProgramDateTime strategy', function(a }, 'syncpoint found for ProgramDateTime set'); }); +QUnit.test('ProgramDateTime strategy finds nearest segment for sync', function(assert) { + let strategy = getStrategy('ProgramDateTime'); + let playlist = playlistWithDuration(40); + let timeline = 0; + let duration = Infinity; + let syncPoint; + + syncPoint = strategy.run(this.syncController, playlist, duration, timeline, 23); + + assert.equal(syncPoint, null, 'no syncpoint when datetimeToDisplayTime not set'); + + playlist.segments.forEach((segment, index) => { + segment.dateTimeObject = new Date(2012, 11, 12, 12, 12, 12 + (index * 10)); + }); + + this.syncController.setDateTimeMapping(playlist); + + let newPlaylist = playlistWithDuration(40); + + syncPoint = strategy.run(this.syncController, newPlaylist, duration, timeline); + + assert.equal(syncPoint, null, 'no syncpoint when datetimeObject not set on playlist'); + + newPlaylist.segments.forEach((segment, index) => { + segment.dateTimeObject = new Date(2012, 11, 12, 12, 12, 22 + (index * 10)); + }); + + syncPoint = strategy.run(this.syncController, newPlaylist, duration, timeline, 23); + + assert.deepEqual(syncPoint, { + time: 20, + segmentIndex: 1 + }, 'syncpoint found for ProgramDateTime set'); +}); + +QUnit.test('Does not set date time mapping if date time info not on first segment', +function(assert) { + let playlist = playlistWithDuration(40); + + playlist.segments[1].dateTimeObject = new Date(2012, 11, 12, 12, 12, 12); + + this.syncController.setDateTimeMapping(playlist); + + assert.notOk(this.syncController.datetimeToDisplayTime, 'did not set datetime mapping'); + + playlist.segments[0].dateTimeObject = new Date(2012, 11, 12, 12, 12, 2); + + this.syncController.setDateTimeMapping(playlist); + + assert.ok(this.syncController.datetimeToDisplayTime, 'did set date time mapping'); +}); + QUnit.test('returns correct sync point for Segment strategy', function(assert) { let strategy = getStrategy('Segment'); let playlist = {