@@ -213,10 +213,12 @@ describe('DashAdapter: destroy', () => {
213
213
dashInstance . _loadPromise . should . be . exist ;
214
214
dashInstance . _sourceObj . should . be . exist ;
215
215
dashInstance . _config . should . be . exist ;
216
+ dashInstance . _buffering = true ;
216
217
dashInstance . destroy ( ) ;
217
218
( ! dashInstance . _loadPromise ) . should . be . true ;
218
219
( ! dashInstance . _sourceObj ) . should . be . true ;
219
220
( ! dashInstance . _config ) . should . be . true ;
221
+ dashInstance . _buffering . should . be . false ;
220
222
done ( ) ;
221
223
} ) ;
222
224
} ) ;
@@ -878,5 +880,96 @@ describe('DashAdapter: get duration', () => {
878
880
} ) ;
879
881
} ) ;
880
882
883
+ describe ( 'DashAdapter: _onBuffering' , ( ) => {
884
+ let video , dashInstance , config ;
885
+
886
+ beforeEach ( ( ) => {
887
+ video = document . createElement ( "video" ) ;
888
+ config = { playback : { options : { html5 : { dash : { } } } } } ;
889
+ } ) ;
890
+
891
+ afterEach ( ( ) => {
892
+ dashInstance . destroy ( ) ;
893
+ dashInstance = null ;
894
+ } ) ;
895
+
896
+ after ( ( ) => {
897
+ TestUtils . removeVideoElementsFromTestPage ( ) ;
898
+ } ) ;
899
+
900
+ it ( 'should dispatch waiting event when buffering is true' , ( done ) => {
901
+ dashInstance = DashAdapter . createAdapter ( video , vodSource , config ) ;
902
+ dashInstance . _videoElement . addEventListener ( 'waiting' , ( ) => {
903
+ done ( ) ;
904
+ } ) ;
905
+ dashInstance . _onBuffering ( { buffering : true } ) ;
906
+ } ) ;
907
+
908
+ it ( 'should dispatch playing event when buffering is false and video is playing' , ( done ) => {
909
+ dashInstance = DashAdapter . createAdapter ( video , vodSource , config ) ;
910
+ let hasPlaying = false ;
911
+ let onPlaying = ( ) => {
912
+ if ( hasPlaying ) {
913
+ dashInstance . _videoElement . removeEventListener ( 'playing' , onPlaying ) ;
914
+ done ( ) ;
915
+ } else {
916
+ hasPlaying = true ;
917
+ dashInstance . _onBuffering ( { buffering : false } ) ;
918
+ }
919
+ } ;
920
+ dashInstance . _videoElement . addEventListener ( 'playing' , onPlaying ) ;
921
+ dashInstance . load ( ) . then ( ( ) => {
922
+ dashInstance . _videoElement . play ( ) ;
923
+ } ) ;
924
+ } ) ;
925
+
926
+ it ( 'should not dispatch playing event when buffering is false but video is paused' , ( done ) => {
927
+ dashInstance = DashAdapter . createAdapter ( video , vodSource , config ) ;
928
+ let t = setTimeout ( done , 0 ) ;
929
+ dashInstance . _videoElement . addEventListener ( 'playing' , ( ) => {
930
+ done ( new Error ( "test fail" ) ) ;
931
+ clearTimeout ( t ) ;
932
+ } ) ;
933
+ dashInstance . _onBuffering ( { buffering : false } ) ;
934
+ } ) ;
935
+ } ) ;
936
+
937
+ describe ( 'DashAdapter: _onPlaying' , ( ) => {
938
+ let video , dashInstance , config ;
939
+
940
+ beforeEach ( ( ) => {
941
+ video = document . createElement ( "video" ) ;
942
+ config = { playback : { options : { html5 : { dash : { } } } } } ;
943
+ } ) ;
944
+
945
+ afterEach ( ( ) => {
946
+ dashInstance . destroy ( ) ;
947
+ dashInstance = null ;
948
+ } ) ;
949
+
950
+ after ( ( ) => {
951
+ TestUtils . removeVideoElementsFromTestPage ( ) ;
952
+ } ) ;
953
+
954
+ it ( 'should dispatch waiting event when buffering is true' , ( done ) => {
955
+ dashInstance = DashAdapter . createAdapter ( video , vodSource , config ) ;
956
+ dashInstance . _videoElement . addEventListener ( 'waiting' , ( ) => {
957
+ done ( ) ;
958
+ } ) ;
959
+ dashInstance . _buffering = true ;
960
+ dashInstance . _onPlaying ( ) ;
961
+ } ) ;
962
+
963
+ it ( 'should not dispatch waiting event when buffering is false' , ( done ) => {
964
+ dashInstance = DashAdapter . createAdapter ( video , vodSource , config ) ;
965
+ let t = setTimeout ( done , 0 ) ;
966
+ dashInstance . _videoElement . addEventListener ( 'waiting' , ( ) => {
967
+ done ( new Error ( "test fail" ) ) ;
968
+ clearTimeout ( t ) ;
969
+ } ) ;
970
+ dashInstance . _onPlaying ( ) ;
971
+ } ) ;
972
+ } ) ;
973
+
881
974
882
975
0 commit comments