@@ -342,6 +342,112 @@ describe('NetworkRequestsHandler', function() {
342342 assert . strictEqual ( initiator . args . data . url , event . args . data . stackTrace ?. [ 0 ] . url ) ;
343343 } ) ;
344344 } ) ;
345+ describe ( 'ThirdParty caches' , ( ) => {
346+ it ( 'Correctly captures entities by network event' , async function ( ) {
347+ const traceEvents = await TraceLoader . rawEvents ( this , 'lantern/paul/trace.json.gz' ) ;
348+ for ( const event of traceEvents ) {
349+ Trace . Handlers . ModelHandlers . Meta . handleEvent ( event ) ;
350+ Trace . Handlers . ModelHandlers . NetworkRequests . handleEvent ( event ) ;
351+ }
352+ await Trace . Handlers . ModelHandlers . Meta . finalize ( ) ;
353+ await Trace . Handlers . ModelHandlers . NetworkRequests . finalize ( ) ;
354+
355+ const { entityMappings} = Trace . Handlers . ModelHandlers . NetworkRequests . data ( ) ;
356+ const syntheticNetworkEventsByEntity = new Map (
357+ Array . from ( entityMappings . eventsByEntity . entries ( ) ) . map ( ( [ entity , events ] ) => {
358+ const syntheticNetworkEvents = events . filter (
359+ event => Trace . Types . Events . isSyntheticNetworkRequest ( event ) ,
360+ ) ;
361+ return [ entity , syntheticNetworkEvents ] ;
362+ } ) ,
363+ ) ;
364+ const requestsByEntityResult = [ ...syntheticNetworkEventsByEntity . entries ( ) ] . map ( ( [ entity , requests ] ) => {
365+ return [ entity . name , requests . map ( r => r . args ?. data ?. url ) ] ;
366+ } ) ;
367+ assert . deepEqual (
368+ requestsByEntityResult ,
369+ [
370+ [
371+ 'paulirish.com' ,
372+ [
373+ 'https://www.paulirish.com/' ,
374+ 'https://www.paulirish.com/assets/wikipedia-flamechart.jpg' ,
375+ 'https://www.paulirish.com/avatar150.jpg' ,
376+ 'https://www.paulirish.com/javascripts/modernizr-2.0.js' ,
377+ 'https://www.paulirish.com/javascripts/ender.js' ,
378+ 'https://www.paulirish.com/javascripts/octopress.js' ,
379+ 'https://www.paulirish.com/javascripts/firebase-performance-standalone.js' ,
380+ 'https://www.paulirish.com/images/noise.png?1418840251' ,
381+ 'https://www.paulirish.com/images/code_bg.png?1418840251' ,
382+ 'https://www.paulirish.com/favicon.ico' ,
383+ ] ,
384+ ] ,
385+ [
386+ 'Google Tag Manager' ,
387+ [
388+ 'https://www.googletagmanager.com/gtag/js?id=G-PGXNGYWP8E' ,
389+ ] ,
390+ ] ,
391+ [
392+ 'Google Fonts' ,
393+ [
394+ 'https://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold|PT+Sans:regular,italic,bold|Droid+Sans:400,700|Lato:700,900' ,
395+ 'https://fonts.gstatic.com/s/droidsans/v18/SlGVmQWMvZQIdix7AFxXkHNSbRYXags.woff2' ,
396+ 'https://fonts.gstatic.com/s/lato/v24/S6u9w4BMUTPHh6UVSwiPGQ3q5d0.woff2' ,
397+ 'https://fonts.gstatic.com/s/ptsans/v17/jizaRExUiTo99u79D0KExcOPIDU.woff2' ,
398+ 'https://fonts.gstatic.com/s/ptsans/v17/jizfRExUiTo99u79B_mh0O6tLR8a8zI.woff2' ,
399+ 'https://fonts.gstatic.com/s/droidsans/v18/SlGWmQWMvZQIdix7AFxXmMh3eDs1ZyHKpWg.woff2' ,
400+ 'https://fonts.gstatic.com/s/ptserif/v18/EJRVQgYoZZY2vCFuvAFWzr-_dSb_.woff2' ,
401+ ] ,
402+ ] ,
403+ [
404+ 'Google Analytics' ,
405+ [
406+ 'https://www.google-analytics.com/analytics.js' ,
407+ 'https://www.google-analytics.com/g/collect?v=2&tid=G-PGXNGYWP8E>m=45je4580v880158425za200&_p=1715625261583&gcd=13l3l3l3l1&npa=0&dma=0&cid=414801335.1715625262&ul=en-us&sr=412x823&uaa=&uab=64&uafvl=Not%252FA)Brand%3B8.0.0.0%7CChromium%3B126.0.6475.0%7CGoogle%2520Chrome%3B126.0.6475.0&uamb=1&uam=moto%20g%20power%20(2022)&uap=Android&uapv=11.0&uaw=0&are=1&frm=0&pscdl=noapi&_s=1&sid=1715625261&sct=1&seg=0&dl=https%3A%2F%2Fwww.paulirish.com%2F&dt=Paul%20Irish&en=page_view&_fv=1&_nsi=1&_ss=1&_ee=1&tfd=353' ,
408+ 'https://www.google-analytics.com/j/collect?v=1&_v=j101&a=272264939&t=pageview&_s=1&dl=https%3A%2F%2Fwww.paulirish.com%2F&ul=en-us&de=UTF-8&dt=Paul%20Irish&sd=30-bit&sr=412x823&vp=412x823&je=0&_u=IADAAEABAAAAACAAI~&jid=1388679807&gjid=654531532&cid=414801335.1715625262&tid=UA-692547-2&_gid=1964734610.1715625262&_r=1&_slc=1&z=1746264594' ,
409+ ] ,
410+ ] ,
411+ [
412+ 'Disqus' ,
413+ [
414+ 'https://paulirish.disqus.com/count.js' ,
415+ ] ,
416+ ] ,
417+ [
418+ 'Firebase' ,
419+ [
420+ 'https://firebaseinstallations.googleapis.com/v1/projects/paulirishcom/installations' ,
421+ 'https://firebaseremoteconfig.googleapis.com/v1/projects/paulirishcom/namespaces/fireperf:fetch?key=AIzaSyCGxLbbFQxH4BV1fY0RODlxTos9nJa2l_g' ,
422+ ] ,
423+ ] ,
424+ ] ,
425+ ) ;
426+ } ) ;
427+ it ( 'Correctly captures entities' , async function ( ) {
428+ const traceEvents = await TraceLoader . rawEvents ( this , 'lantern/paul/trace.json.gz' ) ;
429+ for ( const event of traceEvents ) {
430+ Trace . Handlers . ModelHandlers . Meta . handleEvent ( event ) ;
431+ Trace . Handlers . ModelHandlers . NetworkRequests . handleEvent ( event ) ;
432+ }
433+ await Trace . Handlers . ModelHandlers . Meta . finalize ( ) ;
434+ await Trace . Handlers . ModelHandlers . NetworkRequests . finalize ( ) ;
435+
436+ const { entityMappings} = Trace . Handlers . ModelHandlers . NetworkRequests . data ( ) ;
437+ const expectedEntities = [
438+ 'paulirish.com' ,
439+ 'Google Tag Manager' ,
440+ 'Google Fonts' ,
441+ 'Google Analytics' ,
442+ 'Disqus' ,
443+ 'Firebase' ,
444+ ] ;
445+ const gotEntities = Array . from ( entityMappings . entityByEvent . values ( ) ) . map ( enity => enity . name ) ;
446+ expectedEntities . forEach ( entity => {
447+ assert . isTrue ( gotEntities . includes ( entity ) ) ;
448+ } ) ;
449+ } ) ;
450+ } ) ;
345451} ) ;
346452
347453function assertDataArgsStats < D extends keyof DataArgs > (
0 commit comments