|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | + |
| 4 | +<head> |
| 5 | + <meta charset="utf-8"> |
| 6 | + <title>contentEncoding in resource timing</title> |
| 7 | + <link rel="author" title="Microsoft" href="http://www.microsoft.com/" /> |
| 8 | + <link rel="help" href="https://www.w3.org/TR/resource-timing-2/#sec-performanceresourcetiming" /> |
| 9 | + <script src="/common/get-host-info.sub.js"></script> |
| 10 | + <script src="/resources/testharness.js"></script> |
| 11 | + <script src="/resources/testharnessreport.js"></script> |
| 12 | + <script src="resources/entry-invariants.js"></script> |
| 13 | + <script src="resources/resource-loaders.js"></script> |
| 14 | + <script> |
| 15 | + |
| 16 | + const { ORIGIN, REMOTE_ORIGIN } = get_host_info(); |
| 17 | + |
| 18 | + const run_same_origin_test = (path, contentEncoding) => { |
| 19 | + const url = new URL(path, ORIGIN); |
| 20 | + attribute_test( |
| 21 | + fetch, url, |
| 22 | + entry => { |
| 23 | + assert_equals(entry.contentEncoding, contentEncoding, |
| 24 | + `run_same_origin_test failed, unexpected contentEncoding value.`); |
| 25 | + }); |
| 26 | + } |
| 27 | + |
| 28 | + run_same_origin_test("/resource-timing/resources/compressed-data.py?content_encoding=dcb", "dcb"); |
| 29 | + run_same_origin_test("/resource-timing/resources/compressed-data.py?content_encoding=dcz", "dcz"); |
| 30 | + run_same_origin_test("/resource-timing/resources/gzip_xml.py", "gzip"); |
| 31 | + run_same_origin_test("/resource-timing/resources/foo.text.br", "br"); |
| 32 | + run_same_origin_test("/resource-timing/resources/foo.text.gz", "gzip"); |
| 33 | + run_same_origin_test("/resource-timing/resources/foo.text.zst", "zstd"); |
| 34 | + run_same_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=deflate", "deflate"); |
| 35 | + run_same_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=gzip", "gzip"); |
| 36 | + run_same_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=identity", "identity"); |
| 37 | + // Unrecognized content encoding value should be transformed to "unknown". |
| 38 | + run_same_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=unrecognizedname", "unknown"); |
| 39 | + |
| 40 | + |
| 41 | + const run_cross_origin_test = (path) => { |
| 42 | + const url = new URL(path, REMOTE_ORIGIN); |
| 43 | + attribute_test( |
| 44 | + load.xhr_async, url, |
| 45 | + entry => { |
| 46 | + assert_equals(entry.contentEncoding, "", |
| 47 | + `run_cross_origin_test failed, contentEncoding should be empty.`); |
| 48 | + }); |
| 49 | + } |
| 50 | + |
| 51 | + run_cross_origin_test("/resource-timing/resources/compressed-data.py?content_encoding=dcb"); |
| 52 | + run_cross_origin_test("/resource-timing/resources/gzip_xml.py"); |
| 53 | + run_cross_origin_test("/resource-timing/resources/compressed-data.py?content_encoding=dcz"); |
| 54 | + run_cross_origin_test("/resource-timing/resources/foo.text.br"); |
| 55 | + run_cross_origin_test("/resource-timing/resources/foo.text.gz"); |
| 56 | + run_cross_origin_test("/resource-timing/resources/foo.text.zst"); |
| 57 | + run_cross_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=deflate"); |
| 58 | + run_cross_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=gzip"); |
| 59 | + |
| 60 | + const run_cross_origin_allowed_test = (path, contentEncoding) => { |
| 61 | + const url = new URL(path, REMOTE_ORIGIN); |
| 62 | + url.searchParams.set("allow_origin", ORIGIN); |
| 63 | + attribute_test( |
| 64 | + load.xhr_async, url, |
| 65 | + entry => { |
| 66 | + assert_equals(entry.contentEncoding, contentEncoding, |
| 67 | + `run_cross_origin_allowed_test failed, unexpected contentEncoding value.`); |
| 68 | + }); |
| 69 | + } |
| 70 | + |
| 71 | + run_cross_origin_allowed_test("/resource-timing/resources/compressed-data.py?content_encoding=dcb", "dcb"); |
| 72 | + run_cross_origin_allowed_test("/resource-timing/resources/compressed-data.py?content_encoding=dcz", "dcz"); |
| 73 | + run_cross_origin_allowed_test("/resource-timing/resources/gzip_xml.py", "gzip"); |
| 74 | + run_cross_origin_allowed_test("/resource-timing/resources/compressed-js.py?content_encoding=deflate", "deflate"); |
| 75 | + run_cross_origin_allowed_test("/resource-timing/resources/compressed-js.py?content_encoding=gzip", "gzip"); |
| 76 | + |
| 77 | + // Content-Encoding for iframes is empty when cross origin redirects are present. |
| 78 | + const multiRedirect = new URL(`${ORIGIN}/resource-timing/resources/multi_redirect.py`); |
| 79 | + multiRedirect.searchParams.append("page_origin", ORIGIN); |
| 80 | + multiRedirect.searchParams.append("cross_origin", REMOTE_ORIGIN); |
| 81 | + multiRedirect.searchParams.append("final_resource", "/resource-timing/resources/compressed-js.py?content_encoding=gzip"); |
| 82 | + attribute_test(load.iframe, multiRedirect, (entry) => { |
| 83 | + assert_equals(entry.contentEncoding, "", |
| 84 | + `content-encoding should be empty for iframes having cross origin redirects`); |
| 85 | + }); |
| 86 | + |
| 87 | + |
| 88 | + // Content-Encoding for iframes is exposed for same origin redirects. |
| 89 | + const redirectCORS = new URL(`${ORIGIN}/resource-timing/resources/redirect-cors.py`); |
| 90 | + const dest = `${ORIGIN}/resource-timing/resources/compressed-js.py?content_encoding=gzip`; |
| 91 | + redirectCORS.searchParams.append("location", dest) |
| 92 | + attribute_test(load.iframe, redirectCORS, (entry) => { |
| 93 | + assert_equals(entry.contentEncoding, "gzip", |
| 94 | + `content-encoding should be exposed for iframes having only same origin redirects`); |
| 95 | + }); |
| 96 | + |
| 97 | + </script> |
| 98 | +</head> |
| 99 | + |
| 100 | +<body> |
| 101 | + <h1> |
| 102 | + Description</h1> |
| 103 | + <p> |
| 104 | + This test validates contentEncoding in resource timing.</p> |
| 105 | +</body> |
| 106 | + |
| 107 | +</html> |
0 commit comments