Skip to content

Commit

Permalink
Cope with srcdoc and other headerless docs for EnabledForNone features.
Browse files Browse the repository at this point in the history
This works by special-casing EnabledForNone in GetFeatureValueForOrigin for headerless docs and return true for that case. This produces the correct inherited value.

Bug: 40285153
Change-Id: I4b9ff6353a21ca493f6ccc9a965b10005caa8896
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5311943
Commit-Queue: Fergal Daly <[email protected]>
Reviewed-by: Jeremy Roman <[email protected]>
Reviewed-by: Ian Clelland <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1407698}
  • Loading branch information
fergald authored and chromium-wpt-export-bot committed Jan 17, 2025
1 parent 109d4a6 commit 6622504
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@ async function isUnloadAllowed(remoteContextWrapper) {
});
}

// Checks whether a frame allows running unload handlers by checking the policy.
async function assertWindowAllowsUnload(
remoteContextWrapper, name, {shouldRunUnload}) {
const maybeNot = shouldRunUnload ? '' : 'not ';
assert_equals(
await isUnloadAllowed(remoteContextWrapper), shouldRunUnload,
`${name}: unload in ${name} should ${maybeNot}be allowed`);
}

// 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}) {
await assertWindowAllowsUnload(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) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// META: title='unload' Policy : allowed in headerless doc when allowed in main frame.
// META: script=/common/dispatcher/dispatcher.js
// META: script=/common/utils.js
// META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js
// META: script=./resources/unload-helper.js
// META: variant=?urlType=srcdoc
// META: variant=?urlType=data
// META: variant=?urlType=blob
// META: variant=?urlType=blank

'use strict';

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 url = new URL(location);
const urlType = url.searchParams.get('urlType');

if (urlType == 'srcdoc') {
const subframe = await main.addIframeSrcdoc(
/*extraConfig=*/ {}, /*attributes=*/ {allow: 'unload'});
await assertWindowRunsUnload(subframe, 'subframe', {shouldRunUnload: true});
} else {
const subframe = await main.addIframe(
/*extraConfig=*/ {urlType: urlType}, /*attributes=*/ {allow: 'unload'});
// The other URL types cannot easily test unload directly. `data: and
// `blob:` documents cannot access storage. `about:blank` loses the content
// that was written into it when reloaded on going back and so stops
// functioning as a remote execution context.
await assertWindowAllowsUnload(
subframe, 'subframe', {shouldRunUnload: true});
}

await assertWindowRunsUnload(main, 'main', {shouldRunUnload: true});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// META: title='unload' Policy : disallowed in headerless doc when disallowed in main frame.
// META: script=/common/dispatcher/dispatcher.js
// META: script=/common/utils.js
// META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js
// META: script=./resources/unload-helper.js
// META: variant=?urlType=srcdoc
// META: variant=?urlType=data
// META: variant=?urlType=blob
// META: variant=?urlType=blank

'use strict';

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 url = new URL(location);
const urlType = url.searchParams.get('urlType');

if (urlType == 'srcdoc') {
const subframe = await main.addIframeSrcdoc(
/*extraConfig=*/ {}, /*attributes=*/ {allow: 'unload'});
await assertWindowRunsUnload(
subframe, 'subframe', {shouldRunUnload: false});
} else {
const subframe = await main.addIframe(
/*extraConfig=*/ {urlType: urlType}, /*attributes=*/ {allow: 'unload'});

// The other URL types cannot esaily test unload directly. `data: and
// `blob:` documents cannot access storage. `about:blank` loses the content
// that was written into it when reloaded on going back and so stops
// functioning as a remote execution context.
await assertWindowAllowsUnload(
subframe, 'subframe', {shouldRunUnload: false});
}

await assertWindowRunsUnload(main, 'main', {shouldRunUnload: false});
});

0 comments on commit 6622504

Please sign in to comment.