sizes-cache.any.js (1670B)
1 // META: global=window,worker 2 // META: script=/resource-timing/resources/sizes-helper.js 3 // META: script=/resource-timing/resources/resource-loaders.js 4 5 let url = new URL( 6 '/resource-timing/resources/cacheable-and-validated.py' + 7 '?content=loremipsumblablabla', 8 location.href).href; 9 const bodySize = 19; 10 11 const accumulateEntries = () => { 12 return new Promise(resolve => { 13 const po = new PerformanceObserver(list => { 14 resolve(list); 15 }); 16 po.observe({type: "resource", buffered: true}); 17 }); 18 }; 19 20 const checkResourceSizes = list => { 21 const entries = list.getEntriesByName(url); 22 assert_equals(entries.length, 3, 'Wrong number of entries'); 23 let seenCount = 0; 24 for (let entry of entries) { 25 if (seenCount === 0) { 26 // 200 response 27 checkSizeFields(entry, bodySize, bodySize + headerSize); 28 } else if (seenCount === 1) { 29 // from cache 30 checkSizeFields(entry, bodySize, 0); 31 } else if (seenCount === 2) { 32 // 304 response 33 checkSizeFields(entry, bodySize, headerSize); 34 } else { 35 assert_unreached('Too many matching entries'); 36 } 37 ++seenCount; 38 } 39 }; 40 41 promise_test(() => { 42 // Use a different URL every time so that the cache behaviour does not 43 // depend on execution order. 44 url = load.cache_bust(url); 45 const eatBody = response => response.arrayBuffer(); 46 const mustRevalidate = {headers: {'Cache-Control': 'max-age=0'}}; 47 return fetch(url) 48 .then(eatBody) 49 .then(() => fetch(url)) 50 .then(eatBody) 51 .then(() => fetch(url, mustRevalidate)) 52 .then(eatBody) 53 .then(accumulateEntries) 54 .then(checkResourceSizes); 55 }, 'PerformanceResourceTiming sizes caching test');