Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/http/tests/misc/resource-timing-sizes-cors-preflight.html |
| diff --git a/third_party/WebKit/LayoutTests/http/tests/misc/resource-timing-sizes-cors-preflight.html b/third_party/WebKit/LayoutTests/http/tests/misc/resource-timing-sizes-cors-preflight.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3b8295daadb2553c1549977dd37f2d6b7e0a4313 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/http/tests/misc/resource-timing-sizes-cors-preflight.html |
| @@ -0,0 +1,66 @@ |
| +<!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> |
| +// 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 hostInfo = get_host_info(); |
| +const url = new URL('/misc/resources/cors-preflight.php', |
| + hostInfo['HTTP_REMOTE_ORIGIN']).href; |
| + |
| +// 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; |
| + |
| +var seenCount = 0; |
|
Kunihiko Sakamoto
2016/07/07 09:56:51
nit: move this into checkResourceSizes()
Adam Rice
2016/07/07 11:21:12
Done.
|
| + |
| +function checkResourceSizes() { |
| + var lowerBound, upperBound; |
| + var entries = performance.getEntriesByType('resource'); |
| + // Firefox 47 puts the preflight after the request in the timeline. |
| + // Sort by requestStart for compatibility. |
| + entries.sort((a, b) => b.requestStart > a.requestStart ? 1 : -1); |
|
Kunihiko Sakamoto
2016/07/07 09:56:51
nit: (a, b) => b.requestStart - a.requestStart wo
Adam Rice
2016/07/07 11:21:12
Done.
|
| + for (var entry of entries) { |
| + if (entry.name === url) { |
| + switch (seenCount) { |
| + case 0: |
|
Kunihiko Sakamoto
2016/07/07 09:56:51
-4 indent
Adam Rice
2016/07/07 11:21:12
Done.
|
| + assert_greater_than(entry.transferSize, 0, |
| + 'no preflight transferSize'); |
| + lowerBound = entry.transferSize - fuzzFactor; |
| + upperBound = entry.transferSize + fuzzFactor; |
| + break; |
| + |
| + case 1: |
| + assert_between_exclusive(entry.transferSize, minHeaderSize, |
| + maxHeaderSize, |
| + 'preflight transferSize'); |
| + break; |
| + |
| + case 2: |
| + assert_between_exclusive(entry.transferSize, lowerBound, |
| + upperBound, |
| + 'preflighted transferSize'); |
| + break; |
| + } |
| + ++seenCount; |
| + } |
| + } |
| + assert_equals(seenCount, 3, 'seenCount'); |
| +} |
| + |
| +promise_test(() => { |
| + var eatBody = response => response.arrayBuffer(); |
| + var requirePreflight = {headers: {'X-Require-Preflight': '1'}}; |
| + return fetch(url) |
| + .then(eatBody) |
| + .then(() => fetch(url, requirePreflight)) |
| + .then(eatBody) |
| + .then(runAsyncTasks) |
| + .then(checkResourceSizes); |
| +}, 'PerformanceResourceTiming sizes Fetch with preflight test'); |
| +</script> |