From 354b975444fe355b138fa3f0ffb7cad460ecf376 Mon Sep 17 00:00:00 2001 From: Matt Reichhoff Date: Mon, 6 Mar 2023 13:57:43 +0000 Subject: [PATCH] Bug 1819677 [wpt PR 38775] - [rsafor] Correct activation check in WPT, a=testonly Automatic update from web-platform-tests [rsafor] Correct activation check in WPT Passing is blocked on the outcome of crrev.com/c/4289832 Bug: 1414468 Change-Id: I989af6f11cbfd1e2fb9b3f9644f6041825dd9e2e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4300150 Reviewed-by: Chris Fredrickson Commit-Queue: Matt Reichhoff Cr-Commit-Position: refs/heads/main@{#1111761} -- wpt-commits: 04b986a61c42a98619998e6efcb2e2f1f2f82239 wpt-pr: 38775 --- ...StorageAccessForOrigin.sub.https.window.js | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/testing/web-platform/tests/top-level-storage-access-api/tentative/requestStorageAccessForOrigin.sub.https.window.js b/testing/web-platform/tests/top-level-storage-access-api/tentative/requestStorageAccessForOrigin.sub.https.window.js index 060501d1b007..76e5bf83b1ee 100644 --- a/testing/web-platform/tests/top-level-storage-access-api/tentative/requestStorageAccessForOrigin.sub.https.window.js +++ b/testing/web-platform/tests/top-level-storage-access-api/tentative/requestStorageAccessForOrigin.sub.https.window.js @@ -28,6 +28,8 @@ queryParams.forEach((param) => { } }); +const requestedOrigin = 'https://foo.com'; + // TODO(crbug.com/1351540): when/if requestStorageAccessForOrigin is standardized, // upstream with the Storage Access API helpers file. function RunRequestStorageAccessForOriginInDetachedFrame(site) { @@ -52,6 +54,12 @@ test( '[' + testPrefix + '] document.requestStorageAccessForOrigin() 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'); +}); + promise_test( t => { return promise_rejects_js(t, TypeError, @@ -65,7 +73,7 @@ if (topLevelDocument) { promise_test( t => { return promise_rejects_dom(t, 'NotAllowedError', - document.requestStorageAccessForOrigin('https://test.com'), + document.requestStorageAccessForOrigin(requestedOrigin), 'document.requestStorageAccessForOrigin() call without user gesture'); }, '[' + testPrefix + @@ -75,7 +83,7 @@ if (topLevelDocument) { const description = 'document.requestStorageAccessForOrigin() call in a detached frame'; // Can't use promise_rejects_dom here because the exception is from the wrong global. - return RunRequestStorageAccessForOriginInDetachedFrame('https://foo.com') + return RunRequestStorageAccessForOriginInDetachedFrame(requestedOrigin) .then(t.unreached_func('Should have rejected: ' + description)) .catch((e) => { assert_equals(e.name, 'InvalidStateError', description); @@ -85,13 +93,23 @@ if (topLevelDocument) { promise_test(async t => { const description = 'document.requestStorageAccessForOrigin() in a detached DOMParser result'; - return RunRequestStorageAccessForOriginViaDomParser('https://foo.com') + return RunRequestStorageAccessForOriginViaDomParser(requestedOrigin) .then(t.unreached_func('Should have rejected: ' + description)) .catch((e) => { assert_equals(e.name, 'InvalidStateError', description); }); }, '[non-fully-active] document.requestStorageAccessForOrigin() 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'); + + await document.requestStorageAccessForOrigin(requestedOrigin); + }, + '[' + testPrefix + + '] document.requestStorageAccessForOrigin() should be resolved without a user gesture with an existing permission'); + // Create a test with a single-child same-origin iframe. // This will validate that calls to requestStorageAccessForOrigin are rejected // in non-top-level contexts. @@ -124,18 +142,6 @@ if (topLevelDocument) { '[' + testPrefix + '] document.requestStorageAccessForOrigin() should be rejected when called with an opaque origin'); - - promise_test( - async t => { - await test_driver.set_permission( - { name: 'top-level-storage-access', requestedOrigin: 'https://foo.com' }, 'granted'); - - await RunCallbackWithGesture( - () => document.requestStorageAccessForOrigin('https://foo.com')); - }, - '[' + testPrefix + - '] document.requestStorageAccessForOrigin() should be resolved when called properly with a user gesture'); - } else { promise_test( async t => {