@@ -791,3 +791,287 @@ QUnit.module('SmartTV UI Updates (Progress Bar & Time Display)', function(hooks)
791791 userSeekSpy . restore ( ) ;
792792 } ) ;
793793} ) ;
794+
795+ QUnit . test ( 'VolumeBar initializes with LinearVolumeTransfer by default' , function ( assert ) {
796+ const player = TestHelpers . makePlayer ( { techOrder : [ 'html5' ] } ) ;
797+ const volumeBar = player . controlBar . volumePanel . volumeControl . volumeBar ;
798+
799+ this . clock . tick ( 1 ) ;
800+
801+ assert . ok ( volumeBar . volumeTransfer_ , 'volumeTransfer_ should be initialized' ) ;
802+ assert . equal (
803+ volumeBar . volumeTransfer_ . constructor . name , 'LinearVolumeTransfer' ,
804+ 'should use LinearVolumeTransfer by default'
805+ ) ;
806+
807+ player . dispose ( ) ;
808+ } ) ;
809+
810+ QUnit . test ( 'VolumeBar initializes with LogarithmicVolumeTransfer when logarithmicVolume is true' , function ( assert ) {
811+ const player = TestHelpers . makePlayer ( {
812+ techOrder : [ 'html5' ] ,
813+ logarithmicVolume : true
814+ } ) ;
815+ const volumeBar = player . controlBar . volumePanel . volumeControl . volumeBar ;
816+
817+ this . clock . tick ( 1 ) ;
818+
819+ assert . ok ( volumeBar . volumeTransfer_ , 'volumeTransfer_ should be initialized' ) ;
820+ assert . equal (
821+ volumeBar . volumeTransfer_ . constructor . name , 'LogarithmicVolumeTransfer' ,
822+ 'should use LogarithmicVolumeTransfer when logarithmicVolume is true'
823+ ) ;
824+
825+ player . dispose ( ) ;
826+ } ) ;
827+
828+ QUnit . test ( 'VolumeBar getPercent() uses volume transfer function with logarithmic mode' , function ( assert ) {
829+ const player = TestHelpers . makePlayer ( {
830+ techOrder : [ 'html5' ] ,
831+ logarithmicVolume : true
832+ } ) ;
833+ const volumeBar = player . controlBar . volumePanel . volumeControl . volumeBar ;
834+
835+ this . clock . tick ( 1 ) ;
836+
837+ player . volume ( 0 ) ;
838+ assert . equal ( volumeBar . getPercent ( ) , 0 , 'should return 0 for volume 0' ) ;
839+
840+ player . volume ( 1 ) ;
841+ assert . equal ( volumeBar . getPercent ( ) , 1 , 'should return 1 for volume 1' ) ;
842+
843+ player . volume ( 0.5 ) ;
844+ const percent = volumeBar . getPercent ( ) ;
845+
846+ assert . ok ( percent > 0.5 && percent < 1 , 'should return non-linear value for volume 0.5' ) ;
847+
848+ player . dispose ( ) ;
849+ } ) ;
850+
851+ QUnit . test ( 'VolumeBar handleMouseMove uses volume transfer with logarithmic mode' , function ( assert ) {
852+ const player = TestHelpers . makePlayer ( {
853+ techOrder : [ 'html5' ] ,
854+ logarithmicVolume : true
855+ } ) ;
856+ const volumeBar = player . controlBar . volumePanel . volumeControl . volumeBar ;
857+
858+ this . clock . tick ( 1 ) ;
859+
860+ const originalCalc = volumeBar . calculateDistance ;
861+
862+ volumeBar . calculateDistance = function ( ) {
863+ return 0.5 ;
864+ } ;
865+
866+ volumeBar . handleMouseMove ( { pageX : 100 , pageY : 100 } ) ;
867+
868+ const volume = player . volume ( ) ;
869+
870+ assert . ok ( volume > 0 && volume < 0.5 , 'logarithmic mode should set low volume for 50% position' ) ;
871+
872+ volumeBar . calculateDistance = originalCalc ;
873+ player . dispose ( ) ;
874+ } ) ;
875+
876+ QUnit . test ( 'VolumeBar stepForward increases volume with logarithmic transfer' , function ( assert ) {
877+ const player = TestHelpers . makePlayer ( {
878+ techOrder : [ 'html5' ] ,
879+ logarithmicVolume : true
880+ } ) ;
881+ const volumeBar = player . controlBar . volumePanel . volumeControl . volumeBar ;
882+
883+ this . clock . tick ( 1 ) ;
884+
885+ player . volume ( 0.5 ) ;
886+ const initialVolume = player . volume ( ) ;
887+
888+ volumeBar . stepForward ( ) ;
889+
890+ assert . ok ( player . volume ( ) > initialVolume , 'should increase volume' ) ;
891+ assert . ok ( player . volume ( ) <= 1 , 'should not exceed max volume' ) ;
892+
893+ player . dispose ( ) ;
894+ } ) ;
895+
896+ QUnit . test ( 'VolumeBar stepBack decreases volume with logarithmic transfer' , function ( assert ) {
897+ const player = TestHelpers . makePlayer ( {
898+ techOrder : [ 'html5' ] ,
899+ logarithmicVolume : true
900+ } ) ;
901+ const volumeBar = player . controlBar . volumePanel . volumeControl . volumeBar ;
902+
903+ this . clock . tick ( 1 ) ;
904+
905+ player . volume ( 0.5 ) ;
906+ const initialVolume = player . volume ( ) ;
907+
908+ volumeBar . stepBack ( ) ;
909+
910+ assert . ok ( player . volume ( ) < initialVolume , 'should decrease volume' ) ;
911+ assert . ok ( player . volume ( ) >= 0 , 'should not go below min volume' ) ;
912+
913+ player . dispose ( ) ;
914+ } ) ;
915+
916+ QUnit . test ( 'VolumeBar passes logarithmicVolumeRange option to LogarithmicVolumeTransfer' , function ( assert ) {
917+ const customRange = 60 ;
918+ const player = TestHelpers . makePlayer ( {
919+ techOrder : [ 'html5' ] ,
920+ logarithmicVolume : true ,
921+ logarithmicVolumeRange : customRange
922+ } ) ;
923+
924+ const volumeBar = player . controlBar . volumePanel . volumeControl . volumeBar ;
925+
926+ assert . equal (
927+ volumeBar . volumeTransfer_ . dbRange , customRange ,
928+ 'should use custom logarithmicVolumeRange value'
929+ ) ;
930+
931+ player . dispose ( ) ;
932+ } ) ;
933+
934+ QUnit . test ( 'VolumeBar getPercent() returns correct values with linear transfer' , function ( assert ) {
935+ const player = TestHelpers . makePlayer ( {
936+ techOrder : [ 'html5' ]
937+ } ) ;
938+
939+ const volumeBar = player . controlBar . volumePanel . volumeControl . volumeBar ;
940+
941+ player . volume ( 0 ) ;
942+ assert . equal ( volumeBar . getPercent ( ) , 0 , 'should return 0 for volume 0' ) ;
943+
944+ player . volume ( 0.5 ) ;
945+ assert . equal ( volumeBar . getPercent ( ) , 0.5 , 'should return 0.5 for volume 0.5' ) ;
946+
947+ player . volume ( 1 ) ;
948+ assert . equal ( volumeBar . getPercent ( ) , 1 , 'should return 1 for volume 1' ) ;
949+
950+ player . dispose ( ) ;
951+ } ) ;
952+
953+ QUnit . test ( 'VolumeBar handleMouseMove() sets correct volume with linear transfer' , function ( assert ) {
954+ const player = TestHelpers . makePlayer ( {
955+ techOrder : [ 'html5' ]
956+ } ) ;
957+
958+ const volumeBar = player . controlBar . volumePanel . volumeControl . volumeBar ;
959+
960+ const originalCalculateDistance = volumeBar . calculateDistance ;
961+
962+ volumeBar . calculateDistance = function ( ) {
963+ return 0.5 ;
964+ } ;
965+
966+ const event = {
967+ pageX : 100 ,
968+ pageY : 100
969+ } ;
970+
971+ volumeBar . handleMouseMove ( event ) ;
972+
973+ assert . equal ( player . volume ( ) , 0.5 , 'should set volume to 0.5 for 50% position with linear transfer' ) ;
974+
975+ volumeBar . calculateDistance = originalCalculateDistance ;
976+ player . dispose ( ) ;
977+ } ) ;
978+
979+ QUnit . test ( 'VolumeBar handleMouseMove() sets correct volume with logarithmic transfer' , function ( assert ) {
980+ const player = TestHelpers . makePlayer ( {
981+ techOrder : [ 'html5' ] ,
982+ logarithmicVolume : true
983+ } ) ;
984+
985+ const volumeBar = player . controlBar . volumePanel . volumeControl . volumeBar ;
986+
987+ const originalCalculateDistance = volumeBar . calculateDistance ;
988+
989+ volumeBar . calculateDistance = function ( ) {
990+ return 0.5 ;
991+ } ;
992+
993+ const event = {
994+ pageX : 100 ,
995+ pageY : 100
996+ } ;
997+
998+ volumeBar . handleMouseMove ( event ) ;
999+
1000+ const volume = player . volume ( ) ;
1001+
1002+ assert . ok ( volume < 0.5 , 'logarithmic transfer should set volume < 0.5 for 50% slider position' ) ;
1003+ assert . ok ( volume > 0 , 'volume should be greater than 0' ) ;
1004+
1005+ volumeBar . calculateDistance = originalCalculateDistance ;
1006+ player . dispose ( ) ;
1007+ } ) ;
1008+
1009+ QUnit . test ( 'VolumeBar stepForward() increases volume correctly with linear transfer' , function ( assert ) {
1010+ const player = TestHelpers . makePlayer ( {
1011+ techOrder : [ 'html5' ]
1012+ } ) ;
1013+
1014+ const volumeBar = player . controlBar . volumePanel . volumeControl . volumeBar ;
1015+
1016+ player . volume ( 0.5 ) ;
1017+ volumeBar . stepForward ( ) ;
1018+
1019+ assert . ok ( player . volume ( ) > 0.5 , 'should increase volume' ) ;
1020+ assert . ok ( player . volume ( ) <= 1 , 'should not exceed max volume' ) ;
1021+
1022+ player . dispose ( ) ;
1023+ } ) ;
1024+
1025+ QUnit . test ( 'VolumeBar stepForward() increases volume correctly with logarithmic transfer' , function ( assert ) {
1026+ const player = TestHelpers . makePlayer ( {
1027+ techOrder : [ 'html5' ] ,
1028+ logarithmicVolume : true
1029+ } ) ;
1030+
1031+ const volumeBar = player . controlBar . volumePanel . volumeControl . volumeBar ;
1032+
1033+ const initialVolume = 0.5 ;
1034+
1035+ player . volume ( initialVolume ) ;
1036+ volumeBar . stepForward ( ) ;
1037+
1038+ assert . ok ( player . volume ( ) > initialVolume , 'should increase volume' ) ;
1039+ assert . ok ( player . volume ( ) <= 1 , 'should not exceed max volume' ) ;
1040+
1041+ player . dispose ( ) ;
1042+ } ) ;
1043+
1044+ QUnit . test ( 'VolumeBar stepBack() decreases volume correctly with linear transfer' , function ( assert ) {
1045+ const player = TestHelpers . makePlayer ( {
1046+ techOrder : [ 'html5' ]
1047+ } ) ;
1048+
1049+ const volumeBar = player . controlBar . volumePanel . volumeControl . volumeBar ;
1050+
1051+ player . volume ( 0.5 ) ;
1052+ volumeBar . stepBack ( ) ;
1053+
1054+ assert . ok ( player . volume ( ) < 0.5 , 'should decrease volume' ) ;
1055+ assert . ok ( player . volume ( ) >= 0 , 'should not go below min volume' ) ;
1056+
1057+ player . dispose ( ) ;
1058+ } ) ;
1059+
1060+ QUnit . test ( 'VolumeBar stepBack() decreases volume correctly with logarithmic transfer' , function ( assert ) {
1061+ const player = TestHelpers . makePlayer ( {
1062+ techOrder : [ 'html5' ] ,
1063+ logarithmicVolume : true
1064+ } ) ;
1065+
1066+ const volumeBar = player . controlBar . volumePanel . volumeControl . volumeBar ;
1067+
1068+ const initialVolume = 0.5 ;
1069+
1070+ player . volume ( initialVolume ) ;
1071+ volumeBar . stepBack ( ) ;
1072+
1073+ assert . ok ( player . volume ( ) < initialVolume , 'should decrease volume' ) ;
1074+ assert . ok ( player . volume ( ) >= 0 , 'should not go below min volume' ) ;
1075+
1076+ player . dispose ( ) ;
1077+ } ) ;
0 commit comments