| OLD | NEW |
| 1 <!DOCTYPE html> | 1 // This test code is shared between resource-timing-sizes-content-encoding.html |
| 2 <script src="/resources/testharness.js"></script> | 2 // and resource-timing-sizes-content-encoding-worker.html |
| 3 <script src="/resources/testharnessreport.js"></script> | 3 |
| 4 <script src="/misc/resources/run-async-tasks-promise.js"></script> | 4 if (typeof document === 'undefined') { |
| 5 <script> | 5 importScripts('/resources/testharness.js', |
| 6 '/misc/resources/run-async-tasks-promise.js'); |
| 7 } |
| 8 |
| 6 const url = '/misc/resources/gzip-content-encoding.php'; | 9 const url = '/misc/resources/gzip-content-encoding.php'; |
| 7 const uncompressedSize = 1250; | 10 const uncompressedSize = 1250; |
| 8 | 11 |
| 9 function checkResourceSizes() { | 12 function checkResourceSizes() { |
| 10 var absoluteUrl = new URL(url, location.href).href; | 13 var absoluteUrl = new URL(url, location.href).href; |
| 11 var entries = performance.getEntriesByName(absoluteUrl); | 14 var entries = performance.getEntriesByName(absoluteUrl); |
| 12 assert_equals(entries.length, 2, 'Wrong number of entries'); | 15 assert_equals(entries.length, 2, 'Wrong number of entries'); |
| 13 for (var entry of entries) { | 16 for (var entry of entries) { |
| 14 if (entry.name === absoluteUrl) { | 17 if (entry.name === absoluteUrl) { |
| 15 assert_between_exclusive(entry.encodedBodySize, 0, uncompressedSize, | 18 assert_between_exclusive(entry.encodedBodySize, 0, uncompressedSize, |
| 16 'encodedBodySize'); | 19 'encodedBodySize'); |
| 17 assert_equals(entry.decodedBodySize, uncompressedSize); | 20 assert_equals(entry.decodedBodySize, uncompressedSize); |
| 18 } | 21 } |
| 19 } | 22 } |
| 20 } | 23 } |
| 21 | 24 |
| 22 promise_test(() => { | 25 promise_test(() => { |
| 23 // Fetch twice to ensure at least one fetch comes from the cache. | 26 // Fetch twice to ensure at least one fetch comes from the cache. |
| 24 var eatBody = response => response.arrayBuffer(); | 27 var eatBody = response => response.arrayBuffer(); |
| 25 return fetch(url) | 28 return fetch(url) |
| 26 .then(eatBody) | 29 .then(eatBody) |
| 27 .then(() => fetch(url)) | 30 .then(() => fetch(url)) |
| 28 .then(eatBody) | 31 .then(eatBody) |
| 29 .then(runAsyncTasks) | 32 .then(runAsyncTasks) |
| 30 .then(checkResourceSizes); | 33 .then(checkResourceSizes); |
| 31 }, 'PerformanceResourceTiming sizes compressed content test'); | 34 }, 'PerformanceResourceTiming sizes compressed content test'); |
| 32 </script> | 35 |
| 36 done(); |
| OLD | NEW |