font-timestamps.html (2892B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Test cross-origin fetch redirects have the right values.</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/common/get-host-info.sub.js"></script> 7 <body> 8 <script> 9 const load_font = url => { 10 document.body.innerHTML = ` 11 <style> 12 @font-face { 13 font-family: ahem; 14 src: url('${url}'); 15 } 16 </style> 17 <div style="font-family: ahem;">This fetches ahem font.</div> 18 `; 19 return document.fonts.ready; 20 }; 21 22 const run_test = async (t, url) => { 23 // Set up PerformanceObserver 24 const href = new URL(url).href; 25 const setPerformanceObserver = new Promise(resolve => { 26 const po = new PerformanceObserver(resolve); 27 po.observe({type: "resource"}); 28 }); 29 30 // Load the font resource and wait for it to be fetched. 31 await load_font(href); 32 33 // Wait for an entry 34 const timeout = new Promise(resolve => t.step_timeout(resolve, 3000)); 35 const list = await Promise.race([setPerformanceObserver, timeout]); 36 assert_equals(typeof(list), "object", "No iframe entry was fired"); 37 const entries = list.getEntriesByName(url); 38 assert_equals(entries.length, 1); 39 40 // Test entry values 41 const entry = entries[0]; 42 assert_greater_than(entry.fetchStart, 0, "fetchStart should be greater than 0 in redirects."); 43 assert_greater_than_equal(entry.domainLookupStart, entry.fetchStart, "domainLookupStart should be more than 0 in same-origin redirect."); 44 assert_greater_than_equal(entry.domainLookupEnd, entry.domainLookupStart, "domainLookupEnd should be more than 0 in same-origin redirect."); 45 assert_greater_than_equal(entry.connectStart, entry.domainLookupEnd, "connectStart should be more than 0 in same-origin redirect."); 46 assert_greater_than_equal(entry.secureConnectionStart, entry.connectStart, "secureConnectionStart should be more than 0 in same-origin redirect."); 47 assert_greater_than_equal(entry.connectEnd, entry.secureConnectionStart, "connectEnd should be more than 0 in same-origin redirect."); 48 assert_greater_than_equal(entry.requestStart, entry.connectEnd, "requestStart should be more than 0 in same-origin redirect."); 49 assert_greater_than_equal(entry.responseStart, entry.requestStart, "responseStart should be more than 0 in same-origin redirect."); 50 assert_greater_than_equal(entry.responseEnd, entry.responseStart, "responseEnd should be greater than 0 in redirects."); 51 assert_greater_than_equal(entry.duration, 0, "duration should be greater than 0 in redirects."); 52 } 53 54 const {HTTPS_REMOTE_ORIGIN} = get_host_info(); 55 promise_test(t => { 56 return run_test(t, HTTPS_REMOTE_ORIGIN + "/fonts/Ahem.ttf"); 57 }, "Test a font's timestamps"); 58 59 promise_test(t => { 60 return run_test(t, HTTPS_REMOTE_ORIGIN + "/resource-timing/resources/cors-ahem.py?pipe=trickle(d1)"); 61 }, "Test a font's timestamps with delays"); 62 </script>