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

Unified 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, 9 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: third_party/WebKit/LayoutTests/external/wpt/fetch/api/redirect/redirect-mode.js
diff --git a/third_party/WebKit/LayoutTests/external/wpt/fetch/api/redirect/redirect-mode.js b/third_party/WebKit/LayoutTests/external/wpt/fetch/api/redirect/redirect-mode.js
new file mode 100644
index 0000000000000000000000000000000000000000..b59a8d57b0df7bacb12f2e13e4337e3c5d469e4b
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/fetch/api/redirect/redirect-mode.js
@@ -0,0 +1,41 @@
+if (this.document === undefined) {
+ importScripts("/resources/testharness.js");
+ importScripts("/common/get-host-info.sub.js")
+}
+
+function redirectMode(desc, redirectUrl, redirectLocation, redirectStatus, redirectMode) {
+ var url = redirectUrl;
+ var urlParameters = "?redirect_status=" + redirectStatus;
+ urlParameters += "&location=" + encodeURIComponent(redirectLocation);
+
+ var requestInit = {"redirect": redirectMode};
+
+ promise_test(function(test) {
+ if (redirectMode === "error")
+ return promise_rejects(test, new TypeError(), fetch(url + urlParameters, requestInit));
+ if (redirectMode === "manual")
+ return fetch(url + urlParameters, requestInit).then(function(resp) {
+ assert_equals(resp.status, 0, "Response's status is 0");
+ assert_equals(resp.type, "opaqueredirect", "Response's type is opaqueredirect");
+ assert_equals(resp.statusText, "", "Response's statusText is \"\"");
+ assert_equals(resp.url, url + urlParameters, "Response URL should be the original one");
+ });
+ if (redirectMode === "follow")
+ return fetch(url + urlParameters, requestInit).then(function(resp) {
+ assert_true(new URL(resp.url).pathname.endsWith(locationUrl), "Response's url should be the redirected one");
+ assert_equals(resp.status, 200, "Response's status is 200");
+ });
+ assert_unreached(redirectMode + " is no a valid redirect mode");
+ }, desc);
+}
+
+var redirUrl = get_host_info().HTTP_ORIGIN + "/fetch/api/resources/redirect.py";
+var locationUrl = "top.txt";
+
+for (var statusCode of [301, 302, 303, 307, 308]) {
+ redirectMode("Redirect " + statusCode + " in \"error\" mode ", redirUrl, locationUrl, statusCode, "error");
+ redirectMode("Redirect " + statusCode + " in \"follow\" mode ", redirUrl, locationUrl, statusCode, "follow");
+ redirectMode("Redirect " + statusCode + " in \"manual\" mode ", redirUrl, locationUrl, statusCode, "manual");
+}
+
+done();

Powered by Google App Engine
This is Rietveld 408576698