Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/http/tests/misc/resource-timing-sizes-cache.html |
| diff --git a/third_party/WebKit/LayoutTests/http/tests/misc/resource-timing-sizes-cache.html b/third_party/WebKit/LayoutTests/http/tests/misc/resource-timing-sizes-cache.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b1e66090ed3d503353e7e3a6b2e50bdb11d9e329 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/http/tests/misc/resource-timing-sizes-cache.html |
| @@ -0,0 +1,64 @@ |
| +<!DOCTYPE html> |
| +<script src="/resources/testharness.js"></script> |
| +<script src="/resources/testharnessreport.js"></script> |
| +<script src="/misc/resources/run-async-tasks-promise.js"></script> |
| +<script> |
| +// The header bytes are expected to be > |minHeaderSize| and |
| +// < |maxHeaderSize|. If they are outside this range the test will fail. |
| +const minHeaderSize = 100; |
| +const maxHeaderSize = 1024; |
| + |
| +// The size of this resource must be > maxHeaderSize for the test to be |
| +// reliable. |
| +var url = new URL('/resources/square.png', location.href).href; |
| +const expectedSize = 18299; |
| + |
| +function checkBodySizeFields(entry, expectedSize) { |
| + assert_equals(entry.decodedBodySize, expectedSize, 'decodedBodySize'); |
| + assert_equals(entry.encodedBodySize, expectedSize, 'encodedBodySize'); |
| +} |
| + |
| +function checkResourceSizes() { |
| + var entries = performance.getEntriesByType('resource'); |
| + var seenCount = 0; |
| + for (var entry of entries) { |
| + if (entry.name === url) { |
| + checkBodySizeFields(entry, expectedSize); |
| + if (seenCount === 0) { |
| + // 200 response |
| + assert_between_exclusive(entry.transferSize, |
| + expectedSize + minHeaderSize, |
| + expectedSize + maxHeaderSize, |
| + '200 transferSize'); |
| + } else if (seenCount === 1) { |
| + // from cache |
| + assert_equals(entry.transferSize, 0, 'cached transferSize'); |
| + } else if (seenCount === 2) { |
| + // 304 response |
| + assert_between_exclusive(entry.transferSize, minHeaderSize, |
| + maxHeaderSize, '304 transferSize'); |
| + } else { |
| + assert_unreached('Too many matching fetches.'); |
| + } |
| + ++seenCount; |
| + } |
| + } |
|
Kunihiko Sakamoto
2016/07/07 09:56:50
Add assertion for seenCount value?
Adam Rice
2016/07/07 11:21:12
I switched to using getEntriesByName(url) and adde
|
| +} |
| + |
| +promise_test(() => { |
| + // Use a different URL every time so that the cache behaviour does not |
| + // depend on execution order. |
| + url = url + '?unique=' + Math.random().toString().substring(2); |
| + var eatBody = response => response.arrayBuffer(); |
| + var mustRevalidate = {headers: {'Cache-Control': 'max-age=0'}}; |
| + return fetch(url) |
| + .then(eatBody) |
| + .then(() => fetch(url)) |
| + .then(eatBody) |
| + .then(() => fetch(url, mustRevalidate)) |
| + .then(eatBody) |
| + .then(runAsyncTasks) |
| + .then(checkResourceSizes); |
| +}, 'PerformanceResourceTiming sizes caching test'); |
| + |
| +</script> |