resource-timing.https.html (4090B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Navigation Preload Resource Timing</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="../resources/test-helpers.sub.js"></script> 7 <script> 8 9 function check_timing_entry(entry, url, decodedBodySize, encodedBodySize) { 10 assert_equals(entry.name, url, 'The entry name of '+ url); 11 12 assert_equals( 13 entry.entryType, 'resource', 14 'The entryType of preload response timing entry must be "resource' + 15 '" :' + url); 16 assert_equals( 17 entry.initiatorType, 'navigation', 18 'The initiatorType of preload response timing entry must be ' + 19 '"navigation":' + url); 20 21 // If the server returns the redirect response, |decodedBodySize| is null and 22 // |entry.decodedBodySize| should be 0. Otherwise |entry.decodedBodySize| must 23 // same as |decodedBodySize| 24 assert_equals( 25 entry.decodedBodySize, Number(decodedBodySize), 26 'decodedBodySize must same as the decoded size in the server:' + url); 27 28 // If the server returns the redirect response, |encodedBodySize| is null and 29 // |entry.encodedBodySize| should be 0. Otherwise |entry.encodedBodySize| must 30 // same as |encodedBodySize| 31 assert_equals( 32 entry.encodedBodySize, Number(encodedBodySize), 33 'encodedBodySize must same as the encoded size in the server:' + url); 34 35 assert_greater_than( 36 entry.transferSize, entry.decodedBodySize, 37 'transferSize must greater then encodedBodySize.'); 38 39 assert_greater_than(entry.startTime, 0, 'startTime of ' + url); 40 assert_greater_than_equal(entry.fetchStart, entry.startTime, 41 'fetchStart >= startTime of ' + url); 42 assert_greater_than_equal(entry.domainLookupStart, entry.fetchStart, 43 'domainLookupStart >= fetchStart of ' + url); 44 assert_greater_than_equal(entry.domainLookupEnd, entry.domainLookupStart, 45 'domainLookupEnd >= domainLookupStart of ' + url); 46 assert_greater_than_equal(entry.connectStart, entry.domainLookupEnd, 47 'connectStart >= domainLookupEnd of ' + url); 48 assert_greater_than_equal(entry.connectEnd, entry.connectStart, 49 'connectEnd >= connectStart of ' + url); 50 assert_greater_than_equal(entry.requestStart, entry.connectEnd, 51 'requestStart >= connectEnd of ' + url); 52 assert_greater_than_equal(entry.responseStart, entry.requestStart, 53 'domainLookupStart >= requestStart of ' + url); 54 assert_greater_than_equal(entry.responseEnd, entry.responseStart, 55 'responseEnd >= responseStart of ' + url); 56 assert_greater_than(entry.duration, 0, 'duration of ' + url); 57 } 58 59 promise_test(t => { 60 var script = 'resources/resource-timing-worker.js'; 61 var scope = 'resources/resource-timing-scope.py'; 62 var registration; 63 var frames = []; 64 return service_worker_unregister_and_register(t, script, scope) 65 .then(reg => { 66 registration = reg; 67 add_completion_callback(_ => registration.unregister()); 68 return wait_for_state(t, registration.installing, 'activated'); 69 }) 70 .then(_ => with_iframe(scope + '?type=normal')) 71 .then(frame => { 72 frames.push(frame); 73 return with_iframe(scope + '?type=redirect'); 74 }) 75 .then(frame => { 76 frames.push(frame); 77 frames.forEach(frame => { 78 var result = JSON.parse(frame.contentDocument.body.textContent); 79 assert_equals( 80 result.timingEntries.length, 1, 81 'performance.getEntriesByName() must returns one ' + 82 'PerformanceResourceTiming entry for the navigation preload.'); 83 var entry = result.timingEntries[0]; 84 check_timing_entry(entry, frame.src, result.decodedBodySize, 85 result.encodedBodySize); 86 frame.remove(); 87 }); 88 return registration.unregister(); 89 }); 90 }, 'Navigation Preload Resource Timing.'); 91 92 </script>