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