55 createPairingCompleteResponse ,
66 createPointerProfileResponse ,
77 MAX_POINTER_DELTA ,
8+ NO_ACK_CONTROL_COMMAND_TYPES ,
89 parseProtocolRequest ,
910 PROTOCOL_VERSION ,
1011 validateProtocolRequest ,
@@ -45,15 +46,33 @@ describe('protocol request validation', () => {
4546 }
4647 } ) ;
4748
48- it ( 'accepts no-response mode only for mouse movement' , ( ) => {
49- expect (
50- validateProtocolRequest ( {
51- ...baseCommand ,
52- type : 'mouse.move' ,
53- payload : { dx : 12 , dy : - 6 } ,
54- responseMode : 'none'
55- } )
56- ) . toMatchObject ( { ok : true } ) ;
49+ it ( 'accepts no-response mode only for user control commands' , ( ) => {
50+ const payloads = {
51+ 'mouse.move' : { dx : 12 , dy : - 6 } ,
52+ 'mouse.click' : { button : 'left' } ,
53+ 'mouse.doubleClick' : { button : 'middle' } ,
54+ 'mouse.rightClick' : { } ,
55+ 'mouse.scroll' : { dx : 0 , dy : - 3 } ,
56+ 'mouse.dragStart' : { button : 'left' } ,
57+ 'mouse.dragEnd' : { button : 'left' } ,
58+ 'keyboard.key' : { key : 'Enter' } ,
59+ 'keyboard.shortcut' : { keys : [ 'Ctrl' , 'C' ] } ,
60+ 'keyboard.typeText' : { text : 'Hello' } ,
61+ 'media.control' : { action : 'playPause' } ,
62+ 'window.control' : { action : 'switchNext' }
63+ } ;
64+
65+ for ( const type of NO_ACK_CONTROL_COMMAND_TYPES ) {
66+ expect (
67+ validateProtocolRequest ( {
68+ ...baseCommand ,
69+ type,
70+ payload : payloads [ type ] ,
71+ responseMode : 'none'
72+ } )
73+ ) . toMatchObject ( { ok : true } ) ;
74+ }
75+
5776 expect (
5877 validateProtocolRequest ( {
5978 ...baseCommand ,
@@ -62,22 +81,16 @@ describe('protocol request validation', () => {
6281 responseMode : 'ack'
6382 } )
6483 ) . toMatchObject ( { ok : true } ) ;
65- expect (
66- validateProtocolRequest ( {
67- ...baseCommand ,
68- type : 'mouse.scroll' ,
69- payload : { dx : 0 , dy : - 3 } ,
70- responseMode : 'none'
71- } )
72- ) . toMatchObject ( { ok : false , error : 'invalid_payload' } ) ;
73- expect (
74- validateProtocolRequest ( {
75- ...baseCommand ,
76- type : 'keyboard.key' ,
77- payload : { key : 'Enter' } ,
78- responseMode : 'none'
79- } )
80- ) . toMatchObject ( { ok : false , error : 'invalid_payload' } ) ;
84+ for ( const command of [
85+ { type : 'connection.ping' , payload : { } } ,
86+ { type : 'connection.disconnecting' , payload : { } } ,
87+ { type : 'pointer.profile' , payload : { } }
88+ ] ) {
89+ expect ( validateProtocolRequest ( { ...baseCommand , ...command , responseMode : 'none' } ) ) . toMatchObject ( {
90+ ok : false ,
91+ error : 'invalid_payload'
92+ } ) ;
93+ }
8194 expect (
8295 validateProtocolRequest ( {
8396 ...baseCommand ,
@@ -307,14 +320,44 @@ describe('protocol response validation', () => {
307320 large : 252
308321 } ,
309322 capabilities : {
310- noAckMouseMove : true
323+ noAckMouseMove : true ,
324+ noAckCommands : [ ...NO_ACK_CONTROL_COMMAND_TYPES ]
311325 }
312326 } ) ;
313327
314328 expect ( response . payload . capabilities . noAckMouseMove ) . toBe ( true ) ;
329+ expect ( response . payload . capabilities . noAckCommands ) . toEqual ( [ ...NO_ACK_CONTROL_COMMAND_TYPES ] ) ;
315330 expect ( validateProtocolResponse ( response ) ) . toMatchObject ( { ok : true } ) ;
316331 } ) ;
317332
333+ it ( 'accepts backward-compatible pointer profile capabilities' , ( ) => {
334+ const baseProfile = {
335+ version : PROTOCOL_VERSION ,
336+ id : 'profile-1' ,
337+ type : 'pointer.profile' ,
338+ ok : true ,
339+ payload : {
340+ displayId : '0:0:1280:720:1.5' ,
341+ scaleFactor : 1.5 ,
342+ bounds : { x : 0 , y : 0 , width : 1280 , height : 720 } ,
343+ maxDelta : MAX_POINTER_DELTA ,
344+ recommendedDeltas : { small : 50 , medium : 130 , large : 252 }
345+ } ,
346+ error : null
347+ } ;
348+
349+ expect ( validateProtocolResponse ( baseProfile ) ) . toMatchObject ( { ok : true } ) ;
350+ expect (
351+ validateProtocolResponse ( {
352+ ...baseProfile ,
353+ payload : {
354+ ...baseProfile . payload ,
355+ capabilities : { noAckMouseMove : true }
356+ }
357+ } )
358+ ) . toMatchObject ( { ok : true } ) ;
359+ } ) ;
360+
318361 it ( 'rejects malformed pointer profile responses' , ( ) => {
319362 expect (
320363 validateProtocolResponse ( {
0 commit comments