@@ -3921,6 +3921,83 @@ describe("PreviewManager", () => {
39213921 ) ,
39223922 ) ;
39233923
3924+ effectIt . effect (
3925+ "hands keyboard focus back to the previous renderer after an automation click" ,
3926+ ( ) =>
3927+ withManager ( ( manager ) =>
3928+ Effect . gen ( function * ( ) {
3929+ let humanInput : ( ( _event : unknown , signal : unknown ) => void ) | undefined ;
3930+ const sendCommand = vi . fn ( async ( method : string , params ?: Record < string , unknown > ) => {
3931+ if ( method === "Runtime.evaluate" ) {
3932+ return { result : { value : { width : 800 , height : 600 } } } ;
3933+ }
3934+ if ( method === "Input.dispatchMouseEvent" && params ?. type === "mousePressed" ) {
3935+ humanInput ?.( { } , { kind : "pointer" , x : params . x , y : params . y , button : 0 } ) ;
3936+ }
3937+ return undefined ;
3938+ } ) ;
3939+ const restoreFocus = vi . fn ( ) ;
3940+ getFocusedWebContents . mockReturnValue ( {
3941+ id : 7 ,
3942+ isDestroyed : ( ) => false ,
3943+ focus : restoreFocus ,
3944+ } as never ) ;
3945+ fromId . mockReturnValue ( {
3946+ id : 42 ,
3947+ isDestroyed : ( ) => false ,
3948+ getType : ( ) => "webview" ,
3949+ getURL : ( ) => "https://example.com" ,
3950+ getTitle : ( ) => "Example" ,
3951+ isLoading : ( ) => false ,
3952+ isDevToolsOpened : ( ) => false ,
3953+ getZoomFactor : ( ) => 1 ,
3954+ setZoomFactor : vi . fn ( ) ,
3955+ setAudioMuted : vi . fn ( ) ,
3956+ isCurrentlyAudible : ( ) => false ,
3957+ on : vi . fn ( ) ,
3958+ off : vi . fn ( ) ,
3959+ ipc : {
3960+ on : vi . fn ( ( channel : string , listener : typeof humanInput ) => {
3961+ if ( channel === "preview:human-input" ) humanInput = listener ;
3962+ } ) ,
3963+ off : vi . fn ( ) ,
3964+ } ,
3965+ send : webviewSend ,
3966+ navigationHistory : { canGoBack : ( ) => false , canGoForward : ( ) => false } ,
3967+ setIgnoreMenuShortcuts : vi . fn ( ) ,
3968+ setWindowOpenHandler : vi . fn ( ) ,
3969+ debugger : {
3970+ isAttached : ( ) => false ,
3971+ attach : vi . fn ( ) ,
3972+ sendCommand,
3973+ on : vi . fn ( ) ,
3974+ off : vi . fn ( ) ,
3975+ } ,
3976+ } as never ) ;
3977+
3978+ yield * manager . createTab ( "tab_1" ) ;
3979+ yield * manager . registerWebview ( "tab_1" , 42 ) ;
3980+ const click = yield * manager
3981+ . automationClick ( "tab_1" , { x : 120 , y : 80 } )
3982+ . pipe ( Effect . forkChild ( { startImmediately : true } ) ) ;
3983+ yield * TestClock . adjust ( 200 ) ;
3984+ yield * Fiber . join ( click ) ;
3985+
3986+ expect ( restoreFocus ) . toHaveBeenCalledTimes ( 1 ) ;
3987+ expect ( restoreFocus . mock . invocationCallOrder [ 0 ] ) . toBeGreaterThan (
3988+ sendCommand . mock . invocationCallOrder . at ( - 1 ) ?? 0 ,
3989+ ) ;
3990+
3991+ const offscreen = yield * manager
3992+ . automationClick ( "tab_1" , { x : 5000 , y : 80 } )
3993+ . pipe ( Effect . exit , Effect . forkChild ( { startImmediately : true } ) ) ;
3994+ yield * TestClock . adjust ( 200 ) ;
3995+ expect ( ( yield * Fiber . join ( offscreen ) ) . _tag ) . toBe ( "Failure" ) ;
3996+ expect ( restoreFocus ) . toHaveBeenCalledTimes ( 2 ) ;
3997+ } ) ,
3998+ ) ,
3999+ ) ;
4000+
39244001 effectIt . effect ( "types in background webviews and enables native key input" , ( ) =>
39254002 withManager ( ( manager ) =>
39264003 Effect . gen ( function * ( ) {
0 commit comments