| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="/resources/testharness.js"></script> | 2 <script src="/resources/testharness.js"></script> |
| 3 <script src="/resources/testharnessreport.js"></script> | 3 <script src="/resources/testharnessreport.js"></script> |
| 4 <script src="/misc/resources/run-async-tasks-promise.js"></script> | 4 <script src="/misc/resources/run-async-tasks-promise.js"></script> |
| 5 <script> | 5 <script src="/misc/resources/resource-timing-sizes-cache.js"></script> |
| 6 // The header bytes are expected to be > |minHeaderSize| and | |
| 7 // < |maxHeaderSize|. If they are outside this range the test will fail. | |
| 8 const minHeaderSize = 100; | |
| 9 const maxHeaderSize = 1024; | |
| 10 | |
| 11 // The size of this resource must be > maxHeaderSize for the test to be | |
| 12 // reliable. | |
| 13 var url = new URL('/resources/square.png', location.href).href; | |
| 14 const expectedSize = 18299; | |
| 15 | |
| 16 function checkBodySizeFields(entry, expectedSize) { | |
| 17 assert_equals(entry.decodedBodySize, expectedSize, 'decodedBodySize'); | |
| 18 assert_equals(entry.encodedBodySize, expectedSize, 'encodedBodySize'); | |
| 19 } | |
| 20 | |
| 21 function checkResourceSizes() { | |
| 22 var entries = performance.getEntriesByName(url); | |
| 23 assert_equals(entries.length, 3, 'Wrong number of entries'); | |
| 24 var seenCount = 0; | |
| 25 for (var entry of entries) { | |
| 26 checkBodySizeFields(entry, expectedSize); | |
| 27 if (seenCount === 0) { | |
| 28 // 200 response | |
| 29 assert_between_exclusive(entry.transferSize, | |
| 30 expectedSize + minHeaderSize, | |
| 31 expectedSize + maxHeaderSize, | |
| 32 '200 transferSize'); | |
| 33 } else if (seenCount === 1) { | |
| 34 // from cache | |
| 35 assert_equals(entry.transferSize, 0, 'cached transferSize'); | |
| 36 } else if (seenCount === 2) { | |
| 37 // 304 response | |
| 38 assert_between_exclusive(entry.transferSize, minHeaderSize, | |
| 39 maxHeaderSize, '304 transferSize'); | |
| 40 } else { | |
| 41 assert_unreached('Too many matching entries'); | |
| 42 } | |
| 43 ++seenCount; | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 promise_test(() => { | |
| 48 // Use a different URL every time so that the cache behaviour does not | |
| 49 // depend on execution order. | |
| 50 url = url + '?unique=' + Math.random().toString().substring(2); | |
| 51 var eatBody = response => response.arrayBuffer(); | |
| 52 var mustRevalidate = {headers: {'Cache-Control': 'max-age=0'}}; | |
| 53 return fetch(url) | |
| 54 .then(eatBody) | |
| 55 .then(() => fetch(url)) | |
| 56 .then(eatBody) | |
| 57 .then(() => fetch(url, mustRevalidate)) | |
| 58 .then(eatBody) | |
| 59 .then(runAsyncTasks) | |
| 60 .then(checkResourceSizes); | |
| 61 }, 'PerformanceResourceTiming sizes caching test'); | |
| 62 | |
| 63 </script> | |
| OLD | NEW |