@@ -19,6 +19,7 @@ import EventBus from '../../../../src/core/EventBus.js';
1919import MediaPlayerEvents from '../../../../src/streaming/MediaPlayerEvents.js' ;
2020import sinon from 'sinon' ;
2121import CapabilitiesMock from '../../mocks/CapabilitiesMock.js' ;
22+ import SegmentSequenceProperties from '../../../../src/dash/vo/SegmentSequenceProperties.js' ;
2223
2324describe ( 'AbrController' , function ( ) {
2425 const context = { } ;
@@ -435,6 +436,127 @@ describe('AbrController', function () {
435436 } ) ;
436437 } )
437438
439+ describe ( 'abrCtrl.canPerformQualitySwitch()' , function ( ) {
440+
441+ it ( 'should return true if lastSegment is undefined' , function ( ) {
442+ expect ( abrCtrl . canPerformQualitySwitch ( undefined , { } ) ) . to . be . true ;
443+ } ) ;
444+
445+ it ( 'should return true if lastSegment is not a partial segment' , function ( ) {
446+ expect ( abrCtrl . canPerformQualitySwitch ( { isPartialSegment : false } , { } ) ) . to . be . true ;
447+ } ) ;
448+
449+ it ( 'should return true if lastSegment has no information about total number of segments' , function ( ) {
450+ expect ( abrCtrl . canPerformQualitySwitch ( {
451+ isPartialSegment : true ,
452+ totalNumberOfPartialSegments : NaN ,
453+ replacementSubNumber : 0
454+ } , { } ) ) . to . be . true ;
455+ } ) ;
456+
457+ it ( 'should return true if lastSegment has no information about replacementSubNumber' , function ( ) {
458+ expect ( abrCtrl . canPerformQualitySwitch ( {
459+ isPartialSegment : true ,
460+ totalNumberOfPartialSegments : 2 ,
461+ replacementSubNumber : NaN
462+ } , { } ) ) . to . be . true ;
463+ } ) ;
464+
465+ it ( 'should return true if replacementSubNumber is at the end of the sequence' , function ( ) {
466+ expect ( abrCtrl . canPerformQualitySwitch ( {
467+ isPartialSegment : true ,
468+ totalNumberOfPartialSegments : 3 ,
469+ replacementSubNumber : 2
470+ } , { } ) ) . to . be . true ;
471+ } ) ;
472+
473+ it ( 'should return false if no segmentSequenceProperties are defined' , function ( ) {
474+ expect ( abrCtrl . canPerformQualitySwitch ( {
475+ isPartialSegment : true ,
476+ totalNumberOfPartialSegments : 3 ,
477+ replacementSubNumber : 1
478+ } , {
479+ segmentSequenceProperties : [ ]
480+ } ) ) . to . be . false ;
481+ } ) ;
482+
483+ it ( 'should return false if segmentSequenceProperties are defined but no segmentSequenceProperties with SAP type 0 or 1 are available' , function ( ) {
484+ const ssp = new SegmentSequenceProperties ( ) ;
485+ ssp . sapType = 2
486+ expect ( abrCtrl . canPerformQualitySwitch ( {
487+ isPartialSegment : true ,
488+ totalNumberOfPartialSegments : 4 ,
489+ replacementSubNumber : 1
490+ } , {
491+ segmentSequenceProperties : [ ssp ]
492+ } ) ) . to . be . false ;
493+ } ) ;
494+
495+ it ( 'should return false if next partial segment number does not have the right SAP type' , function ( ) {
496+ const ssp = new SegmentSequenceProperties ( ) ;
497+ ssp . sapType = 1 ;
498+ ssp . cadence = 10
499+ expect ( abrCtrl . canPerformQualitySwitch ( {
500+ isPartialSegment : true ,
501+ totalNumberOfPartialSegments : 4 ,
502+ replacementSubNumber : 0
503+ } , {
504+ segmentSequenceProperties : [ ssp ]
505+ } ) ) . to . be . false ;
506+ } ) ;
507+
508+ it ( 'should return true if all partial segments have the right SAP type' , function ( ) {
509+ const ssp = new SegmentSequenceProperties ( ) ;
510+ expect ( abrCtrl . canPerformQualitySwitch ( {
511+ isPartialSegment : true ,
512+ totalNumberOfPartialSegments : 4 ,
513+ replacementSubNumber : 2
514+ } , {
515+ segmentSequenceProperties : [ ssp ]
516+ } ) ) . to . be . true ;
517+ } ) ;
518+
519+ it ( 'should return true if next partial segment number has the right SAP type' , function ( ) {
520+ const ssp = new SegmentSequenceProperties ( ) ;
521+ ssp . sapType = 1 ;
522+ ssp . cadence = 2 ;
523+ expect ( abrCtrl . canPerformQualitySwitch ( {
524+ isPartialSegment : true ,
525+ totalNumberOfPartialSegments : 4 ,
526+ replacementSubNumber : 1
527+ } , {
528+ segmentSequenceProperties : [ ssp ]
529+ } ) ) . to . be . true ;
530+ } ) ;
531+
532+ it ( 'should return false if next partial segment number has not the right SAP type for high number of partial segments' , function ( ) {
533+ const ssp = new SegmentSequenceProperties ( ) ;
534+ ssp . sapType = 1 ;
535+ ssp . cadence = 16 ;
536+ expect ( abrCtrl . canPerformQualitySwitch ( {
537+ isPartialSegment : true ,
538+ totalNumberOfPartialSegments : 16 ,
539+ replacementSubNumber : 14
540+ } , {
541+ segmentSequenceProperties : [ ssp ]
542+ } ) ) . to . be . false ;
543+ } ) ;
544+
545+ it ( 'should return true if next partial segment number has the right SAP type for high number of partial segments' , function ( ) {
546+ const ssp = new SegmentSequenceProperties ( ) ;
547+ ssp . sapType = 1 ;
548+ ssp . cadence = 16 ;
549+ expect ( abrCtrl . canPerformQualitySwitch ( {
550+ isPartialSegment : true ,
551+ totalNumberOfPartialSegments : 32 ,
552+ replacementSubNumber : 15
553+ } , {
554+ segmentSequenceProperties : [ ssp ]
555+ } ) ) . to . be . true ;
556+ } ) ;
557+
558+ } )
559+
438560 describe ( 'Additional Tests' , function ( ) {
439561 it ( 'should return null when attempting to get abandonment state when abandonmentStateDict array is empty' , function ( ) {
440562 const state = abrCtrl . getAbandonmentStateFor ( '1' , Constants . AUDIO ) ;
0 commit comments