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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/http/tests/fetch/script-tests/response.js
diff --git a/LayoutTests/http/tests/fetch/script-tests/response.js b/LayoutTests/http/tests/fetch/script-tests/response.js
index 46dde766908b3a85a8c2428812c88695792c76b0..4710ec174b393eab25a44ffb9262244f1a617a57 100644
--- a/LayoutTests/http/tests/fetch/script-tests/response.js
+++ b/LayoutTests/http/tests/fetch/script-tests/response.js
@@ -117,8 +117,46 @@ test(function() {
function() {
new Response(new Blob(), {status: status});
},
- 'new Response with status = ' + status + ' should throw');
+ 'new Response with status = ' + status +
+ 'should throw');
});
+
+ [300, 0, 304, 305, 306, 309, 500].forEach(function(status) {
+ assert_throws({name: 'RangeError'},
+ function() {
+ Response.redirect('https://www.example.com/test.html',
+ status);
+ },
+ 'Response.redirect() with invalid status = ' + status +
+ 'should throw');
+ });
+
+ assert_throws(
+ {name: 'TypeError'},
+ function() {
+ Response.redirect('https://', 301);
+ },
+ 'Response.redirect() with invalid URL https://' +
+ '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.
+
+ INVALID_URLS.forEach(function(url) {
+ assert_throws(
+ {name: 'TypeError'},
+ function() {
+ Response.redirect(url);
+ },
+ '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.
+ 'default status value should throw');
+ });
+
+ assert_throws(
+ {name: 'TypeError'},
+ function() {
+ Response.redirect('https://', 300);
+ },
+ 'Response.redirect() with invalid URL https://' +
+ '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.
+
[200, 300, 400, 500, 599].forEach(function(status) {
var response = new Response(new Blob(), {status: status});
assert_equals(response.status, status, 'Response.status should match');
@@ -425,4 +463,32 @@ promise_test(function(t) {
});
}, 'Read after text()');
+promise_test(function() {
+ var response = Response.redirect('https://www.example.com/test.html');
+ return response.text().then(function(text) {
+ assert_equals(response.status, 302,
+ 'default value of status is always 302');
+ assert_equals(response.headers.get('location'),
+ 'https://www.example.com/test.html',
+ 'Location header should be correct absoulte URL');
+ assert_throws({name: 'TypeError'},
+ function() {
+ response.headers.append('Accept-Language', 'test');
+ },
+ 'response.headers must throw since guard is immutable');
+ });
+ }, 'Response.redirect() with default status value');
+
+promise_test(function() {
+ var response = Response.redirect('https://www.example.com/test.html',
+ 301);
+ return response.text().then(function(text) {
+ assert_equals(response.status, 301,
+ 'value of status is 301');
+ assert_equals(response.headers.get('location'),
+ 'https://www.example.com/test.html',
+ 'Location header should be correct absoulte URL');
+ });
+ }, 'Response.redirect() with 301');
+
done();

Powered by Google App Engine
This is Rietveld 408576698