Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Side by Side Diff: LayoutTests/http/tests/fetch/script-tests/response.js

Issue 1098473003: Implement redirect() API for Fetch Response (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 + ' should throw');
121 }); 121 });
122
123 [300, 0, 304, 305, 306, 309, 500].forEach(function(status) {
124 assert_throws({name: 'RangeError'},
125 function() {
126 Response.redirect('https://www.example.com/test.html',
127 status);
128 },
129 'new Response with status code (' + status +
tyoshino (SeeGerritForStatus) 2015/04/20 04:50:00 use the same text as L120 or update the line, too.
shiva.jm 2015/04/27 10:50:54 Done. changed both line to wrap to 80 columns.
130 ') should throw');
131 });
132
133 assert_throws(
134 {name: 'TypeError'},
135 function() {
hiroshige 2015/04/20 07:53:53 -1 indent (L135, L136, L142, L143).
shiva.jm 2015/04/27 10:50:54 Done.
136 Response.redirect('https://', 301);
137 },
138 'new Response with invalid URL http:// should throw');
hiroshige 2015/04/20 07:53:52 The message (http://) and the test code (https://)
shiva.jm 2015/04/27 10:50:54 Done.
139
hiroshige 2015/04/20 07:53:52 Could you add a test with invalid URL and invalid
shiva.jm 2015/04/27 10:50:54 Done.
140 assert_throws(
141 {name: 'TypeError'},
142 function() {
143 Response.redirect('https://');
144 },
145 'new Response with invalid URL http:// should throw');
hiroshige 2015/04/20 07:53:53 Could you add tests of invalid URLs that contains
shiva.jm 2015/04/27 10:50:54 Done.
146
122 [200, 300, 400, 500, 599].forEach(function(status) { 147 [200, 300, 400, 500, 599].forEach(function(status) {
123 var response = new Response(new Blob(), {status: status}); 148 var response = new Response(new Blob(), {status: status});
124 assert_equals(response.status, status, 'Response.status should match'); 149 assert_equals(response.status, status, 'Response.status should match');
125 if (200 <= status && status <= 299) 150 if (200 <= status && status <= 299)
126 assert_true(response.ok, 'Response.ok must be true for ' + status); 151 assert_true(response.ok, 'Response.ok must be true for ' + status);
127 else 152 else
128 assert_false(response.ok, 'Response.ok must be false for ' + status); 153 assert_false(response.ok, 'Response.ok must be false for ' + status);
129 }); 154 });
130 155
131 INVALID_HEADER_NAMES.forEach(function(name) { 156 INVALID_HEADER_NAMES.forEach(function(name) {
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 }).then(function(texts) { 443 }).then(function(texts) {
419 assert_equals(texts[0], ''); 444 assert_equals(texts[0], '');
420 assert_equals(texts[1], ''); 445 assert_equals(texts[1], '');
421 return res.body.getReader().read(); 446 return res.body.getReader().read();
422 }).then(function(r) { 447 }).then(function(r) {
423 assert_true(r.done); 448 assert_true(r.done);
424 assert_equals(r.value, undefined); 449 assert_equals(r.value, undefined);
425 }); 450 });
426 }, 'Read after text()'); 451 }, 'Read after text()');
427 452
453 promise_test(function() {
454 var response = Response.redirect('https://www.example.com/test.html');
455 return response.text().then(function(text) {
456 assert_equals(response.status, 302,
457 'default value of status is always 302');
458 assert_equals(response.headers.get('location'),
459 'https://www.example.com/test.html',
460 'Location header should be correct absoulte URL');
hiroshige 2015/04/20 07:53:53 Could you add assertion that response.headers has
shiva.jm 2015/04/27 10:50:54 Done.
hiroshige 2015/04/27 11:47:25 Not added? e.g. assert_equals(size(respons
461 });
462 }, 'Response.redirect() with default value');
463
464 promise_test(function() {
465 var response = Response.redirect('https://www.example.com/test.html',
466 301);
467 return response.text().then(function(text) {
468 assert_equals(response.status, 301,
469 'value of status is 301');
470 assert_equals(response.headers.get('location'),
471 'https://www.example.com/test.html',
472 'Location header should be correct absoulte URL');
473 });
474 }, 'Response.redirect()');
hiroshige 2015/04/20 07:53:52 optional: How about 'Response.redirect() with 301'
shiva.jm 2015/04/27 10:50:54 Done.
475
428 done(); 476 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698