| 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 self.internals.getInternalResponseURLList(response), |
| 35 ['data:,Foobar']); |
| 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:,Foobar', | 45 return fetch('data:,Foobar', |
| 41 { | 46 { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 56 }, 'fetch data: URL with the POST method'); | 61 }, 'fetch data: URL with the POST method'); |
| 57 | 62 |
| 58 promise_test(function(t) { | 63 promise_test(function(t) { |
| 59 return fetch('data:text/html;charset=utf-8;base64,5paH5a2X') | 64 return fetch('data:text/html;charset=utf-8;base64,5paH5a2X') |
| 60 .then(function(response) { | 65 .then(function(response) { |
| 61 assert_equals(response.status, 200); | 66 assert_equals(response.status, 200); |
| 62 assert_equals(response.statusText, 'OK'); | 67 assert_equals(response.statusText, 'OK'); |
| 63 assert_equals(response.headers.get('Content-Type'), | 68 assert_equals(response.headers.get('Content-Type'), |
| 64 'text/html;charset=utf-8'); | 69 'text/html;charset=utf-8'); |
| 65 assert_equals(size(response.headers), 1); | 70 assert_equals(size(response.headers), 1); |
| 71 if (self.internals) { |
| 72 assert_array_equals( |
| 73 self.internals.getInternalResponseURLList(response), |
| 74 ['data:text/html;charset=utf-8;base64,5paH5a2X']); |
| 75 } |
| 66 return response.text(); | 76 return response.text(); |
| 67 }) | 77 }) |
| 68 .then(function(text) { | 78 .then(function(text) { |
| 69 assert_equals(text, '\u6587\u5b57'); | 79 assert_equals(text, '\u6587\u5b57'); |
| 70 }); | 80 }); |
| 71 }, 'fetch data: URL with non-ASCII characters'); | 81 }, 'fetch data: URL with non-ASCII characters'); |
| 72 | 82 |
| 73 promise_test(function(t) { | 83 promise_test(function(t) { |
| 74 return fetch('data:text/html;base64,***') | 84 return fetch('data:text/html;base64,***') |
| 75 .then( | 85 .then( |
| 76 t.unreached_func('fetching invalid data: URL must fail'), | 86 t.unreached_func('fetching invalid data: URL must fail'), |
| 77 function() {}); | 87 function() {}); |
| 78 }, 'fetch invalid data: URL'); | 88 }, 'fetch invalid data: URL'); |
| 79 | 89 |
| 80 // Only [Exposed=(Window,DedicatedWorker,SharedWorker)]. | 90 // Only [Exposed=(Window,DedicatedWorker,SharedWorker)]. |
| 81 if ('createObjectURL' in URL) { | 91 if ('createObjectURL' in URL) { |
| 82 // Tests for blob: scheme. | 92 // Tests for blob: scheme. |
| 83 promise_test(function(t) { | 93 promise_test(function(t) { |
| 84 var url = URL.createObjectURL(new Blob(['fox'], {type: 'text/fox'})); | 94 var url = URL.createObjectURL(new Blob(['fox'], {type: 'text/fox'})); |
| 85 return fetch(url) | 95 return fetch(url) |
| 86 .then(function(response) { | 96 .then(function(response) { |
| 87 assert_equals(response.status, 200); | 97 assert_equals(response.status, 200); |
| 88 assert_equals(response.statusText, 'OK'); | 98 assert_equals(response.statusText, 'OK'); |
| 89 assert_equals(response.headers.get('Content-Type'), 'text/fox'); | 99 assert_equals(response.headers.get('Content-Type'), 'text/fox'); |
| 90 assert_equals(response.headers.get('Content-Length'), '3'); | 100 assert_equals(response.headers.get('Content-Length'), '3'); |
| 91 assert_equals(size(response.headers), 2); | 101 assert_equals(size(response.headers), 2); |
| 102 if (self.internals) { |
| 103 assert_array_equals( |
| 104 self.internals.getInternalResponseURLList(response), [url]); |
| 105 } |
| 92 return response.text(); | 106 return response.text(); |
| 93 }) | 107 }) |
| 94 .then(function(text) { | 108 .then(function(text) { |
| 95 assert_equals(text, 'fox'); | 109 assert_equals(text, 'fox'); |
| 96 }); | 110 }); |
| 97 }, 'fetch blob: URL'); | 111 }, 'fetch blob: URL'); |
| 98 | 112 |
| 99 promise_test(function(t) { | 113 promise_test(function(t) { |
| 100 var url = URL.createObjectURL(new Blob(['fox'], {type: 'text/fox'})); | 114 var url = URL.createObjectURL(new Blob(['fox'], {type: 'text/fox'})); |
| 101 return fetch(url + 'invalid') | 115 return fetch(url + 'invalid') |
| 102 .then( | 116 .then( |
| 103 t.unreached_func('fetching non-existent blob: URL must fail'), | 117 t.unreached_func('fetching non-existent blob: URL must fail'), |
| 104 function() {}); | 118 function() {}); |
| 105 }, 'fetch non-existent blob: URL'); | 119 }, 'fetch non-existent blob: URL'); |
| 106 } | 120 } |
| 107 | 121 |
| 108 // https://fetch.spec.whatwg.org/#concept-basic-fetch | 122 // https://fetch.spec.whatwg.org/#concept-basic-fetch |
| 109 // The last statement: | 123 // The last statement: |
| 110 // Otherwise | 124 // Otherwise |
| 111 // Return a network error. | 125 // Return a network error. |
| 112 promise_test(function(t) { | 126 promise_test(function(t) { |
| 113 return fetch('foobar://localhost/', {mode: 'no-cors'}) | 127 return fetch('foobar://localhost/', {mode: 'no-cors'}) |
| 114 .then( | 128 .then( |
| 115 t.unreached_func('scheme not listed in basic fetch spec must fail'), | 129 t.unreached_func('scheme not listed in basic fetch spec must fail'), |
| 116 function() {}); | 130 function() {}); |
| 117 }, 'fetch of scheme not listed in basic fetch spec'); | 131 }, 'fetch of scheme not listed in basic fetch spec'); |
| 118 | 132 |
| 119 promise_test(function(t) { | 133 promise_test(function(t) { |
| 120 return fetch('/fetch/resources/fetch-status.php?status=200') | 134 var request = new Request('/fetch/resources/fetch-status.php?status=200'); |
| 135 return fetch(request) |
| 121 .then(function(response) { | 136 .then(function(response) { |
| 122 assert_equals(response.status, 200); | 137 assert_equals(response.status, 200); |
| 123 assert_equals(response.statusText, 'OK'); | 138 assert_equals(response.statusText, 'OK'); |
| 139 if (self.internals) { |
| 140 assert_array_equals( |
| 141 self.internals.getInternalResponseURLList(response), |
| 142 [request.url]); |
| 143 } |
| 124 }); | 144 }); |
| 125 }, 'Fetch result of 200 response'); | 145 }, 'Fetch result of 200 response'); |
| 126 | 146 |
| 127 promise_test(function(t) { | 147 promise_test(function(t) { |
| 128 return fetch('/fetch/resources/fetch-status.php?status=404') | 148 var request = new Request('/fetch/resources/fetch-status.php?status=404'); |
| 149 return fetch(request) |
| 129 .then(function(response) { | 150 .then(function(response) { |
| 130 assert_equals(response.status, 404); | 151 assert_equals(response.status, 404); |
| 131 assert_equals(response.statusText, 'Not Found'); | 152 assert_equals(response.statusText, 'Not Found'); |
| 153 if (self.internals) { |
| 154 assert_array_equals( |
| 155 self.internals.getInternalResponseURLList(response), |
| 156 [request.url]); |
| 157 } |
| 132 }); | 158 }); |
| 133 }, 'Fetch result of 404 response'); | 159 }, 'Fetch result of 404 response'); |
| 134 | 160 |
| 135 promise_test(function(t) { | 161 promise_test(function(t) { |
| 136 var request = new Request( | 162 var request = new Request( |
| 137 '/fetch/resources/fetch-status.php?status=200#fragment'); | 163 '/fetch/resources/fetch-status.php?status=200#fragment'); |
| 138 | 164 |
| 139 // The url attribute's getter must return request's url, | 165 // The url attribute's getter must return request's url, |
| 140 // serialized with the exclude fragment flag set. | 166 // serialized with the exclude fragment flag set. |
| 141 assert_equals(request.url, | 167 assert_equals(request.url, |
| 142 BASE_ORIGIN + '/fetch/resources/fetch-status.php?status=200'); | 168 BASE_ORIGIN + '/fetch/resources/fetch-status.php?status=200'); |
| 143 | 169 |
| 144 return fetch(request) | 170 return fetch(request) |
| 145 .then(function(response) { | 171 .then(function(response) { |
| 146 assert_equals(response.status, 200); | 172 assert_equals(response.status, 200); |
| 147 assert_equals(response.statusText, 'OK'); | 173 assert_equals(response.statusText, 'OK'); |
| 148 // The url attribute's getter must return the empty string | 174 // The url attribute's getter must return the empty string |
| 149 // if response's url is null and response's url, | 175 // if response's url is null and response's url, |
| 150 // serialized with the exclude fragment flag set, otherwise. | 176 // serialized with the exclude fragment flag set, otherwise. |
| 151 assert_equals(response.url, | 177 assert_equals(response.url, |
| 152 BASE_ORIGIN + | 178 BASE_ORIGIN + '/fetch/resources/fetch-status.php?status=200'); |
| 153 '/fetch/resources/fetch-status.php?status=200'); | 179 if (self.internals) { |
| 180 assert_array_equals( |
| 181 self.internals.getInternalResponseURLList(response), |
| 182 [BASE_ORIGIN + |
| 183 '/fetch/resources/fetch-status.php?status=200#fragment']); |
| 184 } |
| 154 }); | 185 }); |
| 155 }, 'Request/response url attribute getter with fragment'); | 186 }, 'Request/response url attribute getter with fragment'); |
| 156 | 187 |
| 157 promise_test(function(t) { | 188 promise_test(function(t) { |
| 158 var redirect_target_url = | 189 var redirect_target_url = |
| 159 BASE_ORIGIN + '/fetch/resources/fetch-status.php?status=200'; | 190 BASE_ORIGIN + '/fetch/resources/fetch-status.php?status=200'; |
| 160 var redirect_original_url = | 191 var redirect_original_url = |
| 161 BASE_ORIGIN + '/serviceworker/resources/redirect.php?Redirect=' + | 192 BASE_ORIGIN + '/serviceworker/resources/redirect.php?Redirect=' + |
| 162 redirect_target_url; | 193 redirect_target_url; |
| 163 | 194 |
| 164 var request = new Request(redirect_original_url); | 195 var request = new Request(redirect_original_url); |
| 165 assert_equals(request.url, redirect_original_url, | 196 assert_equals(request.url, redirect_original_url, |
| 166 'Request\'s url is the original URL'); | 197 'Request\'s url is the original URL'); |
| 167 assert_equals(request.redirect, 'follow'); | 198 assert_equals(request.redirect, 'follow'); |
| 168 | 199 |
| 169 return fetch(request) | 200 return fetch(request) |
| 170 .then(function(response) { | 201 .then(function(response) { |
| 171 assert_equals(response.status, 200); | 202 assert_equals(response.status, 200); |
| 172 assert_equals(response.statusText, 'OK'); | 203 assert_equals(response.statusText, 'OK'); |
| 173 assert_equals(response.url, redirect_target_url, | 204 assert_equals(response.url, redirect_target_url, |
| 174 'Response\'s url is locationURL'); | 205 'Response\'s url is locationURL'); |
| 175 assert_equals(request.url, redirect_original_url, | 206 assert_equals(request.url, redirect_original_url, |
| 176 'Request\'s url remains the original URL'); | 207 'Request\'s url remains the original URL'); |
| 208 if (self.internals) { |
| 209 assert_array_equals( |
| 210 self.internals.getInternalResponseURLList(response), |
| 211 [request.url, response.url]); |
| 212 } |
| 177 }); | 213 }); |
| 178 }, 'Request/response url attribute getter with redirect'); | 214 }, 'Request/response url attribute getter with redirect'); |
| 179 | 215 |
| 180 promise_test(function(t) { | 216 promise_test(function(t) { |
| 181 var redirect_target_url = | 217 var redirect_target_url = |
| 182 BASE_ORIGIN + '/fetch/resources/fetch-status.php?status=200'; | 218 BASE_ORIGIN + '/fetch/resources/fetch-status.php?status=200'; |
| 183 var redirect_original_url = | 219 var redirect_original_url = |
| 184 BASE_ORIGIN + '/serviceworker/resources/redirect.php?Redirect=' + | 220 BASE_ORIGIN + '/serviceworker/resources/redirect.php?Redirect=' + |
| 185 redirect_target_url; | 221 redirect_target_url; |
| 186 | 222 |
| 187 var request = new Request(redirect_original_url, {redirect: 'manual'}); | 223 var request = new Request(redirect_original_url, {redirect: 'manual'}); |
| 188 assert_equals(request.url, redirect_original_url, | 224 assert_equals(request.url, redirect_original_url, |
| 189 'Request\'s url is the original URL'); | 225 'Request\'s url is the original URL'); |
| 190 assert_equals(request.redirect, 'manual'); | 226 assert_equals(request.redirect, 'manual'); |
| 191 | 227 |
| 192 return fetch(request) | 228 return fetch(request) |
| 193 .then(function(response) { | 229 .then(function(response) { |
| 194 assert_equals(response.status, 0); | 230 assert_equals(response.status, 0); |
| 195 assert_equals(response.type, 'opaqueredirect'); | 231 assert_equals(response.type, 'opaqueredirect'); |
| 196 assert_equals(response.url, request.url); | 232 assert_equals(response.url, request.url); |
| 233 if (self.internals) { |
| 234 assert_array_equals( |
| 235 self.internals.getInternalResponseURLList(response), |
| 236 [redirect_original_url]); |
| 237 } |
| 197 }); | 238 }); |
| 198 }, 'Manual redirect fetch returns opaque redirect response'); | 239 }, 'Manual redirect fetch returns opaque redirect response'); |
| 199 | 240 |
| 200 promise_test(function(t) { | 241 promise_test(function(t) { |
| 201 var redirect_target_url = | 242 var redirect_target_url = |
| 202 OTHER_ORIGIN + '/fetch/resources/fetch-status.php?status=200'; | 243 OTHER_ORIGIN + '/fetch/resources/fetch-status.php?status=200'; |
| 203 var redirect_original_url = | 244 var redirect_original_url = |
| 204 OTHER_ORIGIN + '/serviceworker/resources/redirect.php?Redirect=' + | 245 OTHER_ORIGIN + '/serviceworker/resources/redirect.php?Redirect=' + |
| 205 redirect_target_url; | 246 redirect_target_url; |
| 206 | 247 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 237 function() {}); | 278 function() {}); |
| 238 }, 'Redirect response must cause an error when redirect mode is error.'); | 279 }, 'Redirect response must cause an error when redirect mode is error.'); |
| 239 | 280 |
| 240 promise_test(function(test) { | 281 promise_test(function(test) { |
| 241 var url = BASE_ORIGIN + '/fetch/resources/doctype.html'; | 282 var url = BASE_ORIGIN + '/fetch/resources/doctype.html'; |
| 242 return fetch(new Request(url, {redirect: 'manual'})) | 283 return fetch(new Request(url, {redirect: 'manual'})) |
| 243 .then(function(response) { | 284 .then(function(response) { |
| 244 assert_equals(response.status, 200); | 285 assert_equals(response.status, 200); |
| 245 assert_equals(response.statusText, 'OK'); | 286 assert_equals(response.statusText, 'OK'); |
| 246 assert_equals(response.url, url); | 287 assert_equals(response.url, url); |
| 288 if (self.internals) { |
| 289 assert_array_equals( |
| 290 self.internals.getInternalResponseURLList(response), [url]); |
| 291 } |
| 247 return response.text(); | 292 return response.text(); |
| 248 }) | 293 }) |
| 249 .then(function(text) { assert_equals(text, '<!DOCTYPE html>\n'); }) | 294 .then(function(text) { assert_equals(text, '<!DOCTYPE html>\n'); }) |
| 250 }, 'No-redirect fetch completes normally even if redirect mode is manual'); | 295 }, 'No-redirect fetch completes normally even if redirect mode is manual'); |
| 251 | 296 |
| 252 promise_test(function(test) { | 297 promise_test(function(test) { |
| 253 var url = BASE_ORIGIN + '/fetch/resources/doctype.html'; | 298 var url = BASE_ORIGIN + '/fetch/resources/doctype.html'; |
| 254 return fetch(new Request(url, {redirect: 'error'})) | 299 return fetch(new Request(url, {redirect: 'error'})) |
| 255 .then(function(response) { | 300 .then(function(response) { |
| 256 assert_equals(response.status, 200); | 301 assert_equals(response.status, 200); |
| 257 assert_equals(response.statusText, 'OK'); | 302 assert_equals(response.statusText, 'OK'); |
| 258 assert_equals(response.url, url); | 303 assert_equals(response.url, url); |
| 304 if (self.internals) { |
| 305 assert_array_equals( |
| 306 self.internals.getInternalResponseURLList(response), [url]); |
| 307 } |
| 259 return response.text(); | 308 return response.text(); |
| 260 }) | 309 }) |
| 261 .then(function(text) { assert_equals(text, '<!DOCTYPE html>\n'); }) | 310 .then(function(text) { assert_equals(text, '<!DOCTYPE html>\n'); }) |
| 262 }, 'No-redirect fetch completes normally even if redirect mode is error'); | 311 }, 'No-redirect fetch completes normally even if redirect mode is error'); |
| 263 | 312 |
| 264 function evalJsonp(text) { | 313 function evalJsonp(text) { |
| 265 return new Promise(function(resolve) { | 314 return new Promise(function(resolve) { |
| 266 var report = resolve; | 315 var report = resolve; |
| 267 // text must contain report() call. | 316 // text must contain report() call. |
| 268 eval(text); | 317 eval(text); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 assert_true(req.bodyUsed); | 433 assert_true(req.bodyUsed); |
| 385 }, 'Calling fetch() disturbs body if not null'); | 434 }, 'Calling fetch() disturbs body if not null'); |
| 386 | 435 |
| 387 test(t => { | 436 test(t => { |
| 388 var req = new Request('/', {method: 'POST'}); | 437 var req = new Request('/', {method: 'POST'}); |
| 389 fetch(req); | 438 fetch(req); |
| 390 assert_false(req.bodyUsed); | 439 assert_false(req.bodyUsed); |
| 391 }, 'Calling fetch() doesn\'t disturb body if null'); | 440 }, 'Calling fetch() doesn\'t disturb body if null'); |
| 392 | 441 |
| 393 done(); | 442 done(); |
| OLD | NEW |