@@ -124,51 +124,58 @@ describe("preview guest input", () => {
124124 } ,
125125 ) ;
126126
127- it ( "preserves host focus when a sibling tab's press overlaps a stuck one" , async ( ) => {
128- const document = { activeElement : { } as object } ;
129- const composer = {
130- isConnected : true ,
131- focus : ( ) => {
132- document . activeElement = composer ;
133- } ,
134- } ;
135- document . activeElement = composer ;
136- const context = NodeVM . createContext ( { document } ) ;
137- const host = {
138- isDestroyed : ( ) => false ,
139- executeJavaScript : async ( script : string ) => NodeVM . runInContext ( script , context ) ,
140- } ;
141- const stuckPressFocused = Promise . withResolvers < void > ( ) ;
142- const stuckPressEnds = Promise . withResolvers < void > ( ) ;
143- const press = ( id : number , stuck : boolean ) => {
144- const preview = { tagName : "WEBVIEW" , getWebContentsId : ( ) => id } ;
145- const debuggee = {
146- sendCommand : async ( ) => {
147- document . activeElement = preview ;
148- if ( stuck ) {
149- stuckPressFocused . resolve ( ) ;
150- await stuckPressEnds . promise ;
151- }
152- return { } ;
127+ it . each ( [ { userClicksStuckTab : false } , { userClicksStuckTab : true } ] ) (
128+ "keeps the right focus when a sibling tab's press overlaps a stuck one, user clicks: $userClicksStuckTab" ,
129+ async ( { userClicksStuckTab } ) => {
130+ const document = { activeElement : { } as object } ;
131+ const composer = {
132+ isConnected : true ,
133+ focus : ( ) => {
134+ document . activeElement = composer ;
153135 } ,
154136 } ;
155- return sendPageCommand (
156- { id, focusedFrame : null , hostWebContents : host } as unknown as Electron . WebContents ,
157- debuggee as unknown as Electron . Debugger ,
158- "Input.dispatchMouseEvent" ,
159- { type : "mousePressed" , x : 10 , y : 10 , button : "left" } ,
137+ document . activeElement = composer ;
138+ const context = NodeVM . createContext ( { document } ) ;
139+ const host = {
140+ isDestroyed : ( ) => false ,
141+ executeJavaScript : async ( script : string ) => NodeVM . runInContext ( script , context ) ,
142+ } ;
143+ const previews = new Map (
144+ [ 7 , 8 ] . map ( ( id ) => [ id , { tagName : "WEBVIEW" , getWebContentsId : ( ) => id } ] ) ,
160145 ) ;
161- } ;
162- // A press held open, as by a page's confirm() on mousedown, must not block or win focus.
163- const stuck = press ( 7 , true ) ;
164- await stuckPressFocused . promise ;
165- await press ( 8 , false ) ;
166- expect ( document . activeElement ) . toBe ( composer ) ;
167- stuckPressEnds . resolve ( ) ;
168- await stuck ;
169- expect ( document . activeElement ) . toBe ( composer ) ;
170- expect ( Object . keys ( context ) ) . toEqual ( [ "document" ] ) ;
171- } ) ;
146+ const stuckPressFocused = Promise . withResolvers < void > ( ) ;
147+ const stuckPressEnds = Promise . withResolvers < void > ( ) ;
148+ const press = ( id : number ) => {
149+ const debuggee = {
150+ sendCommand : async ( ) => {
151+ document . activeElement = previews . get ( id ) ! ;
152+ if ( id === 7 ) {
153+ stuckPressFocused . resolve ( ) ;
154+ await stuckPressEnds . promise ;
155+ } else if ( userClicksStuckTab ) {
156+ document . activeElement = previews . get ( 7 ) ! ;
157+ }
158+ return { } ;
159+ } ,
160+ } ;
161+ return sendPageCommand (
162+ { id, focusedFrame : null , hostWebContents : host } as unknown as Electron . WebContents ,
163+ debuggee as unknown as Electron . Debugger ,
164+ "Input.dispatchMouseEvent" ,
165+ { type : "mousePressed" , x : 10 , y : 10 , button : "left" } ,
166+ ) ;
167+ } ;
168+ // A press held open, as by a page's confirm() on mousedown, must not block or win focus.
169+ const stuck = press ( 7 ) ;
170+ await stuckPressFocused . promise ;
171+ await press ( 8 ) ;
172+ const expected = userClicksStuckTab ? previews . get ( 7 ) : composer ;
173+ expect ( document . activeElement ) . toBe ( expected ) ;
174+ stuckPressEnds . resolve ( ) ;
175+ await stuck ;
176+ expect ( Object . keys ( context ) ) . toEqual ( [ "document" ] ) ;
177+ } ,
178+ ) ;
172179
173180 it . each ( [
174181 {
0 commit comments