summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/FileAPI/BlobURL
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/FileAPI/BlobURL')
-rw-r--r--testing/web-platform/tests/FileAPI/BlobURL/cross-partition.tentative.https.html276
-rw-r--r--testing/web-platform/tests/FileAPI/BlobURL/support/file_test2.txt0
-rw-r--r--testing/web-platform/tests/FileAPI/BlobURL/test2-manual.html62
3 files changed, 338 insertions, 0 deletions
diff --git a/testing/web-platform/tests/FileAPI/BlobURL/cross-partition.tentative.https.html b/testing/web-platform/tests/FileAPI/BlobURL/cross-partition.tentative.https.html
new file mode 100644
index 0000000000..c75ce07d05
--- /dev/null
+++ b/testing/web-platform/tests/FileAPI/BlobURL/cross-partition.tentative.https.html
@@ -0,0 +1,276 @@
+<!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>
diff --git a/testing/web-platform/tests/FileAPI/BlobURL/support/file_test2.txt b/testing/web-platform/tests/FileAPI/BlobURL/support/file_test2.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/testing/web-platform/tests/FileAPI/BlobURL/support/file_test2.txt
diff --git a/testing/web-platform/tests/FileAPI/BlobURL/test2-manual.html b/testing/web-platform/tests/FileAPI/BlobURL/test2-manual.html
new file mode 100644
index 0000000000..07fb27ef8a
--- /dev/null
+++ b/testing/web-platform/tests/FileAPI/BlobURL/test2-manual.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Blob and File reference URL Test(2)</title>
+ <link rel=help href="http://dev.w3.org/2006/webapi/FileAPI/#convenienceAPI">
+ <link rel=author title="Breezewish" href="mailto:me@breeswish.org">
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+</head>
+<body>
+ <form name="upload">
+ <input type="file" id="fileChooser"><br><input type="button" id="start" value="start">
+ </form>
+
+ <div>
+ <p>Test steps:</p>
+ <ol>
+ <li>Download the <a href="support/file_test2.txt">file</a>.</li>
+ <li>Select the file in the file inputbox.</li>
+ <li>Delete the file.</li>
+ <li>Click the 'start' button.</li>
+ </ol>
+ </div>
+
+ <div id="log"></div>
+
+ <script>
+
+ var fileChooser = document.querySelector('#fileChooser');
+
+ setup({explicit_done: true});
+ setup({explicit_timeout: true});
+
+ on_event(document.querySelector('#start'), 'click', function() {
+
+ async_test(function(t) {
+
+ var url = URL.createObjectURL(fileChooser.files[0]);
+
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', url, true);
+ xhr.onreadystatechange = t.step_func(function() {
+ switch (xhr.readyState) {
+ case xhr.DONE:
+ assert_equals(xhr.status, 500, 'status code should be 500.');
+ t.done();
+ return;
+ }
+ });
+
+ xhr.send();
+
+ }, 'Check whether the browser response 500 in XHR if the selected file which File/Blob URL refered is not found');
+
+ done();
+
+ });
+
+ </script>
+</body>
+</html>