@@ -1836,6 +1836,80 @@ describe("PreviewManager", () => {
18361836 ) ,
18371837 ) ;
18381838
1839+ effectIt . effect ( "does not commit capture transitions when throttling updates fail" , ( ) =>
1840+ withManager ( ( manager ) =>
1841+ Effect . gen ( function * ( ) {
1842+ const setBackgroundThrottling = vi . fn < ( enabled : boolean ) => void > ( ) ;
1843+ const capturePage = vi . fn ( async ( ) => ( {
1844+ toJPEG : ( ) => Buffer . from ( "recording-frame" ) ,
1845+ getSize : ( ) => ( { width : 1280 , height : 720 } ) ,
1846+ } ) ) ;
1847+ fromId . mockReturnValue ( makeTestPreviewWebContents ( capturePage ) ) ;
1848+
1849+ yield * manager . createTab ( "tab_capture_throttling_failure" ) ;
1850+ yield * manager . registerWebview ( "tab_capture_throttling_failure" , 42 ) ;
1851+ yield * manager . setMainWindow ( {
1852+ isDestroyed : ( ) => false ,
1853+ once : vi . fn ( ) ,
1854+ webContents : { setBackgroundThrottling } ,
1855+ } as never ) ;
1856+
1857+ setBackgroundThrottling . mockImplementationOnce ( ( ) => {
1858+ throw new Error ( "start throttling update failed" ) ;
1859+ } ) ;
1860+ const failedStart = yield * Effect . exit (
1861+ manager . startRecording ( "tab_capture_throttling_failure" ) ,
1862+ ) ;
1863+ expect ( Exit . isFailure ( failedStart ) ) . toBe ( true ) ;
1864+
1865+ yield * manager . startRecording ( "tab_capture_throttling_failure" ) ;
1866+ expect ( setBackgroundThrottling . mock . calls ) . toEqual ( [ [ false ] , [ false ] ] ) ;
1867+
1868+ setBackgroundThrottling . mockImplementationOnce ( ( ) => {
1869+ throw new Error ( "stop throttling update failed" ) ;
1870+ } ) ;
1871+ const failedStop = yield * Effect . exit (
1872+ manager . stopRecording ( "tab_capture_throttling_failure" ) ,
1873+ ) ;
1874+ expect ( Exit . isFailure ( failedStop ) ) . toBe ( true ) ;
1875+
1876+ yield * manager . stopRecording ( "tab_capture_throttling_failure" ) ;
1877+ expect ( setBackgroundThrottling . mock . calls ) . toEqual ( [ [ false ] , [ false ] , [ true ] , [ true ] ] ) ;
1878+ } ) ,
1879+ ) ,
1880+ ) ;
1881+
1882+ effectIt . effect ( "does not publish a replacement window when capture reconciliation fails" , ( ) =>
1883+ withManager ( ( manager ) =>
1884+ Effect . gen ( function * ( ) {
1885+ const setBackgroundThrottling = vi . fn ( ( ) => {
1886+ throw new Error ( "replacement throttling update failed" ) ;
1887+ } ) ;
1888+ const capturePage = vi . fn ( async ( ) => ( {
1889+ toJPEG : ( ) => Buffer . from ( "recording-frame" ) ,
1890+ getSize : ( ) => ( { width : 1280 , height : 720 } ) ,
1891+ } ) ) ;
1892+ fromId . mockReturnValue ( makeTestPreviewWebContents ( capturePage ) ) ;
1893+
1894+ yield * manager . createTab ( "tab_capture_replacement_failure" ) ;
1895+ yield * manager . registerWebview ( "tab_capture_replacement_failure" , 42 ) ;
1896+ yield * manager . startRecording ( "tab_capture_replacement_failure" ) ;
1897+
1898+ const failedReplacement = yield * Effect . exit (
1899+ manager . setMainWindow ( {
1900+ isDestroyed : ( ) => false ,
1901+ once : vi . fn ( ) ,
1902+ webContents : { setBackgroundThrottling } ,
1903+ } as never ) ,
1904+ ) ;
1905+ expect ( Exit . isFailure ( failedReplacement ) ) . toBe ( true ) ;
1906+
1907+ yield * manager . stopRecording ( "tab_capture_replacement_failure" ) ;
1908+ expect ( setBackgroundThrottling . mock . calls ) . toEqual ( [ [ false ] ] ) ;
1909+ } ) ,
1910+ ) ,
1911+ ) ;
1912+
18391913 effectIt . effect ( "releases frame capture when the main window closes" , ( ) =>
18401914 withManager ( ( manager ) =>
18411915 Effect . gen ( function * ( ) {
@@ -2199,13 +2273,16 @@ describe("PreviewManager", () => {
21992273 effectIt . effect ( "shares background frame capture between recording and picture-in-picture" , ( ) =>
22002274 withManager ( ( manager ) =>
22012275 Effect . gen ( function * ( ) {
2276+ const setBackgroundThrottling = vi . fn ( ) ;
2277+ const mainWindowWebContents = { setBackgroundThrottling } ;
22022278 const jpeg = Buffer . from ( "shared-preview-frame" ) ;
22032279 const capturePage = vi . fn ( async ( ) => ( {
22042280 toJPEG : ( ) => jpeg ,
22052281 getSize : ( ) => ( { width : 1280 , height : 720 } ) ,
22062282 } ) ) ;
22072283 fromId . mockReturnValue ( {
22082284 id : 42 ,
2285+ hostWebContents : mainWindowWebContents ,
22092286 isDestroyed : ( ) => false ,
22102287 getType : ( ) => "webview" ,
22112288 getURL : ( ) => "https://example.com" ,
@@ -2258,6 +2335,12 @@ describe("PreviewManager", () => {
22582335 const states : PreviewManager . PreviewTabState [ ] = [ ] ;
22592336 const recordingFrames : DesktopPreviewRecordingFrame [ ] = [ ] ;
22602337
2338+ yield * manager . setMainWindow ( {
2339+ isDestroyed : ( ) => false ,
2340+ once : vi . fn ( ) ,
2341+ webContents : mainWindowWebContents ,
2342+ } as never ) ;
2343+
22612344 yield * manager . subscribeStateChanges ( ( _tabId , state ) =>
22622345 Effect . sync ( ( ) => {
22632346 states . push ( state ) ;
@@ -2272,6 +2355,7 @@ describe("PreviewManager", () => {
22722355 yield * manager . registerWebview ( "tab_pip" , 42 ) ;
22732356 yield * manager . openPictureInPicture ( "tab_pip" ) ;
22742357
2358+ expect ( setBackgroundThrottling . mock . calls ) . toEqual ( [ [ false ] ] ) ;
22752359 expect ( browserWindowConstructor ) . toHaveBeenCalledWith (
22762360 expect . objectContaining ( {
22772361 alwaysOnTop : true ,
@@ -2317,6 +2401,7 @@ describe("PreviewManager", () => {
23172401 expect ( recordingFrames ) . toHaveLength ( 1 ) ;
23182402
23192403 yield * manager . stopRecording ( "tab_pip" ) ;
2404+ expect ( setBackgroundThrottling . mock . calls ) . toEqual ( [ [ false ] ] ) ;
23202405 const framesBeforePictureInPictureOnlyTick = pictureInPictureSend . mock . calls . length ;
23212406 yield * TestClock . adjust ( 100 ) ;
23222407 expect ( capturePage ) . toHaveBeenCalledTimes ( 3 ) ;
@@ -2326,6 +2411,7 @@ describe("PreviewManager", () => {
23262411 expect ( recordingFrames ) . toHaveLength ( 1 ) ;
23272412
23282413 yield * manager . closePictureInPicture ( "tab_pip" ) ;
2414+ expect ( setBackgroundThrottling . mock . calls ) . toEqual ( [ [ false ] , [ true ] ] ) ;
23292415 expect ( pictureInPictureWindow . close ) . toHaveBeenCalledOnce ( ) ;
23302416 expect ( states . at ( - 1 ) ?. pictureInPicture ) . toBe ( false ) ;
23312417 const capturesAfterClose = capturePage . mock . calls . length ;
0 commit comments