Skip to content

Commit

Permalink
[rsafor] Fix promise_setup permission resets
Browse files Browse the repository at this point in the history
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 <[email protected]>
Commit-Queue: Matt Reichhoff <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1124207}
  • Loading branch information
mreichhoff authored and chromium-wpt-export-bot committed Mar 31, 2023
1 parent a5dc2e5 commit 6336f0e
Showing 1 changed file with 25 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6336f0e

Please sign in to comment.