OLD | NEW |
---|---|
1 if (self.importScripts) { | 1 if (self.importScripts) { |
2 importScripts('../resources/fetch-test-helpers.js'); | 2 importScripts('../resources/fetch-test-helpers.js'); |
3 } | 3 } |
4 | 4 |
5 promise_test(function(t) { | 5 promise_test(function(t) { |
6 return fetch('http://') | 6 return fetch('http://') |
7 .then( | 7 .then( |
8 t.unreached_func('fetch of invalid URL must fail'), | 8 t.unreached_func('fetch of invalid URL must fail'), |
9 function() {}); | 9 function() {}); |
10 }, 'Fetch invalid URL'); | 10 }, 'Fetch invalid URL'); |
(...skipping 11 matching lines...) Expand all Loading... | |
22 | 22 |
23 // Tests for data: scheme. | 23 // Tests for data: scheme. |
24 promise_test(function(t) { | 24 promise_test(function(t) { |
25 return fetch('data:,Foobar') | 25 return fetch('data:,Foobar') |
26 .then(function(response) { | 26 .then(function(response) { |
27 assert_equals(response.status, 200); | 27 assert_equals(response.status, 200); |
28 assert_equals(response.statusText, 'OK'); | 28 assert_equals(response.statusText, 'OK'); |
29 assert_equals(response.headers.get('Content-Type'), | 29 assert_equals(response.headers.get('Content-Type'), |
30 'text/plain;charset=US-ASCII'); | 30 'text/plain;charset=US-ASCII'); |
31 assert_equals(size(response.headers), 1); | 31 assert_equals(size(response.headers), 1); |
32 if (self.internals) { | |
33 assert_array_equals( | |
34 ['data:,Foobar'], | |
35 self.internals.getInternalResponseURLList(response)); | |
falken
2016/12/09 01:54:15
nit: actual and expected parameters are flipped (t
horo
2016/12/09 05:04:11
Done.
| |
36 } | |
32 return response.text(); | 37 return response.text(); |
33 }) | 38 }) |
34 .then(function(text) { | 39 .then(function(text) { |
35 assert_equals(text, 'Foobar'); | 40 assert_equals(text, 'Foobar'); |
36 }); | 41 }); |
37 }, 'fetch data: URL'); | 42 }, 'fetch data: URL'); |
38 | 43 |
39 promise_test(function(t) { | 44 promise_test(function(t) { |
40 return fetch('data:text/html;charset=utf-8;base64,5paH5a2X') | 45 return fetch('data:text/html;charset=utf-8;base64,5paH5a2X') |
41 .then(function(response) { | 46 .then(function(response) { |
42 assert_equals(response.status, 200); | 47 assert_equals(response.status, 200); |
43 assert_equals(response.statusText, 'OK'); | 48 assert_equals(response.statusText, 'OK'); |
44 assert_equals(response.headers.get('Content-Type'), | 49 assert_equals(response.headers.get('Content-Type'), |
45 'text/html;charset=utf-8'); | 50 'text/html;charset=utf-8'); |
46 assert_equals(size(response.headers), 1); | 51 assert_equals(size(response.headers), 1); |
52 if (self.internals) { | |
53 assert_array_equals( | |
54 ['data:text/html;charset=utf-8;base64,5paH5a2X'], | |
55 self.internals.getInternalResponseURLList(response)); | |
56 } | |
47 return response.text(); | 57 return response.text(); |
48 }) | 58 }) |
49 .then(function(text) { | 59 .then(function(text) { |
50 assert_equals(text, '\u6587\u5b57'); | 60 assert_equals(text, '\u6587\u5b57'); |
51 }); | 61 }); |
52 }, 'fetch data: URL with non-ASCII characters'); | 62 }, 'fetch data: URL with non-ASCII characters'); |
53 | 63 |
54 promise_test(function(t) { | 64 promise_test(function(t) { |
55 return fetch('data:text/html;base64,***') | 65 return fetch('data:text/html;base64,***') |
56 .then( | 66 .then( |
57 t.unreached_func('fetching invalid data: URL must fail'), | 67 t.unreached_func('fetching invalid data: URL must fail'), |
58 function() {}); | 68 function() {}); |
59 }, 'fetch invalid data: URL'); | 69 }, 'fetch invalid data: URL'); |
60 | 70 |
61 // Only [Exposed=(Window,DedicatedWorker,SharedWorker)]. | 71 // Only [Exposed=(Window,DedicatedWorker,SharedWorker)]. |
62 if ('createObjectURL' in URL) { | 72 if ('createObjectURL' in URL) { |
63 // Tests for blob: scheme. | 73 // Tests for blob: scheme. |
64 promise_test(function(t) { | 74 promise_test(function(t) { |
65 var url = URL.createObjectURL(new Blob(['fox'], {type: 'text/fox'})); | 75 var url = URL.createObjectURL(new Blob(['fox'], {type: 'text/fox'})); |
66 return fetch(url) | 76 return fetch(url) |
67 .then(function(response) { | 77 .then(function(response) { |
68 assert_equals(response.status, 200); | 78 assert_equals(response.status, 200); |
69 assert_equals(response.statusText, 'OK'); | 79 assert_equals(response.statusText, 'OK'); |
70 assert_equals(response.headers.get('Content-Type'), 'text/fox'); | 80 assert_equals(response.headers.get('Content-Type'), 'text/fox'); |
71 assert_equals(response.headers.get('Content-Length'), '3'); | 81 assert_equals(response.headers.get('Content-Length'), '3'); |
72 assert_equals(size(response.headers), 2); | 82 assert_equals(size(response.headers), 2); |
83 if (self.internals) { | |
84 assert_array_equals( | |
85 [url], self.internals.getInternalResponseURLList(response)); | |
86 } | |
73 return response.text(); | 87 return response.text(); |
74 }) | 88 }) |
75 .then(function(text) { | 89 .then(function(text) { |
76 assert_equals(text, 'fox'); | 90 assert_equals(text, 'fox'); |
77 }); | 91 }); |
78 }, 'fetch blob: URL'); | 92 }, 'fetch blob: URL'); |
79 | 93 |
80 promise_test(function(t) { | 94 promise_test(function(t) { |
81 var url = URL.createObjectURL(new Blob(['fox'], {type: 'text/fox'})); | 95 var url = URL.createObjectURL(new Blob(['fox'], {type: 'text/fox'})); |
82 return fetch(url + 'invalid') | 96 return fetch(url + 'invalid') |
83 .then( | 97 .then( |
84 t.unreached_func('fetching non-existent blob: URL must fail'), | 98 t.unreached_func('fetching non-existent blob: URL must fail'), |
85 function() {}); | 99 function() {}); |
86 }, 'fetch non-existent blob: URL'); | 100 }, 'fetch non-existent blob: URL'); |
87 } | 101 } |
88 | 102 |
89 // https://fetch.spec.whatwg.org/#concept-basic-fetch | 103 // https://fetch.spec.whatwg.org/#concept-basic-fetch |
90 // The last statement: | 104 // The last statement: |
91 // Otherwise | 105 // Otherwise |
92 // Return a network error. | 106 // Return a network error. |
93 promise_test(function(t) { | 107 promise_test(function(t) { |
94 return fetch('foobar://localhost/', {mode: 'no-cors'}) | 108 return fetch('foobar://localhost/', {mode: 'no-cors'}) |
95 .then( | 109 .then( |
96 t.unreached_func('scheme not listed in basic fetch spec must fail'), | 110 t.unreached_func('scheme not listed in basic fetch spec must fail'), |
97 function() {}); | 111 function() {}); |
98 }, 'fetch of scheme not listed in basic fetch spec'); | 112 }, 'fetch of scheme not listed in basic fetch spec'); |
99 | 113 |
100 promise_test(function(t) { | 114 promise_test(function(t) { |
101 return fetch('/fetch/resources/fetch-status.php?status=200') | 115 var request = new Request('/fetch/resources/fetch-status.php?status=200'); |
116 return fetch(request) | |
102 .then(function(response) { | 117 .then(function(response) { |
103 assert_equals(response.status, 200); | 118 assert_equals(response.status, 200); |
104 assert_equals(response.statusText, 'OK'); | 119 assert_equals(response.statusText, 'OK'); |
120 if (self.internals) { | |
121 assert_array_equals( | |
122 [request.url], | |
123 self.internals.getInternalResponseURLList(response)); | |
124 } | |
105 }); | 125 }); |
106 }, 'Fetch result of 200 response'); | 126 }, 'Fetch result of 200 response'); |
107 | 127 |
108 promise_test(function(t) { | 128 promise_test(function(t) { |
109 return fetch('/fetch/resources/fetch-status.php?status=404') | 129 var request = new Request('/fetch/resources/fetch-status.php?status=404'); |
130 return fetch(request) | |
110 .then(function(response) { | 131 .then(function(response) { |
111 assert_equals(response.status, 404); | 132 assert_equals(response.status, 404); |
112 assert_equals(response.statusText, 'Not Found'); | 133 assert_equals(response.statusText, 'Not Found'); |
134 if (self.internals) { | |
135 assert_array_equals( | |
136 [request.url], | |
137 self.internals.getInternalResponseURLList(response)); | |
138 } | |
113 }); | 139 }); |
114 }, 'Fetch result of 404 response'); | 140 }, 'Fetch result of 404 response'); |
115 | 141 |
116 promise_test(function(t) { | 142 promise_test(function(t) { |
117 var request = new Request( | 143 var request = new Request( |
118 '/fetch/resources/fetch-status.php?status=200#fragment'); | 144 '/fetch/resources/fetch-status.php?status=200#fragment'); |
119 | 145 |
120 // The url attribute's getter must return request's url, | 146 // The url attribute's getter must return request's url, |
121 // serialized with the exclude fragment flag set. | 147 // serialized with the exclude fragment flag set. |
122 assert_equals(request.url, | 148 assert_equals(request.url, |
123 BASE_ORIGIN + '/fetch/resources/fetch-status.php?status=200'); | 149 BASE_ORIGIN + '/fetch/resources/fetch-status.php?status=200'); |
124 | 150 |
125 return fetch(request) | 151 return fetch(request) |
126 .then(function(response) { | 152 .then(function(response) { |
127 assert_equals(response.status, 200); | 153 assert_equals(response.status, 200); |
128 assert_equals(response.statusText, 'OK'); | 154 assert_equals(response.statusText, 'OK'); |
129 // The url attribute's getter must return the empty string | 155 // The url attribute's getter must return the empty string |
130 // if response's url is null and response's url, | 156 // if response's url is null and response's url, |
131 // serialized with the exclude fragment flag set, otherwise. | 157 // serialized with the exclude fragment flag set, otherwise. |
132 assert_equals(response.url, | 158 assert_equals(response.url, |
133 BASE_ORIGIN + | 159 BASE_ORIGIN + '/fetch/resources/fetch-status.php?status=200'); |
134 '/fetch/resources/fetch-status.php?status=200'); | 160 if (self.internals) { |
161 assert_array_equals( | |
162 [BASE_ORIGIN + | |
163 '/fetch/resources/fetch-status.php?status=200#fragment'], | |
164 self.internals.getInternalResponseURLList(response)); | |
165 } | |
135 }); | 166 }); |
136 }, 'Request/response url attribute getter with fragment'); | 167 }, 'Request/response url attribute getter with fragment'); |
137 | 168 |
138 promise_test(function(t) { | 169 promise_test(function(t) { |
139 var redirect_target_url = | 170 var redirect_target_url = |
140 BASE_ORIGIN + '/fetch/resources/fetch-status.php?status=200'; | 171 BASE_ORIGIN + '/fetch/resources/fetch-status.php?status=200'; |
141 var redirect_original_url = | 172 var redirect_original_url = |
142 BASE_ORIGIN + '/serviceworker/resources/redirect.php?Redirect=' + | 173 BASE_ORIGIN + '/serviceworker/resources/redirect.php?Redirect=' + |
143 redirect_target_url; | 174 redirect_target_url; |
144 | 175 |
145 var request = new Request(redirect_original_url); | 176 var request = new Request(redirect_original_url); |
146 assert_equals(request.url, redirect_original_url, | 177 assert_equals(request.url, redirect_original_url, |
147 'Request\'s url is the original URL'); | 178 'Request\'s url is the original URL'); |
148 assert_equals(request.redirect, 'follow'); | 179 assert_equals(request.redirect, 'follow'); |
149 | 180 |
150 return fetch(request) | 181 return fetch(request) |
151 .then(function(response) { | 182 .then(function(response) { |
152 assert_equals(response.status, 200); | 183 assert_equals(response.status, 200); |
153 assert_equals(response.statusText, 'OK'); | 184 assert_equals(response.statusText, 'OK'); |
154 assert_equals(response.url, redirect_target_url, | 185 assert_equals(response.url, redirect_target_url, |
155 'Response\'s url is locationURL'); | 186 'Response\'s url is locationURL'); |
156 assert_equals(request.url, redirect_original_url, | 187 assert_equals(request.url, redirect_original_url, |
157 'Request\'s url remains the original URL'); | 188 'Request\'s url remains the original URL'); |
189 if (self.internals) { | |
190 assert_array_equals( | |
191 [request.url, response.url], | |
192 self.internals.getInternalResponseURLList(response)); | |
193 } | |
158 }); | 194 }); |
159 }, 'Request/response url attribute getter with redirect'); | 195 }, 'Request/response url attribute getter with redirect'); |
160 | 196 |
161 promise_test(function(t) { | 197 promise_test(function(t) { |
162 var redirect_target_url = | 198 var redirect_target_url = |
163 BASE_ORIGIN + '/fetch/resources/fetch-status.php?status=200'; | 199 BASE_ORIGIN + '/fetch/resources/fetch-status.php?status=200'; |
164 var redirect_original_url = | 200 var redirect_original_url = |
165 BASE_ORIGIN + '/serviceworker/resources/redirect.php?Redirect=' + | 201 BASE_ORIGIN + '/serviceworker/resources/redirect.php?Redirect=' + |
166 redirect_target_url; | 202 redirect_target_url; |
167 | 203 |
168 var request = new Request(redirect_original_url, {redirect: 'manual'}); | 204 var request = new Request(redirect_original_url, {redirect: 'manual'}); |
169 assert_equals(request.url, redirect_original_url, | 205 assert_equals(request.url, redirect_original_url, |
170 'Request\'s url is the original URL'); | 206 'Request\'s url is the original URL'); |
171 assert_equals(request.redirect, 'manual'); | 207 assert_equals(request.redirect, 'manual'); |
172 | 208 |
173 return fetch(request) | 209 return fetch(request) |
174 .then(function(response) { | 210 .then(function(response) { |
175 assert_equals(response.status, 0); | 211 assert_equals(response.status, 0); |
176 assert_equals(response.type, 'opaqueredirect'); | 212 assert_equals(response.type, 'opaqueredirect'); |
177 assert_equals(response.url, request.url); | 213 assert_equals(response.url, request.url); |
214 if (self.internals) { | |
215 assert_array_equals( | |
216 [redirect_original_url], | |
217 self.internals.getInternalResponseURLList(response)); | |
218 } | |
178 }); | 219 }); |
179 }, 'Manual redirect fetch returns opaque redirect response'); | 220 }, 'Manual redirect fetch returns opaque redirect response'); |
180 | 221 |
181 promise_test(function(t) { | 222 promise_test(function(t) { |
182 var redirect_target_url = | 223 var redirect_target_url = |
183 OTHER_ORIGIN + '/fetch/resources/fetch-status.php?status=200'; | 224 OTHER_ORIGIN + '/fetch/resources/fetch-status.php?status=200'; |
184 var redirect_original_url = | 225 var redirect_original_url = |
185 OTHER_ORIGIN + '/serviceworker/resources/redirect.php?Redirect=' + | 226 OTHER_ORIGIN + '/serviceworker/resources/redirect.php?Redirect=' + |
186 redirect_target_url; | 227 redirect_target_url; |
187 | 228 |
(...skipping 30 matching lines...) Expand all Loading... | |
218 function() {}); | 259 function() {}); |
219 }, 'Redirect response must cause an error when redirect mode is error.'); | 260 }, 'Redirect response must cause an error when redirect mode is error.'); |
220 | 261 |
221 promise_test(function(test) { | 262 promise_test(function(test) { |
222 var url = BASE_ORIGIN + '/fetch/resources/doctype.html'; | 263 var url = BASE_ORIGIN + '/fetch/resources/doctype.html'; |
223 return fetch(new Request(url, {redirect: 'manual'})) | 264 return fetch(new Request(url, {redirect: 'manual'})) |
224 .then(function(response) { | 265 .then(function(response) { |
225 assert_equals(response.status, 200); | 266 assert_equals(response.status, 200); |
226 assert_equals(response.statusText, 'OK'); | 267 assert_equals(response.statusText, 'OK'); |
227 assert_equals(response.url, url); | 268 assert_equals(response.url, url); |
269 if (self.internals) { | |
270 assert_array_equals( | |
271 [url], self.internals.getInternalResponseURLList(response)); | |
272 } | |
228 return response.text(); | 273 return response.text(); |
229 }) | 274 }) |
230 .then(function(text) { assert_equals(text, '<!DOCTYPE html>\n'); }) | 275 .then(function(text) { assert_equals(text, '<!DOCTYPE html>\n'); }) |
231 }, 'No-redirect fetch completes normally even if redirect mode is manual'); | 276 }, 'No-redirect fetch completes normally even if redirect mode is manual'); |
232 | 277 |
233 promise_test(function(test) { | 278 promise_test(function(test) { |
234 var url = BASE_ORIGIN + '/fetch/resources/doctype.html'; | 279 var url = BASE_ORIGIN + '/fetch/resources/doctype.html'; |
235 return fetch(new Request(url, {redirect: 'error'})) | 280 return fetch(new Request(url, {redirect: 'error'})) |
236 .then(function(response) { | 281 .then(function(response) { |
237 assert_equals(response.status, 200); | 282 assert_equals(response.status, 200); |
238 assert_equals(response.statusText, 'OK'); | 283 assert_equals(response.statusText, 'OK'); |
239 assert_equals(response.url, url); | 284 assert_equals(response.url, url); |
285 if (self.internals) { | |
286 assert_array_equals( | |
287 [url], self.internals.getInternalResponseURLList(response)); | |
288 } | |
240 return response.text(); | 289 return response.text(); |
241 }) | 290 }) |
242 .then(function(text) { assert_equals(text, '<!DOCTYPE html>\n'); }) | 291 .then(function(text) { assert_equals(text, '<!DOCTYPE html>\n'); }) |
243 }, 'No-redirect fetch completes normally even if redirect mode is error'); | 292 }, 'No-redirect fetch completes normally even if redirect mode is error'); |
244 | 293 |
245 function evalJsonp(text) { | 294 function evalJsonp(text) { |
246 return new Promise(function(resolve) { | 295 return new Promise(function(resolve) { |
247 var report = resolve; | 296 var report = resolve; |
248 // text must contain report() call. | 297 // text must contain report() call. |
249 eval(text); | 298 eval(text); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 assert_true(req.bodyUsed); | 414 assert_true(req.bodyUsed); |
366 }, 'Calling fetch() disturbs body if not null'); | 415 }, 'Calling fetch() disturbs body if not null'); |
367 | 416 |
368 test(t => { | 417 test(t => { |
369 var req = new Request('/', {method: 'POST'}); | 418 var req = new Request('/', {method: 'POST'}); |
370 fetch(req); | 419 fetch(req); |
371 assert_false(req.bodyUsed); | 420 assert_false(req.bodyUsed); |
372 }, 'Calling fetch() doesn\'t disturb body if null'); | 421 }, 'Calling fetch() doesn\'t disturb body if null'); |
373 | 422 |
374 done(); | 423 done(); |
OLD | NEW |