@@ -22,6 +22,7 @@ const mockDashInstance = {
22
22
duration : jest . fn ( ) ,
23
23
attachSource : jest . fn ( ) ,
24
24
reset : jest . fn ( ) ,
25
+ destroy : jest . fn ( ) ,
25
26
isPaused : jest . fn ( ) ,
26
27
pause : jest . fn ( ) ,
27
28
play : jest . fn ( ) ,
@@ -654,14 +655,106 @@ describe("Media Source Extensions Playback Strategy", () => {
654
655
} )
655
656
} )
656
657
658
+ describe ( "reset()" , ( ) => {
659
+ describe ( "when resetMSEPlayer is configured as true" , ( ) => {
660
+ beforeEach ( ( ) => {
661
+ window . bigscreenPlayer . overrides = {
662
+ resetMSEPlayer : true ,
663
+ }
664
+ } )
665
+
666
+ it ( "should destroy the player and listeners" , ( ) => {
667
+ setUpMSE ( )
668
+ mseStrategy . load ( null , 0 )
669
+
670
+ expect ( playbackElement . childElementCount ) . toBe ( 1 )
671
+
672
+ mseStrategy . reset ( )
673
+
674
+ expect ( mockDashInstance . destroy ) . toHaveBeenCalledWith ( )
675
+
676
+ expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "timeupdate" , expect . any ( Function ) )
677
+ expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "loadedmetadata" , expect . any ( Function ) )
678
+ expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "loadeddata" , expect . any ( Function ) )
679
+ expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "play" , expect . any ( Function ) )
680
+ expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "playing" , expect . any ( Function ) )
681
+ expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "pause" , expect . any ( Function ) )
682
+ expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "waiting" , expect . any ( Function ) )
683
+ expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "seeking" , expect . any ( Function ) )
684
+ expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "seeked" , expect . any ( Function ) )
685
+ expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "ended" , expect . any ( Function ) )
686
+ expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "ratechange" , expect . any ( Function ) )
687
+
688
+ expect ( playbackElement . childElementCount ) . toBe ( 0 )
689
+ } )
690
+
691
+ it ( "should setup player and element on a load after a reset" , ( ) => {
692
+ setUpMSE ( )
693
+ mseStrategy . load ( null , 0 )
694
+
695
+ mseStrategy . reset ( )
696
+
697
+ jest . clearAllMocks ( )
698
+
699
+ jest . spyOn ( document , "createElement" ) . mockImplementationOnce ( ( elementType ) => {
700
+ if ( [ "audio" , "video" ] . includes ( elementType ) ) {
701
+ mediaElement = mockMediaElement ( elementType )
702
+ return mediaElement
703
+ }
704
+
705
+ return document . createElement ( elementType )
706
+ } )
707
+
708
+ mseStrategy . load ( null , 0 )
709
+
710
+ expect ( mockDashInstance . initialize ) . toHaveBeenCalledTimes ( 1 )
711
+ expect ( mockDashInstance . initialize ) . toHaveBeenCalledWith ( mediaElement , null , true )
712
+ expect ( mockDashInstance . attachSource ) . toHaveBeenCalledWith ( cdnArray [ 0 ] . url )
713
+
714
+ expect ( playbackElement . childElementCount ) . toBe ( 1 )
715
+ expect ( playbackElement . firstChild ) . toBeInstanceOf ( HTMLVideoElement )
716
+ expect ( playbackElement . firstChild ) . toBe ( mediaElement )
717
+ expect ( isMockedElement ( playbackElement . firstChild ) ) . toBe ( true )
718
+ } )
719
+ } )
720
+ describe ( "when resetMSEPlayer is configured as false" , ( ) => {
721
+ beforeEach ( ( ) => {
722
+ window . bigscreenPlayer . overrides = {
723
+ resetMSEPlayer : false ,
724
+ }
725
+ } )
726
+
727
+ it ( "should not destroy the player or listeners" , ( ) => {
728
+ setUpMSE ( )
729
+ mseStrategy . load ( null , 0 )
730
+ mseStrategy . reset ( )
731
+
732
+ expect ( mockDashInstance . destroy ) . not . toHaveBeenCalledWith ( )
733
+ expect ( playbackElement . childElementCount ) . toBe ( 1 )
734
+
735
+ expect ( mediaElement . removeEventListener ) . not . toHaveBeenCalledWith ( "timeupdate" , expect . any ( Function ) )
736
+ expect ( mediaElement . removeEventListener ) . not . toHaveBeenCalledWith ( "loadedmetadata" , expect . any ( Function ) )
737
+ expect ( mediaElement . removeEventListener ) . not . toHaveBeenCalledWith ( "loadeddata" , expect . any ( Function ) )
738
+ expect ( mediaElement . removeEventListener ) . not . toHaveBeenCalledWith ( "play" , expect . any ( Function ) )
739
+ expect ( mediaElement . removeEventListener ) . not . toHaveBeenCalledWith ( "playing" , expect . any ( Function ) )
740
+ expect ( mediaElement . removeEventListener ) . not . toHaveBeenCalledWith ( "pause" , expect . any ( Function ) )
741
+ expect ( mediaElement . removeEventListener ) . not . toHaveBeenCalledWith ( "waiting" , expect . any ( Function ) )
742
+ expect ( mediaElement . removeEventListener ) . not . toHaveBeenCalledWith ( "seeking" , expect . any ( Function ) )
743
+ expect ( mediaElement . removeEventListener ) . not . toHaveBeenCalledWith ( "seeked" , expect . any ( Function ) )
744
+ expect ( mediaElement . removeEventListener ) . not . toHaveBeenCalledWith ( "ended" , expect . any ( Function ) )
745
+ expect ( mediaElement . removeEventListener ) . not . toHaveBeenCalledWith ( "ratechange" , expect . any ( Function ) )
746
+ } )
747
+ } )
748
+ } )
749
+
657
750
describe ( "tearDown()" , ( ) => {
658
- it ( "should reset the MediaPlayer" , ( ) => {
751
+ it ( "should destroy the MediaPlayer" , ( ) => {
659
752
setUpMSE ( )
660
753
mseStrategy . load ( null , 0 )
661
754
662
755
mseStrategy . tearDown ( )
663
756
664
- expect ( mockDashInstance . reset ) . toHaveBeenCalledWith ( )
757
+ expect ( mockDashInstance . destroy ) . toHaveBeenCalledWith ( )
665
758
} )
666
759
667
760
it ( "should tear down bindings to MediaPlayer Events correctly" , ( ) => {
@@ -671,12 +764,17 @@ describe("Media Source Extensions Playback Strategy", () => {
671
764
mseStrategy . tearDown ( )
672
765
673
766
expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "timeupdate" , expect . any ( Function ) )
767
+ expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "loadedmetadata" , expect . any ( Function ) )
768
+ expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "loadeddata" , expect . any ( Function ) )
769
+ expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "play" , expect . any ( Function ) )
674
770
expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "playing" , expect . any ( Function ) )
675
771
expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "pause" , expect . any ( Function ) )
676
772
expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "waiting" , expect . any ( Function ) )
677
773
expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "seeking" , expect . any ( Function ) )
678
774
expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "seeked" , expect . any ( Function ) )
679
775
expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "ended" , expect . any ( Function ) )
776
+ expect ( mediaElement . removeEventListener ) . toHaveBeenCalledWith ( "ratechange" , expect . any ( Function ) )
777
+
680
778
expect ( mockDashInstance . off ) . toHaveBeenCalledWith ( dashjsMediaPlayerEvents . ERROR , expect . any ( Function ) )
681
779
expect ( mockDashInstance . off ) . toHaveBeenCalledWith (
682
780
dashjsMediaPlayerEvents . QUALITY_CHANGE_RENDERED ,
0 commit comments