mirror of
https://github.com/servo/servo.git
synced 2025-08-15 02:15:33 +01:00
Update web-platform-tests to revision b'a3cb53d786edfd9106825e312866624150382075'
This commit is contained in:
parent
9acb9cc5cf
commit
40def0914a
549 changed files with 16001 additions and 1815 deletions
|
@ -27,13 +27,3 @@ for (const method of ['GET', 'POST']) {
|
|||
assertStashedTokenAsync(`simple ${method} request: no payload`, token1);
|
||||
}, `simple ${method} request: no payload; setting up`);
|
||||
}
|
||||
|
||||
promise_test(async (test) => {
|
||||
const w = window.open(`${
|
||||
HTTP_NOTSAMESITE_ORIGIN}/fetch/api/resources/keepalive-redirect-window.html`);
|
||||
const token = await getTokenFromMessage();
|
||||
w.close();
|
||||
|
||||
assertStashedTokenAsync(
|
||||
'keepalive in onunload in nested frame in another window', token);
|
||||
}, 'keepalive in onunload in nested frame in another window; setting up');
|
||||
|
|
|
@ -38,3 +38,90 @@
|
|||
assert_equals(blob.type, newMIMEType);
|
||||
}, `${bodyContainer.constructor.name}: setting missing Content-Type`);
|
||||
});
|
||||
|
||||
[
|
||||
() => new Request("about:blank", { method: "POST" }),
|
||||
() => new Response(),
|
||||
].forEach(bodyContainerCreator => {
|
||||
const bodyContainer = bodyContainerCreator();
|
||||
promise_test(async t => {
|
||||
const blob = await bodyContainer.blob();
|
||||
assert_equals(blob.type, "");
|
||||
}, `${bodyContainer.constructor.name}: MIME type for Blob from empty body`);
|
||||
});
|
||||
|
||||
[
|
||||
() => new Request("about:blank", { method: "POST", headers: [["Content-Type", "Mytext/Plain"]] }),
|
||||
() => new Response("", { headers: [["Content-Type", "Mytext/Plain"]] })
|
||||
].forEach(bodyContainerCreator => {
|
||||
const bodyContainer = bodyContainerCreator();
|
||||
promise_test(async t => {
|
||||
const blob = await bodyContainer.blob();
|
||||
assert_equals(blob.type, 'mytext/plain');
|
||||
}, `${bodyContainer.constructor.name}: MIME type for Blob from empty body with Content-Type`);
|
||||
});
|
||||
|
||||
[
|
||||
() => new Request("about:blank", { body: new Blob([""]), method: "POST" }),
|
||||
() => new Response(new Blob([""]))
|
||||
].forEach(bodyContainerCreator => {
|
||||
const bodyContainer = bodyContainerCreator();
|
||||
promise_test(async t => {
|
||||
const blob = await bodyContainer.blob();
|
||||
assert_equals(blob.type, "");
|
||||
assert_equals(bodyContainer.headers.get("Content-Type"), null);
|
||||
}, `${bodyContainer.constructor.name}: MIME type for Blob`);
|
||||
});
|
||||
|
||||
[
|
||||
() => new Request("about:blank", { body: new Blob([""], { type: "Text/Plain" }), method: "POST" }),
|
||||
() => new Response(new Blob([""], { type: "Text/Plain" }))
|
||||
].forEach(bodyContainerCreator => {
|
||||
const bodyContainer = bodyContainerCreator();
|
||||
promise_test(async t => {
|
||||
const blob = await bodyContainer.blob();
|
||||
assert_equals(blob.type, "text/plain");
|
||||
assert_equals(bodyContainer.headers.get("Content-Type"), "text/plain");
|
||||
}, `${bodyContainer.constructor.name}: MIME type for Blob with non-empty type`);
|
||||
});
|
||||
|
||||
[
|
||||
() => new Request("about:blank", { method: "POST", body: new Blob([""], { type: "Text/Plain" }), headers: [["Content-Type", "Text/Html"]] }),
|
||||
() => new Response(new Blob([""], { type: "Text/Plain" }, { headers: [["Content-Type", "Text/Html"]] }))
|
||||
].forEach(bodyContainerCreator => {
|
||||
const bodyContainer = bodyContainerCreator();
|
||||
const cloned = bodyContainer.clone();
|
||||
promise_test(async t => {
|
||||
const blobs = [await bodyContainer.blob(), await cloned.blob()];
|
||||
assert_equals(blobs[0].type, "text/html");
|
||||
assert_equals(blobs[1].type, "text/html");
|
||||
assert_equals(bodyContainer.headers.get("Content-Type"), "Text/Html");
|
||||
assert_equals(cloned.headers.get("Content-Type"), "Text/Html");
|
||||
}, `${bodyContainer.constructor.name}: Extract a MIME type with clone`);
|
||||
});
|
||||
|
||||
[
|
||||
() => new Request("about:blank", { body: new Blob([], { type: "text/plain" }), method: "POST", headers: [["Content-Type", "text/html"]] }),
|
||||
() => new Response(new Blob([], { type: "text/plain" }), { headers: [["Content-Type", "text/html"]] }),
|
||||
].forEach(bodyContainerCreator => {
|
||||
const bodyContainer = bodyContainerCreator();
|
||||
promise_test(async t => {
|
||||
assert_equals(bodyContainer.headers.get("Content-Type"), "text/html");
|
||||
const blob = await bodyContainer.blob();
|
||||
assert_equals(blob.type, "text/html");
|
||||
}, `${bodyContainer.constructor.name}: Content-Type in headers wins Blob"s type`);
|
||||
});
|
||||
|
||||
[
|
||||
() => new Request("about:blank", { body: new Blob([], { type: "text/plain" }), method: "POST" }),
|
||||
() => new Response(new Blob([], { type: "text/plain" })),
|
||||
].forEach(bodyContainerCreator => {
|
||||
const bodyContainer = bodyContainerCreator();
|
||||
promise_test(async t => {
|
||||
assert_equals(bodyContainer.headers.get("Content-Type"), "text/plain");
|
||||
const newMIMEType = "text/html";
|
||||
bodyContainer.headers.set("Content-Type", newMIMEType);
|
||||
const blob = await bodyContainer.blob();
|
||||
assert_equals(blob.type, newMIMEType);
|
||||
}, `${bodyContainer.constructor.name}: setting missing Content-Type in headers and it wins Blob"s type`);
|
||||
});
|
||||
|
|
|
@ -14,43 +14,81 @@ const {
|
|||
HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT
|
||||
} = get_host_info();
|
||||
|
||||
promise_test(async (test) => {
|
||||
const token1 = token();
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.src = getKeepAliveAndRedirectIframeUrl(
|
||||
token1, '', '', /*withPreflight=*/ false);
|
||||
document.body.appendChild(iframe);
|
||||
await iframeLoaded(iframe);
|
||||
assert_equals(await getTokenFromMessage(), token1);
|
||||
iframe.remove();
|
||||
/**
|
||||
* In an iframe, test to fetch a keepalive URL that involves in redirect to
|
||||
* another URL.
|
||||
*/
|
||||
function keepaliveRedirectTest(
|
||||
desc, {origin1 = '', origin2 = '', withPreflight = false} = {}) {
|
||||
desc = `[keepalive] ${desc}`;
|
||||
promise_test(async (test) => {
|
||||
const tokenToStash = token();
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.src = getKeepAliveAndRedirectIframeUrl(
|
||||
tokenToStash, origin1, origin2, withPreflight);
|
||||
document.body.appendChild(iframe);
|
||||
await iframeLoaded(iframe);
|
||||
assert_equals(await getTokenFromMessage(), tokenToStash);
|
||||
iframe.remove();
|
||||
|
||||
assertStashedTokenAsync('same-origin redirect', token1);
|
||||
}, 'same-origin redirect; setting up');
|
||||
assertStashedTokenAsync(desc, tokenToStash);
|
||||
}, `${desc}; setting up`);
|
||||
}
|
||||
|
||||
promise_test(async (test) => {
|
||||
const token1 = token();
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.src = getKeepAliveAndRedirectIframeUrl(
|
||||
token1, HTTP_REMOTE_ORIGIN, HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT,
|
||||
/*withPreflight=*/ false);
|
||||
document.body.appendChild(iframe);
|
||||
await iframeLoaded(iframe);
|
||||
assert_equals(await getTokenFromMessage(), token1);
|
||||
iframe.remove();
|
||||
/**
|
||||
* Opens a different site window, and in `unload` event handler, test to fetch
|
||||
* a keepalive URL that involves in redirect to another URL.
|
||||
*/
|
||||
function keepaliveRedirectInUnloadTest(desc, {
|
||||
origin1 = '',
|
||||
origin2 = '',
|
||||
url2 = '',
|
||||
withPreflight = false,
|
||||
shouldPass = true
|
||||
} = {}) {
|
||||
desc = `[keepalive][new window][unload] ${desc}`;
|
||||
|
||||
assertStashedTokenAsync('cross-origin redirect', token1);
|
||||
}, 'cross-origin redirect; setting up');
|
||||
promise_test(async (test) => {
|
||||
const targetUrl =
|
||||
`${HTTP_NOTSAMESITE_ORIGIN}/fetch/api/resources/keepalive-redirect-window.html?` +
|
||||
`origin1=${origin1}&` +
|
||||
`origin2=${origin2}&` +
|
||||
`url2=${url2}&` + (withPreflight ? `with-headers` : ``);
|
||||
const w = window.open(targetUrl);
|
||||
const token = await getTokenFromMessage();
|
||||
w.close();
|
||||
|
||||
promise_test(async (test) => {
|
||||
const token1 = token();
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.src = getKeepAliveAndRedirectIframeUrl(
|
||||
token1, HTTP_REMOTE_ORIGIN, HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT,
|
||||
/*withPreflight=*/ true);
|
||||
document.body.appendChild(iframe);
|
||||
await iframeLoaded(iframe);
|
||||
assert_equals(await getTokenFromMessage(), token1);
|
||||
iframe.remove();
|
||||
assertStashedTokenAsync(desc, token, {shouldPass});
|
||||
}, `${desc}; setting up`);
|
||||
}
|
||||
|
||||
assertStashedTokenAsync('cross-origin redirect with preflight', token1);
|
||||
}, 'cross-origin redirect with preflight; setting up');
|
||||
keepaliveRedirectTest(`same-origin redirect`);
|
||||
keepaliveRedirectTest(
|
||||
`same-origin redirect + preflight`, {withPreflight: true});
|
||||
keepaliveRedirectTest(`cross-origin redirect`, {
|
||||
origin1: HTTP_REMOTE_ORIGIN,
|
||||
origin2: HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT
|
||||
});
|
||||
keepaliveRedirectTest(`cross-origin redirect + preflight`, {
|
||||
origin1: HTTP_REMOTE_ORIGIN,
|
||||
origin2: HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT,
|
||||
withPreflight: true
|
||||
});
|
||||
|
||||
keepaliveRedirectInUnloadTest('same-origin redirect');
|
||||
keepaliveRedirectInUnloadTest(
|
||||
'same-origin redirect + preflight', {withPreflight: true});
|
||||
keepaliveRedirectInUnloadTest('cross-origin redirect', {
|
||||
origin1: HTTP_REMOTE_ORIGIN,
|
||||
origin2: HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT
|
||||
});
|
||||
keepaliveRedirectInUnloadTest('cross-origin redirect + preflight', {
|
||||
origin1: HTTP_REMOTE_ORIGIN,
|
||||
origin2: HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT,
|
||||
withPreflight: true
|
||||
});
|
||||
keepaliveRedirectInUnloadTest(
|
||||
'redirect to file URL', {url2: 'file://tmp/bar.txt', shouldPass: false});
|
||||
keepaliveRedirectInUnloadTest(
|
||||
'redirect to data URL',
|
||||
{url2: 'data:text/plain;base64,cmVzcG9uc2UncyBib2R5', shouldPass: false});
|
||||
|
|
|
@ -60,7 +60,7 @@ async function queryToken(token) {
|
|||
// for the rest of the work. Note that we want the serialized behavior
|
||||
// for the steps so far, so we don't want to make the entire test case
|
||||
// an async_test.
|
||||
function assertStashedTokenAsync(testName, token) {
|
||||
function assertStashedTokenAsync(testName, token, {shouldPass = true} = {}) {
|
||||
async_test((test) => {
|
||||
new Promise((resolve) => test.step_timeout(resolve, 3000))
|
||||
.then(() => {
|
||||
|
@ -73,7 +73,11 @@ function assertStashedTokenAsync(testName, token) {
|
|||
test.done();
|
||||
})
|
||||
.catch(test.step_func((e) => {
|
||||
assert_unreached(e);
|
||||
if (shouldPass) {
|
||||
assert_unreached(e);
|
||||
} else {
|
||||
test.done();
|
||||
}
|
||||
}));
|
||||
}, testName);
|
||||
}
|
||||
|
|
|
@ -10,20 +10,28 @@ const {
|
|||
HTTP_REMOTE_ORIGIN,
|
||||
HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT
|
||||
} = get_host_info();
|
||||
const REDIRECT_DESTINATION =
|
||||
`${HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT}/fetch/api/resources/stash-put.py` +
|
||||
|
||||
const SEARCH_PARAMS = new URL(location.href).searchParams;
|
||||
const WITH_HEADERS = !!SEARCH_PARAMS.has('with-headers');
|
||||
const ORIGIN1 = SEARCH_PARAMS.get('origin1') || '';
|
||||
const ORIGIN2 = SEARCH_PARAMS.get('origin2') || '';
|
||||
const URL2 = SEARCH_PARAMS.get('url2') || '';
|
||||
|
||||
const REDIRECT_DESTINATION = URL2 ? URL2 :
|
||||
`${ORIGIN2}/fetch/api/resources/stash-put.py` +
|
||||
`?key=${TOKEN}&value=on`;
|
||||
const URL =
|
||||
`${HTTP_REMOTE_ORIGIN}/fetch/api/resources/redirect.py?` +
|
||||
const FROM_URL =
|
||||
`${ORIGIN1}/fetch/api/resources/redirect.py?` +
|
||||
`delay=500&` +
|
||||
`allow_headers=foo&` +
|
||||
`location=${encodeURIComponent(REDIRECT_DESTINATION)}`;
|
||||
|
||||
addEventListener('load', () => {
|
||||
const headers = WITH_HEADERS ? {'foo': 'bar'} : undefined;
|
||||
const iframe = document.createElement('iframe');
|
||||
document.body.appendChild(iframe);
|
||||
iframe.contentWindow.addEventListener('unload', () => {
|
||||
iframe.contentWindow.fetch(URL, {keepalive: true, headers: {foo: 'bar'}});
|
||||
iframe.contentWindow.fetch(FROM_URL, {keepalive: true, headers});
|
||||
});
|
||||
|
||||
window.opener.postMessage(TOKEN, '*');
|
||||
|
|
|
@ -103,7 +103,21 @@ function testReadableStreamClone(initialBuffer, bufferType)
|
|||
return stream2.getReader().read();
|
||||
}).then(function(data) {
|
||||
assert_false(data.done);
|
||||
assert_array_equals(data.value, initialBuffer, "Cloned buffer chunks have the same content");
|
||||
if (initialBuffer instanceof ArrayBuffer) {
|
||||
assert_true(data.value instanceof ArrayBuffer, "Cloned buffer is ArrayBufer");
|
||||
assert_equals(initialBuffer.byteLength, data.value.byteLength, "Length equal");
|
||||
assert_array_equals(new Uint8Array(data.value), new Uint8Array(initialBuffer), "Cloned buffer chunks have the same content");
|
||||
} else if (initialBuffer instanceof DataView) {
|
||||
assert_true(data.value instanceof DataView, "Cloned buffer is DataView");
|
||||
assert_equals(initialBuffer.byteLength, data.value.byteLength, "Lengths equal");
|
||||
assert_equals(initialBuffer.byteOffset, data.value.byteOffset, "Offsets equal");
|
||||
for (let i = 0; i < initialBuffer.byteLength; ++i) {
|
||||
assert_equals(
|
||||
data.value.getUint8(i), initialBuffer.getUint8(i), "Mismatch at byte ${i}");
|
||||
}
|
||||
} else {
|
||||
assert_array_equals(data.value, initialBuffer, "Cloned buffer chunks have the same content");
|
||||
}
|
||||
assert_equals(Object.getPrototypeOf(data.value), Object.getPrototypeOf(initialBuffer), "Cloned buffers have the same type");
|
||||
assert_not_equals(data.value, initialBuffer, "Buffer of cloned response stream is a clone of the original buffer");
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue