From 6336f0e8105c2e37d0380f695e2ef496bd1acd07 Mon Sep 17 00:00:00 2001 From: Matt Reichhoff Date: Fri, 31 Mar 2023 11:43:25 -0700 Subject: [PATCH] [rsafor] Fix promise_setup permission resets This depends on crrev.com/c/4382128 for deflaking of the test. Change-Id: I289db165a5b9078d4e1825d9277b077511ac92d2 Bug: 1427180 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4381927 Reviewed-by: Chris Fredrickson Commit-Queue: Matt Reichhoff Cr-Commit-Position: refs/heads/main@{#1124207} --- ...equestStorageAccessFor.sub.https.window.js | 65 +++++++------------ 1 file changed, 25 insertions(+), 40 deletions(-) diff --git a/top-level-storage-access-api/tentative/requestStorageAccessFor.sub.https.window.js b/top-level-storage-access-api/tentative/requestStorageAccessFor.sub.https.window.js index 03d9c2822235d0..fc7c8c6de1ef83 100644 --- a/top-level-storage-access-api/tentative/requestStorageAccessFor.sub.https.window.js +++ b/top-level-storage-access-api/tentative/requestStorageAccessFor.sub.https.window.js @@ -15,6 +15,7 @@ if (!topLevelDocument) { } const requestedOrigin = 'https://foo.com'; +const altOrigin = 'https://{{hosts[alt][www]}}:{{ports[https][0]}}'; // Common tests to run in all frames. test( @@ -24,13 +25,6 @@ test( '[' + testPrefix + '] document.requestStorageAccessFor() should be supported on the document interface'); -// Promise tests should all start with the feature in "prompt" state. -promise_setup(async () => { - await test_driver.set_permission( - { name: 'top-level-storage-access', requestedOrigin }, 'prompt'); - await test_driver.set_permission({name: 'storage-access'}, 'prompt'); -}); - promise_test( t => { return promise_rejects_js(t, TypeError, @@ -40,9 +34,20 @@ promise_test( '[' + testPrefix + '] document.requestStorageAccessFor() should be rejected when called with no argument'); +// Most tests need to start with the feature in "prompt" state. +// For tests that rely on the permission state, this function is intended to be +// run prior to executing test logic, rather than using clean-up functions for +// the permission. +async function CommonSetup() { + await test_driver.set_permission( + { name: 'top-level-storage-access', requestedOrigin }, 'prompt'); + await test_driver.set_permission( + { name: 'top-level-storage-access', requestedOrigin: altOrigin }, 'prompt'); +} + if (topLevelDocument) { - promise_test( - t => { + promise_test(async t => { + await CommonSetup(); return promise_rejects_dom(t, 'NotAllowedError', document.requestStorageAccessFor(requestedOrigin), 'document.requestStorageAccessFor() call without user gesture'); @@ -72,24 +77,19 @@ if (topLevelDocument) { }, '[non-fully-active] document.requestStorageAccessFor() should not resolve when run in a detached DOMParser document'); promise_test( - async t => { - await test_driver.set_permission( - { name: 'top-level-storage-access', requestedOrigin }, 'granted'); + async t => { + await CommonSetup(); + await test_driver.set_permission( + {name: 'top-level-storage-access', requestedOrigin}, 'granted'); - await document.requestStorageAccessFor(requestedOrigin); - }, - '[' + testPrefix + - '] document.requestStorageAccessFor() should be resolved without a user gesture with an existing permission'); + await document.requestStorageAccessFor(requestedOrigin); + }, + '[' + testPrefix + + '] document.requestStorageAccessFor() should be resolved without a user gesture with an existing permission'); promise_test( async t => { - const altOrigin = 'https://{{hosts[alt][www]}}:{{ports[https][0]}}'; - t.add_cleanup(async () => { - await test_driver.set_permission( - {name: 'top-level-storage-access', requestedOrigin: altOrigin}, - 'prompt'); - await test_driver.set_permission({name: 'storage-access'}, 'prompt'); - }); + await CommonSetup(); await test_driver.set_permission( {name: 'top-level-storage-access', requestedOrigin: altOrigin}, 'granted'); @@ -140,18 +140,11 @@ if (topLevelDocument) { promise_test( async (t) => { - const altOrigin = 'https://{{hosts[alt][www]}}:{{ports[https][0]}}'; const altEchoCookieHeaderUrl = `${altOrigin}/storage-access-api/resources/echo-cookie-header.py`; await MaybeSetStorageAccess('*', '*', 'blocked'); - t.add_cleanup(async () => { - await test_driver.delete_all_cookies(); - await test_driver.set_permission( - {name: 'top-level-storage-access', requestedOrigin: altOrigin}, - 'prompt'); - await MaybeSetStorageAccess('*', '*', 'allowed'); - }); + await CommonSetup(); await test_driver.set_permission( {name: 'top-level-storage-access', requestedOrigin: altOrigin}, @@ -194,16 +187,8 @@ if (topLevelDocument) { promise_test( async (t) => { - const altOrigin = 'https://{{hosts[alt][www]}}:{{ports[https][0]}}'; - await MaybeSetStorageAccess('*', '*', 'blocked'); - t.add_cleanup(async () => { - await test_driver.delete_all_cookies(); - await test_driver.set_permission( - {name: 'top-level-storage-access', requestedOrigin: altOrigin}, - 'prompt'); - await MaybeSetStorageAccess('*', '*', 'allowed'); - }); + await CommonSetup(); // Set cross-site cookie for altOrigin. Note that cookie won't be set // even with an existing top-level storage access permission in an