@@ -40,6 +40,47 @@ describe('time utils', () => {
4040 } ) ;
4141
4242 describe ( 'adjustPerfTimeOrigin' , ( ) => {
43+ function createNavTiming ( { requestStart, responseStart} :
44+ { requestStart : number , responseStart : number } ) :
45+ PerformanceNavigationTiming {
46+ return {
47+ // This are used by the time adjustment function below.
48+ requestStart, // Client start time in performance clock millis.
49+ responseStart, // Client end time in performance clock millis.
50+ // These are needed to satisfy the interface.
51+ connectEnd : 0 ,
52+ connectStart : 0 ,
53+ decodedBodySize : 0 ,
54+ domComplete : 0 ,
55+ domContentLoadedEventEnd : 0 ,
56+ domContentLoadedEventStart : 0 ,
57+ domInteractive : 0 ,
58+ domainLookupEnd : 0 ,
59+ domainLookupStart : 0 ,
60+ duration : 0 ,
61+ encodedBodySize : 0 ,
62+ entryType : '' ,
63+ fetchStart : 0 ,
64+ initiatorType : '' ,
65+ loadEventEnd : 0 ,
66+ loadEventStart : 0 ,
67+ name : '' ,
68+ nextHopProtocol : '' ,
69+ redirectCount : 0 ,
70+ redirectEnd : 0 ,
71+ redirectStart : 0 ,
72+ responseEnd : 0 ,
73+ secureConnectionStart : 0 ,
74+ startTime : 0 ,
75+ toJSON : ( ) => ( { } ) ,
76+ transferSize : 0 ,
77+ type : 'navigate' ,
78+ unloadEventEnd : 0 ,
79+ unloadEventStart : 0 ,
80+ workerStart : 0 ,
81+ } ;
82+ }
83+
4384 const CLIENT_TIME_ORIGIN = 1548000000000 ;
4485 beforeEach ( ( ) => {
4586 mockGetterOrValue ( performance , 'timeOrigin' , CLIENT_TIME_ORIGIN ) ;
@@ -48,35 +89,31 @@ describe('time utils', () => {
4889 TEST_ONLY . clearAdjustedPerfTime ( ) ;
4990 } ) ;
5091
51- it ( 'keeps client time origin if performance timing missing' , ( ) => {
52- spyOnProperty ( performance , 'timing' ) . and . returnValue ( undefined ) ;
53- adjustPerfTimeOrigin ( 1548000001000.2 , 5.1 ) ;
54- expect ( getPerfTimeOrigin ( ) ) . toBe ( CLIENT_TIME_ORIGIN ) ;
55- } ) ;
56-
5792 it ( 'keeps client time origin if server time longer than client' , ( ) => {
5893 // Client nav fetch duration is 5ms
59- spyOnProperty ( performance . timing , 'requestStart' ) . and . returnValue ( 10.1 ) ;
60- spyOnProperty ( performance . timing , ' responseStart' ) . and . returnValue ( 15.1 ) ;
94+ const perfNavTiming =
95+ createNavTiming ( { requestStart : 10.1 , responseStart : 15.1 } ) ;
6196
6297 // Server nav fetch duration is 10ms
63- adjustPerfTimeOrigin ( 1548000001000.2 , /* serverNavFetchDuration */ 10 ) ;
98+ adjustPerfTimeOrigin (
99+ 1548000001000.2 , /* serverNavFetchDuration */ 10 , perfNavTiming ) ;
64100
65101 expect ( getPerfTimeOrigin ( ) ) . toBe ( CLIENT_TIME_ORIGIN ) ;
66102 } ) ;
67103
68104 it ( 'adjusts origin to center server span in client span' , ( ) => {
69- const clientNavFetchStartInPerfTime = 10 ; // Performance clock millis.
70- spyOnProperty ( performance . timing , 'requestStart' )
71- . and . returnValue ( clientNavFetchStartInPerfTime ) ;
72- const clientNavFetchEndInPerfTime = 18 ; // Performance clock millis.
73- spyOnProperty ( performance . timing , 'responseStart' )
74- . and . returnValue ( clientNavFetchEndInPerfTime ) ;
75-
105+ const clientNavFetchStartInPerfTime = 10 ;
106+ const clientNavFetchEndInPerfTime = 18 ;
107+ const perfNavTiming = createNavTiming ( {
108+ requestStart : clientNavFetchStartInPerfTime ,
109+ responseStart : clientNavFetchEndInPerfTime ,
110+ } ) ;
76111 const serverNavFetchStartEpochMillis = 1500000001000 ; // Epoch millis.
77112 const serverNavFetchDuration = 6 ; // Duration millis
113+
78114 adjustPerfTimeOrigin (
79- serverNavFetchStartEpochMillis , serverNavFetchDuration ) ;
115+ serverNavFetchStartEpochMillis , serverNavFetchDuration ,
116+ perfNavTiming ) ;
80117
81118 // Calculations to make the expectation clearer:
82119 const clientNavFetchDuration =
0 commit comments