@@ -34,6 +34,8 @@ describe('DashHandler', function () {
3434 const segmentsController = objectsHelper . getDummySegmentsController ( ) ;
3535 const dashMetrics = new DashMetricsMock ( ) ;
3636
37+ let dummyRepresentation ;
38+ let dummyMediaInfo ;
3739
3840 const config = {
3941 eventBus,
@@ -51,6 +53,41 @@ describe('DashHandler', function () {
5153 const dashHandler = DashHandler ( context ) . create ( config ) ;
5254 dashHandler . initialize ( streamProcessor ) ;
5355
56+ beforeEach ( ( ) => {
57+ dummyRepresentation = {
58+ index : 0 ,
59+ adaptation : {
60+ index : 0 ,
61+ period : {
62+ mpd : {
63+ manifest : {
64+ Period : [
65+ {
66+ AdaptationSet : [
67+ {
68+ Representation : [
69+ {
70+ bandwidth : 3000
71+ }
72+ ]
73+ }
74+ ]
75+ }
76+ ]
77+ }
78+ } ,
79+ start : 0 ,
80+ duration : 30 ,
81+ index : 0
82+ }
83+ } ,
84+ segmentInfoType : 'SegmentTimeline' ,
85+ timescale : 1 ,
86+ segmentDuration : 2
87+ } ;
88+ dummyMediaInfo = { } ;
89+ } )
90+
5491 it ( 'should generate an init segment for a representation' , ( ) => {
5592 const representation = voHelper . getDummyRepresentation ( testType ) ;
5693
@@ -93,9 +130,55 @@ describe('DashHandler', function () {
93130 expect ( mediaSegment ) . to . be . null ; // jshint ignore:line
94131 } ) ;
95132
133+ describe ( 'getNextSegmentRequest' , ( ) => {
134+ let segRequestStub ;
135+
136+ beforeEach ( ( ) => {
137+ segRequestStub = sinon . stub ( segmentsController , 'getSegmentByIndex' ) . callsFake ( ( representation , index ) => {
138+ return {
139+ replacementNumber : index ,
140+ index,
141+ duration : representation . segmentDuration ,
142+ representation,
143+ media : 'http://someurl' ,
144+ endNumber : 2
145+ }
146+ } ) ;
147+ } )
148+
149+ afterEach ( ( ) => {
150+ segRequestStub . restore ( ) ;
151+ } ) ;
152+
153+ it ( 'it returns a segment request' , ( ) => {
154+ const mediaSegment = dashHandler . getNextSegmentRequest ( { } , { segmentInfoType : DashConstants . SEGMENT_TEMPLATE , adaptation : { index : 1 } } ) ;
155+ expect ( mediaSegment ) . not . to . be . null ; // jshint ignore:line
156+ } )
157+
158+ it ( 'returns null if the next segment is after @endNumber' , ( ) => {
159+ const dashHandler = DashHandler ( context ) . create ( config ) ;
160+ const representation = { segmentInfoType : DashConstants . SEGMENT_TEMPLATE , adaptation : { index : 1 } , endNumber : 2 } ;
161+ dashHandler . initialize ( streamProcessor ) ;
162+ dashHandler . getNextSegmentRequest ( { } , representation ) ;
163+ dashHandler . getNextSegmentRequest ( { } , representation ) ;
164+ dashHandler . getNextSegmentRequest ( { } , representation ) ;
165+ dashHandler . getNextSegmentRequest ( { } , representation ) ;
166+ const mediaSegment = dashHandler . getNextSegmentRequest ( { } , representation ) ;
167+ expect ( mediaSegment ) . to . be . null ; // jshint ignore:line
168+ } )
169+
170+ it ( 'returns null if representation is null' , ( ) => {
171+ const mediaSegment = dashHandler . getNextSegmentRequest ( { } , null ) ;
172+ expect ( mediaSegment ) . to . be . null ; // jshint ignore:line
173+ } )
174+
175+ it ( 'returns null if representation.segmentInfoType is null' , ( ) => {
176+ const mediaSegment = dashHandler . getNextSegmentRequest ( { } , { segmentInfoType : null } ) ;
177+ expect ( mediaSegment ) . to . be . null ; // jshint ignore:line
178+ } )
179+ } )
180+
96181 describe ( 'getValidTimeAheadOfTargetTime()' , ( ) => {
97- let dummyRepresentation ;
98- let dummyMediaInfo ;
99182 let segRequestStub ;
100183
101184 beforeEach ( ( ) => {
@@ -111,39 +194,6 @@ describe('DashHandler', function () {
111194 media : 'http://someurl'
112195 }
113196 } ) ;
114-
115- dummyRepresentation = {
116- index : 0 ,
117- adaptation : {
118- index : 0 ,
119- period : {
120- mpd : {
121- manifest : {
122- Period : [
123- {
124- AdaptationSet : [
125- {
126- Representation : [
127- {
128- bandwidth : 3000
129- }
130- ]
131- }
132- ]
133- }
134- ]
135- }
136- } ,
137- start : 0 ,
138- duration : 30 ,
139- index : 0
140- }
141- } ,
142- segmentInfoType : 'SegmentTimeline' ,
143- timescale : 1 ,
144- segmentDuration : 2
145- } ;
146- dummyMediaInfo = { } ;
147197 } )
148198
149199 afterEach ( ( ) => {
0 commit comments