@@ -840,53 +840,64 @@ describe('browser-agent session', () => {
840840 }
841841 } )
842842
843- it ( 'extends an in-flight background restore without restarting its load' , async ( ) => {
844- vi . useFakeTimers ( )
845- try {
846- const tabs = Array . from ( { length : 4 } , ( _ , index ) => ( {
847- url : `https://active-restore-${ index } .example/` ,
848- } ) )
849- const { persistence } = memoryBrowserPersistence ( {
850- 'chat-active-restore' : { v : 1 , tabs, activeIndex : 0 , downloads : [ ] } ,
851- } )
852- const createdContents : MockView [ 'webContents' ] [ ] = [ ]
853- const selectedLoads : Array < ( ) => void > = [ ]
854- session = freshSession (
855- win ,
856- {
857- onTabCreated : ( webContents ) => {
858- const contents = webContents as unknown as MockView [ 'webContents' ]
859- const index = createdContents . push ( contents ) - 1
860- contents . loadURL . mockImplementation (
861- ( ) =>
862- new Promise < void > ( ( resolve ) => {
863- if ( index === 1 ) selectedLoads . push ( resolve )
864- } )
865- )
843+ it . each ( [ 'loaded' , 'timed-out' ] as const ) (
844+ 'gives a late foreground promotion its full loading window (%s)' ,
845+ async ( outcome ) => {
846+ vi . useFakeTimers ( )
847+ try {
848+ const tabs = Array . from ( { length : 4 } , ( _ , index ) => ( {
849+ url : `https://active-restore-${ index } .example/` ,
850+ } ) )
851+ const { persistence } = memoryBrowserPersistence ( {
852+ 'chat-active-restore' : { v : 1 , tabs, activeIndex : 0 , downloads : [ ] } ,
853+ } )
854+ const createdContents : MockView [ 'webContents' ] [ ] = [ ]
855+ const selectedLoads : Array < ( ) => void > = [ ]
856+ session = freshSession (
857+ win ,
858+ {
859+ onTabCreated : ( webContents ) => {
860+ const contents = webContents as unknown as MockView [ 'webContents' ]
861+ const index = createdContents . push ( contents ) - 1
862+ contents . loadURL . mockImplementation (
863+ ( ) =>
864+ new Promise < void > ( ( resolve ) => {
865+ if ( index === 1 ) selectedLoads . push ( resolve )
866+ } )
867+ )
868+ } ,
866869 } ,
867- } ,
868- persistence
869- )
870-
871- const selected = session . withBrowserScope ( 'chat-active-restore' , ( ) => {
872- session . restoreBrowserSession ( )
873- return session . switchAutomationTab ( '2' )
874- } )
875- const selection = session . withBrowserScope ( 'chat-active-restore' , ( ) =>
876- session . waitForPendingTabRestore ( selected )
877- )
878-
879- expect ( createdContents [ 1 ] . loadURL ) . toHaveBeenCalledOnce ( )
880- expect ( createdContents [ 1 ] . stop ) . not . toHaveBeenCalled ( )
881- await vi . advanceTimersByTimeAsync ( 15_000 )
882- expect ( createdContents [ 1 ] . stop ) . not . toHaveBeenCalled ( )
883-
884- selectedLoads [ 0 ] ?.( )
885- await expect ( selection ) . resolves . toBe ( true )
886- } finally {
887- vi . useRealTimers ( )
870+ persistence
871+ )
872+
873+ session . withBrowserScope ( 'chat-active-restore' , ( ) => session . restoreBrowserSession ( ) )
874+ await vi . advanceTimersByTimeAsync ( 14_000 )
875+ const selected = session . withBrowserScope ( 'chat-active-restore' , ( ) =>
876+ session . switchAutomationTab ( '2' )
877+ )
878+ const selection = session . withBrowserScope ( 'chat-active-restore' , ( ) =>
879+ session . waitForPendingTabRestore ( selected )
880+ )
881+
882+ expect ( createdContents [ 1 ] . loadURL ) . toHaveBeenCalledOnce ( )
883+ expect ( createdContents [ 1 ] . stop ) . not . toHaveBeenCalled ( )
884+ await vi . advanceTimersByTimeAsync ( 19_999 )
885+ expect ( createdContents [ 1 ] . stop ) . not . toHaveBeenCalled ( )
886+
887+ if ( outcome === 'loaded' ) {
888+ selectedLoads [ 0 ] ?.( )
889+ await expect ( selection ) . resolves . toBe ( true )
890+ } else {
891+ session . withBrowserScope ( 'chat-active-restore' , ( ) => session . switchAutomationTab ( '2' ) )
892+ await vi . advanceTimersByTimeAsync ( 1 )
893+ await expect ( selection ) . resolves . toBe ( false )
894+ expect ( createdContents [ 1 ] . stop ) . toHaveBeenCalledOnce ( )
895+ }
896+ } finally {
897+ vi . useRealTimers ( )
898+ }
888899 }
889- } )
900+ )
890901
891902 it ( 'queues a fifth foreground restore without preempting another foreground restore' , async ( ) => {
892903 const snapshots = Object . fromEntries (
0 commit comments