[rsafor] Add requestStorageAccess integration WPT

Bug: 1419893
Change-Id: Id06c246ffe3026c1e171c4613d4c0f9ef744f8c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4320910
Reviewed-by: danakj <danakj@chromium.org>
Commit-Queue: Matt Reichhoff <mreichhoff@chromium.org>
Reviewed-by: Chris Fredrickson <cfredric@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1115332}
diff --git a/top-level-storage-access-api/tentative/requestStorageAccessForOrigin.sub.https.window.js b/top-level-storage-access-api/tentative/requestStorageAccessForOrigin.sub.https.window.js
index 76e5bf8..6fff9e9 100644
--- a/top-level-storage-access-api/tentative/requestStorageAccessForOrigin.sub.https.window.js
+++ b/top-level-storage-access-api/tentative/requestStorageAccessForOrigin.sub.https.window.js
@@ -58,6 +58,7 @@
 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(
@@ -110,6 +111,29 @@
     '[' + testPrefix +
     '] document.requestStorageAccessForOrigin() 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 test_driver.set_permission(
+            {name: 'top-level-storage-access', requestedOrigin: altOrigin},
+            'granted');
+
+        await RunCallbackWithGesture(() => {
+          document.requestStorageAccessForOrigin(altOrigin).then(() => {
+            RunTestsInIFrame(
+                'https://{{hosts[alt][www]}}:{{ports[https][0]}}/top-level-storage-access-api/tentative/resources/requestStorageAccess-integration-iframe.https.html');
+          });
+        });
+      },
+      '[' + testPrefix +
+          '] document.requestStorageAccess() should be resolved without a user gesture after a successful requestStorageAccessForOrigin() call');
+
   // Create a test with a single-child same-origin iframe.
   // This will validate that calls to requestStorageAccessForOrigin are rejected
   // in non-top-level contexts.
diff --git a/top-level-storage-access-api/tentative/resources/requestStorageAccess-integration-iframe.https.html b/top-level-storage-access-api/tentative/resources/requestStorageAccess-integration-iframe.https.html
new file mode 100644
index 0000000..f4db5cf
--- /dev/null
+++ b/top-level-storage-access-api/tentative/resources/requestStorageAccess-integration-iframe.https.html
@@ -0,0 +1,15 @@
+<!doctype html>
+<meta charset=utf-8>
+
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<!-- no testharnessreport.js -->
+<script src="../../storage-access-api/helpers.js"></script>
+<div id=log></div>
+<script>
+  promise_test(
+  async t =>  document.requestStorageAccess(),
+  '[request-storage-access-integration] ' +
+  'document.requestStorageAccess() should be resolved without a user gesture with an existing top-level-storage-access permission');
+</script>