preconnect.html (1524B)
1 <!DOCTYPE html> 2 <html> 3 <title>Makes sure that preloaded resources reduce connection time to zero</title> 4 <meta name="timeout" content="long"> 5 <meta name="pac" content="/common/proxy-all.sub.pac"> 6 <script src="/common/utils.js"></script> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 10 <body> 11 <script> 12 const FAKE_PORT = 30303; 13 promise_test(async t => { 14 const fake_remote_origin = `http://${token()}.wpt:${FAKE_PORT}`; 15 const link = document.createElement('link'); 16 link.rel = "preconnect"; 17 link.href = fake_remote_origin; 18 document.head.appendChild(link); 19 await new Promise(r => t.step_timeout(r, 1000)); 20 const url = `${fake_remote_origin}/images/smiley.png`; 21 const entryPromise = new Promise(resolve => { 22 new PerformanceObserver(list => { 23 const entries = list.getEntriesByName(url); 24 if (entries.length) 25 resolve(entries[0]); 26 }).observe({type: "resource"}); 27 }); 28 29 const img = document.createElement('img'); 30 img.src = url; 31 document.body.appendChild(img); 32 const entry = await entryPromise; 33 assert_equals(entry.domainLookupStart, entry.domainLookupEnd); 34 assert_equals(entry.domainLookupStart, entry.connectStart); 35 assert_equals(entry.domainLookupStart, entry.connectEnd); 36 }, "Test that preconnect reduces connection time to zero"); 37 </script> 38 </body> 39 </html>