@@ -2967,6 +2967,108 @@ describe('Remote Frame Buffer Protocol Client', function () {
2967
2967
expect ( RFB . messages . clientEncodings . getCall ( 0 ) . args [ 1 ] ) . to . include ( encodings . pseudoEncodingQualityLevel0 + newQuality ) ;
2968
2968
} ) ;
2969
2969
} ) ;
2970
+
2971
+ describe ( 'Compression level setting' , function ( ) {
2972
+ const defaultCompression = 2 ;
2973
+
2974
+ let client ;
2975
+
2976
+ beforeEach ( function ( ) {
2977
+ client = make_rfb ( ) ;
2978
+ sinon . spy ( RFB . messages , "clientEncodings" ) ;
2979
+ } ) ;
2980
+
2981
+ afterEach ( function ( ) {
2982
+ RFB . messages . clientEncodings . restore ( ) ;
2983
+ } ) ;
2984
+
2985
+ it ( `should equal ${ defaultCompression } by default` , function ( ) {
2986
+ expect ( client . _compressionLevel ) . to . equal ( defaultCompression ) ;
2987
+ } ) ;
2988
+
2989
+ it ( 'should ignore non-integers when set' , function ( ) {
2990
+ client . compressionLevel = '1' ;
2991
+ expect ( RFB . messages . clientEncodings ) . to . not . have . been . called ;
2992
+
2993
+ RFB . messages . clientEncodings . resetHistory ( ) ;
2994
+
2995
+ client . compressionLevel = 1.5 ;
2996
+ expect ( RFB . messages . clientEncodings ) . to . not . have . been . called ;
2997
+
2998
+ RFB . messages . clientEncodings . resetHistory ( ) ;
2999
+
3000
+ client . compressionLevel = null ;
3001
+ expect ( RFB . messages . clientEncodings ) . to . not . have . been . called ;
3002
+
3003
+ RFB . messages . clientEncodings . resetHistory ( ) ;
3004
+
3005
+ client . compressionLevel = undefined ;
3006
+ expect ( RFB . messages . clientEncodings ) . to . not . have . been . called ;
3007
+
3008
+ RFB . messages . clientEncodings . resetHistory ( ) ;
3009
+
3010
+ client . compressionLevel = { } ;
3011
+ expect ( RFB . messages . clientEncodings ) . to . not . have . been . called ;
3012
+ } ) ;
3013
+
3014
+ it ( 'should ignore integers out of range [0, 9]' , function ( ) {
3015
+ client . compressionLevel = - 1 ;
3016
+ expect ( RFB . messages . clientEncodings ) . to . not . have . been . called ;
3017
+
3018
+ RFB . messages . clientEncodings . resetHistory ( ) ;
3019
+
3020
+ client . compressionLevel = 10 ;
3021
+ expect ( RFB . messages . clientEncodings ) . to . not . have . been . called ;
3022
+ } ) ;
3023
+
3024
+ it ( 'should send clientEncodings with new compression value' , function ( ) {
3025
+ let newCompression ;
3026
+
3027
+ newCompression = 5 ;
3028
+ client . compressionLevel = newCompression ;
3029
+ expect ( client . compressionLevel ) . to . equal ( newCompression ) ;
3030
+ expect ( RFB . messages . clientEncodings ) . to . have . been . calledOnce ;
3031
+ expect ( RFB . messages . clientEncodings . getCall ( 0 ) . args [ 1 ] ) . to . include ( encodings . pseudoEncodingCompressLevel0 + newCompression ) ;
3032
+ } ) ;
3033
+
3034
+ it ( 'should not send clientEncodings if compression is the same' , function ( ) {
3035
+ let newCompression ;
3036
+
3037
+ newCompression = 9 ;
3038
+ client . compressionLevel = newCompression ;
3039
+ expect ( RFB . messages . clientEncodings ) . to . have . been . calledOnce ;
3040
+ expect ( RFB . messages . clientEncodings . getCall ( 0 ) . args [ 1 ] ) . to . include ( encodings . pseudoEncodingCompressLevel0 + newCompression ) ;
3041
+
3042
+ RFB . messages . clientEncodings . resetHistory ( ) ;
3043
+
3044
+ client . compressionLevel = newCompression ;
3045
+ expect ( RFB . messages . clientEncodings ) . to . not . have . been . called ;
3046
+ } ) ;
3047
+
3048
+ it ( 'should not send clientEncodings if not in connected state' , function ( ) {
3049
+ let newCompression ;
3050
+
3051
+ client . _rfb_connection_state = '' ;
3052
+ newCompression = 7 ;
3053
+ client . compressionLevel = newCompression ;
3054
+ expect ( RFB . messages . clientEncodings ) . to . not . have . been . called ;
3055
+
3056
+ RFB . messages . clientEncodings . resetHistory ( ) ;
3057
+
3058
+ client . _rfb_connection_state = 'connnecting' ;
3059
+ newCompression = 6 ;
3060
+ client . compressionLevel = newCompression ;
3061
+ expect ( RFB . messages . clientEncodings ) . to . not . have . been . called ;
3062
+
3063
+ RFB . messages . clientEncodings . resetHistory ( ) ;
3064
+
3065
+ client . _rfb_connection_state = 'connected' ;
3066
+ newCompression = 5 ;
3067
+ client . compressionLevel = newCompression ;
3068
+ expect ( RFB . messages . clientEncodings ) . to . have . been . calledOnce ;
3069
+ expect ( RFB . messages . clientEncodings . getCall ( 0 ) . args [ 1 ] ) . to . include ( encodings . pseudoEncodingCompressLevel0 + newCompression ) ;
3070
+ } ) ;
3071
+ } ) ;
2970
3072
} ) ;
2971
3073
2972
3074
describe ( 'RFB messages' , function ( ) {
0 commit comments