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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/fetch/api/redirect/redirect-location.js

Issue 2785123002: Make no-location redirect response to be "opaque redirect" when redirect mode is manual. (Closed)
Patch Set: add link to crbug.com/707185 Created 3 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 (this.document === undefined) { 1 if (this.document === undefined) {
2 importScripts("/resources/testharness.js"); 2 importScripts("/resources/testharness.js");
3 importScripts("../resources/utils.js"); 3 importScripts("../resources/utils.js");
4 } 4 }
5 5
6 function redirectLocation(desc, redirectUrl, redirectLocation, redirectStatus, r edirectMode, shouldPass) { 6 function redirectLocation(desc, redirectUrl, redirectLocation, redirectStatus, r edirectMode, shouldPass) {
7 var url = redirectUrl; 7 var url = redirectUrl;
8 var urlParameters = "?redirect_status=" + redirectStatus; 8 var urlParameters = "?redirect_status=" + redirectStatus;
9 if (redirectLocation) 9 if (redirectLocation)
10 urlParameters += "&location=" + encodeURIComponent(redirectLocation); 10 urlParameters += "&location=" + encodeURIComponent(redirectLocation);
11 11
12 var requestInit = {"redirect": redirectMode}; 12 var requestInit = {"redirect": redirectMode};
13 13
14 promise_test(function(test) { 14 promise_test(function(test) {
15 if (redirectMode === "error" || !shouldPass) 15 if (redirectMode === "error" || !shouldPass)
16 return promise_rejects(test, new TypeError(), fetch(url + urlParameters, r equestInit)); 16 return promise_rejects(test, new TypeError(), fetch(url + urlParameters, r equestInit));
17 if (redirectLocation && redirectMode === "manual") 17 if (redirectMode === "manual")
18 return fetch(url + urlParameters, requestInit).then(function(resp) { 18 return fetch(url + urlParameters, requestInit).then(function(resp) {
19 assert_equals(resp.status, 0, "Response's status is 0"); 19 assert_equals(resp.status, 0, "Response's status is 0");
20 assert_equals(resp.type, "opaqueredirect", "Response's type is opaquered irect"); 20 assert_equals(resp.type, "opaqueredirect", "Response's type is opaquered irect");
21 assert_equals(resp.statusText, "", "Response's statusText is \"\""); 21 assert_equals(resp.statusText, "", "Response's statusText is \"\"");
22 assert_true(resp.headers.entries().next().done, "Headers should be empty "); 22 assert_true(resp.headers.entries().next().done, "Headers should be empty ");
23 }); 23 });
24 24
25 if (redirectMode === "manual" || redirectMode === "follow") 25 if (redirectMode === "follow")
26 return fetch(url + urlParameters, requestInit).then(function(resp) { 26 return fetch(url + urlParameters, requestInit).then(function(resp) {
27 assert_equals(resp.status, redirectStatus, "Response's status is " + red irectStatus); 27 assert_equals(resp.status, redirectStatus, "Response's status is " + red irectStatus);
28 }); 28 });
29 assert_unreached(redirectMode + " is not a valid redirect mode"); 29 assert_unreached(redirectMode + " is not a valid redirect mode");
30 }, desc); 30 }, desc);
31 } 31 }
32 32
33 var redirUrl = RESOURCES_DIR + "redirect.py"; 33 var redirUrl = RESOURCES_DIR + "redirect.py";
34 var locationUrl = "top.txt"; 34 var locationUrl = "top.txt";
35 var invalidLocationUrl = "#invalidurl:"; 35 var invalidLocationUrl = "#invalidurl:";
36 var dataLocationUrl = "data:,data%20url"; 36 var dataLocationUrl = "data:,data%20url";
37 // FIXME: We may want to mix redirect-mode and cors-mode. 37 // FIXME: We may want to mix redirect-mode and cors-mode.
38 // FIXME: Add tests for "error" redirect-mode. 38 // FIXME: Add tests for "error" redirect-mode.
39 for (var statusCode of [301, 302, 303, 307, 308]) { 39 for (var statusCode of [301, 302, 303, 307, 308]) {
40 redirectLocation("Redirect " + statusCode + " in \"follow\" mode without locat ion", redirUrl, undefined, statusCode, "follow", true); 40 redirectLocation("Redirect " + statusCode + " in \"follow\" mode without locat ion", redirUrl, undefined, statusCode, "follow", true);
41 redirectLocation("Redirect " + statusCode + " in \"manual\" mode without locat ion", redirUrl, undefined, statusCode, "manual", true); 41 redirectLocation("Redirect " + statusCode + " in \"manual\" mode without locat ion", redirUrl, undefined, statusCode, "manual", true);
42 42
43 redirectLocation("Redirect " + statusCode + " in \"follow\" mode with invalid location", redirUrl, invalidLocationUrl, statusCode, "follow", false); 43 redirectLocation("Redirect " + statusCode + " in \"follow\" mode with invalid location", redirUrl, invalidLocationUrl, statusCode, "follow", false);
44 redirectLocation("Redirect " + statusCode + " in \"manual\" mode with invalid location", redirUrl, invalidLocationUrl, statusCode, "manual", true); 44 redirectLocation("Redirect " + statusCode + " in \"manual\" mode with invalid location", redirUrl, invalidLocationUrl, statusCode, "manual", true);
45 45
46 redirectLocation("Redirect " + statusCode + " in \"follow\" mode with data loc ation", redirUrl, dataLocationUrl, statusCode, "follow", false); 46 redirectLocation("Redirect " + statusCode + " in \"follow\" mode with data loc ation", redirUrl, dataLocationUrl, statusCode, "follow", false);
47 redirectLocation("Redirect " + statusCode + " in \"manual\" mode with data loc ation", redirUrl, dataLocationUrl, statusCode, "manual", true); 47 redirectLocation("Redirect " + statusCode + " in \"manual\" mode with data loc ation", redirUrl, dataLocationUrl, statusCode, "manual", true);
48 } 48 }
49 49
50 done(); 50 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698