@@ -580,4 +580,108 @@ describe('fetchSource', function () {
580580 ] ,
581581 } ) ;
582582 } ) ;
583+
584+ it ( 'fetches JS source from browser with sourceId' , async function ( ) {
585+ expect (
586+ await fetchSource (
587+ '/path/to/script.js' ,
588+ 'https://symbolication.services.mozilla.com' ,
589+ null ,
590+ new Map ( ) ,
591+ {
592+ fetchUrlResponse : async ( _url : string , _postData ?: MixedObject ) => {
593+ throw new Error ( 'Should not fetch from URL' ) ;
594+ } ,
595+ queryBrowserSymbolicationApi : async (
596+ _path : string ,
597+ _requestJson : string
598+ ) => {
599+ throw new Error ( 'Should not query symbolication API' ) ;
600+ } ,
601+ fetchJSSourceFromBrowser : async ( {
602+ pid,
603+ sourceId,
604+ } : GlobalJSSourceId ) => {
605+ if ( pid === '123' && sourceId === 42 ) {
606+ return 'console.log("Hello from browser with sourceId 42");' ;
607+ }
608+ throw new Error ( `Unexpected sourceId: ${ sourceId } ` ) ;
609+ } ,
610+ } ,
611+ { pid : '123' , sourceId : 42 }
612+ )
613+ ) . toEqual ( {
614+ type : 'SUCCESS' ,
615+ source : 'console.log("Hello from browser with sourceId 42");' ,
616+ } ) ;
617+ } ) ;
618+
619+ it ( 'handles fetch JS source from browser with invalid sourceId' , async function ( ) {
620+ expect (
621+ await fetchSource (
622+ '/path/to/script.js' ,
623+ 'https://symbolication.services.mozilla.com' ,
624+ null ,
625+ new Map ( ) ,
626+ {
627+ fetchUrlResponse : async ( _url : string , _postData ?: MixedObject ) => {
628+ throw new Error ( 'Should not fetch from URL' ) ;
629+ } ,
630+ queryBrowserSymbolicationApi : async (
631+ _path : string ,
632+ _requestJson : string
633+ ) => {
634+ throw new Error ( 'Should not query symbolication API' ) ;
635+ } ,
636+ fetchJSSourceFromBrowser : async ( { sourceId } : GlobalJSSourceId ) = > {
637+ throw new Error ( `Source not found for sourceId: ${ sourceId } ` ) ;
638+ } ,
639+ } ,
640+ { pid : '111' , sourceId : 123 }
641+ )
642+ ) . toEqual ( {
643+ type : 'ERROR' ,
644+ errors : [
645+ {
646+ type : 'BROWSER_API_ERROR' ,
647+ apiErrorMessage : 'Source not found for sourceId: 123' ,
648+ } ,
649+ ] ,
650+ } ) ;
651+ } ) ;
652+
653+ it ( 'falls back to other methods when fetchJSSourceFromBrowser fails' , async function ( ) {
654+ expect (
655+ await fetchSource (
656+ 'hg:hg.mozilla.org/mozilla-central:widget/cocoa/nsAppShell.mm:997f00815e6bc28806b75448c8829f0259d2cb28' ,
657+ 'https://symbolication.services.mozilla.com' ,
658+ null ,
659+ new Map ( ) ,
660+ {
661+ fetchUrlResponse : async ( url : string , _postData ?: MixedObject ) => {
662+ const r = new Response ( `Fallback response from ${ url } ` , {
663+ status : 200 ,
664+ } ) ;
665+ return r ;
666+ } ,
667+ queryBrowserSymbolicationApi : async (
668+ _path : string ,
669+ _requestJson : string
670+ ) => {
671+ throw new Error ( 'No browser connection' ) ;
672+ } ,
673+ fetchJSSourceFromBrowser : async (
674+ _globalSourceId : GlobalJSSourceId
675+ ) = > {
676+ throw new Error ( 'Source not found in browser' ) ;
677+ } ,
678+ } ,
679+ { pid : '123' , sourceId : 42 } // Should still try browser first but fall back to URL fetch
680+ )
681+ ) . toEqual ( {
682+ type : 'SUCCESS' ,
683+ source :
684+ 'Fallback response from https://hg.mozilla.org/mozilla-central/raw-file/997f00815e6bc28806b75448c8829f0259d2cb28/widget/cocoa/nsAppShell.mm' ,
685+ } ) ;
686+ } ) ;
583687} ) ;
0 commit comments