@@ -2201,6 +2201,48 @@ describe("PreviewManager", () => {
22012201 ) ,
22022202 ) ;
22032203
2204+ effectIt . effect ( "shows picture-in-picture and keeps capturing after stalled captures" , ( ) =>
2205+ withManager ( ( manager ) =>
2206+ Effect . gen ( function * ( ) {
2207+ const image = {
2208+ toJPEG : ( ) => Buffer . from ( "preview-frame" ) ,
2209+ getSize : ( ) => ( { width : 1280 , height : 720 } ) ,
2210+ } ;
2211+ const stalledInitial = Promise . withResolvers < typeof image > ( ) ;
2212+ const stalledLoop = Promise . withResolvers < typeof image > ( ) ;
2213+ const capturePage = vi
2214+ . fn < ( ) => Promise < typeof image > > ( )
2215+ . mockImplementationOnce ( ( ) => stalledInitial . promise )
2216+ . mockImplementationOnce ( ( ) => stalledLoop . promise )
2217+ . mockResolvedValue ( image ) ;
2218+ fromId . mockReturnValue ( makeTestPreviewWebContents ( capturePage ) ) ;
2219+ const { pictureInPictureWindow, send } = makeTestPictureInPictureWindow ( ) ;
2220+ browserWindowConstructor . mockImplementation ( function ( ) {
2221+ return pictureInPictureWindow ;
2222+ } ) ;
2223+ yield * manager . createTab ( "tab_pip_stalled_capture" ) ;
2224+ yield * manager . registerWebview ( "tab_pip_stalled_capture" , 42 ) ;
2225+
2226+ try {
2227+ const open = yield * manager
2228+ . openPictureInPicture ( "tab_pip_stalled_capture" )
2229+ . pipe ( Effect . forkChild ( { startImmediately : true } ) ) ;
2230+ yield * TestClock . adjust ( 1_000 ) ;
2231+ expect ( pictureInPictureWindow . showInactive ) . toHaveBeenCalledOnce ( ) ;
2232+ yield * Fiber . join ( open ) ;
2233+
2234+ expect ( send ) . not . toHaveBeenCalled ( ) ;
2235+ yield * TestClock . adjust ( 500 ) ;
2236+ expect ( send ) . toHaveBeenCalled ( ) ;
2237+ } finally {
2238+ // Release stalled native calls after a failing assertion against unchanged base.
2239+ stalledInitial . resolve ( image ) ;
2240+ stalledLoop . resolve ( image ) ;
2241+ }
2242+ } ) ,
2243+ ) ,
2244+ ) ;
2245+
22042246 effectIt . effect ( "rejects picture-in-picture when its webview changes during initialization" , ( ) =>
22052247 withManager ( ( manager ) =>
22062248 Effect . gen ( function * ( ) {
0 commit comments