summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/private-network-access/resources/support.sub.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/fetch/private-network-access/resources/support.sub.js')
-rw-r--r--testing/web-platform/tests/fetch/private-network-access/resources/support.sub.js84
1 files changed, 84 insertions, 0 deletions
diff --git a/testing/web-platform/tests/fetch/private-network-access/resources/support.sub.js b/testing/web-platform/tests/fetch/private-network-access/resources/support.sub.js
index 46a9d9e076..1cb432b787 100644
--- a/testing/web-platform/tests/fetch/private-network-access/resources/support.sub.js
+++ b/testing/web-platform/tests/fetch/private-network-access/resources/support.sub.js
@@ -480,6 +480,13 @@ const NavigationTestResult = {
};
async function windowOpenTest(t, { source, target, expected }) {
+ if (target.behavior && target.behavior.redirect) {
+ target.behavior.redirect.searchParams.set('file', 'openee.html');
+ target.behavior.redirect.searchParams.set(
+ 'file-if-no-preflight-received',
+ 'no-preflight-received.html',
+ );
+ }
const targetUrl = preflightUrl(target);
targetUrl.searchParams.set("file", "openee.html");
targetUrl.searchParams.set(
@@ -507,6 +514,13 @@ async function windowOpenTest(t, { source, target, expected }) {
}
async function windowOpenExistingTest(t, { source, target, expected }) {
+ if (target.behavior && target.behavior.redirect) {
+ target.behavior.redirect.searchParams.set('file', 'openee.html');
+ target.behavior.redirect.searchParams.set(
+ 'file-if-no-preflight-received',
+ 'no-preflight-received.html',
+ );
+ }
const targetUrl = preflightUrl(target);
targetUrl.searchParams.set("file", "openee.html");
targetUrl.searchParams.set(
@@ -535,6 +549,13 @@ async function windowOpenExistingTest(t, { source, target, expected }) {
}
async function anchorTest(t, { source, target, expected }) {
+ if (target.behavior && target.behavior.redirect) {
+ target.behavior.redirect.searchParams.set('file', 'openee.html');
+ target.behavior.redirect.searchParams.set(
+ 'file-if-no-preflight-received',
+ 'no-preflight-received.html',
+ );
+ }
const targetUrl = preflightUrl(target);
targetUrl.searchParams.set("file", "openee.html");
targetUrl.searchParams.set(
@@ -855,3 +876,66 @@ async function sharedWorkerBlobFetchTest(t, { source, target, expected }) {
assert_equals(status, expected.status, "response status");
assert_equals(body, expected.body, "response body");
}
+
+async function makeServiceWorkerTest(t, { source, target, expected, fetch_document=false }) {
+ const bridgeUrl = resolveUrl(
+ "resources/service-worker-bridge.html",
+ sourceResolveOptions({ server: source.server }));
+
+ const scriptUrl = fetch_document?
+ resolveUrl("resources/service-worker-fetch-all.js", sourceResolveOptions(source)):
+ resolveUrl("resources/service-worker.js", sourceResolveOptions(source));
+
+ const realTargetUrl = preflightUrl(target);
+
+ // Fetch a URL within the service worker's scope, but tell it which URL to
+ // really fetch.
+ const targetUrl = new URL("service-worker-proxy", scriptUrl);
+ targetUrl.searchParams.append("proxied-url", realTargetUrl.href);
+
+ const iframe = await appendIframe(t, document, bridgeUrl);
+
+ const request = (message) => {
+ const reply = futureMessage();
+ iframe.contentWindow.postMessage(message, "*");
+ return reply;
+ };
+
+ {
+ const { error, loaded } = await request({
+ action: "register",
+ url: scriptUrl.href,
+ });
+
+ assert_equals(error, undefined, "register error");
+ assert_true(loaded, "response loaded");
+ }
+
+ try {
+ const { controlled, numControllerChanges } = await request({
+ action: "wait",
+ numControllerChanges: 1,
+ });
+
+ assert_equals(numControllerChanges, 1, "controller change");
+ assert_true(controlled, "bridge script is controlled");
+
+ const { error, ok, body } = await request({
+ action: "fetch",
+ url: targetUrl.href,
+ });
+
+ assert_equals(error, expected.error, "fetch error");
+ assert_equals(ok, expected.ok, "response ok");
+ assert_equals(body, expected.body, "response body");
+ } finally {
+ // Always unregister the service worker.
+ const { error, unregistered } = await request({
+ action: "unregister",
+ scope: new URL("./", scriptUrl).href,
+ });
+
+ assert_equals(error, undefined, "unregister error");
+ assert_true(unregistered, "unregistered");
+ }
+}