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

Unified Diff: third_party/WebKit/LayoutTests/external/wpt/fetch/api/redirect/redirect-count.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-count.js
diff --git a/third_party/WebKit/LayoutTests/external/wpt/fetch/api/redirect/redirect-count.js b/third_party/WebKit/LayoutTests/external/wpt/fetch/api/redirect/redirect-count.js
new file mode 100644
index 0000000000000000000000000000000000000000..0103280f6e2319f2dd4cccf1834b9d815130db40
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/fetch/api/redirect/redirect-count.js
@@ -0,0 +1,43 @@
+if (this.document === undefined) {
+ importScripts("/resources/testharness.js");
+ importScripts("../resources/utils.js");
+ importScripts("/common/utils.js");
+}
+
+function redirectCount(desc, redirectUrl, redirectLocation, redirectStatus, maxCount, shouldPass) {
+ var uuid_token = token();
+
+ var urlParameters = "?token=" + uuid_token + "&max_age=0";
+ urlParameters += "&redirect_status=" + redirectStatus;
+ urlParameters += "&max_count=" + maxCount;
+ if (redirectLocation)
+ urlParameters += "&location=" + encodeURIComponent(redirectLocation);
+
+ var url = redirectUrl;
+ var requestInit = {"redirect": "follow"};
+
+ promise_test(function(test) {
+ return fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(function(resp) {
+ assert_equals(resp.status, 200, "Clean stash response's status is 200");
+
+ if (!shouldPass)
+ return promise_rejects(test, new TypeError(), fetch(url + urlParameters, requestInit));
+
+ return fetch(url + urlParameters, requestInit).then(function(resp) {
+ assert_equals(resp.status, 200, "Response's status is 200");
+ return resp.text();
+ }).then(function(body) {
+ assert_equals(body, maxCount.toString(), "Redirected " + maxCount + " times");
+ });
+ });
+ }, desc);
+}
+
+var redirUrl = RESOURCES_DIR + "redirect.py";
+
+for (var statusCode of [301, 302, 303, 307, 308]) {
+ redirectCount("Redirect " + statusCode + " 20 times", redirUrl, redirUrl, statusCode, 20, true);
+ redirectCount("Redirect " + statusCode + " 21 times", redirUrl, redirUrl, statusCode, 21, false);
+}
+
+done();

Powered by Google App Engine
This is Rietveld 408576698