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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/fetch/api/cors/cors-preflight-referrer.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/utils.js");
4 importScripts("/common/get-host-info.sub.js");
5 importScripts("../resources/utils.js");
6 }
7
8 function corsPreflightReferrer(desc, corsUrl, referrerPolicy, referrer, expected Referrer) {
9 var uuid_token = token();
10 var url = corsUrl;
11 var urlParameters = "?token=" + uuid_token + "&max_age=0";
12 var requestInit = {"mode": "cors", "referrerPolicy": referrerPolicy};
13
14 if (referrer)
15 requestInit.referrer = referrer;
16
17 /* Force preflight */
18 requestInit["headers"] = {"x-force-preflight": ""};
19 urlParameters += "&allow_headers=x-force-preflight";
20
21 promise_test(function(test) {
22 return fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(func tion(resp) {
23 assert_equals(resp.status, 200, "Clean stash response's status is 200");
24 return fetch(url + urlParameters, requestInit).then(function(resp) {
25 assert_equals(resp.status, 200, "Response's status is 200");
26 assert_equals(resp.headers.get("x-did-preflight"), "1", "Preflight reque st has been made");
27 assert_equals(resp.headers.get("x-preflight-referrer"), expectedReferrer , "Preflight's referrer is correct");
28 assert_equals(resp.headers.get("x-referrer"), expectedReferrer, "Request 's referrer is correct");
29 assert_equals(resp.headers.get("x-control-request-headers"), "", "Access -Control-Allow-Headers value");
30 });
31 });
32 }, desc + " and referrer: " + (referrer ? "'" + referrer + "'" : "default"));
33 }
34
35 var corsUrl = get_host_info().HTTP_REMOTE_ORIGIN + dirname(location.pathname) + RESOURCES_DIR + "preflight.py";
36 var origin = get_host_info().HTTP_ORIGIN + "/";
37
38 corsPreflightReferrer("Referrer policy: no-referrer", corsUrl, "no-referrer", un defined, "");
39 corsPreflightReferrer("Referrer policy: no-referrer", corsUrl, "no-referrer", "m yreferrer", "");
40
41 corsPreflightReferrer("Referrer policy: \"\"", corsUrl, "", undefined, location. toString())
42 corsPreflightReferrer("Referrer policy: \"\"", corsUrl, "", "myreferrer", new UR L("myreferrer", location).toString());
43
44 corsPreflightReferrer("Referrer policy: origin", corsUrl, "origin", undefined, o rigin);
45 corsPreflightReferrer("Referrer policy: origin", corsUrl, "origin", "myreferrer" , origin);
46
47 corsPreflightReferrer("Referrer policy: origin-when-cross-origin", corsUrl, "ori gin-when-cross-origin", undefined, origin);
48 corsPreflightReferrer("Referrer policy: origin-when-cross-origin", corsUrl, "ori gin-when-cross-origin", "myreferrer", origin);
49
50 corsPreflightReferrer("Referrer policy: unsafe-url", corsUrl, "unsafe-url", unde fined, location.toString());
51 corsPreflightReferrer("Referrer policy: unsafe-url", corsUrl, "unsafe-url", "myr eferrer", new URL("myreferrer", location).toString());
52
53 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698