Added: branches/safari-605-branch/LayoutTests/http/wpt/service-workers/cors-preflight-star.any.js (0 => 228363)
--- branches/safari-605-branch/LayoutTests/http/wpt/service-workers/cors-preflight-star.any.js (rev 0)
+++ branches/safari-605-branch/LayoutTests/http/wpt/service-workers/cors-preflight-star.any.js 2018-02-10 06:25:46 UTC (rev 228363)
@@ -0,0 +1,44 @@
+// META: script=/fetch/api/resources/utils.js
+// META: script=/common/get-host-info.sub.js
+
+const url = "" + dirname(location.pathname) + RESOURCES_DIR + "preflight.py",
+ origin = location.origin // assuming an ASCII origin
+
+function preflightTest(succeeds, withCredentials, allowMethod, allowHeader, useMethod, useHeader) {
+ return promise_test(t => {
+ let testURL = url + "?",
+ requestInit = {}
+ if (withCredentials) {
+ testURL += "origin=" + origin + "&"
+ testURL += "credentials&"
+ requestInit.credentials = "include"
+ }
+ if (useMethod) {
+ requestInit.method = useMethod
+ }
+ if (useHeader.length > 0) {
+ requestInit.headers = [useHeader]
+ }
+ testURL += "allow_methods=" + allowMethod + "&"
+ testURL += "allow_headers=" + allowHeader + "&"
+
+ if (succeeds) {
+ return fetch(testURL, requestInit).then(resp => {
+ assert_equals(resp.headers.get("x-origin"), origin)
+ })
+ } else {
+ return promise_rejects(t, new TypeError(), fetch(testURL, requestInit))
+ }
+ }, "CORS that " + (succeeds ? "succeeds" : "fails") + " with credentials: " + withCredentials + "; method: " + useMethod + " (allowed: " + allowMethod + "); header: " + useHeader + " (allowed: " + allowHeader + ")")
+}
+
+preflightTest(true, false, "get", "x-test", "GET", ["X-Test", "1"])
+preflightTest(true, false, "*", "x-test", "SUPER", ["X-Test", "1"])
+preflightTest(true, false, "*", "*", "OK", ["X-Test", "1"])
+preflightTest(false, true, "*", "*", "OK", ["X-Test", "1"])
+preflightTest(false, true, "*", "", "PUT", [])
+preflightTest(true, true, "PUT", "*", "PUT", [])
+preflightTest(false, true, "put", "*", "PUT", [])
+preflightTest(false, true, "get", "*", "GET", ["X-Test", "1"])
+preflightTest(false, true, "*", "*", "GET", ["X-Test", "1"])
+preflightTest(true, true, "*", "*", "*", ["*", "1"])
Added: branches/safari-605-branch/LayoutTests/http/wpt/service-workers/cors-preflight-star.any.serviceworker-expected.txt (0 => 228363)
--- branches/safari-605-branch/LayoutTests/http/wpt/service-workers/cors-preflight-star.any.serviceworker-expected.txt (rev 0)
+++ branches/safari-605-branch/LayoutTests/http/wpt/service-workers/cors-preflight-star.any.serviceworker-expected.txt 2018-02-10 06:25:46 UTC (rev 228363)
@@ -0,0 +1,13 @@
+
+PASS Setting up tests
+FAIL CORS that succeeds with credentials: false; method: GET (allowed: get); header: X-Test,1 (allowed: x-test) promise_test: Unhandled rejection with value: object "TypeError: Preflight response is not successful"
+FAIL CORS that succeeds with credentials: false; method: SUPER (allowed: *); header: X-Test,1 (allowed: x-test) promise_test: Unhandled rejection with value: object "TypeError: Preflight response is not successful"
+FAIL CORS that succeeds with credentials: false; method: OK (allowed: *); header: X-Test,1 (allowed: *) promise_test: Unhandled rejection with value: object "TypeError: Preflight response is not successful"
+PASS CORS that fails with credentials: true; method: OK (allowed: *); header: X-Test,1 (allowed: *)
+PASS CORS that fails with credentials: true; method: PUT (allowed: *); header: (allowed: )
+FAIL CORS that succeeds with credentials: true; method: PUT (allowed: PUT); header: (allowed: *) promise_test: Unhandled rejection with value: object "TypeError: Preflight response is not successful"
+PASS CORS that fails with credentials: true; method: PUT (allowed: put); header: (allowed: *)
+PASS CORS that fails with credentials: true; method: GET (allowed: get); header: X-Test,1 (allowed: *)
+PASS CORS that fails with credentials: true; method: GET (allowed: *); header: X-Test,1 (allowed: *)
+FAIL CORS that succeeds with credentials: true; method: * (allowed: *); header: *,1 (allowed: *) promise_test: Unhandled rejection with value: object "TypeError: Preflight response is not successful"
+
Added: branches/safari-605-branch/LayoutTests/http/wpt/service-workers/cors-preflight-star.any.serviceworker.html (0 => 228363)
--- branches/safari-605-branch/LayoutTests/http/wpt/service-workers/cors-preflight-star.any.serviceworker.html (rev 0)
+++ branches/safari-605-branch/LayoutTests/http/wpt/service-workers/cors-preflight-star.any.serviceworker.html 2018-02-10 06:25:46 UTC (rev 228363)
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Service Worker: Fetch API CORS preflight tests</title>
+</head>
+<body>
+<script src=""
+<script src=""
+<script src=""
+<script>
+'use strict';
+
+// FIXME: Remove this test once https://github.com/w3c/web-platform-tests/issues/4210 is resolved.
+promise_test(async (t) => {
+ var url = '';
+ var scope = 'empty.html';
+ var frame_sw, sw_registration;
+
+ await service_worker_unregister(t, scope);
+ var f = await with_iframe(scope);
+ t.add_cleanup(function() {
+ f.remove();
+ });
+ frame_sw = f.contentWindow.navigator.serviceWorker;
+ var registration = await navigator.serviceWorker.register(url, {scope: scope});
+ sw_registration = registration;
+ await wait_for_state(t, registration.installing, 'activated');
+ fetch_tests_from_worker(sw_registration.active);
+}, 'Setting up tests');
+
+</script>
+</body>
+</html>