| Blink WPT Bot | 9e8b0db | 2022-08-30 21:59:23 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <head> |
| 3 | <meta charset="utf-8" /> |
| Yoav Weiss | 128a6f3 | 2023-01-02 21:36:51 | [diff] [blame] | 4 | <meta name="timeout" content="long"> |
| Blink WPT Bot | 9e8b0db | 2022-08-30 21:59:23 | [diff] [blame] | 5 | <title>This test validates the response status of resources.</title> |
| 6 | <link rel="help" href="https://www.w3.org/TR/resource-timing-2/#sec-performanceresourcetiming"/> |
| 7 | <script src="/resources/testharness.js"></script> |
| 8 | <script src="/resources/testharnessreport.js"></script> |
| 9 | <script src="resources/entry-invariants.js"></script> |
| 10 | <script src="resources/resource-loaders.js"></script> |
| 11 | <script src="/common/get-host-info.sub.js"></script> |
| 12 | </head> |
| 13 | <body> |
| 14 | <script> |
| 15 | const {ORIGIN, REMOTE_ORIGIN} = get_host_info(); |
| Abin K Paul | 345545e | 2022-10-18 11:37:47 | [diff] [blame] | 16 | const SAME_ORIGIN = location.origin; |
| Blink WPT Bot | 9e8b0db | 2022-08-30 21:59:23 | [diff] [blame] | 17 | const status_codes = [ |
| 18 | 200, 203, |
| 19 | 400, 401, 403, 404, |
| 20 | 500, 501, 502, 503, |
| 21 | ]; |
| 22 | |
| Blink WPT Bot | feaf79e | 2023-01-02 21:29:45 | [diff] [blame] | 23 | const load_image_object = async path => { |
| 24 | return load.object(path, "image/png"); |
| Blink WPT Bot | 9e8b0db | 2022-08-30 21:59:23 | [diff] [blame] | 25 | } |
| 26 | |
| Yoav Weiss | a1e1b8f | 2023-01-25 10:39:30 | [diff] [blame] | 27 | const load_frame_object = async path => { |
| 28 | return load.object(path, "text/html"); |
| 29 | } |
| 30 | |
| Blink WPT Bot | feaf79e | 2023-01-02 21:29:45 | [diff] [blame] | 31 | const load_null_object = async path => { |
| 32 | return load.object(path, null); |
| 33 | } |
| 34 | |
| 35 | // Response status for same origin resources is exposed. |
| 36 | for(const loader of [ |
| Blink WPT Bot | 9e8b0db | 2022-08-30 21:59:23 | [diff] [blame] | 37 | load.font, |
| 38 | load.image, |
| 39 | load.script, |
| 40 | load.stylesheet, |
| 41 | load.xhr_sync, |
| 42 | load.xhr_async, |
| Blink WPT Bot | feaf79e | 2023-01-02 21:29:45 | [diff] [blame] | 43 | load.iframe, |
| 44 | load_image_object, |
| Yoav Weiss | a1e1b8f | 2023-01-25 10:39:30 | [diff] [blame] | 45 | load_frame_object, |
| Blink WPT Bot | feaf79e | 2023-01-02 21:29:45 | [diff] [blame] | 46 | load_null_object |
| 47 | ]) { |
| 48 | for(const status of status_codes) { |
| Yoav Weiss | 128a6f3 | 2023-01-02 21:36:51 | [diff] [blame] | 49 | let path = (loader == load.font) ? '/fonts/pass.woff' : |
| 50 | '/resource-timing/resources/empty.js'; |
| 51 | path += `?pipe=status(${status})`; |
| Blink WPT Bot | feaf79e | 2023-01-02 21:29:45 | [diff] [blame] | 52 | attribute_test( |
| 53 | loader, new URL(path, ORIGIN), |
| 54 | entry => { |
| Blink WPT Bot | 9e8b0db | 2022-08-30 21:59:23 | [diff] [blame] | 55 | assert_equals(entry.responseStatus, status, |
| Blink WPT Bot | feaf79e | 2023-01-02 21:29:45 | [diff] [blame] | 56 | `response status for ${entry.name} should be ${status}`); |
| 57 | } |
| 58 | ); |
| 59 | } |
| Blink WPT Bot | 9e8b0db | 2022-08-30 21:59:23 | [diff] [blame] | 60 | } |
| 61 | |
| Blink WPT Bot | feaf79e | 2023-01-02 21:29:45 | [diff] [blame] | 62 | // Response status is exposed for CORS requests for cross-origin resources. |
| 63 | for(const loader of [ |
| Blink WPT Bot | 9e8b0db | 2022-08-30 21:59:23 | [diff] [blame] | 64 | load.image_with_attrs, |
| 65 | load.script_with_attrs, |
| 66 | load.stylesheet_with_attrs |
| Blink WPT Bot | feaf79e | 2023-01-02 21:29:45 | [diff] [blame] | 67 | ]) { |
| 68 | for(const status of status_codes) { |
| 69 | const path = `/resource-timing/resources/empty.js?pipe=status(${status})` |
| 70 | + `|header(access-control-allow-origin, ${ORIGIN})`; |
| 71 | loader_with_crossOrigin_attr = async url => { |
| 72 | return loader(url, {"crossOrigin": "anonymous"}); |
| 73 | } |
| 74 | attribute_test( |
| 75 | loader_with_crossOrigin_attr, new URL(path, REMOTE_ORIGIN), |
| 76 | entry => { |
| 77 | assert_equals(entry.responseStatus, status, |
| 78 | `response status for ${entry.name} should be ${status}`); |
| 79 | } |
| 80 | ); |
| 81 | } |
| 82 | } |
| Blink WPT Bot | 9e8b0db | 2022-08-30 21:59:23 | [diff] [blame] | 83 | |
| 84 | // Response status is 0 when a no-cors request is made for cross origin |
| 85 | // fonts, images, scripts, stylesheets. |
| 86 | // Response status is 0 when request's mode is "navigate" and response's |
| 87 | // URL's origin is not same origin with request's origin. So response |
| 88 | // status is not exposed for cross origin iframes. |
| Blink WPT Bot | feaf79e | 2023-01-02 21:29:45 | [diff] [blame] | 89 | for(const loader of [ |
| Blink WPT Bot | 9e8b0db | 2022-08-30 21:59:23 | [diff] [blame] | 90 | load.font, |
| 91 | load.image, |
| 92 | load.script, |
| 93 | load.stylesheet, |
| Blink WPT Bot | feaf79e | 2023-01-02 21:29:45 | [diff] [blame] | 94 | load.iframe, |
| 95 | load_image_object, |
| Yoav Weiss | a1e1b8f | 2023-01-25 10:39:30 | [diff] [blame] | 96 | load_frame_object, |
| Blink WPT Bot | feaf79e | 2023-01-02 21:29:45 | [diff] [blame] | 97 | load_null_object |
| 98 | ]) { |
| 99 | for(const tao of [false, true]) { |
| 100 | for(const status of status_codes) { |
| Yoav Weiss | 128a6f3 | 2023-01-02 21:36:51 | [diff] [blame] | 101 | let path = (loader == load.font) ? '/fonts/pass.woff' : |
| 102 | '/resource-timing/resources/empty.js'; |
| 103 | path += `?pipe=status(${status})`; |
| Blink WPT Bot | feaf79e | 2023-01-02 21:29:45 | [diff] [blame] | 104 | if (tao) { |
| Yoav Weiss | 128a6f3 | 2023-01-02 21:36:51 | [diff] [blame] | 105 | path += `|header(timing-allow-origin, *)`; |
| Blink WPT Bot | feaf79e | 2023-01-02 21:29:45 | [diff] [blame] | 106 | } |
| 107 | attribute_test( |
| 108 | loader, new URL(path, REMOTE_ORIGIN), |
| 109 | entry => { |
| 110 | assert_equals(entry.responseStatus, 0, |
| 111 | `response status for ${entry.name} should be 0`); |
| 112 | } |
| 113 | ); |
| 114 | } |
| 115 | } |
| 116 | } |
| Blink WPT Bot | 9e8b0db | 2022-08-30 21:59:23 | [diff] [blame] | 117 | |
| Abin K Paul | 345545e | 2022-10-18 11:37:47 | [diff] [blame] | 118 | // Response status for iframes is 0 when cross origin redirects are present |
| 119 | // Same-Origin => Cross-Origin => Same-Origin => Same-Origin redirect chain |
| Blink WPT Bot | feaf79e | 2023-01-02 21:29:45 | [diff] [blame] | 120 | for(const loader of [ |
| 121 | load.iframe, |
| Yoav Weiss | a1e1b8f | 2023-01-25 10:39:30 | [diff] [blame] | 122 | load_frame_object, |
| Blink WPT Bot | feaf79e | 2023-01-02 21:29:45 | [diff] [blame] | 123 | load_null_object |
| 124 | ]) { |
| 125 | for(const status of status_codes) { |
| 126 | const destUrl = |
| 127 | `${SAME_ORIGIN}/resource-timing/resources/multi_redirect.py` + |
| 128 | `?page_origin=${SAME_ORIGIN}` + |
| 129 | `&cross_origin=${REMOTE_ORIGIN}` + |
| 130 | `&final_resource=` + |
| 131 | `/resource-timing/resources/empty.js?pipe=status(${status})`; |
| 132 | attribute_test( |
| 133 | loader, new URL(destUrl), |
| 134 | entry => { |
| Abin K Paul | 345545e | 2022-10-18 11:37:47 | [diff] [blame] | 135 | assert_equals(entry.responseStatus, 0, |
| Blink WPT Bot | feaf79e | 2023-01-02 21:29:45 | [diff] [blame] | 136 | `response status should be 0 for iframes having cross origin` |
| 137 | + ` redirects`); |
| 138 | } |
| 139 | ); |
| 140 | } |
| 141 | } |
| Abin K Paul | 345545e | 2022-10-18 11:37:47 | [diff] [blame] | 142 | |
| 143 | // Response status for iframes is exposed for same origin redirects |
| Blink WPT Bot | feaf79e | 2023-01-02 21:29:45 | [diff] [blame] | 144 | for(const loader of [ |
| 145 | load.iframe, |
| Yoav Weiss | a1e1b8f | 2023-01-25 10:39:30 | [diff] [blame] | 146 | load_frame_object, |
| Blink WPT Bot | feaf79e | 2023-01-02 21:29:45 | [diff] [blame] | 147 | load_null_object |
| 148 | ]) { |
| 149 | for(const status of status_codes) { |
| 150 | const destUrl = `${SAME_ORIGIN}/resource-timing/resources/redirect-cors.py` |
| 151 | + `?location=${SAME_ORIGIN}/resource-timing/resources/empty.js` |
| 152 | + `?pipe=status(${status})`; |
| 153 | attribute_test( |
| 154 | loader, new URL(destUrl), |
| 155 | entry => { |
| 156 | assert_equals(entry.responseStatus, status, |
| 157 | `response status should be exposed for iframes having only same` |
| 158 | + ` origin redirects`); |
| 159 | } |
| 160 | ); |
| 161 | } |
| 162 | }; |
| Blink WPT Bot | 9e8b0db | 2022-08-30 21:59:23 | [diff] [blame] | 163 | </script> |
| 164 | </body> |
| Yoav Weiss | 128a6f3 | 2023-01-02 21:36:51 | [diff] [blame] | 165 | </html> |