@@ -256,4 +256,44 @@ describe("CDP relay downloads", () => {
256256 relay . event ( "Page.downloadProgress" , { guid : "g1" , state : "completed" } , "" ) ;
257257 expect ( written ) . toEqual ( [ ] ) ;
258258 } ) ;
259+
260+ it . each ( [ false , true ] ) (
261+ "keeps the previous download event setting (%s) when configuration fails" ,
262+ async ( enabled ) => {
263+ const send = vi
264+ . fn ( async ( ) => ( { } ) )
265+ . mockResolvedValueOnce ( { } )
266+ . mockRejectedValueOnce ( new Error ( "Page command rejected" ) ) ;
267+ const written : Array < Record < string , unknown > > = [ ] ;
268+ const relay = createCdpRelayConnection ( makeTarget ( send ) , ( raw ) =>
269+ written . push ( JSON . parse ( raw ) ) ,
270+ ) ;
271+ relay . receive ( JSON . stringify ( { id : 1 , method : "Target.setAutoAttach" , params : { } } ) ) ;
272+ for ( const [ id , eventsEnabled ] of [ enabled , ! enabled ] . entries ( ) ) {
273+ relay . receive (
274+ JSON . stringify ( {
275+ id : id + 2 ,
276+ method : "Browser.setDownloadBehavior" ,
277+ params : { behavior : "allowAndName" , downloadPath : "/srv/artifacts" , eventsEnabled } ,
278+ } ) ,
279+ ) ;
280+ await settle ( ) ;
281+ }
282+ expect ( written ) . toContainEqual ( {
283+ id : 3 ,
284+ error : { code : - 32000 , message : "Page command rejected" } ,
285+ } ) ;
286+ written . length = 0 ;
287+ relay . event ( "Page.downloadWillBegin" , { guid : "g1" } , "" ) ;
288+ relay . event ( "Page.downloadProgress" , { guid : "g1" , state : "completed" } , "" ) ;
289+ expect ( written ) . toEqual (
290+ enabled
291+ ? [
292+ { method : "Browser.downloadWillBegin" , params : { guid : "g1" } } ,
293+ { method : "Browser.downloadProgress" , params : { guid : "g1" , state : "completed" } } ,
294+ ]
295+ : [ ] ,
296+ ) ;
297+ } ,
298+ ) ;
259299} ) ;
0 commit comments