mirror of
https://github.com/servo/servo.git
synced 2025-08-18 11:55:39 +01:00
Update web-platform-tests to revision ea14651f262003177d0ba5819bd2806a1327b12a
This commit is contained in:
parent
847115ba04
commit
816185f094
272 changed files with 5766 additions and 2855 deletions
|
@ -0,0 +1,22 @@
|
|||
self.addEventListener('fetch', (event) => {
|
||||
const params = new URL(event.request.url).searchParams;
|
||||
if (params.has('ignore')) {
|
||||
return;
|
||||
}
|
||||
if (!params.has('name')) {
|
||||
event.respondWith(Promise.reject(TypeError('No name is provided.')));
|
||||
return;
|
||||
}
|
||||
|
||||
event.respondWith(Promise.resolve().then(async () => {
|
||||
const name = params.get('name');
|
||||
await caches.delete('foo');
|
||||
const cache = await caches.open('foo');
|
||||
await cache.put(event.request, new Response('hello'));
|
||||
const keys = await cache.keys();
|
||||
|
||||
const original = event.request[name];
|
||||
const stored = keys[0][name];
|
||||
return new Response(`original: ${original}, stored: ${stored}`);
|
||||
}));
|
||||
});
|
|
@ -0,0 +1,36 @@
|
|||
<!DOCTYPE html>
|
||||
<title>Cache.keys (checking request attributes that can be set only on service workers)</title>
|
||||
<link rel="help" href="https://w3c.github.io/ServiceWorker/#cache-keys">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="../../service-worker/resources/test-helpers.sub.js"></script>
|
||||
<script>
|
||||
const worker = '../resources/cache-keys-attributes-for-service-worker.js';
|
||||
|
||||
promise_test(async (t) => {
|
||||
const scope = '../resources/blank.html?name=isReloadNavigation';
|
||||
let frame;
|
||||
let reg;
|
||||
|
||||
try {
|
||||
reg = await service_worker_unregister_and_register(t, worker, scope);
|
||||
await wait_for_state(t, reg.installing, 'activated');
|
||||
frame = await with_iframe(scope);
|
||||
assert_equals(frame.contentDocument.body.textContent,
|
||||
'original: false, stored: false');
|
||||
await new Promise((resolve) => {
|
||||
frame.onload = resolve;
|
||||
frame.contentWindow.location.reload();
|
||||
});
|
||||
assert_equals(frame.contentDocument.body.textContent,
|
||||
'original: true, stored: true');
|
||||
} finally {
|
||||
if (frame) {
|
||||
frame.remove();
|
||||
}
|
||||
if (reg) {
|
||||
await reg.unregister();
|
||||
}
|
||||
}
|
||||
}, 'Request.IsReloadNavigation should persist.');
|
||||
</script>
|
|
@ -0,0 +1,31 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/get-host-info.sub.js"></script>
|
||||
<script src="resources/test-helpers.sub.js"></script>
|
||||
<body>
|
||||
<script>
|
||||
const worker = 'resources/fetch-event-test-worker.js';
|
||||
|
||||
promise_test(async (t) => {
|
||||
const scope = 'resources/simple.html?isReloadNavigation';
|
||||
|
||||
const reg = await service_worker_unregister_and_register(t, worker, scope);
|
||||
await wait_for_state(t, reg.installing, 'activated');
|
||||
const frame = await with_iframe(scope);
|
||||
assert_equals(frame.contentDocument.body.textContent,
|
||||
'method = GET, isReloadNavigation = false');
|
||||
await new Promise((resolve) => {
|
||||
frame.addEventListener('load', resolve);
|
||||
frame.contentDocument.body.innerText =
|
||||
'Reload this frame manually!';
|
||||
});
|
||||
assert_equals(frame.contentDocument.body.textContent,
|
||||
'method = GET, isReloadNavigation = true');
|
||||
frame.remove();
|
||||
await reg.unregister();
|
||||
}, 'FetchEvent#request.isReloadNavigation is true for manual reload.');
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,8 @@
|
|||
<!DOCTYPE html>
|
||||
<body>
|
||||
<p>Click <a href="resources/install-worker.html?isReloadNavigation&script=fetch-event-test-worker.js">this link</a>.
|
||||
Once you see "method = GET,..." in the page, reload the page.
|
||||
You will see "method = GET, isReloadNavigation = true".
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
|
@ -6,6 +6,9 @@
|
|||
<body>
|
||||
<script>
|
||||
var worker = 'resources/fetch-event-test-worker.js';
|
||||
function wait(ms) {
|
||||
return new Promise(resolve => step_timeout(resolve, ms));
|
||||
}
|
||||
|
||||
async_test(function(t) {
|
||||
const scope = 'resources/simple.html?headers';
|
||||
|
@ -629,5 +632,143 @@ promise_test(async (t) => {
|
|||
frame.remove();
|
||||
await service_worker_unregister_and_done(t, scope);
|
||||
}, 'Service Worker responds to fetch event with the correct keepalive value');
|
||||
|
||||
promise_test(async (t) => {
|
||||
const scope = 'resources/simple.html?isReloadNavigation';
|
||||
let frame;
|
||||
let reg;
|
||||
try {
|
||||
reg = await service_worker_unregister_and_register(t, worker, scope);
|
||||
await wait_for_state(t, reg.installing, 'activated');
|
||||
frame = await with_iframe(scope);
|
||||
assert_equals(frame.contentDocument.body.textContent,
|
||||
'method = GET, isReloadNavigation = false');
|
||||
await new Promise((resolve) => {
|
||||
frame.addEventListener('load', resolve);
|
||||
frame.contentWindow.location.reload();
|
||||
});
|
||||
assert_equals(frame.contentDocument.body.textContent,
|
||||
'method = GET, isReloadNavigation = true');
|
||||
} finally {
|
||||
if (frame) {
|
||||
frame.remove();
|
||||
}
|
||||
if (reg) {
|
||||
await reg.unregister();
|
||||
}
|
||||
}
|
||||
}, 'FetchEvent#request.isReloadNavigation is true (location.reload())');
|
||||
|
||||
promise_test(async (t) => {
|
||||
const scope = 'resources/simple.html?isReloadNavigation';
|
||||
let frame;
|
||||
let reg;
|
||||
try {
|
||||
reg = await service_worker_unregister_and_register(t, worker, scope);
|
||||
await wait_for_state(t, reg.installing, 'activated');
|
||||
frame = await with_iframe(scope);
|
||||
assert_equals(frame.contentDocument.body.textContent,
|
||||
'method = GET, isReloadNavigation = false');
|
||||
await new Promise((resolve) => {
|
||||
frame.addEventListener('load', resolve);
|
||||
frame.contentWindow.history.go(0);
|
||||
});
|
||||
assert_equals(frame.contentDocument.body.textContent,
|
||||
'method = GET, isReloadNavigation = true');
|
||||
} finally {
|
||||
if (frame) {
|
||||
frame.remove();
|
||||
}
|
||||
if (reg) {
|
||||
await reg.unregister();
|
||||
}
|
||||
}
|
||||
}, 'FetchEvent#request.isReloadNavigation is true (history.go(0))');
|
||||
|
||||
promise_test(async (t) => {
|
||||
const scope = 'resources/simple.html?isReloadNavigation';
|
||||
let frame;
|
||||
let reg;
|
||||
|
||||
try {
|
||||
reg = await service_worker_unregister_and_register(t, worker, scope);
|
||||
await wait_for_state(t, reg.installing, 'activated');
|
||||
frame = await with_iframe(scope);
|
||||
assert_equals(frame.contentDocument.body.textContent,
|
||||
'method = GET, isReloadNavigation = false');
|
||||
await new Promise((resolve) => {
|
||||
frame.addEventListener('load', resolve);
|
||||
const form = frame.contentDocument.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.name = 'form';
|
||||
form.action = new Request(scope).url;
|
||||
frame.contentDocument.body.appendChild(form);
|
||||
form.submit();
|
||||
});
|
||||
assert_equals(frame.contentDocument.body.textContent,
|
||||
'method = POST, isReloadNavigation = false');
|
||||
await new Promise((resolve) => {
|
||||
frame.addEventListener('load', resolve);
|
||||
frame.contentWindow.location.reload();
|
||||
});
|
||||
assert_equals(frame.contentDocument.body.textContent,
|
||||
'method = POST, isReloadNavigation = true');
|
||||
} finally {
|
||||
if (frame) {
|
||||
frame.remove();
|
||||
}
|
||||
if (reg) {
|
||||
await reg.unregister();
|
||||
}
|
||||
}
|
||||
}, 'FetchEvent#request.isReloadNavigation is true (POST + location.reload())');
|
||||
|
||||
promise_test(async (t) => {
|
||||
const scope = 'resources/simple.html?isReloadNavigation';
|
||||
const anotherUrl = new Request('resources/simple.html').url;
|
||||
let frame;
|
||||
let reg;
|
||||
|
||||
try {
|
||||
reg = await service_worker_unregister_and_register(t, worker, scope);
|
||||
await wait_for_state(t, reg.installing, 'activated');
|
||||
frame = await with_iframe(scope);
|
||||
assert_equals(frame.contentDocument.body.textContent,
|
||||
'method = GET, isReloadNavigation = false');
|
||||
// Use step_timeout(0) to ensure the history entry is created for Blink
|
||||
// and WebKit. See https://bugs.webkit.org/show_bug.cgi?id=42861.
|
||||
await wait(0);
|
||||
await new Promise((resolve) => {
|
||||
frame.addEventListener('load', resolve);
|
||||
frame.src = anotherUrl;
|
||||
});
|
||||
assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n");
|
||||
await new Promise((resolve) => {
|
||||
frame.addEventListener('load', resolve);
|
||||
frame.contentWindow.history.go(-1);
|
||||
});
|
||||
assert_equals(frame.contentDocument.body.textContent,
|
||||
'method = GET, isReloadNavigation = false');
|
||||
await new Promise((resolve) => {
|
||||
frame.addEventListener('load', resolve);
|
||||
frame.contentWindow.history.go(0);
|
||||
});
|
||||
assert_equals(frame.contentDocument.body.textContent,
|
||||
'method = GET, isReloadNavigation = true');
|
||||
await new Promise((resolve) => {
|
||||
frame.addEventListener('load', resolve);
|
||||
frame.contentWindow.history.go(1);
|
||||
});
|
||||
assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n");
|
||||
} finally {
|
||||
if (frame) {
|
||||
frame.remove();
|
||||
}
|
||||
if (reg) {
|
||||
await reg.unregister();
|
||||
}
|
||||
}
|
||||
}, 'FetchEvent#request.isReloadNavigation is true (with history traversal)');
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -129,6 +129,14 @@ function handleKeepalive(event) {
|
|||
event.respondWith(new Response(event.request.keepalive));
|
||||
}
|
||||
|
||||
function handleIsReloadNavigation(event) {
|
||||
const request = event.request;
|
||||
const body =
|
||||
`method = ${request.method}, ` +
|
||||
`isReloadNavigation = ${request.isReloadNavigation}`;
|
||||
event.respondWith(new Response(body));
|
||||
}
|
||||
|
||||
self.addEventListener('fetch', function(event) {
|
||||
var url = event.request.url;
|
||||
var handlers = [
|
||||
|
@ -151,6 +159,7 @@ self.addEventListener('fetch', function(event) {
|
|||
{ pattern: '?integrity', fn: handleIntegrity },
|
||||
{ pattern: '?request-body', fn: handleRequestBody },
|
||||
{ pattern: '?keepalive', fn: handleKeepalive },
|
||||
{ pattern: '?isReloadNavigation', fn: handleIsReloadNavigation },
|
||||
];
|
||||
|
||||
var handler = null;
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<p>Loading...</p>
|
||||
<script>
|
||||
async function install() {
|
||||
let script;
|
||||
for (const q of location.search.slice(1).split('&')) {
|
||||
if (q.split('=')[0] === 'script') {
|
||||
script = q.split('=')[1];
|
||||
}
|
||||
}
|
||||
const scope = location.href;
|
||||
const reg = await navigator.serviceWorker.register(script, {scope});
|
||||
await navigator.serviceWorker.ready;
|
||||
location.reload();
|
||||
}
|
||||
|
||||
install();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,23 @@
|
|||
<!DOCTYPE html>
|
||||
<title>Service Worker: update() should resolve a ServiceWorkerRegistration</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="resources/test-helpers.sub.js"></script>
|
||||
<body>
|
||||
<script>
|
||||
|
||||
promise_test(async function(t) {
|
||||
const script = './resources/empty.js';
|
||||
const scope = './resources/empty.html?update-result';
|
||||
|
||||
let reg = await navigator.serviceWorker.register(script, { scope });
|
||||
t.add_cleanup(async _ => await reg.unregister());
|
||||
await wait_for_state(t, reg.installing, 'activated');
|
||||
|
||||
let result = await reg.update();
|
||||
assert_true(result instanceof ServiceWorkerRegistration,
|
||||
'update() should resolve a ServiceWorkerRegistration');
|
||||
}, 'ServiceWorkerRegistration.update() should resolve a registration object');
|
||||
|
||||
</script>
|
||||
</body>
|
Loading…
Add table
Add a link
Reference in a new issue