Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebKit export of https://bugs.webkit.org/show_bug.cgi?id=202792 #19618

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions service-workers/service-worker/fetch-error-worker.js
@@ -0,0 +1,22 @@
importScripts("/resources/testharness.js");

function doTest(event)
{
if (!event.request.url.includes("fetch-error-test"))
return;

let counter = 0;
const stream = new ReadableStream({ pull: controller => {
switch (++counter) {
case 1:
controller.enqueue(new Uint8Array([1]));
return;
default:
// We asynchronously error the stream so that there is ample time to resolve the fetch promise and call text() on the response.
step_timeout(() => controller.error("Sorry"), 50);
}
}});
event.respondWith(new Response(stream));
}

self.addEventListener("fetch", doTest);
40 changes: 40 additions & 0 deletions service-workers/service-worker/fetch-error.https.html
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
</head>
<body>
<script>
var scope = "resources";
var registration;

promise_test(async (test) => {
registration = await navigator.serviceWorker.register("fetch-error-worker.js", { scope : scope });
var activeWorker = registration.active;
if (activeWorker)
return;
activeWorker = registration.installing;
return new Promise(resolve => {
activeWorker.addEventListener('statechange', () => {
if (activeWorker.state === "activated")
resolve();
});
});
}, "Setup service worker");

promise_test(async (test) => {
const iframe = await with_iframe(scope);

const response = await iframe.contentWindow.fetch("fetch-error-test");
await response.text().then(assert_unreached, (error) => { assert_true(error.message.includes("Sorry")); });
iframe.remove();
}, "Make sure a load that makes progress does not time out");

promise_test(async () => {
registration.unregister();
}, "Unregister service worker");
</script>
</body>
</html>