navigation-timing-sizes.https.html (2436B)
1 <!DOCTYPE html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="/common/dispatcher/dispatcher.js"></script> 5 <script src="/common/utils.js"></script> 6 <script src="../resources/utils.js"></script> 7 <script src="resources/utils.sub.js"></script> 8 9 <meta name="variant" content="?default"> 10 <meta name="variant" content="?bypass_cache=true"> 11 <meta name="variant" content="?prefetch=true"> 12 <meta name="variant" content="?prefetch=true&bypass_cache=true"> 13 14 <script> 15 setup(() => assertSpeculationRulesIsSupported()); 16 17 const searchParams = new URLSearchParams(location.search); 18 const prefetchEnabled = searchParams.has('prefetch'); 19 const bypassCache = searchParams.has('bypass_cache'); 20 21 // Header size: https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-transfersize 22 const headerSize = 300; 23 24 promise_test(async t => { 25 const agent = await spawnWindow(t); 26 // Some meaningless query param to avoid cached response. 27 const prefetchUrl = 28 bypassCache ? agent.getExecutorURL({ a: "b" }) : agent.getExecutorURL(); 29 30 if (prefetchEnabled) 31 await agent.forceSinglePrefetch(prefetchUrl); 32 33 await agent.navigate(prefetchUrl); 34 35 if (prefetchEnabled) 36 assert_prefetched(await agent.getRequestHeaders(), 37 `Prefetch ${prefetchUrl.href} should work.`); 38 else 39 assert_not_prefetched(await agent.getRequestHeaders(), 40 `${prefetchUrl.href} should not be prefetched.`); 41 42 await agent.execute_script( 43 () => window.entries = performance.getEntriesByType('navigation')); 44 45 // TODO(crbug/1317756): Currently the initial prefetch request bypasses the 46 // HTTP cache. Expand test coverage for cache and cache+revalidation cases. 47 // 48 // We do not assert the exact size of `resources/executor.sub.html` since it 49 // would be a headache to update this test everytime executor.sub.html 50 // changes. 51 assert_equals(await agent.execute_script(() => window.entries.length), 1, 52 'Wrong number of entries'); 53 const entry = 54 await agent.execute_script(() => window.entries[0]); 55 const bodySize = entry.encodedBodySize; 56 assert_greater_than(bodySize, 0); 57 assert_equals(entry.transferSize, headerSize + bodySize); 58 assert_equals(entry.decodedBodySize, bodySize); 59 }, `PerformanceNavigationTiming.transferSize/encodedBodySize/decodedBodySize test, same origin prefetch.`); 60 </script>