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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/fetch/api/cors/cors-preflight-star.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/get-host-info.sub.js");
5 }
6
7 const url = get_host_info().HTTP_REMOTE_ORIGIN + dirname(location.pathname) + RE SOURCES_DIR + "preflight.py",
8 origin = location.origin // assuming an ASCII origin
9
10 function preflightTest(succeeds, withCredentials, allowMethod, allowHeader, useM ethod, useHeader) {
11 return promise_test(t => {
12 let testURL = url + "?",
13 requestInit = {}
14 if (withCredentials) {
15 testURL += "origin=" + origin + "&"
16 testURL += "credentials&"
17 requestInit.credentials = "include"
18 }
19 if (useMethod) {
20 requestInit.method = useMethod
21 }
22 if (useHeader) {
23 requestInit.headers = [useHeader]
24 }
25 testURL += "allow_methods=" + allowMethod + "&"
26 testURL += "allow_headers=" + allowHeader + "&"
27
28 if (succeeds) {
29 return fetch(testURL, requestInit).then(resp => {
30 assert_equals(resp.headers.get("x-origin"), origin)
31 })
32 } else {
33 return promise_rejects(t, new TypeError(), fetch(testURL, requestInit))
34 }
35 }, "CORS that " + (succeeds ? "succeeds" : "fails") + " with credentials: " + withCredentials + "; method: " + useMethod + " (allowed: " + allowMethod + "); h eader: " + useHeader + " (allowed: " + allowHeader + ")")
36 }
37
38 preflightTest(true, false, "get", "x-test", "GET", ["X-Test", "1"])
39 preflightTest(true, false, "*", "x-test", "SUPER", ["X-Test", "1"])
40 preflightTest(true, false, "*", "*", "OK", ["X-Test", "1"])
41 preflightTest(false, true, "*", "*", "OK", ["X-Test", "1"])
42 preflightTest(false, true, "*", "", "PUT", undefined)
43 preflightTest(false, true, "put", "*", "PUT", undefined)
44 preflightTest(false, true, "get", "*", "GET", ["X-Test", "1"])
45 preflightTest(false, true, "*", "*", "GET", ["X-Test", "1"])
46
47 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698