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

Aborting fetch #6484

Merged
merged 13 commits into from
Aug 2, 2017
57 changes: 57 additions & 0 deletions fetch/api/abort/cache.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Request signals &amp; the cache API</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
promise_test(async () => {
await caches.delete('test');
const controller = new AbortController();
const signal = controller.signal;
const request = new Request('../resources/data.json', { signal });

const cache = await caches.open('test');
await cache.put(request, new Response(''));

const requests = await cache.keys();

assert_equals(requests.length, 1, 'Ensuring cleanup worked');

const [cachedRequest] = requests;

controller.abort();

assert_false(cachedRequest.signal.aborted, "Request from cache shouldn't be aborted");

const data = await fetch(cachedRequest).then(r => r.json());
assert_equals(data.key, 'value', 'Fetch fully completes');
}, "Signals are not stored in the cache API");

promise_test(async () => {
await caches.delete('test');
const controller = new AbortController();
const signal = controller.signal;
const request = new Request('../resources/data.json', { signal });
controller.abort();

const cache = await caches.open('test');
await cache.put(request, new Response(''));

const requests = await cache.keys();

assert_equals(requests.length, 1, 'Ensuring cleanup worked');

const [cachedRequest] = requests;

assert_false(cachedRequest.signal.aborted, "Request from cache shouldn't be aborted");

const data = await fetch(cachedRequest).then(r => r.json());
assert_equals(data.key, 'value', 'Fetch fully completes');
}, "Signals are not stored in the cache API, even if they're already aborted");
</script>
</body>
</html>
23 changes: 23 additions & 0 deletions fetch/api/abort/general-serviceworker.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>General fetch abort tests in a service worker</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
(async function() {
const scope = 'does/not/exist';

let reg = await navigator.serviceWorker.getRegistration(scope);
if (reg) await reg.unregister();

reg = await navigator.serviceWorker.register('general.js', {scope});

fetch_tests_from_worker(reg.installing);
})();
</script>
</body>
</html>
19 changes: 19 additions & 0 deletions fetch/api/abort/general.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>General fetch abort tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="general.js"></script>
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("general.js"));
if (window.SharedWorker) {
fetch_tests_from_worker(new SharedWorker("general.js"));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I found generating multiple tests with a wrapper simpler than contextualTestName: see https://github.com/w3c/web-platform-tests/tree/master/streams readme and https://github.com/w3c/web-platform-tests/blob/master/streams/generate-test-wrappers.js

</script>
</body>
</html>
Loading