@@ -61,11 +61,22 @@ function createOopifFrameFixture() {
6161 }
6262}
6363
64+ /** Callbacks for a page with no user to ask, so the shell answers every dialog. */
65+ const shellAnswersDialogs = {
66+ claimUserDialog : ( ) => false ,
67+ onDialogClosed : ( ) => { } ,
68+ claimUserLeave : ( ) => false ,
69+ }
70+
6471describe ( 'browser-agent CDP instrumentation' , ( ) => {
6572 it ( 'leaves file chooser dialogs native so users can upload files' , async ( ) => {
6673 const contents = new WebContentsView ( ) . webContents
6774
68- await ensureInstrumented ( contents , { onDialog : vi . fn ( ) , dialogResponse : ( ) => null } )
75+ await ensureInstrumented ( contents , {
76+ onDialog : vi . fn ( ) ,
77+ dialogResponse : ( ) => null ,
78+ ...shellAnswersDialogs ,
79+ } )
6980
7081 expect ( contents . debugger . sendCommand ) . toHaveBeenCalledWith ( 'Page.enable' , undefined )
7182 expect ( contents . debugger . sendCommand ) . not . toHaveBeenCalledWith (
@@ -86,10 +97,18 @@ describe('browser-agent CDP instrumentation', () => {
8697 } )
8798
8899 await expect (
89- ensureInstrumented ( contents , { onDialog : vi . fn ( ) , dialogResponse : ( ) => null } )
100+ ensureInstrumented ( contents , {
101+ onDialog : vi . fn ( ) ,
102+ dialogResponse : ( ) => null ,
103+ ...shellAnswersDialogs ,
104+ } )
90105 ) . rejects . toThrow ( 'setup acknowledgement lost' )
91106 await expect (
92- ensureInstrumented ( contents , { onDialog : vi . fn ( ) , dialogResponse : ( ) => null } )
107+ ensureInstrumented ( contents , {
108+ onDialog : vi . fn ( ) ,
109+ dialogResponse : ( ) => null ,
110+ ...shellAnswersDialogs ,
111+ } )
93112 ) . resolves . toBeUndefined ( )
94113
95114 expect ( autoAttachAttempts ) . toBe ( 2 )
@@ -98,7 +117,11 @@ describe('browser-agent CDP instrumentation', () => {
98117 it ( 'dismisses an OOPIF dialog on the flattened child session' , async ( ) => {
99118 const contents = new WebContentsView ( ) . webContents
100119 const onDialog = vi . fn ( )
101- await ensureInstrumented ( contents , { onDialog, dialogResponse : ( ) => null } )
120+ await ensureInstrumented ( contents , {
121+ onDialog,
122+ dialogResponse : ( ) => null ,
123+ ...shellAnswersDialogs ,
124+ } )
102125 const listener = vi
103126 . mocked ( contents . debugger . on )
104127 . mock . calls . find ( ( [ event ] ) => event === 'message' ) ?. [ 1 ] as
@@ -132,7 +155,7 @@ describe('browser-agent CDP instrumentation', () => {
132155 const contents = new WebContentsView ( ) . webContents
133156 const onDialog = vi . fn ( )
134157 const dialogResponse = vi . fn ( ( ) => ( { accept : true } ) )
135- await ensureInstrumented ( contents , { onDialog, dialogResponse } )
158+ await ensureInstrumented ( contents , { onDialog, dialogResponse, ... shellAnswersDialogs } )
136159 const listener = vi
137160 . mocked ( contents . debugger . on )
138161 . mock . calls . find ( ( [ event ] ) => event === 'message' ) ?. [ 1 ] as
@@ -275,7 +298,11 @@ describe('browser-agent CDP instrumentation', () => {
275298 async ( treeKind ) => {
276299 const contents = new WebContentsView ( ) . webContents
277300 const { child, frameTree } = createOopifFrameFixture ( )
278- await ensureInstrumented ( contents , { onDialog : vi . fn ( ) , dialogResponse : ( ) => null } )
301+ await ensureInstrumented ( contents , {
302+ onDialog : vi . fn ( ) ,
303+ dialogResponse : ( ) => null ,
304+ ...shellAnswersDialogs ,
305+ } )
279306 const listener = vi
280307 . mocked ( contents . debugger . on )
281308 . mock . calls . find ( ( [ event ] ) => event === 'message' ) ?. [ 1 ] as
@@ -378,7 +405,11 @@ describe('browser-agent CDP instrumentation', () => {
378405 it ( 'falls back to the root target when OOPIF isolated-world creation fails' , async ( ) => {
379406 const contents = new WebContentsView ( ) . webContents
380407 const { child, frameTree } = createOopifFrameFixture ( )
381- await ensureInstrumented ( contents , { onDialog : vi . fn ( ) , dialogResponse : ( ) => null } )
408+ await ensureInstrumented ( contents , {
409+ onDialog : vi . fn ( ) ,
410+ dialogResponse : ( ) => null ,
411+ ...shellAnswersDialogs ,
412+ } )
382413 const listener = vi
383414 . mocked ( contents . debugger . on )
384415 . mock . calls . find ( ( [ event ] ) => event === 'message' ) ?. [ 1 ] as
@@ -458,7 +489,11 @@ describe('browser-agent file input handles', () => {
458489 async function fileInputFixture ( childSession = false ) {
459490 const contents = new WebContentsView ( ) . webContents
460491 const { child, frameTree } = createOopifFrameFixture ( )
461- await ensureInstrumented ( contents , { onDialog : vi . fn ( ) , dialogResponse : ( ) => null } )
492+ await ensureInstrumented ( contents , {
493+ onDialog : vi . fn ( ) ,
494+ dialogResponse : ( ) => null ,
495+ ...shellAnswersDialogs ,
496+ } )
462497 if ( childSession ) {
463498 const onMessage = vi . mocked ( contents . debugger . on ) . mock . calls [ 0 ] ?. [ 1 ] as
464499 | ( ( event : unknown , method : string , params : unknown , sessionId ?: string ) => void )
0 commit comments