From 45dd7255db5f8f95549679fa212665d3125a23be Mon Sep 17 00:00:00 2001 From: Ari Chivukula Date: Mon, 8 Apr 2024 17:02:26 +0000 Subject: [PATCH] Bug 1888518 [wpt PR 45413] - [SAA] Use async functions in wpts where possible, a=testonly Automatic update from web-platform-tests [SAA] Use async functions in wpts where possible It's still easier to keep the top level as an async_test (which cannot be async), but the inner functions can be async as needed. Bug: 40282415 Change-Id: I6001912cf2510e140f7980154e24705a30088cc4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5402469 Reviewed-by: Dylan Cutler Commit-Queue: Ari Chivukula Auto-Submit: Ari Chivukula Cr-Commit-Position: refs/heads/main@{#1280016} -- wpt-commits: 4f6add9c038f36f063a8fb5dbff015a376fec0ce wpt-pr: 45413 --- ...SharedWorker.tentative.sub.https.window.js | 7 +++---- ...okies.caches.tentative.sub.https.window.js | 20 +++++++++---------- ...kies.cookies.tentative.sub.https.window.js | 7 +++---- ...ies.estimate.tentative.sub.https.window.js | 20 +++++++++---------- ...getDirectory.tentative.sub.https.window.js | 13 ++++++------ 5 files changed, 30 insertions(+), 37 deletions(-) diff --git a/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.SharedWorker.tentative.sub.https.window.js b/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.SharedWorker.tentative.sub.https.window.js index ed4f25517f716..613a47ba1b7c5 100644 --- a/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.SharedWorker.tentative.sub.https.window.js +++ b/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.SharedWorker.tentative.sub.https.window.js @@ -30,11 +30,10 @@ async_test(t => { assert_equals(e.data, "Same-origin handle access", "Relay worker should divert messages here"); // Step 8 const cookie_worker = new SharedWorker("/storage-access-api/resources/shared-worker-cookies.py", {name: id, sameSiteCookies: 'none'}); - cookie_worker.port.onmessage = t.step_func(e => { + cookie_worker.port.onmessage = t.step_func(async (e) => { assert_equals(e.data, "ReadOnLoad:None,ReadOnFetch:None,ConnectionsMade:2", "Worker should already have been opened and only see SameSite=None cookies"); - test_driver.delete_all_cookies().then(t.step_func(() => { - t.done(); - })); + await test_driver.delete_all_cookies(); + t.done(); }); }); diff --git a/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.caches.tentative.sub.https.window.js b/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.caches.tentative.sub.https.window.js index 2d85cdd1615d0..51e5c648a64cd 100644 --- a/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.caches.tentative.sub.https.window.js +++ b/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.caches.tentative.sub.https.window.js @@ -15,15 +15,14 @@ async_test(t => { // Step 1 - window.addEventListener("message", t.step_func(e => { + window.addEventListener("message", t.step_func((e) => { if (e.data.type != "result") { return; } // Step 8 assert_equals(e.data.message, "HasAccess for caches", "Storage Access API should be accessible and return first-party data"); - test_driver.delete_all_cookies().then(t.step_func(() => { - t.done(); - })); + t.add_cleanup(() => {test_driver.delete_all_cookies();}); + t.done(); })); // Step 2 @@ -32,12 +31,11 @@ async_test(t => { document.cookie = "samesite_lax=test; SameSite=Lax; Secure"; document.cookie = "samesite_none=test; SameSite=None; Secure"; - window.caches.open(id).then((cache) => { - cache.add("https://{{hosts[][]}}:{{ports[https][0]}}/storage-access-api/resources/get_cookies.py?1").then(() => { - // Step 3 - let iframe = document.createElement("iframe"); - iframe.src = "https://{{hosts[alt][]}}:{{ports[https][0]}}/storage-access-api/resources/storage-access-beyond-cookies-iframe.sub.html?type=caches&id="+id; - document.body.appendChild(iframe); - }); + window.caches.open(id).then(async (cache) => { + await cache.add("https://{{hosts[][]}}:{{ports[https][0]}}/storage-access-api/resources/get_cookies.py?1"); + // Step 3 + let iframe = document.createElement("iframe"); + iframe.src = "https://{{hosts[alt][]}}:{{ports[https][0]}}/storage-access-api/resources/storage-access-beyond-cookies-iframe.sub.html?type=caches&id="+id; + document.body.appendChild(iframe); }); }, "Verify StorageAccessAPIBeyondCookies for Cache Storage"); diff --git a/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.cookies.tentative.sub.https.window.js b/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.cookies.tentative.sub.https.window.js index 1ff00fa91938d..ad760cfda7d8e 100644 --- a/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.cookies.tentative.sub.https.window.js +++ b/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.cookies.tentative.sub.https.window.js @@ -15,15 +15,14 @@ async_test(t => { // Step 1 - window.addEventListener("message", t.step_func(e => { + window.addEventListener("message", t.step_func((e) => { if (e.data.type != "result") { return; } // Step 8 assert_equals(e.data.message, "HasAccess for cookies", "Storage Access API should be accessible and return first-party data"); - test_driver.delete_all_cookies().then(t.step_func(() => { - t.done(); - })); + t.add_cleanup(() => {test_driver.delete_all_cookies();}); + t.done(); })); // Step 2 diff --git a/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.estimate.tentative.sub.https.window.js b/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.estimate.tentative.sub.https.window.js index fb15dfee09288..eb8cb0c68d0ad 100644 --- a/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.estimate.tentative.sub.https.window.js +++ b/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.estimate.tentative.sub.https.window.js @@ -17,24 +17,22 @@ async_test(t => { const id = "test"; // Step 1 - window.addEventListener("message", t.step_func(e => { + window.addEventListener("message", t.step_func((e) => { if (e.data.type != "result") { return; } // Step 8 assert_equals(e.data.message, "HasAccess for estimate", "Storage Access API should be accessible and return first-party data"); - caches.delete(id).then(() => { - t.done(); - }); + t.add_cleanup(() => {caches.delete(id);}); + t.done(); })); // Step 2 - window.caches.open(id).then((cache) => { - cache.put('/test.json', new Response('x'.repeat(1024*1024))).then(() => { - // Step 3 - let iframe = document.createElement("iframe"); - iframe.src = "https://{{hosts[alt][]}}:{{ports[https][0]}}/storage-access-api/resources/storage-access-beyond-cookies-iframe.sub.html?type=estimate&id="+id; - document.body.appendChild(iframe); - }); + window.caches.open(id).then(async (cache) => { + await cache.put('/test.json', new Response('x'.repeat(1024*1024))); + // Step 3 + let iframe = document.createElement("iframe"); + iframe.src = "https://{{hosts[alt][]}}:{{ports[https][0]}}/storage-access-api/resources/storage-access-beyond-cookies-iframe.sub.html?type=estimate&id="+id; + document.body.appendChild(iframe); }); }, "Verify StorageAccessAPIBeyondCookies for Quota"); diff --git a/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.getDirectory.tentative.sub.https.window.js b/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.getDirectory.tentative.sub.https.window.js index b3b8f7e8e2301..d59caa93cd63b 100644 --- a/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.getDirectory.tentative.sub.https.window.js +++ b/testing/web-platform/tests/storage-access-api/storage-access-beyond-cookies.getDirectory.tentative.sub.https.window.js @@ -26,12 +26,11 @@ async_test(t => { // Step 2 const id = Date.now(); - window.navigator.storage.getDirectory().then((root) => { - root.getFileHandle(id, {create: true}).then(() => { - // Step 3 - let iframe = document.createElement("iframe"); - iframe.src = "https://{{hosts[alt][]}}:{{ports[https][0]}}/storage-access-api/resources/storage-access-beyond-cookies-iframe.sub.html?type=getDirectory&id="+id; - document.body.appendChild(iframe); - }); + window.navigator.storage.getDirectory().then(async (root) => { + await root.getFileHandle(id, {create: true}); + // Step 3 + let iframe = document.createElement("iframe"); + iframe.src = "https://{{hosts[alt][]}}:{{ports[https][0]}}/storage-access-api/resources/storage-access-beyond-cookies-iframe.sub.html?type=getDirectory&id="+id; + document.body.appendChild(iframe); }); }, "Verify StorageAccessAPIBeyondCookies for Origin Private File System");