mirror of
https://github.com/servo/servo
synced 2026-05-12 09:56:50 +02:00
135 lines
4.7 KiB
HTML
135 lines
4.7 KiB
HTML
<!DOCTYPE html>
|
|
<title>Service Worker: the body of FetchEvent using XMLHttpRequest</title>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="/common/get-host-info.sub.js"></script>
|
|
<script src="/common/media.js"></script>
|
|
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
|
|
<script>
|
|
let frame;
|
|
|
|
// Set up the service worker and the frame.
|
|
promise_test(t => {
|
|
const kScope = 'resources/empty.https.html';
|
|
const kScript = 'resources/fetch-destination-worker.js';
|
|
return service_worker_unregister_and_register(t, kScript, kScope)
|
|
.then(registration => {
|
|
add_completion_callback(() => {
|
|
registration.unregister();
|
|
});
|
|
|
|
return wait_for_state(t, registration.installing, 'activated');
|
|
})
|
|
.then(() => {
|
|
return with_iframe(kScope);
|
|
})
|
|
.then(f => {
|
|
frame = f;
|
|
add_completion_callback(() => { f.remove(); });
|
|
});
|
|
}, 'Initialize global state');
|
|
|
|
// Actual tests
|
|
|
|
// HTMLImageElement - image destination
|
|
promise_test(async t => {
|
|
await new Promise((resolve, reject) => {
|
|
var node = frame.contentWindow.document.createElement("img");
|
|
node.onload = resolve;
|
|
node.onerror = reject;
|
|
node.src = "dummy.png?dest=image";
|
|
}).catch(() => {
|
|
assert_unreached("Fetch errored.");
|
|
});
|
|
}, 'HTMLImageElement fetches with an "image" Request.destination');
|
|
|
|
// fetch() - empty string destination
|
|
promise_test(async t => {
|
|
let response = await frame.contentWindow.fetch("dummy?dest=");
|
|
assert_true(response.ok);
|
|
}, 'fetch() fetches with an empty string Request.destination');
|
|
|
|
// HTMLAudioElement - audio destination
|
|
promise_test(async t => {
|
|
await new Promise((resolve, reject) => {
|
|
var audioURL = getAudioURI("dummy_audio");
|
|
var node = frame.contentWindow.document.createElement("audio");
|
|
node.onloadeddata = resolve;
|
|
node.onerror = reject;
|
|
node.src = audioURL + "?dest=audio";
|
|
}).catch(() => {
|
|
assert_unreached("Fetch errored.");
|
|
});
|
|
}, 'HTMLAudioElement fetches with an "audio" Request.destination');
|
|
|
|
// HTMLVideoElement - video destination
|
|
promise_test(async t => {
|
|
await new Promise((resolve, reject) => {
|
|
var videoURL = getVideoURI("dummy_video");
|
|
var node = frame.contentWindow.document.createElement("video");
|
|
node.onloadeddata = resolve;
|
|
node.onerror = reject;
|
|
node.src = videoURL + "?dest=video";
|
|
}).catch(() => {
|
|
assert_unreached("Fetch errored.");
|
|
});
|
|
}, 'HTMLVideoElement fetches with a "video" Request.destination');
|
|
|
|
// HTMLScriptElement - script destination
|
|
promise_test(async t => {
|
|
await new Promise((resolve, reject) => {
|
|
var node = frame.contentWindow.document.createElement("script");
|
|
node.onload = resolve;
|
|
node.onerror = reject;
|
|
node.src = "dummy?dest=script";
|
|
frame.contentWindow.document.body.appendChild(node);
|
|
}).catch(() => {
|
|
assert_unreached("Fetch errored.");
|
|
});
|
|
}, 'HTMLScriptElement fetches with a "script" Request.destination');
|
|
|
|
// HTMLLinkElement with rel=stylesheet - script destination
|
|
promise_test(async t => {
|
|
await new Promise((resolve, reject) => {
|
|
var node = frame.contentWindow.document.createElement("link");
|
|
node.rel = "stylesheet";
|
|
node.onload = resolve;
|
|
node.onerror = reject;
|
|
node.href = "dummy?dest=style";
|
|
frame.contentWindow.document.body.appendChild(node);
|
|
}).catch(() => {
|
|
assert_unreached("Fetch errored.");
|
|
});
|
|
}, 'HTMLLinkElement with rel=stylesheet fetches with a "style" Request.destination');
|
|
|
|
// HTMLLinkElement with rel=preload and as=fetch - empty string destination
|
|
promise_test(async t => {
|
|
await new Promise((resolve, reject) => {
|
|
var node = frame.contentWindow.document.createElement("link");
|
|
node.rel = "preload";
|
|
node.as = "fetch";
|
|
node.onload = resolve;
|
|
node.onerror = reject;
|
|
node.href = "dummy?t=2&dest=";
|
|
frame.contentWindow.document.body.appendChild(node);
|
|
}).catch(() => {
|
|
assert_unreached("Fetch errored.");
|
|
});
|
|
}, 'HTMLLinkElement with rel=preload and as=fetch fetches with an empty string Request.destination');
|
|
|
|
// HTMLLinkElement with rel=preload and as=style - style destination
|
|
promise_test(async t => {
|
|
await new Promise((resolve, reject) => {
|
|
var node = frame.contentWindow.document.createElement("link");
|
|
node.rel = "preload";
|
|
node.as = "style";
|
|
node.onload = resolve;
|
|
node.onerror = reject;
|
|
node.href = "dummy?t=2&dest=style";
|
|
frame.contentWindow.document.body.appendChild(node);
|
|
}).catch(() => {
|
|
assert_unreached("Fetch errored.");
|
|
});
|
|
}, 'HTMLLinkElement with rel=preload and as=style fetches with a "style" Request.destination');
|
|
</script>
|