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

Side by Side 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, 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("../resources/utils.js");
4 importScripts("/common/utils.js");
5 }
6
7 function redirectCount(desc, redirectUrl, redirectLocation, redirectStatus, maxC ount, shouldPass) {
8 var uuid_token = token();
9
10 var urlParameters = "?token=" + uuid_token + "&max_age=0";
11 urlParameters += "&redirect_status=" + redirectStatus;
12 urlParameters += "&max_count=" + maxCount;
13 if (redirectLocation)
14 urlParameters += "&location=" + encodeURIComponent(redirectLocation);
15
16 var url = redirectUrl;
17 var requestInit = {"redirect": "follow"};
18
19 promise_test(function(test) {
20 return fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(func tion(resp) {
21 assert_equals(resp.status, 200, "Clean stash response's status is 200");
22
23 if (!shouldPass)
24 return promise_rejects(test, new TypeError(), fetch(url + urlParameters, requestInit));
25
26 return fetch(url + urlParameters, requestInit).then(function(resp) {
27 assert_equals(resp.status, 200, "Response's status is 200");
28 return resp.text();
29 }).then(function(body) {
30 assert_equals(body, maxCount.toString(), "Redirected " + maxCount + " ti mes");
31 });
32 });
33 }, desc);
34 }
35
36 var redirUrl = RESOURCES_DIR + "redirect.py";
37
38 for (var statusCode of [301, 302, 303, 307, 308]) {
39 redirectCount("Redirect " + statusCode + " 20 times", redirUrl, redirUrl, stat usCode, 20, true);
40 redirectCount("Redirect " + statusCode + " 21 times", redirUrl, redirUrl, stat usCode, 21, false);
41 }
42
43 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698