@@ -83,7 +83,7 @@ describeWithMockConnection('PreloadingModel', () => {
8383 } ,
8484 } ,
8585 ] ) ;
86- assert . deepEqual ( model . getPreloadingAttempts ( null ) , [
86+ assert . deepEqual ( model . getRepresentativePreloadingAttempts ( null ) , [
8787 {
8888 id : `${ loaderId } :Prefetch:https://example.com/subresource.js:undefined` ,
8989 value : {
@@ -189,7 +189,7 @@ describeWithMockConnection('PreloadingModel', () => {
189189 } ,
190190 } ,
191191 ] ) ;
192- assert . deepEqual ( model . getPreloadingAttempts ( null ) , [
192+ assert . deepEqual ( model . getRepresentativePreloadingAttempts ( null ) , [
193193 {
194194 id : `${ loaderId } :Prefetch:https://example.com/subresource.js:undefined` ,
195195 value : {
@@ -275,7 +275,7 @@ describeWithMockConnection('PreloadingModel', () => {
275275 } ,
276276 } ,
277277 ] ) ;
278- assert . deepEqual ( model . getPreloadingAttempts ( null ) , [
278+ assert . deepEqual ( model . getRepresentativePreloadingAttempts ( null ) , [
279279 {
280280 id : `${ loaderId } :Prerender:https://example.com/page.html:undefined` ,
281281 value : {
@@ -336,7 +336,7 @@ describeWithMockConnection('PreloadingModel', () => {
336336 ] ,
337337 } ) ;
338338
339- assert . deepEqual ( model . getPreloadingAttempts ( null ) , [
339+ assert . deepEqual ( model . getRepresentativePreloadingAttempts ( null ) , [
340340 {
341341 id : `${ loaderId } :Prefetch:https://example.com/subresource.js:undefined` ,
342342 value : {
@@ -364,7 +364,7 @@ describeWithMockConnection('PreloadingModel', () => {
364364 assert . exists ( model ) ;
365365
366366 assert . deepEqual ( model . getAllRuleSets ( ) , [ ] ) ;
367- assert . deepEqual ( model . getPreloadingAttempts ( null ) , [ ] ) ;
367+ assert . deepEqual ( model . getRepresentativePreloadingAttempts ( null ) , [ ] ) ;
368368
369369 let loaderId = getMainFrame ( target ) . loaderId as Protocol . Network . LoaderId ;
370370
@@ -471,7 +471,7 @@ describeWithMockConnection('PreloadingModel', () => {
471471 } ,
472472 } ,
473473 ] ) ;
474- assert . deepEqual ( model . getPreloadingAttempts ( null ) , [
474+ assert . deepEqual ( model . getRepresentativePreloadingAttempts ( null ) , [
475475 {
476476 id : `${ loaderId } :Prefetch:https://example.com/subresource2.js:undefined` ,
477477 value : {
@@ -498,7 +498,7 @@ describeWithMockConnection('PreloadingModel', () => {
498498 assert . exists ( model ) ;
499499
500500 assert . deepEqual ( model . getAllRuleSets ( ) , [ ] ) ;
501- assert . deepEqual ( model . getPreloadingAttempts ( null ) , [ ] ) ;
501+ assert . deepEqual ( model . getRepresentativePreloadingAttempts ( null ) , [ ] ) ;
502502
503503 const loaderId = getMainFrame ( target ) . loaderId as Protocol . Network . LoaderId ;
504504
@@ -580,7 +580,7 @@ describeWithMockConnection('PreloadingModel', () => {
580580 requestId : 'requestId:2' ,
581581 } ) ;
582582
583- assert . deepEqual ( model . getPreloadingAttempts ( null ) , [
583+ assert . deepEqual ( model . getRepresentativePreloadingAttempts ( null ) , [
584584 {
585585 id : `${ loaderId } :Prefetch:https://example.com/subresource12.js:undefined` ,
586586 value : {
@@ -617,7 +617,7 @@ describeWithMockConnection('PreloadingModel', () => {
617617 } ,
618618 ] ) ;
619619
620- assert . deepEqual ( model . getPreloadingAttempts ( 'ruleSetId:1' as Protocol . Preload . RuleSetId ) , [
620+ assert . deepEqual ( model . getRepresentativePreloadingAttempts ( 'ruleSetId:1' as Protocol . Preload . RuleSetId ) , [
621621 {
622622 id : `${ loaderId } :Prefetch:https://example.com/subresource12.js:undefined` ,
623623 value : {
@@ -637,7 +637,7 @@ describeWithMockConnection('PreloadingModel', () => {
637637 } ,
638638 ] ) ;
639639
640- assert . deepEqual ( model . getPreloadingAttempts ( 'ruleSetId:2' as Protocol . Preload . RuleSetId ) , [
640+ assert . deepEqual ( model . getRepresentativePreloadingAttempts ( 'ruleSetId:2' as Protocol . Preload . RuleSetId ) , [
641641 {
642642 id : `${ loaderId } :Prefetch:https://example.com/subresource12.js:undefined` ,
643643 value : {
@@ -674,4 +674,202 @@ describeWithMockConnection('PreloadingModel', () => {
674674 } ,
675675 ] ) ;
676676 } ) ;
677+
678+ it ( 'regards attempts with strongest action as representative' , async ( ) => {
679+ const target = createTarget ( ) ;
680+ const model = target . model ( SDK . PreloadingModel . PreloadingModel ) ;
681+ assert . exists ( model ) ;
682+
683+ assert . deepEqual ( model . getAllRuleSets ( ) , [ ] ) ;
684+ assert . deepEqual ( model . getRepresentativePreloadingAttempts ( null ) , [ ] ) ;
685+
686+ const loaderId = getMainFrame ( target ) . loaderId as Protocol . Network . LoaderId ;
687+
688+ dispatchEvent ( target , 'Preload.ruleSetUpdated' , {
689+ ruleSet : {
690+ id : 'ruleSetId:1' ,
691+ loaderId,
692+ sourceText : `
693+ {
694+ "prerender": [
695+ {
696+ "source": "list",
697+ "urls": ["/prerendered.html"]
698+ }
699+ ]
700+ }
701+ ` ,
702+ } ,
703+ } ) ;
704+ dispatchEvent ( target , 'Preload.preloadingAttemptSourcesUpdated' , {
705+ loaderId,
706+ preloadingAttemptSources : [
707+ {
708+ action : Protocol . Preload . SpeculationAction . Prerender ,
709+ key : {
710+ loaderId,
711+ action : Protocol . Preload . SpeculationAction . Prerender ,
712+ url : 'https://example.com/prerendered.html' ,
713+ } ,
714+ ruleSetIds : [ 'ruleSetId:1' ] ,
715+ nodeIds : [ 1 ] ,
716+ } ,
717+ ] ,
718+ } ) ;
719+
720+ assert . deepEqual ( model . getRepresentativePreloadingAttempts ( null ) , [
721+ {
722+ id : `${ loaderId } :Prerender:https://example.com/prerendered.html:undefined` ,
723+ value : {
724+ action : Protocol . Preload . SpeculationAction . Prerender ,
725+ key : {
726+ loaderId,
727+ action : Protocol . Preload . SpeculationAction . Prerender ,
728+ url : 'https://example.com/prerendered.html' as Platform . DevToolsPath . UrlString ,
729+ } ,
730+ pipelineId : null ,
731+ status : SDK . PreloadingModel . PreloadingStatus . NOT_TRIGGERED ,
732+ prerenderStatus : null ,
733+ disallowedMojoInterface : null ,
734+ mismatchedHeaders : null ,
735+ ruleSetIds : [ 'ruleSetId:1' ] as Protocol . Preload . RuleSetId [ ] ,
736+ nodeIds : [ 1 ] as Protocol . DOM . BackendNodeId [ ] ,
737+ } ,
738+ } ,
739+ ] ) ;
740+
741+ dispatchEvent ( target , 'Preload.prefetchStatusUpdated' , {
742+ key : {
743+ loaderId,
744+ action : Protocol . Preload . SpeculationAction . Prefetch ,
745+ url : 'https://example.com/prerendered.html' ,
746+ } ,
747+ pipelineId : 'pipelineId:1' ,
748+ status : SDK . PreloadingModel . PreloadingStatus . RUNNING ,
749+ requestId : 'requestId:1' ,
750+ } ) ;
751+
752+ // Here, we get two different attemtps, which should sit in the same pipeline actually.
753+ // It is because
754+ //
755+ // - The `NOT_TRIGGERED` entry is synthesized from
756+ // `Preload.preloadingAttemptSourcesUpdated` event.
757+ // - It is associated with the following entry for *prerender*, not prefetch.
758+ //
759+ // We admit the phenomenon as prefetch and prerender are triggered simultaneously and we don't
760+ // expect the duration is very short that these entries are shown.
761+ assert . deepEqual ( model . getRepresentativePreloadingAttempts ( null ) , [
762+ {
763+ id : `${ loaderId } :Prerender:https://example.com/prerendered.html:undefined` ,
764+ value : {
765+ action : Protocol . Preload . SpeculationAction . Prerender ,
766+ key : {
767+ loaderId,
768+ action : Protocol . Preload . SpeculationAction . Prerender ,
769+ url : 'https://example.com/prerendered.html' as Platform . DevToolsPath . UrlString ,
770+ } ,
771+ pipelineId : null ,
772+ status : SDK . PreloadingModel . PreloadingStatus . NOT_TRIGGERED ,
773+ prerenderStatus : null ,
774+ disallowedMojoInterface : null ,
775+ mismatchedHeaders : null ,
776+ ruleSetIds : [ 'ruleSetId:1' ] as Protocol . Preload . RuleSetId [ ] ,
777+ nodeIds : [ 1 ] as Protocol . DOM . BackendNodeId [ ] ,
778+ } ,
779+ } ,
780+ {
781+ id : `${ loaderId } :Prefetch:https://example.com/prerendered.html:undefined` ,
782+ value : {
783+ action : Protocol . Preload . SpeculationAction . Prefetch ,
784+ key : {
785+ loaderId,
786+ action : Protocol . Preload . SpeculationAction . Prefetch ,
787+ url : 'https://example.com/prerendered.html' as Platform . DevToolsPath . UrlString ,
788+ } ,
789+ pipelineId : 'pipelineId:1' as Protocol . Preload . PreloadPipelineId ,
790+ status : SDK . PreloadingModel . PreloadingStatus . RUNNING ,
791+ prefetchStatus : null ,
792+ requestId : 'requestId:1' as Protocol . Network . RequestId ,
793+ ruleSetIds : [ ] as Protocol . Preload . RuleSetId [ ] ,
794+ nodeIds : [ ] as Protocol . DOM . BackendNodeId [ ] ,
795+ } ,
796+ } ,
797+ ] ) ;
798+
799+ dispatchEvent ( target , 'Preload.prerenderStatusUpdated' , {
800+ key : {
801+ loaderId,
802+ action : Protocol . Preload . SpeculationAction . Prerender ,
803+ url : 'https://example.com/prerendered.html' ,
804+ } ,
805+ pipelineId : 'pipelineId:1' ,
806+ status : SDK . PreloadingModel . PreloadingStatus . RUNNING ,
807+ } ) ;
808+
809+ // Converges to an entry.
810+ assert . deepEqual ( model . getRepresentativePreloadingAttempts ( null ) , [
811+ {
812+ id : `${ loaderId } :Prerender:https://example.com/prerendered.html:undefined` ,
813+ value : {
814+ action : Protocol . Preload . SpeculationAction . Prerender ,
815+ key : {
816+ loaderId,
817+ action : Protocol . Preload . SpeculationAction . Prerender ,
818+ url : 'https://example.com/prerendered.html' as Platform . DevToolsPath . UrlString ,
819+ } ,
820+ pipelineId : 'pipelineId:1' as Protocol . Preload . PreloadPipelineId ,
821+ status : SDK . PreloadingModel . PreloadingStatus . RUNNING ,
822+ prerenderStatus : null ,
823+ disallowedMojoInterface : null ,
824+ mismatchedHeaders : null ,
825+ ruleSetIds : [ 'ruleSetId:1' ] as Protocol . Preload . RuleSetId [ ] ,
826+ nodeIds : [ 1 ] as Protocol . DOM . BackendNodeId [ ] ,
827+ } ,
828+ } ,
829+ ] ) ;
830+
831+ dispatchEvent ( target , 'Preload.prefetchStatusUpdated' , {
832+ key : {
833+ loaderId,
834+ action : Protocol . Preload . SpeculationAction . Prefetch ,
835+ url : 'https://example.com/prerendered.html' ,
836+ } ,
837+ pipelineId : 'pipelineId:1' ,
838+ status : SDK . PreloadingModel . PreloadingStatus . SUCCESS ,
839+ requestId : 'requestId:1' ,
840+ } ) ;
841+ dispatchEvent ( target , 'Preload.prerenderStatusUpdated' , {
842+ key : {
843+ loaderId,
844+ action : Protocol . Preload . SpeculationAction . Prerender ,
845+ url : 'https://example.com/prerendered.html' ,
846+ } ,
847+ pipelineId : 'pipelineId:1' ,
848+ status : SDK . PreloadingModel . PreloadingStatus . FAILURE ,
849+ prerenderStatus : Protocol . Preload . PrerenderFinalStatus . MojoBinderPolicy ,
850+ disallowedMojoInterface : 'device.mojom.GamepadMonitor' ,
851+ } ) ;
852+
853+ // The prerender is the representative of the pipeline even if it failed.
854+ assert . deepEqual ( model . getRepresentativePreloadingAttempts ( null ) , [
855+ {
856+ id : `${ loaderId } :Prerender:https://example.com/prerendered.html:undefined` ,
857+ value : {
858+ action : Protocol . Preload . SpeculationAction . Prerender ,
859+ key : {
860+ loaderId,
861+ action : Protocol . Preload . SpeculationAction . Prerender ,
862+ url : 'https://example.com/prerendered.html' as Platform . DevToolsPath . UrlString ,
863+ } ,
864+ pipelineId : 'pipelineId:1' as Protocol . Preload . PreloadPipelineId ,
865+ status : SDK . PreloadingModel . PreloadingStatus . FAILURE ,
866+ prerenderStatus : Protocol . Preload . PrerenderFinalStatus . MojoBinderPolicy ,
867+ disallowedMojoInterface : 'device.mojom.GamepadMonitor' ,
868+ mismatchedHeaders : null ,
869+ ruleSetIds : [ 'ruleSetId:1' ] as Protocol . Preload . RuleSetId [ ] ,
870+ nodeIds : [ 1 ] as Protocol . DOM . BackendNodeId [ ] ,
871+ } ,
872+ } ,
873+ ] ) ;
874+ } ) ;
677875} ) ;
0 commit comments