| Index: third_party/WebKit/LayoutTests/http/tests/misc/resource-timing-sizes-redirect.html
|
| diff --git a/third_party/WebKit/LayoutTests/http/tests/misc/resource-timing-sizes-redirect.html b/third_party/WebKit/LayoutTests/http/tests/misc/resource-timing-sizes-redirect.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9adbaa0e5809686effc8e4664892d8169f87dbbd
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/http/tests/misc/resource-timing-sizes-redirect.html
|
| @@ -0,0 +1,99 @@
|
| +<!DOCTYPE html>
|
| +<script src="/resources/testharness.js"></script>
|
| +<script src="/resources/testharnessreport.js"></script>
|
| +<script src="/resources/get-host-info.js?pipe=sub"></script>
|
| +<script src="/misc/resources/run-async-tasks-promise.js"></script>
|
| +<script>
|
| +const baseUrl =
|
| + new URL('/security/resources/cors-hello.php', location.href).href;
|
| +const expectedSize = 73;
|
| +
|
| +// Because apache decrements the Keep-Alive max value on each request, the
|
| +// transferSize will vary slightly between requests for the same resource.
|
| +const fuzzFactor = 3; // bytes
|
| +
|
| +const minHeaderSize = 100;
|
| +
|
| +const hostInfo = get_host_info();
|
| +
|
| +var directUrl, sameOriginRedirect, crossOriginRedirect, mixedRedirect;
|
| +var complexRedirect;
|
| +var seenCount = 0;
|
| +
|
| +function checkBodySizeFields(entry) {
|
| + assert_equals(entry.decodedBodySize, expectedSize, 'decodedBodySize');
|
| + assert_equals(entry.encodedBodySize, expectedSize, 'encodedBodySize');
|
| +}
|
| +
|
| +function checkResourceSizes() {
|
| + var entries = performance.getEntriesByType('resource');
|
| + var lowerBound, upperBound, withRedirectLowerBound;
|
| + for (var entry of entries) {
|
| + switch (entry.name) {
|
| + case directUrl:
|
| + checkBodySizeFields(entry);
|
| + assert_greater_than(entry.transferSize, expectedSize,
|
| + 'transferSize');
|
| + lowerBound = entry.transferSize - fuzzFactor;
|
| + upperBound = entry.transferSize + fuzzFactor;
|
| + withRedirectLowerBound = entry.transferSize + minHeaderSize;
|
| + ++seenCount;
|
| + break;
|
| +
|
| + case sameOriginRedirect:
|
| + checkBodySizeFields(entry);
|
| + assert_greater_than(entry.transferSize, withRedirectLowerBound,
|
| + 'transferSize');
|
| + ++seenCount;
|
| + break;
|
| +
|
| + case crossOriginRedirect:
|
| + case mixedRedirect:
|
| + case complexRedirect:
|
| + checkBodySizeFields(entry);
|
| + assert_between_exclusive(entry.transferSize, lowerBound, upperBound,
|
| + 'transferSize');
|
| + ++seenCount;
|
| + break;
|
| +
|
| + default:
|
| + break;
|
| + }
|
| + }
|
| + assert_equals(seenCount, 5, 'seenCount');
|
| +}
|
| +
|
| +function redirectUrl(redirectSourceOrigin, allowOrigin, targetUrl) {
|
| + return redirectSourceOrigin +
|
| + '/resources/redirect.php?cors_allow_origin=' +
|
| + encodeURIComponent(allowOrigin) +
|
| + '&url=' + encodeURIComponent(targetUrl);
|
| +}
|
| +
|
| +promise_test(() => {
|
| + // Use a different URL every time so that the cache behaviour does not
|
| + // depend on execution order.
|
| + directUrl = baseUrl + '?unique=' + Math.random().toString().substring(2) +
|
| + '&cors=*';
|
| + sameOriginRedirect = redirectUrl(hostInfo.HTTP_ORIGIN, '*', directUrl);
|
| + crossOriginRedirect = redirectUrl(hostInfo.HTTP_REMOTE_ORIGIN,
|
| + hostInfo.HTTP_ORIGIN, directUrl);
|
| + mixedRedirect = redirectUrl(hostInfo.HTTP_REMOTE_ORIGIN,
|
| + hostInfo.HTTP_ORIGIN, sameOriginRedirect);
|
| + complexRedirect = redirectUrl(hostInfo.HTTP_ORIGIN,
|
| + hostInfo.HTTP_REMOTE_ORIGIN, mixedRedirect);
|
| + var eatBody = response => response.arrayBuffer();
|
| + return fetch(directUrl)
|
| + .then(eatBody)
|
| + .then(() => fetch(sameOriginRedirect))
|
| + .then(eatBody)
|
| + .then(() => fetch(crossOriginRedirect))
|
| + .then(eatBody)
|
| + .then(() => fetch(mixedRedirect))
|
| + .then(eatBody)
|
| + .then(() => fetch(complexRedirect))
|
| + .then(eatBody)
|
| + .then(runAsyncTasks)
|
| + .then(checkResourceSizes);
|
| +}, 'PerformanceResourceTiming sizes Fetch with redirect test');
|
| +</script>
|
|
|