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

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

Issue 2778753002: Import //fetch from Web Platform Tests. (Closed)
Patch Set: Baselines. 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
(Empty)
1 if (this.document === undefined) {
2 importScripts("/resources/testharness.js");
3 importScripts("/common/get-host-info.sub.js")
4 }
5
6 function redirectMode(desc, redirectUrl, redirectLocation, redirectStatus, redir ectMode) {
7 var url = redirectUrl;
8 var urlParameters = "?redirect_status=" + redirectStatus;
9 urlParameters += "&location=" + encodeURIComponent(redirectLocation);
10
11 var requestInit = {"redirect": redirectMode};
12
13 promise_test(function(test) {
14 if (redirectMode === "error")
15 return promise_rejects(test, new TypeError(), fetch(url + urlParameters, r equestInit));
16 if (redirectMode === "manual")
17 return fetch(url + urlParameters, requestInit).then(function(resp) {
18 assert_equals(resp.status, 0, "Response's status is 0");
19 assert_equals(resp.type, "opaqueredirect", "Response's type is opaquered irect");
20 assert_equals(resp.statusText, "", "Response's statusText is \"\"");
21 assert_equals(resp.url, url + urlParameters, "Response URL should be the original one");
22 });
23 if (redirectMode === "follow")
24 return fetch(url + urlParameters, requestInit).then(function(resp) {
25 assert_true(new URL(resp.url).pathname.endsWith(locationUrl), "Response' s url should be the redirected one");
26 assert_equals(resp.status, 200, "Response's status is 200");
27 });
28 assert_unreached(redirectMode + " is no a valid redirect mode");
29 }, desc);
30 }
31
32 var redirUrl = get_host_info().HTTP_ORIGIN + "/fetch/api/resources/redirect.py";
33 var locationUrl = "top.txt";
34
35 for (var statusCode of [301, 302, 303, 307, 308]) {
36 redirectMode("Redirect " + statusCode + " in \"error\" mode ", redirUrl, locat ionUrl, statusCode, "error");
37 redirectMode("Redirect " + statusCode + " in \"follow\" mode ", redirUrl, loca tionUrl, statusCode, "follow");
38 redirectMode("Redirect " + statusCode + " in \"manual\" mode ", redirUrl, loca tionUrl, statusCode, "manual");
39 }
40
41 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698