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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/fetch/api/credentials/cookies.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 }
5
6 function cookies(desc, credentials1, credentials2 ,cookies) {
7 var url = RESOURCES_DIR + "top.txt"
8 var urlParameters = "";
9 var urlCleanParameters = "";
10 if (cookies) {
11 urlParameters +="?pipe=header(Set-Cookie,";
12 urlParameters += cookies.join(",True)|header(Set-Cookie,") + ",True)";
13 urlCleanParameters +="?pipe=header(Set-Cookie,";
14 urlCleanParameters += cookies.join("%3B%20max-age=0,True)|header(Set-Cookie ,") + "%3B%20max-age=0,True)";
15 }
16
17 var requestInit = {"credentials": credentials1}
18 promise_test(function(test){
19 var requestInit = {"credentials": credentials1}
20 return fetch(url + urlParameters, requestInit).then(function(resp) {
21 assert_equals(resp.status, 200, "HTTP status is 200");
22 assert_equals(resp.type , "basic", "Response's type is basic");
23 //check cookies sent
24 return fetch(RESOURCES_DIR + "inspect-headers.py?headers=cookie" , {"crede ntials": credentials2});
25 }).then(function(resp) {
26 assert_equals(resp.status, 200, "HTTP status is 200");
27 assert_equals(resp.type , "basic", "Response's type is basic");
28 assert_false(resp.headers.has("Cookie") , "Cookie header is not exposed in response");
29 if (credentials1 != "omit" && credentials2 != "omit") {
30 assert_equals(resp.headers.get("x-request-cookie") , cookies.join("; "), "Request include cookie(s)");
31 }
32 else {
33 assert_false(resp.headers.has("x-request-cookie") , "Request does not ha ve cookie(s)");
34 }
35 //clean cookies
36 return fetch(url + urlCleanParameters, {"credentials": "include"});
37 }).catch(function(e) {
38 return fetch(url + urlCleanParameters, {"credentials": "include"}).then(fu nction() {
39 return Promise.reject(e);
40 });
41 });
42 }, desc);
43 }
44
45 cookies("Include mode: 1 cookie", "include", "include", ["a=1"]);
46 cookies("Include mode: 2 cookies", "include", "include", ["b=2", "c=3"]);
47 cookies("Omit mode: discard cookies", "omit", "omit", ["d=4"]);
48 cookies("Omit mode: no cookie is stored", "omit", "include", ["e=5"]);
49 cookies("Omit mode: no cookie is sent", "include", "omit", ["f=6"]);
50 cookies("Same-origin mode: 1 cookie", "same-origin", "same-origin", ["a=1"]);
51 cookies("Same-origin mode: 2 cookies", "same-origin", "same-origin", ["b=2", "c= 3"]);
52
53 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698