@@ -124,6 +124,69 @@ describe("preview guest input", () => {
124124 } ,
125125 ) ;
126126
127+ it . each ( [
128+ {
129+ method : "Input.dispatchMouseEvent" ,
130+ press : "mousePressed" ,
131+ release : "mouseReleased" ,
132+ failPress : false ,
133+ } ,
134+ {
135+ method : "Input.dispatchTouchEvent" ,
136+ press : "touchStart" ,
137+ release : "touchEnd" ,
138+ failPress : false ,
139+ } ,
140+ {
141+ method : "Input.dispatchMouseEvent" ,
142+ press : "mousePressed" ,
143+ release : "mouseReleased" ,
144+ failPress : true ,
145+ } ,
146+ ] ) (
147+ "keeps $method releases behind presses waiting for host focus, failed press: $failPress" ,
148+ async ( { method, press, release, failPress } ) => {
149+ const captureStarted = Promise . withResolvers < void > ( ) ;
150+ const finishCapture = Promise . withResolvers < void > ( ) ;
151+ const events : Array < unknown > = [ ] ;
152+ const guest = {
153+ id : 7 ,
154+ focusedFrame : null ,
155+ hostWebContents : {
156+ isDestroyed : ( ) => false ,
157+ executeJavaScript : async ( ) => {
158+ captureStarted . resolve ( ) ;
159+ await finishCapture . promise ;
160+ } ,
161+ } ,
162+ } ;
163+ const debuggee = {
164+ sendCommand : async ( _method : string , params : Record < string , unknown > ) => {
165+ events . push ( params [ "type" ] ) ;
166+ if ( failPress && params [ "type" ] === press ) throw new Error ( "Press failed" ) ;
167+ return { } ;
168+ } ,
169+ } ;
170+ const send = ( type : string ) =>
171+ sendPageCommand (
172+ guest as unknown as Electron . WebContents ,
173+ debuggee as unknown as Electron . Debugger ,
174+ method ,
175+ { type } ,
176+ ) ;
177+ const pressed = send ( press ) ;
178+ await captureStarted . promise ;
179+ const released = send ( release ) ;
180+ finishCapture . resolve ( ) ;
181+ const results = await Promise . allSettled ( [ pressed , released ] ) ;
182+ expect ( results . map ( ( result ) => result . status ) ) . toEqual ( [
183+ failPress ? "rejected" : "fulfilled" ,
184+ "fulfilled" ,
185+ ] ) ;
186+ expect ( events ) . toEqual ( [ press , release ] ) ;
187+ } ,
188+ ) ;
189+
127190 it ( "refuses input when a cross-site frame holds the unfocused page's focus" , async ( ) => {
128191 const guest = makeGuest ( { focused : false , focusedDocument : false } ) ;
129192 await expect ( guest . send ( "Input.insertText" , { text : "secret" } ) ) . rejects . toThrow (
0 commit comments