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 function consume(reader) { | 5 function consume(reader) { |
6 var chunks = []; | 6 var chunks = []; |
7 function rec(reader) { | 7 function rec(reader) { |
8 return reader.read().then(function(r) { | 8 return reader.read().then(function(r) { |
9 if (r.done) { | 9 if (r.done) { |
10 return chunks; | 10 return chunks; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 'Response.headers must not have Content-Type ' + | 110 'Response.headers must not have Content-Type ' + |
111 'for Blob with type = empty string (2)'); | 111 'for Blob with type = empty string (2)'); |
112 }, 'Response content type test'); | 112 }, 'Response content type test'); |
113 | 113 |
114 test(function() { | 114 test(function() { |
115 [0, 1, 100, 199, 600, 700].forEach(function(status) { | 115 [0, 1, 100, 199, 600, 700].forEach(function(status) { |
116 assert_throws({name: 'RangeError'}, | 116 assert_throws({name: 'RangeError'}, |
117 function() { | 117 function() { |
118 new Response(new Blob(), {status: status}); | 118 new Response(new Blob(), {status: status}); |
119 }, | 119 }, |
120 'new Response with status = ' + status + ' should throw'); | 120 'new Response with status = ' + status + |
121 'should throw'); | |
121 }); | 122 }); |
123 | |
124 [300, 0, 304, 305, 306, 309, 500].forEach(function(status) { | |
125 assert_throws({name: 'RangeError'}, | |
126 function() { | |
127 Response.redirect('https://www.example.com/test.html', | |
128 status); | |
129 }, | |
130 'Response.redirect() with invalid status = ' + status + | |
131 'should throw'); | |
132 }); | |
133 | |
134 assert_throws( | |
135 {name: 'TypeError'}, | |
136 function() { | |
137 Response.redirect('https://', 301); | |
138 }, | |
139 'Response.redirect() with invalid URL https://' + | |
140 'status as 301 should throw'); | |
hiroshige
2015/04/27 11:47:25
nit: ' and status 301 should throw'.
- space after
shiva.jm
2015/04/28 06:06:48
Done.
| |
141 | |
142 INVALID_URLS.forEach(function(url) { | |
143 assert_throws( | |
144 {name: 'TypeError'}, | |
145 function() { | |
146 Response.redirect(url); | |
147 }, | |
148 'Response.redirect() with invalid URL' + url + | |
hiroshige
2015/04/27 11:47:25
nit: 'Response.redirect() with invalid URL ' + url
shiva.jm
2015/04/28 06:06:48
Done.
| |
149 'default status value should throw'); | |
150 }); | |
151 | |
152 assert_throws( | |
153 {name: 'TypeError'}, | |
154 function() { | |
155 Response.redirect('https://', 300); | |
156 }, | |
157 'Response.redirect() with invalid URL https://' + | |
158 'invalid status 300 should throw'); | |
hiroshige
2015/04/27 11:47:25
nit: ' and invalid status 300 should throw TypeErr
shiva.jm
2015/04/28 06:06:48
Done.
| |
159 | |
122 [200, 300, 400, 500, 599].forEach(function(status) { | 160 [200, 300, 400, 500, 599].forEach(function(status) { |
123 var response = new Response(new Blob(), {status: status}); | 161 var response = new Response(new Blob(), {status: status}); |
124 assert_equals(response.status, status, 'Response.status should match'); | 162 assert_equals(response.status, status, 'Response.status should match'); |
125 if (200 <= status && status <= 299) | 163 if (200 <= status && status <= 299) |
126 assert_true(response.ok, 'Response.ok must be true for ' + status); | 164 assert_true(response.ok, 'Response.ok must be true for ' + status); |
127 else | 165 else |
128 assert_false(response.ok, 'Response.ok must be false for ' + status); | 166 assert_false(response.ok, 'Response.ok must be false for ' + status); |
129 }); | 167 }); |
130 | 168 |
131 INVALID_HEADER_NAMES.forEach(function(name) { | 169 INVALID_HEADER_NAMES.forEach(function(name) { |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 }).then(function(texts) { | 456 }).then(function(texts) { |
419 assert_equals(texts[0], ''); | 457 assert_equals(texts[0], ''); |
420 assert_equals(texts[1], ''); | 458 assert_equals(texts[1], ''); |
421 return res.body.getReader().read(); | 459 return res.body.getReader().read(); |
422 }).then(function(r) { | 460 }).then(function(r) { |
423 assert_true(r.done); | 461 assert_true(r.done); |
424 assert_equals(r.value, undefined); | 462 assert_equals(r.value, undefined); |
425 }); | 463 }); |
426 }, 'Read after text()'); | 464 }, 'Read after text()'); |
427 | 465 |
466 promise_test(function() { | |
467 var response = Response.redirect('https://www.example.com/test.html'); | |
468 return response.text().then(function(text) { | |
469 assert_equals(response.status, 302, | |
470 'default value of status is always 302'); | |
471 assert_equals(response.headers.get('location'), | |
472 'https://www.example.com/test.html', | |
473 'Location header should be correct absoulte URL'); | |
474 assert_throws({name: 'TypeError'}, | |
475 function() { | |
476 response.headers.append('Accept-Language', 'test'); | |
477 }, | |
478 'response.headers must throw since guard is immutable'); | |
479 }); | |
480 }, 'Response.redirect() with default status value'); | |
481 | |
482 promise_test(function() { | |
483 var response = Response.redirect('https://www.example.com/test.html', | |
484 301); | |
485 return response.text().then(function(text) { | |
486 assert_equals(response.status, 301, | |
487 'value of status is 301'); | |
488 assert_equals(response.headers.get('location'), | |
489 'https://www.example.com/test.html', | |
490 'Location header should be correct absoulte URL'); | |
491 }); | |
492 }, 'Response.redirect() with 301'); | |
493 | |
428 done(); | 494 done(); |
OLD | NEW |