prefetch-transfer-size-executor.html (2339B)
1 <!DOCTYPE html> 2 <html> 3 4 <head> 5 <title>Navigation Timing Transfert Size of Prefetched Page</title> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="/common/utils.js"></script> 9 <script src="/common/dispatcher/dispatcher.js"></script> 10 </head> 11 <!-- 12 This test uses RemoteContext and Executor to execute JavaScript in another 13 page opened by this test page. This is because we need to simulate 14 navigating away from current page in this test. It will cause all Javascript 15 code on the test page to be lost if we do it in the test page. We can't do it 16 in an iframe because currently the prefetch behaves differently in an iframe 17 in this particular test case. For detailed information about RemoteContext and 18 Executor, see /common/dispatcher/README.md. 19 --> 20 <body> 21 <script> 22 const addLink = (url) => { 23 return new Promise(resolve => { 24 const link = document.createElement('link'); 25 link.onload = function () { resolve(); }; 26 link.rel = 'prefetch'; 27 link.as = 'document'; 28 link.href = url; 29 document.body.appendChild(link); 30 }); 31 } 32 33 const navigateToPrefetchedUrl = (url) => { 34 document.location.href = url; 35 } 36 37 const getTransferSize = () => window.performance.getEntriesByType('navigation')[0].transferSize; 38 39 promise_test(async t => { 40 const testPage = new RemoteContext(token()); 41 42 // Function remoteExecutorUrl is defined in /common/dispatcher/dispatcher.js 43 const url = remoteExecutorUrl(testPage.context_id); 44 const handler = window.open(url); 45 t.add_cleanup(() => handler.close()); 46 47 const prefetchedPage = new RemoteContext(token()); 48 49 const url_to_prefetch = '/navigation-timing/resources/blank_page_prefetch.html?uuid=' 50 + prefetchedPage.context_id; 51 52 // Prefetch link. 53 await testPage.execute_script(addLink, [url_to_prefetch]); 54 55 // Navigate to the prefetched link. 56 await testPage.execute_script(navigateToPrefetchedUrl, [url_to_prefetch]); 57 58 // Get navigation timing transfer size. 59 const size = await prefetchedPage.execute_script(getTransferSize); 60 61 assert_equals(0, size); 62 }, "Navigation timing transfer size for a prefetched navigation should be 0."); 63 </script> 64 </body> 65 66 </html>