@@ -2124,6 +2124,170 @@ describe('Remote Frame Buffer Protocol Client', function () {
2124
2124
} ) ;
2125
2125
} ) ;
2126
2126
2127
+ describe ( 'the VMware Cursor pseudo-encoding handler' , function ( ) {
2128
+ beforeEach ( function ( ) {
2129
+ sinon . spy ( client . _cursor , 'change' ) ;
2130
+ } ) ;
2131
+ afterEach ( function ( ) {
2132
+ client . _cursor . change . resetHistory ( ) ;
2133
+ } ) ;
2134
+
2135
+ it ( 'should handle the VMware cursor pseudo-encoding' , function ( ) {
2136
+ let data = [ 0x00 , 0x00 , 0xff , 0 ,
2137
+ 0x00 , 0xff , 0x00 , 0 ,
2138
+ 0x00 , 0xff , 0x00 , 0 ,
2139
+ 0x00 , 0x00 , 0xff , 0 ] ;
2140
+ let rect = [ ] ;
2141
+ push8 ( rect , 0 ) ;
2142
+ push8 ( rect , 0 ) ;
2143
+
2144
+ //AND-mask
2145
+ for ( let i = 0 ; i < data . length ; i ++ ) {
2146
+ push8 ( rect , data [ i ] ) ;
2147
+ }
2148
+ //XOR-mask
2149
+ for ( let i = 0 ; i < data . length ; i ++ ) {
2150
+ push8 ( rect , data [ i ] ) ;
2151
+ }
2152
+
2153
+ send_fbu_msg ( [ { x : 0 , y : 0 , width : 2 , height : 2 ,
2154
+ encoding : 0x574d5664 } ] ,
2155
+ [ rect ] , client ) ;
2156
+ expect ( client . _FBU . rects ) . to . equal ( 0 ) ;
2157
+ } ) ;
2158
+
2159
+ it ( 'should handle insufficient cursor pixel data' , function ( ) {
2160
+
2161
+ // Specified 14x23 pixels for the cursor,
2162
+ // but only send 2x2 pixels worth of data
2163
+ let w = 14 ;
2164
+ let h = 23 ;
2165
+ let data = [ 0x00 , 0x00 , 0xff , 0 ,
2166
+ 0x00 , 0xff , 0x00 , 0 ] ;
2167
+ let rect = [ ] ;
2168
+
2169
+ push8 ( rect , 0 ) ;
2170
+ push8 ( rect , 0 ) ;
2171
+
2172
+ //AND-mask
2173
+ for ( let i = 0 ; i < data . length ; i ++ ) {
2174
+ push8 ( rect , data [ i ] ) ;
2175
+ }
2176
+ //XOR-mask
2177
+ for ( let i = 0 ; i < data . length ; i ++ ) {
2178
+ push8 ( rect , data [ i ] ) ;
2179
+ }
2180
+
2181
+ send_fbu_msg ( [ { x : 0 , y : 0 , width : w , height : h ,
2182
+ encoding : 0x574d5664 } ] ,
2183
+ [ rect ] , client ) ;
2184
+
2185
+ // expect one FBU to remain unhandled
2186
+ expect ( client . _FBU . rects ) . to . equal ( 1 ) ;
2187
+ } ) ;
2188
+
2189
+ it ( 'should update the cursor when type is classic' , function ( ) {
2190
+ let and_mask =
2191
+ [ 0xff , 0xff , 0xff , 0xff , //Transparent
2192
+ 0xff , 0xff , 0xff , 0xff , //Transparent
2193
+ 0x00 , 0x00 , 0x00 , 0x00 , //Opaque
2194
+ 0xff , 0xff , 0xff , 0xff ] ; //Inverted
2195
+
2196
+ let xor_mask =
2197
+ [ 0x00 , 0x00 , 0x00 , 0x00 , //Transparent
2198
+ 0x00 , 0x00 , 0x00 , 0x00 , //Transparent
2199
+ 0x11 , 0x22 , 0x33 , 0x44 , //Opaque
2200
+ 0xff , 0xff , 0xff , 0x44 ] ; //Inverted
2201
+
2202
+ let rect = [ ] ;
2203
+ push8 ( rect , 0 ) ; //cursor_type
2204
+ push8 ( rect , 0 ) ; //padding
2205
+ let hotx = 0 ;
2206
+ let hoty = 0 ;
2207
+ let w = 2 ;
2208
+ let h = 2 ;
2209
+
2210
+ //AND-mask
2211
+ for ( let i = 0 ; i < and_mask . length ; i ++ ) {
2212
+ push8 ( rect , and_mask [ i ] ) ;
2213
+ }
2214
+ //XOR-mask
2215
+ for ( let i = 0 ; i < xor_mask . length ; i ++ ) {
2216
+ push8 ( rect , xor_mask [ i ] ) ;
2217
+ }
2218
+
2219
+ let expected_rgba = [ 0x00 , 0x00 , 0x00 , 0x00 ,
2220
+ 0x00 , 0x00 , 0x00 , 0x00 ,
2221
+ 0x33 , 0x22 , 0x11 , 0xff ,
2222
+ 0x00 , 0x00 , 0x00 , 0xff ] ;
2223
+
2224
+ send_fbu_msg ( [ { x : hotx , y : hoty ,
2225
+ width : w , height : h ,
2226
+ encoding : 0x574d5664 } ] ,
2227
+ [ rect ] , client ) ;
2228
+
2229
+ expect ( client . _cursor . change )
2230
+ . to . have . been . calledOnce ;
2231
+ expect ( client . _cursor . change )
2232
+ . to . have . been . calledWith ( expected_rgba ,
2233
+ hotx , hoty ,
2234
+ w , h ) ;
2235
+ } ) ;
2236
+
2237
+ it ( 'should update the cursor when type is alpha' , function ( ) {
2238
+ let data = [ 0xee , 0x55 , 0xff , 0x00 , // bgra
2239
+ 0x00 , 0xff , 0x00 , 0xff ,
2240
+ 0x00 , 0xff , 0x00 , 0x22 ,
2241
+ 0x00 , 0xff , 0x00 , 0x22 ,
2242
+ 0x00 , 0xff , 0x00 , 0x22 ,
2243
+ 0x00 , 0x00 , 0xff , 0xee ] ;
2244
+ let rect = [ ] ;
2245
+ push8 ( rect , 1 ) ; //cursor_type
2246
+ push8 ( rect , 0 ) ; //padding
2247
+ let hotx = 0 ;
2248
+ let hoty = 0 ;
2249
+ let w = 3 ;
2250
+ let h = 2 ;
2251
+
2252
+ for ( let i = 0 ; i < data . length ; i ++ ) {
2253
+ push8 ( rect , data [ i ] ) ;
2254
+ }
2255
+
2256
+ let expected_rgba = [ 0xff , 0x55 , 0xee , 0x00 ,
2257
+ 0x00 , 0xff , 0x00 , 0xff ,
2258
+ 0x00 , 0xff , 0x00 , 0x22 ,
2259
+ 0x00 , 0xff , 0x00 , 0x22 ,
2260
+ 0x00 , 0xff , 0x00 , 0x22 ,
2261
+ 0xff , 0x00 , 0x00 , 0xee ] ;
2262
+
2263
+ send_fbu_msg ( [ { x : hotx , y : hoty ,
2264
+ width : w , height : h ,
2265
+ encoding : 0x574d5664 } ] ,
2266
+ [ rect ] , client ) ;
2267
+
2268
+ expect ( client . _cursor . change )
2269
+ . to . have . been . calledOnce ;
2270
+ expect ( client . _cursor . change )
2271
+ . to . have . been . calledWith ( expected_rgba ,
2272
+ hotx , hoty ,
2273
+ w , h ) ;
2274
+ } ) ;
2275
+
2276
+ it ( 'should not update cursor when incorrect cursor type given' , function ( ) {
2277
+ let rect = [ ] ;
2278
+ push8 ( rect , 3 ) ; // invalid cursor type
2279
+ push8 ( rect , 0 ) ; // padding
2280
+
2281
+ client . _cursor . change . resetHistory ( ) ;
2282
+ send_fbu_msg ( [ { x : 0 , y : 0 , width : 2 , height : 2 ,
2283
+ encoding : 0x574d5664 } ] ,
2284
+ [ rect ] , client ) ;
2285
+
2286
+ expect ( client . _cursor . change )
2287
+ . to . not . have . been . called ;
2288
+ } ) ;
2289
+ } ) ;
2290
+
2127
2291
it ( 'should handle the last_rect pseudo-encoding' , function ( ) {
2128
2292
send_fbu_msg ( [ { x : 0 , y : 0 , width : 0 , height : 0 , encoding : - 224 } ] , [ [ ] ] , client , 100 ) ;
2129
2293
expect ( client . _FBU . rects ) . to . equal ( 0 ) ;
0 commit comments