test: update FileAPI tests from WPT

PR-URL: https://github.com/nodejs/node/pull/61750
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Ms2ger authored and Antoine du Hamel committed 2026-04-08 23:53:04 +02:00
1 parent 207ba4f89f
commit 5cf001736e
19 files changed
+1128 -343

No files matched your search

@@ -0,0 +1,251 @@
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<!-- Pull in executor_path needed by newPopup / newIframe -->
<script src="/html/cross-origin-embedder-policy/credentialless/resources/common.js"></script>
<!-- Pull in importScript / newPopup / newIframe -->
<script src="/html/anonymous-iframe/resources/common.js"></script>
<script src="resources/common.js"></script>
<body>
<script>
const navigation_handle_null = "Navigation handle returns null";
const navigation_handle_not_null = "Navigation handle returns not null";
const opener_null_response = "Window.opener is null";
const opener_not_null_response = "Window.opener isn't null";
const does_blob_url_open_return_handle = (blob_url, response_queue_name) => `
async function test() {
const handle = window.open("${blob_url}")
if (!handle) {
return send("${response_queue_name}", "${navigation_handle_null}");
}
return send("${response_queue_name}", "${navigation_handle_not_null}");
}
await test();
`;
const opener_check_frame_html = (noopener_response_queue) => `
<!doctype html>
<!-- dispatcher.js requires the baseURI to be set in order to compute
the server path correctly in the blob URL page. -->
<base href="${window.location.href}">
<script src="/html/cross-origin-embedder-policy/credentialless/resources/common.js"><\/script>
<script src="/html/anonymous-iframe/resources/common.js"><\/script>
<script src="/common/utils.js"><\/script>
<script src="/common/dispatcher/dispatcher.js"><\/script>
<script>
if (window.opener === null) {
send("${noopener_response_queue}", "${opener_null_response}")
} else {
send("${noopener_response_queue}", "${opener_not_null_response}")
}
<\/script>
`;
// Tests blob URL window.open for same and cross partition iframes.
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
// Creates same and cross partition iframes.
const response_queue_uuid = token();
const noopener_response_queue = token();
const [cross_site_iframe_uuid, same_site_iframe_uuid] =
await create_test_iframes(t, response_queue_uuid);
const blob = new Blob([opener_check_frame_html(noopener_response_queue)], {type : "text/html"});
const blob_url = URL.createObjectURL(blob);
// Attempt to open blob URL in cross partition iframe.
await send(cross_site_iframe_uuid, does_blob_url_open_return_handle(blob_url, response_queue_uuid));
const response_1 = await receive(response_queue_uuid);
if (response_1 !== navigation_handle_null) {
reject(`Blob URL handle wasn't null in not-same-top-level-site iframe: ${response_1}`);
}
const noopener_response_1 = await receive(noopener_response_queue);
if (noopener_response_1 !== opener_null_response) {
reject(`Blob URL page opener wasn't null in not-same-top-level-site iframe.`);
}
// Attempt to open blob URL in same partition iframe.
await send(same_site_iframe_uuid, does_blob_url_open_return_handle(blob_url, response_queue_uuid));
const response_2 = await receive(response_queue_uuid);
if (response_2 !== navigation_handle_not_null) {
reject(`Blob URL wasn't opened in same-top-level-site iframe: ${response_2}`);
}
const noopener_response_2 = await receive(noopener_response_queue);
if (noopener_response_2 !== opener_not_null_response) {
reject(`Blob URL page opener was null in same-top-level-site iframe`);
}
resolve();
} catch (e) {
reject(e);
}
});
}, "Blob URL window.open should enforce noopener for a cross-top-level-site navigation");
const blob_url_iframe_html = (response_queue_uuid, message) => `
<!doctype html>
<!-- dispatcher.js requires the baseURI to be set in order to compute
the server path correctly in the blob URL page. -->
<base href="${window.location.href}">
<script src="/html/cross-origin-embedder-policy/credentialless/resources/common.js"><\/script>
<script src="/html/anonymous-iframe/resources/common.js"><\/script>
<script src="/common/utils.js"><\/script>
<script src="/common/dispatcher/dispatcher.js"><\/script>
<script>
send("${response_queue_uuid}", "${message}");
<\/script>
`;
const create_iframe_with_blob_url = (blob_url, response_queue_uuid) => `
const iframe = document.createElement('iframe');
iframe.src = "${blob_url}";
iframe.onload = () => {
const same_site_message = "same_partition_loaded";
const blob_url_iframe_html = ${blob_url_iframe_html};
const same_top_level_site_blob = new Blob([blob_url_iframe_html("${response_queue_uuid}", same_site_message)], {type : "text/html"});
const same_top_level_site_blob_url = URL.createObjectURL(same_top_level_site_blob);
const iframe2 = document.createElement('iframe');
iframe2.src = same_top_level_site_blob_url;
document.body.appendChild(iframe2);
};
document.body.appendChild(iframe);
`;
// Tests blob URL subframe navigations for same and cross partition iframes.
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
// Creates same and cross partition iframes.
const response_queue_uuid = token();
const cross_site_message = "cross_partition_loaded";
const [cross_site_iframe_uuid, same_site_iframe_uuid] =
await create_test_iframes(t, response_queue_uuid);
// Create blob URL for the cross-site test.
const cross_site_blob = new Blob([blob_url_iframe_html(response_queue_uuid, cross_site_message)], {type: "text/html"});
const cross_site_blob_url = URL.createObjectURL(cross_site_blob);
// Attempt to open blob URL in cross partition iframe.
await send(cross_site_iframe_uuid, create_iframe_with_blob_url(cross_site_blob_url, response_queue_uuid));
const response = await receive(response_queue_uuid);
if (response === cross_site_message) {
reject(`Blob URL subframe navigation succeeded in not-same-top-level-site iframe.`);
}
resolve();
} catch (e) {
reject(e);
}
});
}, "Blob URL should partition subframe navigation.");
const open_blob_url_window_via_a_click = (blob_url) => `
const link = document.createElement("a");
link.href = "${blob_url}";
link.target = "_blank";
link.rel = "opener";
document.body.appendChild(link);
link.click();
`;
// Tests blob URL `<a target="_blank" rel="opener">` click for same and cross partition iframes.
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
// Creates same and cross partition iframes.
const noopener_response_queue = token();
const [cross_site_iframe_uuid, same_site_iframe_uuid] = await create_test_iframes(t, token());
const blob = new Blob([opener_check_frame_html(noopener_response_queue)], {type : "text/html"});
const blob_url = URL.createObjectURL(blob);
// Attempt to click blob URL in cross partition iframe.
await send(cross_site_iframe_uuid, open_blob_url_window_via_a_click(blob_url));
const noopener_response_1 = await receive(noopener_response_queue);
if (noopener_response_1 !== opener_null_response) {
reject(`Blob URL page opener wasn't null in not-same-top-level-site iframe.`);
}
// Attempt to click blob URL in same partition iframe.
await send(same_site_iframe_uuid, open_blob_url_window_via_a_click(blob_url));
const noopener_response_2 = await receive(noopener_response_queue);
if (noopener_response_2 !== opener_not_null_response) {
reject(`Blob URL page opener was null in same-top-level-site iframe`);
}
resolve();
} catch (e) {
reject(e);
}
});
}, "Blob URL link click should enforce noopener for a cross-top-level-site navigation");
const open_blob_url_window_via_area_click = (blob_url) => `
const canvas = document.createElement("canvas");
canvas.height = 1;
canvas.width = 1;
const dataURL = canvas.toDataURL();
const image = document.createElement("img");
image.src = dataURL;
document.body.appendChild(image);
const map = document.createElement("map");
map.name = "map";
image.useMap = "#map";
document.body.appendChild(map);
const area = document.createElement("area");
area.shape = "rect";
area.coords = "0,0,1,1";
area.href = "${blob_url}";
area.target = "_blank";
area.rel = "opener";
map.appendChild(area);
area.click();
`;
// Tests blob URL `<area target="_blank" rel="opener">` click for same and cross partition iframes.
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
// Creates same and cross partition iframes.
const noopener_response_queue = token();
const [cross_site_iframe_uuid, same_site_iframe_uuid] = await create_test_iframes(t, token());
const blob = new Blob([opener_check_frame_html(noopener_response_queue)], {type : "text/html"});
const blob_url = URL.createObjectURL(blob);
// Attempt to click blob URL in cross partition iframe.
await send(cross_site_iframe_uuid, open_blob_url_window_via_area_click(blob_url));
const noopener_response_1 = await receive(noopener_response_queue);
if (noopener_response_1 !== opener_null_response) {
reject(`Blob URL page opener wasn't null in not-same-top-level-site iframe.`);
}
// Attempt to click blob URL in same partition iframe.
await send(same_site_iframe_uuid, open_blob_url_window_via_area_click(blob_url));
const noopener_response_2 = await receive(noopener_response_queue);
if (noopener_response_2 !== opener_not_null_response) {
reject(`Blob URL page opener was null in same-top-level-site iframe`);
}
resolve();
} catch (e) {
reject(e);
}
});
}, "Blob URL area element click should enforce noopener for a cross-top-level-site navigation");
</script>
</body>
@@ -0,0 +1,76 @@
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<!-- Pull in executor_path needed by newPopup / newIframe -->
<script src="/html/cross-origin-embedder-policy/credentialless/resources/common.js"></script>
<!-- Pull in importScript / newPopup / newIframe -->
<script src="/html/anonymous-iframe/resources/common.js"></script>
<script src="resources/common.js"></script>
<body>
<script>
// Creates a Blob URL for an HTML document that fetches itself and sends the result to the
// specified response queue UUID. This is somewhat contrived but aims to test a more common
// scenario where a Blob URL with a video/audio mime type is navigated to and has an HTML document
// created for to allow media controls to be present. In that scenario the Blob URL will be used
// via a "src" attribute, resulting in a first-party resource load.
const create_blob_url_and_send_js = (fetch_response_uuid, iframe_response_uuid) => `
const blob_url_iframe_html = \`
<!doctype html>
<base href="\${window.location.href}">
<script src="/html/cross-origin-embedder-policy/credentialless/resources/common.js"><\/script>
<script src="/html/anonymous-iframe/resources/common.js"><\/script>
<script src="/common/utils.js"><\/script>
<script src="/common/dispatcher/dispatcher.js"><\/script>
<script>
(async () => {
try {
const response = await fetch(window.location.href);
await response.text();
send("${fetch_response_uuid}", "success");
} catch (e) {
send("${fetch_response_uuid}", "failure");
}
})();
<\/script>
\`;
const blob = new Blob([blob_url_iframe_html], {type: 'text/html'});
const blob_url = URL.createObjectURL(blob);
send("${iframe_response_uuid}", blob_url);
`;
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
const iframe_response_uuid = token();
const fetch_response_uuid = token();
const response_queue_uuid = token();
const [cross_site_iframe_uuid, same_site_iframe_uuid] =
await create_test_iframes(t, response_queue_uuid);
await send(cross_site_iframe_uuid,
create_blob_url_and_send_js(fetch_response_uuid, iframe_response_uuid));
const blob_url = await receive(iframe_response_uuid);
window.open(blob_url);
const fetch_result = await receive(fetch_response_uuid);
assert_equals(fetch_result, "success", "Blob URL created in a cross-partition context should be able to fetch itself in a same-partition context.");
resolve();
} catch (e) {
reject(e);
}
});
}, "Blob URL created in a cross-partition context can fetch itself in a same-partition context.");
</script>
</body>
@@ -0,0 +1,117 @@
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<!-- Pull in executor_path needed by newPopup / newIframe -->
<script src="/html/cross-origin-embedder-policy/credentialless/resources/common.js"></script>
<!-- Pull in importScript / newPopup / newIframe -->
<script src="/html/anonymous-iframe/resources/common.js"></script>
<script src="resources/common.js"></script>
<body>
<script>
const create_worker_unsuccessful = "Worker creation failed.";
const create_worker_successful = "Worker creation succeeded.";
const can_create_blob_url_shared_worker_js = (blob_url, response_queue_name) => `
const worker = new SharedWorker("${blob_url}");
worker.onerror = (e) => {
send("${response_queue_name}", "${create_worker_unsuccessful}");
};
worker.port.onmessage = (e) => {
send("${response_queue_name}", "${create_worker_successful}");
};
`;
// Tests cross-partition Shared Worker creation from blob URL.
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
const response_queue_uuid = token();
const [cross_site_iframe_uuid, same_site_iframe_uuid] =
await create_test_iframes(t, response_queue_uuid);
const worker_js = `
onconnect = function(e) {
e.ports[0].postMessage('ping');
self.close();
};
`;
const blob = new Blob([worker_js], {type : "text/javascript"});
const blob_url = window.URL.createObjectURL(blob);
t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));
// Create a shared worker in the cross-top-level-site iframe.
await send(cross_site_iframe_uuid, can_create_blob_url_shared_worker_js(blob_url, response_queue_uuid));
const response_1 = await receive(response_queue_uuid);
if (response_1 !== create_worker_unsuccessful) {
reject(`Shared worker was created in not-same-top-level-site iframe`);
}
// Create a shared worker in the same-top-level-site iframe.
await send(same_site_iframe_uuid, can_create_blob_url_shared_worker_js(blob_url, response_queue_uuid));
const response_2 = await receive(response_queue_uuid);
if (response_2 !== create_worker_successful) {
reject(`Shared worker wasn't created in same-top-level-site iframe`);
}
resolve();
} catch (e) {
reject(e);
}
});
}, "Cross-partition Shared worker shouldn't be created from blob URL.");
const can_create_blob_url_dedicated_worker_js = (blob_url, response_queue_name) => `
const worker = new Worker("${blob_url}");
worker.onerror = (e) => {
send("${response_queue_name}", "${create_worker_unsuccessful}");
};
worker.onmessage = (e) => {
send("${response_queue_name}", "${create_worker_successful}");
worker.terminate();
};
`;
// Tests cross-partition Dedicated Worker creation from blob URL.
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
const response_queue_uuid = token();
const [cross_site_iframe_uuid, same_site_iframe_uuid] =
await create_test_iframes(t, response_queue_uuid);
const blob = new Blob(["postMessage('ping');"], {type : "text/javascript"});
const blob_url = window.URL.createObjectURL(blob);
t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));
// Create a dedicated worker in the cross-top-level-site iframe.
await send(cross_site_iframe_uuid, can_create_blob_url_dedicated_worker_js(blob_url, response_queue_uuid));
const response_1 = await receive(response_queue_uuid);
if (response_1 !== create_worker_unsuccessful) {
reject(`Dedicated worker was created in not-same-top-level-site iframe`);
}
// Create a dedicated worker in the same-top-level-site iframe.
await send(same_site_iframe_uuid, can_create_blob_url_dedicated_worker_js(blob_url, response_queue_uuid));
const response_2 = await receive(response_queue_uuid);
if (response_2 !== create_worker_successful) {
reject(`Dedicated worker wasn't created in same-top-level-site iframe`);
}
resolve();
} catch (e) {
reject(e);
}
});
}, "Cross-partition Dedicated worker shouldn't be created from blob URL.");
</script>
</body>
@@ -0,0 +1,482 @@
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<!-- Pull in executor_path needed by newPopup / newIframe -->
<script src="/html/cross-origin-embedder-policy/credentialless/resources/common.js"></script>
<!-- Pull in importScript / newPopup / newIframe -->
<script src="/html/anonymous-iframe/resources/common.js"></script>
<script src="resources/common.js"></script>
<body>
<script>
const fetch_unsuccessful_response = "Fetch failed";
const fetch_successful_response = "Fetch succeeded";
const js_finished = "revoking blob_url js finished";
// Fetches a previously revoked blob_url to see if the revoking was successful.
async function fetch_contents_check(blob_url) {
try {
const blob = await fetch(blob_url).then(response => response.blob());
await blob.text();
} catch(e) {
return fetch_unsuccessful_response;
}
return fetch_successful_response;
}
const can_blob_url_be_revoked_js = (blob_url, response_queue_name) => `
async function test() {
if (!('revokeObjectURL' in URL)) {
return send("${response_queue_name}", "URL.revokeObjectURL is not exposed");
}
try {
URL.revokeObjectURL("${blob_url}");
} catch(e) {
return send("${response_queue_name}", e.toString());
}
// Create, fetch, and revoke a separate blob URL to better ensure that the
// revoke call above has had time to take effect before we return.
const blob_1 = new Blob(["blob data"], {type : "text/plain"});
const blob_url_1 = URL.createObjectURL(blob_1);
await fetch(blob_url_1).then(response => response.blob());
URL.revokeObjectURL(blob_url_1);
return send("${response_queue_name}", "${js_finished}");
}
await test();
`;
const can_blob_url_be_fetched_js = (blob_url, response_queue_name) => `
async function test() {
try {
const blob = await fetch("${blob_url}").then(response => response.blob());
await blob.text();
} catch(e) {
return send("${response_queue_name}", "${fetch_unsuccessful_response}");
}
return send("${response_queue_name}", "${fetch_successful_response}");
}
await test();
`;
const same_site_origin = get_host_info().HTTPS_ORIGIN;
// Tests revoking blob URL for same and cross partition iframes.
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
// Creates blob URL.
const blob = new Blob(["blob data"], {type : "text/plain"});
const blob_url = window.URL.createObjectURL(blob);
// Fetches blob URL to ensure that it's valid.
const blob_fetch = await fetch_contents_check(blob_url);
if (blob_fetch !== fetch_successful_response) {
reject("Blob URL invalid");
}
// Creates same and cross partition iframes.
const response_queue_uuid = token();
const [cross_site_iframe_uuid, same_site_iframe_uuid] =
await create_test_iframes(t, response_queue_uuid);
// Attempt to revoke blob URL in cross partition iframe.
await send(cross_site_iframe_uuid, can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
var response_1 = await receive(response_queue_uuid);
if (response_1 !== js_finished) {
reject(response_1);
}
response_1 = await fetch_contents_check(blob_url);
if (response_1 !== fetch_successful_response) {
reject(`Blob URL was revoked in not-same-top-level-site iframe: ${response_1}`);
}
// Attempt to revoke blob URL in same partition iframe.
await send(same_site_iframe_uuid, can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
var response_2 = await receive(response_queue_uuid);
if (response_2 !== js_finished) {
reject(response_2);
}
response_2 = await fetch_contents_check(blob_url);
if (response_2 !== fetch_unsuccessful_response) {
t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));
reject(`Blob URL wasn't revoked in same-top-level-site iframe: ${response_2}`);
}
resolve();
} catch (e) {
reject(e);
}
});
}, "Blob URL shouldn't be revocable from a cross-partition iframe");
const newWorker = (origin) => {
const worker_token = token();
const worker_url = origin + executor_worker_path + `&uuid=${worker_token}`;
const worker = new Worker(worker_url);
return worker_token;
}
const create_dedicated_worker_js = (origin, response_queue_uuid) => `
const importScript = ${importScript};
await importScript("/html/cross-origin-embedder-policy/credentialless" +
"/resources/common.js");
await importScript("/html/anonymous-iframe/resources/common.js");
await importScript("/common/utils.js");
// dispatcher.js has already been loaded by the popup this is running in.
const newWorker = ${newWorker};
await send("${response_queue_uuid}", newWorker("${origin}"));
`;
// Tests revoking blob URL from same and cross partition dedicated worker.
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
const response_queue_uuid = token();
const [cross_site_iframe_uuid, same_site_iframe_uuid] =
await create_test_iframes(t, response_queue_uuid);
await send(cross_site_iframe_uuid, create_dedicated_worker_js(same_site_origin, response_queue_uuid));
const worker_1_uuid = await receive(response_queue_uuid);
await send(same_site_iframe_uuid, create_dedicated_worker_js(same_site_origin, response_queue_uuid));
const worker_2_uuid = await receive(response_queue_uuid);
const blob = new Blob(["blob data"], {type : "text/plain"});
const blob_url = window.URL.createObjectURL(blob);
await send(worker_1_uuid, can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
var response_1 = await receive(response_queue_uuid);
if (response_1 !== js_finished) {
reject(response_1);
}
response_1 = await fetch_contents_check(blob_url);
if (response_1 !== fetch_successful_response) {
reject(`Blob URL was revoked in not-same-top-level-site dedicated worker: ${response_1}`);
}
await send(worker_2_uuid, can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
var response_2 = await receive(response_queue_uuid);
if (response_2 !== js_finished) {
reject(response_2);
}
response_2 = await fetch_contents_check(blob_url);
if (response_2 !== fetch_unsuccessful_response) {
t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));
reject(`Blob URL wasn't revoked in same-top-level-site dedicated worker: ${response_2}`);
}
resolve();
} catch (e) {
reject(e);
}
});
}, "Blob URL shouldn't be revocable from a cross-partition dedicated worker");
const newSharedWorker = (origin) => {
const worker_token = token();
const worker_url = origin + executor_worker_path + `&uuid=${worker_token}`;
const worker = new SharedWorker(worker_url, worker_token);
return worker_token;
}
const create_shared_worker_js = (origin, response_queue_uuid) => `
const importScript = ${importScript};
await importScript("/html/cross-origin-embedder-policy/credentialless" +
"/resources/common.js");
await importScript("/html/anonymous-iframe/resources/common.js");
await importScript("/common/utils.js");
// dispatcher.js has already been loaded by the popup this is running in.
const newSharedWorker = ${newSharedWorker};
await send("${response_queue_uuid}", newSharedWorker("${origin}"));
`;
// Tests revoking blob URL from same and cross partition shared worker.
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
const response_queue_uuid = token();
const [cross_site_iframe_uuid, same_site_iframe_uuid] =
await create_test_iframes(t, response_queue_uuid);
// Create a shared worker in the cross-top-level-site iframe.
await send(cross_site_iframe_uuid, create_shared_worker_js(same_site_origin, response_queue_uuid));
const worker_1_uuid = await receive(response_queue_uuid);
// Create a shared worker in the same-top-level-site iframe.
await send(same_site_iframe_uuid, create_shared_worker_js(same_site_origin, response_queue_uuid));
const worker_2_uuid = await receive(response_queue_uuid);
const blob = new Blob(["blob data"], {type : "text/plain"});
const blob_url = window.URL.createObjectURL(blob);
await send(worker_1_uuid, can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
var response_1 = await receive(response_queue_uuid);
if (response_1 !== js_finished) {
reject(response_1);
}
response_1 = await fetch_contents_check(blob_url);
if (response_1 !== fetch_successful_response) {
reject(`Blob URL was revoked in not-same-top-level-site shared worker: ${response_1}`);
}
await send(worker_2_uuid, can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
var response_2 = await receive(response_queue_uuid);
if (response_2 !== js_finished) {
reject(response_2);
}
response_2 = await fetch_contents_check(blob_url);
if (response_2 !== fetch_unsuccessful_response) {
t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));
reject(`Blob URL wasn't revoked in same-top-level-site shared worker: ${response_2}`);
}
resolve();
} catch (e) {
reject(e);
}
});
}, "Blob URL shouldn't be revocable from a cross-partition shared worker");
const newServiceWorker = async (origin) => {
const worker_token = token();
const worker_url = origin + executor_service_worker_path +
`&uuid=${worker_token}`;
const worker_url_path = executor_service_worker_path.substring(0,
executor_service_worker_path.lastIndexOf('/'));
const scope = worker_url_path + "/not-used/";
const reg = await navigator.serviceWorker.register(worker_url,
{'scope': scope});
return worker_token;
}
const create_service_worker_js = (origin, response_queue_uuid) => `
const importScript = ${importScript};
await importScript("/html/cross-origin-embedder-policy/credentialless" +
"/resources/common.js");
await importScript("/html/anonymous-iframe/resources/common.js");
await importScript("/common/utils.js");
// dispatcher.js has already been loaded by the popup this is running in.
const newServiceWorker = ${newServiceWorker};
await send("${response_queue_uuid}", await newServiceWorker("${origin}"));
`;
// Tests revoking blob URL from a service worker.
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
const response_queue_uuid = token();
const [cross_site_iframe_uuid, same_site_iframe_uuid] =
await create_test_iframes(t, response_queue_uuid);
// Create a service worker in either iframe.
await send(cross_site_iframe_uuid, create_service_worker_js(same_site_origin, response_queue_uuid));
var worker_1_uuid = await receive(response_queue_uuid);
t.add_cleanup(() =>
send(worker_1_uuid, "self.registration.unregister();"));
const blob = new Blob(["blob data"], {type : "text/plain"});
const blob_url = window.URL.createObjectURL(blob);
t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));
await send(worker_1_uuid,
can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
const response = await receive(response_queue_uuid);
if (response !== "URL.revokeObjectURL is not exposed") {
reject(`URL.revokeObjectURL is exposed in a Service Worker context: ${response}`);
}
resolve();
} catch (e) {
reject(e);
}
});
}, "Blob URL shouldn't be revocable from a service worker");
// Tests fetching blob URL for same and cross partition iframes.
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
// Creates blob URL.
const blob = new Blob(["blob data"], {type : "text/plain"});
const blob_url = window.URL.createObjectURL(blob);
t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));
// Fetches blob URL to ensure that it's valid.
const blob_fetch = await fetch_contents_check(blob_url);
if (blob_fetch !== fetch_successful_response) {
reject("Blob URL invalid");
}
// Creates same and cross partition iframes.
const response_queue_uuid = token();
const [cross_site_iframe_uuid, same_site_iframe_uuid] =
await create_test_iframes(t, response_queue_uuid);
// Attempt to fetch blob URL in cross partition iframe.
await send(cross_site_iframe_uuid, can_blob_url_be_fetched_js(blob_url, response_queue_uuid));
var response_1 = await receive(response_queue_uuid);
if (response_1 !== fetch_unsuccessful_response) {
reject(`Blob URL was fetched in not-same-top-level-site iframe: ${response_1}`);
}
// Attempt to fetch blob URL in same partition iframe.
await send(same_site_iframe_uuid, can_blob_url_be_fetched_js(blob_url, response_queue_uuid));
var response_2 = await receive(response_queue_uuid);
if (response_2 !== fetch_successful_response) {
reject(`Blob URL wasn't fetched in same-top-level-site iframe: ${response_2}`);
}
resolve();
} catch (e) {
reject(e);
}
});
}, "Blob URL shouldn't be fetched from a cross-partition iframe");
// Tests fetching blob URL from same and cross partition dedicated worker.
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
const response_queue_uuid = token();
// Creates same and cross partition iframes.
const [cross_site_iframe_uuid, same_site_iframe_uuid] =
await create_test_iframes(t, response_queue_uuid);
// Creates a dedicated worker in the cross-top-level-site iframe.
await send(cross_site_iframe_uuid, create_dedicated_worker_js(same_site_origin, response_queue_uuid));
const worker_1_uuid = await receive(response_queue_uuid);
// Creates a dedicated worker in the same-top-level-site iframe.
await send(same_site_iframe_uuid, create_dedicated_worker_js(same_site_origin, response_queue_uuid));
const worker_2_uuid = await receive(response_queue_uuid);
const blob = new Blob(["blob data"], {type : "text/plain"});
const blob_url = window.URL.createObjectURL(blob);
t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));
// Attempts to fetch in the cross-top-level-site dedicated worker.
await send(worker_1_uuid, can_blob_url_be_fetched_js(blob_url, response_queue_uuid));
var response_1 = await receive(response_queue_uuid);
if (response_1 !== fetch_unsuccessful_response) {
reject(`Blob URL was fetched in not-same-top-level-site dedicated worker: ${response_1}`);
}
// Attempts to fetch in the same-top-level-site dedicated worker.
await send(worker_2_uuid, can_blob_url_be_fetched_js(blob_url, response_queue_uuid));
var response_2 = await receive(response_queue_uuid);
if (response_2 !== fetch_successful_response) {
reject(`Blob URL wasn't fetched in same-top-level-site dedicated worker: ${response_2}`);
}
resolve();
} catch (e) {
reject(e);
}
});
}, "Blob URL shouldn't be fetched from a cross-partition dedicated worker");
// Tests fetching blob URL from same and cross partition shared worker.
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
const response_queue_uuid = token();
const [cross_site_iframe_uuid, same_site_iframe_uuid] =
await create_test_iframes(t, response_queue_uuid);
// Create a shared worker in the cross-top-level-site iframe.
await send(cross_site_iframe_uuid, create_shared_worker_js(same_site_origin, response_queue_uuid));
const worker_1_uuid = await receive(response_queue_uuid);
// Create a shared worker in the same-top-level-site iframe.
await send(same_site_iframe_uuid, create_shared_worker_js(same_site_origin, response_queue_uuid));
const worker_2_uuid = await receive(response_queue_uuid);
const blob = new Blob(["blob data"], {type : "text/plain"});
const blob_url = window.URL.createObjectURL(blob);
t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));
// Attempts to fetch in the cross-top-level-site shared worker.
await send(worker_1_uuid, can_blob_url_be_fetched_js(blob_url, response_queue_uuid));
var response_1 = await receive(response_queue_uuid);
if (response_1 !== fetch_unsuccessful_response) {
reject(`Blob URL was fetched in not-same-top-level-site shared worker: ${response_1}`);
}
// Attempts to fetch in the same-top-level-site shared worker.
await send(worker_2_uuid, can_blob_url_be_fetched_js(blob_url, response_queue_uuid));
var response_2 = await receive(response_queue_uuid);
if (response_2 !== fetch_successful_response) {
reject(`Blob URL wasn't fetched in same-top-level-site shared worker: ${response_2}`);
}
resolve();
} catch (e) {
reject(e);
}
});
}, "Blob URL shouldn't be fetched from a cross-partition shared worker");
// Tests fetching blob URL from a cross partition service worker.
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
const response_queue_uuid = token();
const [cross_site_iframe_uuid, same_site_iframe_uuid] =
await create_test_iframes(t, response_queue_uuid);
const blob = new Blob(["blob data"], {type : "text/plain"});
const blob_url = window.URL.createObjectURL(blob);
t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));
// Create a service worker in cross-top-level-site iframe.
await send(cross_site_iframe_uuid, create_service_worker_js(same_site_origin, response_queue_uuid));
var worker_1_uuid = await receive(response_queue_uuid);
t.add_cleanup(() =>
send(worker_1_uuid, "self.registration.unregister();"));
await send(worker_1_uuid,
can_blob_url_be_fetched_js(blob_url, response_queue_uuid));
const response_1 = await receive(response_queue_uuid);
if (response_1 !== fetch_unsuccessful_response) {
reject(`Blob URL was fetched in not-same-top-level-site service worker: ${response_1}`);
}
// Create a service worker in same-top-level-site iframe.
await send(same_site_iframe_uuid, create_service_worker_js(same_site_origin, response_queue_uuid));
var worker_2_uuid = await receive(response_queue_uuid);
t.add_cleanup(() =>
send(worker_2_uuid, "self.registration.unregister();"));
await send(worker_2_uuid,
can_blob_url_be_fetched_js(blob_url, response_queue_uuid));
const response_2 = await receive(response_queue_uuid);
if (response_2 !== fetch_successful_response) {
reject(`Blob URL wasn't fetched in same-top-level-site service worker: ${response_2}`);
}
resolve();
} catch (e) {
reject(e);
}
});
}, "Blob URL shouldn't be fetched from a cross-partition service worker");
</script>
</body>
@@ -1,276 +0,0 @@
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<!-- Pull in executor_path needed by newPopup / newIframe -->
<script src="/html/cross-origin-embedder-policy/credentialless/resources/common.js"></script>
<!-- Pull in importScript / newPopup / newIframe -->
<script src="/html/anonymous-iframe/resources/common.js"></script>
<body>
<script>
const did_revoke_response = "URL.revokeObjectURL did revoke";
const did_not_revoke_response = "URL.revokeObjectURL did not revoke";
const can_blob_url_be_revoked_js = (blob_url, response_queue_name) => `
async function test() {
if (!('revokeObjectURL' in URL)) {
return send("${response_queue_name}", "URL.revokeObjectURL is not exposed");
}
try {
var blob = await fetch("${blob_url}").then(response => response.blob());
await blob.text();
} catch {
return send("${response_queue_name}", "Blob URL invalid");
}
try {
URL.revokeObjectURL("${blob_url}");
} catch(e) {
return send("${response_queue_name}", e.toString());
}
try {
const blob = await fetch("${blob_url}").then(response => response.blob());
} catch(e) {
return send("${response_queue_name}", "${did_revoke_response}");
}
return send("${response_queue_name}", "${did_not_revoke_response}");
}
await test();
`;
const add_iframe_js = (iframe_origin, response_queue_uuid) => `
const importScript = ${importScript};
await importScript("/html/cross-origin-embedder-policy/credentialless" +
"/resources/common.js");
await importScript("/html/anonymous-iframe/resources/common.js");
await importScript("/common/utils.js");
await send("${response_queue_uuid}", newIframe("${iframe_origin}"));
`;
const same_site_origin = get_host_info().HTTPS_ORIGIN;
const cross_site_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
async function create_test_iframes(t, response_queue_uuid) {
// Create a same-origin iframe in a cross-site popup.
const not_same_site_popup_uuid = newPopup(t, cross_site_origin);
await send(not_same_site_popup_uuid,
add_iframe_js(same_site_origin, response_queue_uuid));
const iframe_1_uuid = await receive(response_queue_uuid);
// Create a same-origin iframe in a same-site popup.
const same_origin_popup_uuid = newPopup(t, same_site_origin);
await send(same_origin_popup_uuid,
add_iframe_js(same_site_origin, response_queue_uuid));
const iframe_2_uuid = await receive(response_queue_uuid);
return [iframe_1_uuid, iframe_2_uuid];
}
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
const response_queue_uuid = token();
const [iframe_1_uuid, iframe_2_uuid] =
await create_test_iframes(t, response_queue_uuid);
const blob = new Blob(["blob data"], {type : "text/plain"});
const blob_url = window.URL.createObjectURL(blob);
t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));
await send(iframe_1_uuid,
can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
var response = await receive(response_queue_uuid);
if (response !== did_not_revoke_response) {
reject(`Blob URL was revoked in not-same-top-level-site iframe: ${response}`);
}
await send(iframe_2_uuid,
can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
response = await receive(response_queue_uuid);
if (response !== did_revoke_response) {
reject(`Blob URL wasn't revoked in same-top-level-site iframe: ${response}`);
}
resolve();
} catch (e) {
reject(e);
}
});
}, "Blob URL shouldn't be revocable from a cross-partition iframe");
const newWorker = (origin) => {
const worker_token = token();
const worker_url = origin + executor_worker_path + `&uuid=${worker_token}`;
const worker = new Worker(worker_url);
return worker_token;
}
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
const response_queue_uuid = token();
const create_worker_js = (origin) => `
const importScript = ${importScript};
await importScript("/html/cross-origin-embedder-policy/credentialless" +
"/resources/common.js");
await importScript("/html/anonymous-iframe/resources/common.js");
await importScript("/common/utils.js");
const newWorker = ${newWorker};
await send("${response_queue_uuid}", newWorker("${origin}"));
`;
const [iframe_1_uuid, iframe_2_uuid] =
await create_test_iframes(t, response_queue_uuid);
// Create a dedicated worker in the cross-top-level-site iframe.
await send(iframe_1_uuid, create_worker_js(same_site_origin));
const worker_1_uuid = await receive(response_queue_uuid);
// Create a dedicated worker in the same-top-level-site iframe.
await send(iframe_2_uuid, create_worker_js(same_site_origin));
const worker_2_uuid = await receive(response_queue_uuid);
const blob = new Blob(["blob data"], {type : "text/plain"});
const blob_url = window.URL.createObjectURL(blob);
t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));
await send(worker_1_uuid,
can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
var response = await receive(response_queue_uuid);
if (response !== did_not_revoke_response) {
reject(`Blob URL was revoked in not-same-top-level-site dedicated worker: ${response}`);
}
await send(worker_2_uuid,
can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
response = await receive(response_queue_uuid);
if (response !== did_revoke_response) {
reject(`Blob URL wasn't revoked in same-top-level-site dedicated worker: ${response}`);
}
resolve();
} catch (e) {
reject(e);
}
});
}, "Blob URL shouldn't be revocable from a cross-partition dedicated worker");
const newSharedWorker = (origin) => {
const worker_token = token();
const worker_url = origin + executor_worker_path + `&uuid=${worker_token}`;
const worker = new SharedWorker(worker_url, worker_token);
return worker_token;
}
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
const response_queue_uuid = token();
const create_worker_js = (origin) => `
const importScript = ${importScript};
await importScript("/html/cross-origin-embedder-policy/credentialless" +
"/resources/common.js");
await importScript("/html/anonymous-iframe/resources/common.js");
await importScript("/common/utils.js");
const newSharedWorker = ${newSharedWorker};
await send("${response_queue_uuid}", newSharedWorker("${origin}"));
`;
const [iframe_1_uuid, iframe_2_uuid] =
await create_test_iframes(t, response_queue_uuid);
// Create a shared worker in the cross-top-level-site iframe.
await send(iframe_1_uuid, create_worker_js(same_site_origin));
const worker_1_uuid = await receive(response_queue_uuid);
// Create a shared worker in the same-top-level-site iframe.
await send(iframe_2_uuid, create_worker_js(same_site_origin));
const worker_2_uuid = await receive(response_queue_uuid);
const blob = new Blob(["blob data"], {type : "text/plain"});
const blob_url = window.URL.createObjectURL(blob);
t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));
await send(worker_1_uuid,
can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
var response = await receive(response_queue_uuid);
if (response !== did_not_revoke_response) {
reject(`Blob URL was revoked in not-same-top-level-site shared worker: ${response}`);
}
await send(worker_2_uuid,
can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
response = await receive(response_queue_uuid);
if (response !== did_revoke_response) {
reject(`Blob URL wasn't revoked in same-top-level-site shared worker: ${response}`);
}
resolve();
} catch (e) {
reject(e);
}
});
}, "Blob URL shouldn't be revocable from a cross-partition shared worker");
const newServiceWorker = async (origin) => {
const worker_token = token();
const worker_url = origin + executor_service_worker_path +
`&uuid=${worker_token}`;
const worker_url_path = executor_service_worker_path.substring(0,
executor_service_worker_path.lastIndexOf('/'));
const scope = worker_url_path + "/not-used/";
const reg = await navigator.serviceWorker.register(worker_url,
{'scope': scope});
return worker_token;
}
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
const response_queue_uuid = token();
const create_worker_js = (origin) => `
const importScript = ${importScript};
await importScript("/html/cross-origin-embedder-policy/credentialless" +
"/resources/common.js");
await importScript("/html/anonymous-iframe/resources/common.js");
await importScript("/common/utils.js");
const newServiceWorker = ${newServiceWorker};
await send("${response_queue_uuid}", await newServiceWorker("${origin}"));
`;
const [iframe_1_uuid, iframe_2_uuid] =
await create_test_iframes(t, response_queue_uuid);
// Create a service worker in either iframe.
await send(iframe_1_uuid, create_worker_js(same_site_origin));
var worker_1_uuid = await receive(response_queue_uuid);
t.add_cleanup(() =>
send(worker_1_uuid, "self.registration.unregister();"));
const blob = new Blob(["blob data"], {type : "text/plain"});
const blob_url = window.URL.createObjectURL(blob);
t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));
await send(worker_1_uuid,
can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
const response = await receive(response_queue_uuid);
if (response !== "URL.revokeObjectURL is not exposed") {
reject(`URL.revokeObjectURL is exposed in a Service Worker context: ${response}`);
}
resolve();
} catch (e) {
reject(e);
}
});
}, "Blob URL shouldn't be revocable from a service worker");
</script>
</body>
+33
View File
@@ -0,0 +1,33 @@
const add_iframe_js = (iframe_origin, response_queue_uuid) => `
const importScript = ${importScript};
await importScript("/html/cross-origin-embedder-policy/credentialless" +
"/resources/common.js");
await importScript("/html/anonymous-iframe/resources/common.js");
await importScript("/common/utils.js");
// dispatcher.js has already been loaded by the popup this is running in.
await send("${response_queue_uuid}", newIframe("${iframe_origin}"));
`;
async function create_test_iframes(t, response_queue_uuid) {
const same_site_origin = get_host_info().HTTPS_ORIGIN;
const cross_site_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
assert_equals("https://" + window.location.host, same_site_origin,
"this test assumes that the page's window.location.host corresponds to " +
"get_host_info().HTTPS_ORIGIN");
// Create a same-origin iframe in a cross-site popup.
const not_same_site_popup_uuid = newPopup(t, cross_site_origin);
await send(not_same_site_popup_uuid,
add_iframe_js(same_site_origin, response_queue_uuid));
const cross_site_iframe_uuid = await receive(response_queue_uuid);
// Create a same-origin iframe in a same-site popup.
const same_origin_popup_uuid = newPopup(t, same_site_origin);
await send(same_origin_popup_uuid,
add_iframe_js(same_site_origin, response_queue_uuid));
const same_site_iframe_uuid = await receive(response_queue_uuid);
return [cross_site_iframe_uuid, same_site_iframe_uuid];
}
Whitespace-only changes.
+3
View File
@@ -0,0 +1,3 @@
features:
- name: file
files: "**"
+63 -2
View File
@@ -104,6 +104,59 @@ test_blob(function() {
desc: "A Uint8Array object should be treated as a sequence for the blobParts argument."
});
test(function() {
assert_throws_js(TypeError, function() { new Blob(true) });
}, "blobParts not an object: boolean");
test(function() {
Boolean.prototype[Symbol.iterator] = () => ["FAIL"][Symbol.iterator]()
this.add_cleanup(function() { delete Boolean.prototype[Symbol.iterator] });
assert_throws_js(TypeError, function() { new Blob(true) });
}, "blobParts not an object: boolean with Boolean.prototype[Symbol.iterator]");
test(function() {
assert_throws_js(TypeError, function() { new Blob("fail") });
}, "blobParts not an object: string");
test(function() {
const original = String.prototype[Symbol.iterator];
String.prototype[Symbol.iterator] = () => ["FAIL"][Symbol.iterator]()
this.add_cleanup(function() { String.prototype[Symbol.iterator] = original });
assert_throws_js(TypeError, function() { new Blob("fail") });
}, "blobParts not an object: string with String.prototype[Symbol.iterator]");
test(function() {
assert_throws_js(TypeError, function() { new Blob(7) });
}, "blobParts not an object: number");
test(function() {
Number.prototype[Symbol.iterator] = () => ["FAIL"][Symbol.iterator]()
this.add_cleanup(function() { delete Number.prototype[Symbol.iterator] });
assert_throws_js(TypeError, function() { new Blob(7) });
}, "blobParts not an object: number with Number.prototype[Symbol.iterator]");
test(function() {
assert_throws_js(TypeError, function() { new Blob(7n) });
}, "blobParts not an object: BigInt");
test(function() {
BigInt.prototype[Symbol.iterator] = () => ["FAIL"][Symbol.iterator]()
this.add_cleanup(function() { delete BigInt.prototype[Symbol.iterator] });
assert_throws_js(TypeError, function() { new Blob(7n) });
}, "blobParts not an object: BigInt with BigInt.prototype[Symbol.iterator]");
test(function() {
const symbol = Symbol();
assert_throws_js(TypeError, function() { new Blob(symbol) });
}, "blobParts not an object: Symbol");
test(function() {
const symbol = Symbol();
Symbol.prototype[Symbol.iterator] = () => ["FAIL"][Symbol.iterator]()
this.add_cleanup(function() { delete Symbol.prototype[Symbol.iterator] });
assert_throws_js(TypeError, function() { new Blob(symbol) });
}, "blobParts not an object: Symbol with Symbol.prototype[Symbol.iterator]");
var test_error = {
name: "test",
message: "test error",
@@ -290,14 +343,22 @@ test_blob(function() {
new Int16Array([0x4150, 0x5353]),
new Uint32Array([0x53534150]),
new Int32Array([0x53534150]),
new Float16Array([2.65625, 58.59375]),
new Float32Array([0xD341500000])
]);
}, {
expected: "PASSPASSPASSPASSPASSPASSPASSPASS",
expected: "PASSPASSPASSPASSPASSPASSPASS",
type: "",
desc: "Passing typed arrays as elements of the blobParts array should work."
});
test_blob(function() {
return new Blob([
new Float16Array([2.65625, 58.59375])
]);
}, {
expected: "PASS",
type: "",
desc: "Passing a Float16Array as element of the blobParts array should work."
});
test_blob(function() {
return new Blob([
// 0x535 3415053534150
+12
View File
@@ -0,0 +1,12 @@
// META: title=Blob methods return new objects ([NewObject])
// META: global=window,worker
'use strict';
['stream', 'text', 'arrayBuffer', 'bytes'].forEach(method => {
test(() => {
const blob = new Blob(['PASS']);
const a = blob[method]();
const b = blob[method]();
assert_not_equals(a, b, `Blob.${method}() must return a new object`);
}, `Blob.${method}() returns [NewObject]`);
});
+48 -7
View File
@@ -12,24 +12,50 @@ test_blob(function() {
});
test(function() {
var blob1, blob2;
var blob1 = new Blob(["squiggle"]);
var blob2 = new Blob(["steak"], {type: "content/type"});
test_blob(function() {
return blob1 = new Blob(["squiggle"]);
}, {
test_blob(() => blob1,
{
expected: "squiggle",
type: "",
desc: "blob1."
});
test_blob(function() {
return blob2 = new Blob(["steak"], {type: "content/type"});
}, {
test_blob(() => blob2,
{
expected: "steak",
type: "content/type",
desc: "blob2."
});
test_blob(function() {
var blob = new Blob(["abcd"]);
return blob.slice(undefined, undefined, "content/type");
}, {
expected: "abcd",
type: "content/type",
desc: "undefined start/end Blob slice"
});
test_blob(function() {
var blob = new Blob(["abcd"]);
return blob.slice(undefined, 2, "content/type");
}, {
expected: "ab",
type: "content/type",
desc: "undefined start Blob slice"
});
test_blob(function() {
var blob = new Blob(["abcd"]);
return blob.slice(2, undefined, "content/type");
}, {
expected: "cd",
type: "content/type",
desc: "undefined end Blob slice"
});
test_blob(function() {
return new Blob().slice(0,0,null);
}, {
@@ -74,6 +100,21 @@ test(function() {
{start: 7, end: 4, contents: ""}]
],
// Test double start/end values
[
["abcd"],
[{start: 0.5, contents: "abcd"},
{start: 1.5, contents: "cd"},
{start: 2.5, contents: "cd"},
{start: 3.5, contents: ""},
{start: 0, end: 0.5, contents: ""},
{start: 0, end: 1.5, contents: "ab"},
{start: 0, end: 2.5, contents: "ab"},
{start: 0, end: 3.5, contents: "abcd"},
{start: 1.5, end: 2.5, contents: ""},
{start: 1.5, end: 3.5, contents: "cd"}]
],
// Test 3 strings
[
["foo", "bar", "baz"],
@@ -7,6 +7,7 @@
reader.onload = this.step_func(function(evt) {
assert_equals(reader.result.byteLength, 4, "The byteLength is 4");
assert_true(reader.result instanceof ArrayBuffer, "The result is instanceof ArrayBuffer");
assert_array_equals(new Uint8Array(reader.result), [84, 69, 83, 84]);
assert_equals(reader.readyState, reader.DONE);
this.done();
});
+10 -24
View File
@@ -5,23 +5,16 @@ self.test_blob = (fn, expectations) => {
type = expectations.type,
desc = expectations.desc;
var t = async_test(desc);
t.step(function() {
promise_test(async (t) => {
var blob = fn();
assert_true(blob instanceof Blob);
assert_false(blob instanceof File);
assert_equals(blob.type, type);
assert_equals(blob.size, expected.length);
var fr = new FileReader();
fr.onload = t.step_func_done(function(event) {
assert_equals(this.result, expected);
}, fr);
fr.onerror = t.step_func(function(e) {
assert_unreached("got error event on FileReader");
});
fr.readAsText(blob, "UTF-8");
});
const text = await blob.text();
assert_equals(text, expected);
}, desc);
}
self.test_blob_binary = (fn, expectations) => {
@@ -29,25 +22,18 @@ self.test_blob_binary = (fn, expectations) => {
type = expectations.type,
desc = expectations.desc;
var t = async_test(desc);
t.step(function() {
promise_test(async (t) => {
var blob = fn();
assert_true(blob instanceof Blob);
assert_false(blob instanceof File);
assert_equals(blob.type, type);
assert_equals(blob.size, expected.length);
var fr = new FileReader();
fr.onload = t.step_func_done(function(event) {
assert_true(this.result instanceof ArrayBuffer,
"Result should be an ArrayBuffer");
assert_array_equals(new Uint8Array(this.result), expected);
}, fr);
fr.onerror = t.step_func(function(e) {
assert_unreached("got error event on FileReader");
});
fr.readAsArrayBuffer(blob);
});
const ab = await blob.arrayBuffer();
assert_true(ab instanceof ArrayBuffer,
"Result should be an ArrayBuffer");
assert_array_equals(new Uint8Array(ab), expected);
}, desc);
}
// Assert that two TypedArray objects have the same byte values
+1 -1
View File
@@ -180,7 +180,7 @@ const formPostFileUploadTest = ({
// Used to verify that the browser agrees with the test about
// field value replacement and encoding independently of file system
// idiosyncrasies.
// idiosyncracies.
form.append(Object.assign(document.createElement('input'), {
type: 'hidden',
name: 'filename',
@@ -34,7 +34,7 @@ const formDataPostFileUploadTest = ({
// Used to verify that the browser agrees with the test about
// field value replacement and encoding independently of file system
// idiosyncrasies.
// idiosyncracies.
formData.append("filename", fileBaseName);
// Same, but with name and value reversed to ensure field names
+7
View File
@@ -1,3 +1,10 @@
setup(() => {
const viewport_meta = document.createElement('meta');
viewport_meta.name = "viewport";
viewport_meta.content = "width=device-width,initial-scale=1";
document.head.appendChild(viewport_meta);
});
async_test(t => {
const run_result = 'test_script_OK';
const blob_contents = 'window.test_result = "' + run_result + '";';
+1 -1
View File
@@ -17,7 +17,7 @@ Last update:
- dom/events: https://github.com/web-platform-tests/wpt/tree/0a811c5161/dom/events
- encoding: https://github.com/web-platform-tests/wpt/tree/1ac8deee08/encoding
- fetch/data-urls/resources: https://github.com/web-platform-tests/wpt/tree/7c79d998ff/fetch/data-urls/resources
- FileAPI: https://github.com/web-platform-tests/wpt/tree/cceaf3628d/FileAPI
- FileAPI: https://github.com/web-platform-tests/wpt/tree/7f51301888/FileAPI
- hr-time: https://github.com/web-platform-tests/wpt/tree/34cafd797e/hr-time
- html/webappapis/atob: https://github.com/web-platform-tests/wpt/tree/f267e1dca6/html/webappapis/atob
- html/webappapis/microtask-queuing: https://github.com/web-platform-tests/wpt/tree/2c5c3c4c27/html/webappapis/microtask-queuing
+1 -1
View File
@@ -28,7 +28,7 @@
"path": "fetch/data-urls/resources"
},
"FileAPI": {
"commit": "cceaf3628da950621004d9b5d8c1d1f367073347",
"commit": "7f5130188818b6c12c636491186b459ec2bf131f",
"path": "FileAPI"
},
"hr-time": {
+21 -30
View File
@@ -4,38 +4,20 @@
},
"Blob-constructor.any.js": {
"fail": {
"note": "Depends on File API",
"expected": [
"A plain object with @@iterator should be treated as a sequence for the blobParts argument.",
"A plain object with @@iterator and a length property should be treated as a sequence for the blobParts argument.",
"A String object should be treated as a sequence for the blobParts argument.",
"A Uint8Array object should be treated as a sequence for the blobParts argument.",
"blobParts not an object: boolean with Boolean.prototype[Symbol.iterator]",
"blobParts not an object: number with Number.prototype[Symbol.iterator]",
"blobParts not an object: BigInt with BigInt.prototype[Symbol.iterator]",
"blobParts not an object: Symbol with Symbol.prototype[Symbol.iterator]",
"Getters and value conversions should happen in order until an exception is thrown.",
"Changes to the blobParts array should be reflected in the returned Blob (pop).",
"Changes to the blobParts array should be reflected in the returned Blob (unshift).",
"ToString should be called on elements of the blobParts array.",
"ArrayBuffer elements of the blobParts array should be supported.",
"Passing typed arrays as elements of the blobParts array should work.",
"Passing a Float64Array as element of the blobParts array should work.",
"Passing BigInt typed arrays as elements of the blobParts array should work.",
"Array with two blobs",
"Array with two buffers",
"Array with two bufferviews",
"Array with mixed types",
"options properties should be accessed in lexicographic order.",
"Arguments should be evaluated from left to right.",
"Passing null (index 0) for options should use the defaults.",
"Passing null (index 0) for options should use the defaults (with newlines).",
"Passing undefined (index 1) for options should use the defaults.",
"Passing undefined (index 1) for options should use the defaults (with newlines).",
"Passing object \"[object Object]\" (index 2) for options should use the defaults.",
"Passing object \"[object Object]\" (index 2) for options should use the defaults (with newlines).",
"Passing object \"[object Object]\" (index 3) for options should use the defaults.",
"Passing object \"[object Object]\" (index 3) for options should use the defaults (with newlines).",
"Passing object \"/regex/\" (index 4) for options should use the defaults.",
"Passing object \"/regex/\" (index 4) for options should use the defaults (with newlines).",
"Passing function \"function() {}\" (index 5) for options should use the defaults.",
"Passing function \"function() {}\" (index 5) for options should use the defaults (with newlines)."
"Arguments should be evaluated from left to right."
],
"flaky": [
"Passing typed arrays as elements of the blobParts array should work.",
"Passing a Float16Array as element of the blobParts array should work.",
"Passing a Float64Array as element of the blobParts array should work.",
"Passing BigInt typed arrays as elements of the blobParts array should work."
]
}
},
@@ -43,6 +25,15 @@
"skip": "Depends on Web Workers API"
},
"Blob-slice.any.js": {
"skip": "Depends on File API"
"fail": {
"expected": [
"Slicing test: slice (1,1).",
"Slicing test: slice (1,3).",
"Slicing test: slice (1,5).",
"Slicing test: slice (1,7).",
"Slicing test: slice (1,8).",
"Slicing test: slice (1,9)."
]
}
}
}