mirror of
https://github.com/servo/servo.git
synced 2025-08-25 23:28:21 +01:00
Update web-platform-tests to revision 74bae78af4b95a2f0ca3a81df9c7fe3143f24bbc
This commit is contained in:
parent
fb95f9df9c
commit
02c1eed999
150 changed files with 2395 additions and 829 deletions
|
@ -2,16 +2,21 @@
|
|||
<meta charset="utf-8">
|
||||
<title>iframe for xhr tests</title>
|
||||
<script>
|
||||
async function xhr(url) {
|
||||
async function xhr(url, options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
const opts = options ? options : {};
|
||||
xhr.onload = () => {
|
||||
resolve(xhr);
|
||||
};
|
||||
xhr.onerror = () => {
|
||||
reject('xhr failed');
|
||||
};
|
||||
|
||||
xhr.open('GET', url);
|
||||
if (opts.responseType) {
|
||||
xhr.responseType = opts.responseType;
|
||||
}
|
||||
xhr.send();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
// Service worker for the xhr-response-url test.
|
||||
|
||||
self.addEventListener('fetch', event => {
|
||||
const url = new URL(event.request.url);
|
||||
const respondWith = url.searchParams.get('respondWith');
|
||||
if (!respondWith)
|
||||
return;
|
||||
|
||||
if (respondWith == 'fetch') {
|
||||
const target = url.searchParams.get('url');
|
||||
event.respondWith(fetch(target));
|
||||
return;
|
||||
}
|
||||
|
||||
if (respondWith == 'string') {
|
||||
const headers = {'content-type': 'text/plain'};
|
||||
event.respondWith(new Response('hello', {headers}));
|
||||
return;
|
||||
}
|
||||
|
||||
if (respondWith == 'document') {
|
||||
const doc = `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<title>hi</title>
|
||||
<body>hello</body>
|
||||
</html>`;
|
||||
const headers = {'content-type': 'text/html'};
|
||||
event.respondWith(new Response(doc, {headers}));
|
||||
return;
|
||||
}
|
||||
});
|
|
@ -6,31 +6,98 @@
|
|||
<script src="resources/test-helpers.sub.js"></script>
|
||||
<script>
|
||||
const scope = 'resources/xhr-iframe.html';
|
||||
const script = 'resources/fetch-rewrite-worker.js';
|
||||
const script = 'resources/xhr-response-url-worker.js';
|
||||
let iframe;
|
||||
|
||||
// Test that XMLHttpRequest.responseURL uses the response URL from the service
|
||||
// worker.
|
||||
promise_test(async (t) => {
|
||||
t.add_cleanup(async () => {
|
||||
if (iframe)
|
||||
iframe.remove();
|
||||
await service_worker_unregister(t, scope);
|
||||
});
|
||||
function build_url(options) {
|
||||
const url = new URL('test', window.location);
|
||||
const opts = options ? options : {};
|
||||
if (opts.respondWith)
|
||||
url.searchParams.set('respondWith', opts.respondWith);
|
||||
if (opts.url)
|
||||
url.searchParams.set('url', opts.url.href);
|
||||
return url.href;
|
||||
}
|
||||
|
||||
// Set up a controlled iframe.
|
||||
promise_test(async (t) => {
|
||||
const registration =
|
||||
await service_worker_unregister_and_register(t, script, scope);
|
||||
await wait_for_state(t, registration.installing, 'activated');
|
||||
iframe = await with_iframe(scope);
|
||||
}, 'global setup');
|
||||
|
||||
// Build the XHR URL. Set the |url| param to tell the service worker
|
||||
// to respondWith(fetch(|url|)).
|
||||
// Test that XMLHttpRequest.responseURL uses the response URL from the service
|
||||
// worker.
|
||||
promise_test(async (t) => {
|
||||
// Build a URL that tells the service worker to respondWith(fetch(|target|)).
|
||||
const target = new URL('resources/dummy.txt', window.location);
|
||||
const url = `test?url=${encodeURIComponent(target)}`;
|
||||
const url = build_url({
|
||||
respondWith: 'fetch',
|
||||
url: target
|
||||
});
|
||||
|
||||
// Perform the XHR.
|
||||
const xhr = await iframe.contentWindow.xhr(url);
|
||||
assert_equals(xhr.responseURL, target.href);
|
||||
assert_equals(xhr.responseURL, target.href, 'responseURL');
|
||||
}, 'XHR responseURL should be the response URL');
|
||||
|
||||
// Same as above with a generated response.
|
||||
promise_test(async (t) => {
|
||||
// Build a URL that tells the service worker to respondWith(new Response()).
|
||||
const url = build_url({respondWith: 'string'});
|
||||
|
||||
// Perform the XHR.
|
||||
const xhr = await iframe.contentWindow.xhr(url);
|
||||
assert_equals(xhr.responseURL, url, 'responseURL');
|
||||
}, 'XHR responseURL should be the response URL (generated response)');
|
||||
|
||||
// Test that XMLHttpRequest.responseXML is a Document whose URL is the
|
||||
// response URL from the service worker.
|
||||
promise_test(async (t) => {
|
||||
// Build a URL that tells the service worker to respondWith(fetch(|target|)).
|
||||
const target = new URL('resources/blank.html', window.location);
|
||||
const url = build_url({
|
||||
respondWith: 'fetch',
|
||||
url: target
|
||||
});
|
||||
|
||||
// Perform the XHR.
|
||||
const xhr = await iframe.contentWindow.xhr(url, {responseType: 'document'});
|
||||
assert_equals(xhr.responseURL, target.href, 'responseURL');
|
||||
|
||||
// The document's URL uses the response URL:
|
||||
// "Set |document|’s URL to |response|’s url."
|
||||
// https://xhr.spec.whatwg.org/#document-response
|
||||
assert_equals(xhr.responseXML.URL, target.href, 'responseXML.URL');
|
||||
|
||||
// The document's base URL falls back to the document URL:
|
||||
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#document-base-url
|
||||
assert_equals(xhr.responseXML.baseURI, target.href, 'responseXML.baseURI');
|
||||
}, 'XHR Document should use the response URL');
|
||||
|
||||
// Same as above with a generated response from the service worker.
|
||||
promise_test(async (t) => {
|
||||
// Build a URL that tells the service worker to
|
||||
// respondWith(new Response()) with a document response.
|
||||
const url = build_url({respondWith: 'document'});
|
||||
|
||||
// Perform the XHR.
|
||||
const xhr = await iframe.contentWindow.xhr(url, {responseType: 'document'});
|
||||
assert_equals(xhr.responseURL, url, 'responseURL');
|
||||
|
||||
// The document's URL uses the response URL, which is the request URL:
|
||||
// "Set |document|’s URL to |response|’s url."
|
||||
// https://xhr.spec.whatwg.org/#document-response
|
||||
assert_equals(xhr.responseXML.URL, url, 'responseXML.URL');
|
||||
|
||||
// The document's base URL falls back to the document URL:
|
||||
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#document-base-url
|
||||
assert_equals(xhr.responseXML.baseURI, url, 'responseXML.baseURI');
|
||||
}, 'XHR Document should use the response URL (generated response)');
|
||||
|
||||
promise_test(async (t) => {
|
||||
if (iframe)
|
||||
iframe.remove();
|
||||
await service_worker_unregister(t, scope);
|
||||
}, 'global cleanup');
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue