Files
sousa-gecko/testing/web-platform/tests/speculation-rules/prerender/csp-form-action.https.html
T
HuanPo Lin 004a130a6b Bug 2033794 [wpt PR 59338] - Add prerender form submission CSP WPT, a=testonly
Automatic update from web-platform-tests
Add prerender form submission CSP WPT

Add a test verifying that prerender form submission initial navigation
can be blocked by CSP policy.

Bug: 346555939
Change-Id: Idd5dfff3e0d5876b9cec5a3b24e495ec715f1504
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7768029
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Huanpo Lin <robertlin@chromium.org>
Reviewed-by: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1617948}

--

wpt-commits: 47b463f096cf3877336b905c3222eca3a3f083fe
wpt-pr: 59338
2026-04-28 18:12:50 +00:00

45 lines
1.8 KiB
HTML

<!DOCTYPE html>
<title>Prerender initial navigation as form submission is blocked by CSP form-action 'none'</title>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js"></script>
<script src="../resources/utils.js"></script>
<script src="resources/utils.js"></script>
<body>
<script>
setup(() => assertSpeculationRulesIsSupported());
promise_test(async t => {
const rcHelper = new PrerenderingRemoteContextHelper();
// Create an initiator window with the form-action 'none' CSP.
const referrerRC = await rcHelper.addWindow({
headers: [['Content-Security-Policy', "form-action 'none'"]]
}, { features: 'noopener' });
// Setup CSP violation listener synchronously and store the promise globally.
await referrerRC.executeScript(() => {
window.violationPromise = new Promise(resolve => {
window.addEventListener('securitypolicyviolation', e => {
resolve(e.violatedDirective);
});
});
});
// Add a prerendered page as a form submission.
// The prerender initial navigation should be treated as a form submission
// and be blocked by the CSP.
await referrerRC.addPreload('prerender', {
extrasInSpeculationRule: { form_submission: true }
});
const violatedDirective = await referrerRC.executeScript(() => window.violationPromise);
assert_equals(violatedDirective, 'form-action', 'Prerender initial navigation should violate form-action CSP.');
}, "Prerender initial navigation with form_submission is blocked by CSP form-action 'none'");
</script>