-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1781703 [wpt PR 35242] - Adds
unload
to Permissions-Policy., a=…
…testonly Automatic update from web-platform-tests Adds `unload` to Permissions-Policy. This policy controls whether unload handlers can be set. See w3c/webappsec-permissions-policy#444 Bug: 1324111 Change-Id: Ia7c418e7ca3131f5102fde407011e00048a94182 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3750822 Reviewed-by: Ian Clelland <[email protected]> Commit-Queue: Fergal Daly <[email protected]> Reviewed-by: Mason Freed <[email protected]> Reviewed-by: Andrey Kosyakov <[email protected]> Reviewed-by: Dominick Ng <[email protected]> Cr-Commit-Position: refs/heads/main@{#1032917} -- wpt-commits: c4ad1de47c85a65efde93aae9362359475fac31a wpt-pr: 35242
- Loading branch information
1 parent
c41d7ae
commit 3ebf624
Showing
4 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...ng/web-platform/tests/permissions-policy/experimental-features/resources/unload-helper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Code used by controlling frame of the unload policy tests. | ||
|
||
const MAIN_FRAME = 'main'; | ||
const SUBFRAME = 'sub'; | ||
|
||
async function isUnloadAllowed(remoteContextWrapper) { | ||
return remoteContextWrapper.executeScript(() => { | ||
return document.featurePolicy.allowsFeature('unload'); | ||
}); | ||
} | ||
|
||
// Checks whether a frame runs unload handlers. | ||
// This checks the policy directly and also installs an unload handler and | ||
// navigates the frame checking that the handler ran. | ||
async function assertWindowRunsUnload( | ||
remoteContextWrapper, name, {shouldRunUnload}) { | ||
const maybeNot = shouldRunUnload ? '' : 'not '; | ||
assert_equals( | ||
await isUnloadAllowed(remoteContextWrapper), shouldRunUnload, | ||
`${name}: unload in ${name} should ${maybeNot}be allowed`); | ||
|
||
// Set up recording of whether unload handler ran. | ||
await remoteContextWrapper.executeScript((name) => { | ||
localStorage.setItem(name, 'did not run'); | ||
addEventListener('unload', () => localStorage.setItem(name, 'did run')); | ||
}, [name]); | ||
|
||
// Navigate away and then back. | ||
const second = await remoteContextWrapper.navigateToNew(); | ||
// Navigating back ensures that the unload has completed. | ||
// Also if the navigation is cross-site then we have to return | ||
// to the original origin in order to read the recorded unload. | ||
second.historyBack(); | ||
|
||
// Check that unload handlers ran as expected. | ||
const recordedUnload = await remoteContextWrapper.executeScript( | ||
(name) => localStorage.getItem(name), [name]); | ||
assert_equals( | ||
recordedUnload, `did ${maybeNot}run`, | ||
`${name}: unload should ${maybeNot}have run`); | ||
} |
20 changes: 20 additions & 0 deletions
20
...ts/permissions-policy/experimental-features/unload-allowed-by-default.tentative.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// META: title='unload' Policy : allowed by default | ||
// META: script=/common/dispatcher/dispatcher.js | ||
// META: script=/common/utils.js | ||
// META: script=/resources/testharness.js | ||
// META: script=/resources/testharnessreport.js | ||
// META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js | ||
// META: script=./resources/unload-helper.js | ||
|
||
'use strict'; | ||
|
||
// Check that unload is allowed by policy in main frame and subframe by default. | ||
promise_test(async t => { | ||
const rcHelper = | ||
new RemoteContextHelper({scripts: ['./resources/unload-helper.js']}); | ||
// In the same browsing context group to ensure BFCache is not used. | ||
const main = await rcHelper.addWindow(); | ||
const subframe = await main.addIframe(); | ||
await assertWindowRunsUnload(subframe, 'subframe', {shouldRunUnload: true}); | ||
await assertWindowRunsUnload(main, 'main', {shouldRunUnload: true}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
...s/permissions-policy/experimental-features/unload-disallowed-subframe.tentative.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// META: title='unload' Policy : allowed in main frame but disallowed in subframe | ||
// META: script=/common/dispatcher/dispatcher.js | ||
// META: script=/common/utils.js | ||
// META: script=/resources/testharness.js | ||
// META: script=/resources/testharnessreport.js | ||
// META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js | ||
// META: script=./resources/unload-helper.js | ||
|
||
'use strict'; | ||
|
||
// Check that unload is allowed by policy in main but can be disabled in the | ||
// subframe. | ||
promise_test(async t => { | ||
const rcHelper = | ||
new RemoteContextHelper({scripts: ['./resources/unload-helper.js']}); | ||
// In the same browsing context group to ensure BFCache is not used. | ||
const main = await rcHelper.addWindow(); | ||
const subframe = | ||
await main.addIframe({headers: [['Permissions-Policy', 'unload=()']]}); | ||
await assertWindowRunsUnload(subframe, 'subframe', {shouldRunUnload: false}); | ||
await assertWindowRunsUnload(main, 'main', {shouldRunUnload: true}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
...form/tests/permissions-policy/experimental-features/unload-disallowed.tentative.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// META: title='unload' Policy : disallowed when header is () | ||
// META: script=/common/dispatcher/dispatcher.js | ||
// META: script=/common/utils.js | ||
// META: script=/resources/testharness.js | ||
// META: script=/resources/testharnessreport.js | ||
// META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js | ||
// META: script=./resources/unload-helper.js | ||
|
||
'use strict'; | ||
|
||
// Check that unload can be disabled by policy in main frame and subframe. | ||
promise_test(async t => { | ||
const rcHelper = | ||
new RemoteContextHelper({scripts: ['./resources/unload-helper.js']}); | ||
// In the same browsing context group to ensure BFCache is not used. | ||
const main = await rcHelper.addWindow( | ||
{headers: [['Permissions-Policy', 'unload=()']]}, | ||
); | ||
const subframe = await main.addIframe(); | ||
await assertWindowRunsUnload(subframe, 'subframe', {shouldRunUnload: false}); | ||
await assertWindowRunsUnload(main, 'main', {shouldRunUnload: false}); | ||
}); |