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