blob: 3a184c6f016b28c7003ea4650b7827b74388faf8 [file] [log] [blame]
Blink WPT Bot9e8b0db2022-08-30 21:59:231<!DOCTYPE html>
2<head>
3<meta charset="utf-8" />
Yoav Weiss128a6f32023-01-02 21:36:514<meta name="timeout" content="long">
Blink WPT Bot9e8b0db2022-08-30 21:59:235<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>
15const {ORIGIN, REMOTE_ORIGIN} = get_host_info();
Abin K Paul345545e2022-10-18 11:37:4716const SAME_ORIGIN = location.origin;
Blink WPT Bot9e8b0db2022-08-30 21:59:2317const status_codes = [
18 200, 203,
19 400, 401, 403, 404,
20 500, 501, 502, 503,
21];
22
Blink WPT Botfeaf79e2023-01-02 21:29:4523const load_image_object = async path => {
24 return load.object(path, "image/png");
Blink WPT Bot9e8b0db2022-08-30 21:59:2325}
26
Yoav Weissa1e1b8f2023-01-25 10:39:3027const load_frame_object = async path => {
28 return load.object(path, "text/html");
29}
30
Blink WPT Botfeaf79e2023-01-02 21:29:4531const load_null_object = async path => {
32 return load.object(path, null);
33}
34
35// Response status for same origin resources is exposed.
36for(const loader of [
Blink WPT Bot9e8b0db2022-08-30 21:59:2337 load.font,
38 load.image,
39 load.script,
40 load.stylesheet,
41 load.xhr_sync,
42 load.xhr_async,
Blink WPT Botfeaf79e2023-01-02 21:29:4543 load.iframe,
44 load_image_object,
Yoav Weissa1e1b8f2023-01-25 10:39:3045 load_frame_object,
Blink WPT Botfeaf79e2023-01-02 21:29:4546 load_null_object
47]) {
48 for(const status of status_codes) {
Yoav Weiss128a6f32023-01-02 21:36:5149 let path = (loader == load.font) ? '/fonts/pass.woff' :
50 '/resource-timing/resources/empty.js';
51 path += `?pipe=status(${status})`;
Blink WPT Botfeaf79e2023-01-02 21:29:4552 attribute_test(
53 loader, new URL(path, ORIGIN),
54 entry => {
Blink WPT Bot9e8b0db2022-08-30 21:59:2355 assert_equals(entry.responseStatus, status,
Blink WPT Botfeaf79e2023-01-02 21:29:4556 `response status for ${entry.name} should be ${status}`);
57 }
58 );
59 }
Blink WPT Bot9e8b0db2022-08-30 21:59:2360}
61
Blink WPT Botfeaf79e2023-01-02 21:29:4562// Response status is exposed for CORS requests for cross-origin resources.
63for(const loader of [
Blink WPT Bot9e8b0db2022-08-30 21:59:2364 load.image_with_attrs,
65 load.script_with_attrs,
66 load.stylesheet_with_attrs
Blink WPT Botfeaf79e2023-01-02 21:29:4567]) {
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 Bot9e8b0db2022-08-30 21:59:2383
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 Botfeaf79e2023-01-02 21:29:4589for(const loader of [
Blink WPT Bot9e8b0db2022-08-30 21:59:2390 load.font,
91 load.image,
92 load.script,
93 load.stylesheet,
Blink WPT Botfeaf79e2023-01-02 21:29:4594 load.iframe,
95 load_image_object,
Yoav Weissa1e1b8f2023-01-25 10:39:3096 load_frame_object,
Blink WPT Botfeaf79e2023-01-02 21:29:4597 load_null_object
98]) {
99 for(const tao of [false, true]) {
100 for(const status of status_codes) {
Yoav Weiss128a6f32023-01-02 21:36:51101 let path = (loader == load.font) ? '/fonts/pass.woff' :
102 '/resource-timing/resources/empty.js';
103 path += `?pipe=status(${status})`;
Blink WPT Botfeaf79e2023-01-02 21:29:45104 if (tao) {
Yoav Weiss128a6f32023-01-02 21:36:51105 path += `|header(timing-allow-origin, *)`;
Blink WPT Botfeaf79e2023-01-02 21:29:45106 }
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 Bot9e8b0db2022-08-30 21:59:23117
Abin K Paul345545e2022-10-18 11:37:47118// 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 Botfeaf79e2023-01-02 21:29:45120for(const loader of [
121 load.iframe,
Yoav Weissa1e1b8f2023-01-25 10:39:30122 load_frame_object,
Blink WPT Botfeaf79e2023-01-02 21:29:45123 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 Paul345545e2022-10-18 11:37:47135 assert_equals(entry.responseStatus, 0,
Blink WPT Botfeaf79e2023-01-02 21:29:45136 `response status should be 0 for iframes having cross origin`
137 + ` redirects`);
138 }
139 );
140 }
141}
Abin K Paul345545e2022-10-18 11:37:47142
143// Response status for iframes is exposed for same origin redirects
Blink WPT Botfeaf79e2023-01-02 21:29:45144for(const loader of [
145 load.iframe,
Yoav Weissa1e1b8f2023-01-25 10:39:30146 load_frame_object,
Blink WPT Botfeaf79e2023-01-02 21:29:45147 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 Bot9e8b0db2022-08-30 21:59:23163</script>
164</body>
Yoav Weiss128a6f32023-01-02 21:36:51165</html>