Commit 10c9e1cb authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[devtools] Add inspector protocol test for new COEP error reporting

The error reporting was landed recently here:
https://chromium-review.googlesource.com/c/chromium/src/+/2070409

This CL adds a layout test that checks that the new errors are actually
reported via the Chrome DevTools Protocol (CDP).

Note that this test relies on the --cross-origin-isolation flag to
be turned on, which it is for layout tests, and we don't expect it
to be turned off. If the flag gets turned off, this test will fail
and needs to be disabled.

Bug: chromium:1051473
Change-Id: Iaccb843923ae1b2654ea11f3eec3f5b04bd1d551
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2087913
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: default avatarPeter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746779}
parent 4e26f273
Tests that cross-origin embedder policy (COEP) related blocking is reported correctly.
https://devtools.test:8443/inspector-protocol/network/cross-origin-isolation/resources/coep-page-with-resources.php: *loading finished*
https://devtools.oopif.test:8443/inspector-protocol/network/cross-origin-isolation/resources/page-with-coep-corp.php: net::ERR_BLOCKED_BY_RESPONSE corp-not-same-origin-after-defaulted-to-same-origin-by-coep
https://devtools.oopif.test:8443/inspector-protocol/network/cross-origin-isolation/resources/page-with-coep-corp.php?corp=cross-origin: *loading finished*
https://devtools.oopif.test:8443/inspector-protocol/network/cross-origin-isolation/resources/page-with-coep-corp.php?corp=same-site: net::ERR_BLOCKED_BY_RESPONSE corp-not-same-site
https://devtools.oopif.test:8443/inspector-protocol/network/cross-origin-isolation/resources/page-with-coep-corp.php?corp=same-origin: net::ERR_BLOCKED_BY_RESPONSE corp-not-same-origin
https://devtools.oopif.test:8443/inspector-protocol/network/cross-origin-isolation/resources/page-with-coep-corp.php: net::ERR_BLOCKED_BY_RESPONSE coep-frame-resource-needs-coep-header
https://devtools.oopif.test:8443/inspector-protocol/network/cross-origin-isolation/resources/page-with-coep-corp.php?coep: net::ERR_BLOCKED_BY_RESPONSE corp-not-same-origin-after-defaulted-to-same-origin-by-coep
https://devtools.oopif.test:8443/inspector-protocol/network/cross-origin-isolation/resources/page-with-coep-corp.php?coep&corp=same-site: net::ERR_BLOCKED_BY_RESPONSE corp-not-same-site
https://devtools.oopif.test:8443/inspector-protocol/network/cross-origin-isolation/resources/page-with-coep-corp.php?coep&corp=same-origin: net::ERR_BLOCKED_BY_RESPONSE corp-not-same-origin
https://devtools.oopif.test:8443/inspector-protocol/network/cross-origin-isolation/resources/page-with-coep-corp.php&coop: net::ERR_BLOCKED_BY_RESPONSE coep-frame-resource-needs-coep-header
(async function(testRunner) {
const {page, session, dp} = await testRunner.startBlank(
`Tests that cross-origin embedder policy (COEP) related blocking is reported correctly.`);
await session.protocol.Network.clearBrowserCache();
await session.protocol.Network.setCacheDisabled({cacheDisabled: true});
await dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: true, flatten: true});
let numberOfMessages = 0;
const expectedNumberOfMessages = 21;
const resources = new Map();
function record(requestId, info) {
resources.set(requestId, {...resources.get(requestId), ...info});
if (++numberOfMessages === expectedNumberOfMessages) {
function compareInfo(a, b) {
return a.requestWillBeSent?.request?.url < b.requestWillBeSent?.request?.url;
}
const entries = Array.from(resources.values()).sort(compareInfo);
for (const entry of entries) {
if (entry.loadingFailed) {
testRunner.log(`${entry.requestWillBeSent.request?.url}: ${entry.loadingFailed.errorText} ${entry.loadingFailed.blockedReason}`);
}
if (entry.loadingFinished) {
testRunner.log(`${entry.requestWillBeSent.request?.url}: *loading finished*`);
}
}
testRunner.completeTest();
}
}
async function initalizeTarget(dp) {
dp.Network.onLoadingFailed(event => record(event.params.requestId, {loadingFailed: event.params})),
dp.Network.onLoadingFinished(event => record(event.params.requestId, {loadingFinished: event.params})),
dp.Network.onRequestWillBeSent(event => record(event.params.requestId, {requestWillBeSent: event.params})),
await Promise.all([
dp.Network.enable(),
dp.Page.enable()
]);
}
await initalizeTarget(dp);
dp.Target.onAttachedToTarget(async e => {
const dp = session.createChild(e.params.sessionId).protocol;
await initalizeTarget(dp);
});
page.navigate('https://devtools.test:8443/inspector-protocol/network/cross-origin-isolation/resources/coep-page-with-resources.php');
// `record` above makes sure to complete the test.
})
<?php
header("Cross-Origin-Embedder-Policy: require-corp");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Page with Cross-Origin-Embedder-Policy</title>
<meta charset="utf-8">
</head>
<body>
<div>
This is a COEP page embedding resources.
</div>
None/None<br/>
<iframe src="https://devtools.oopif.test:8443/inspector-protocol/network/cross-origin-isolation/resources/page-with-coep-corp.php">
</iframe><br/>
COEP/None<br/>
<iframe src="https://devtools.oopif.test:8443/inspector-protocol/network/cross-origin-isolation/resources/page-with-coep-corp.php?coep">
</iframe><br/>
COEP/Same-Site<br/>
<iframe src="https://devtools.oopif.test:8443/inspector-protocol/network/cross-origin-isolation/resources/page-with-coep-corp.php?coep&corp=same-site">
</iframe><br/>
COEP/Same-Origin<br/>
<iframe src="https://devtools.oopif.test:8443/inspector-protocol/network/cross-origin-isolation/resources/page-with-coep-corp.php?coep&corp=same-origin">
</iframe><br/>
COEP/Cross-Origin<br/>
<iframe src="https://devtools.oopif.test:8443/inspector-protocol/network/cross-origin-isolation/resources/page-with-coep-corp.php?coep&corp=cross-origin">
</iframe><br/>
Script CORP None <span id="script-corp-none">not loaded</span>
<script src="https://devtools.oopif.test:8443/inspector-protocol/network/cross-origin-isolation/resources/page-with-coep-corp.php" defer>
</script><br/>
Script CORP cross origin <span id="script-corp-cross-origin">not loaded</span>
<script src="https://devtools.oopif.test:8443/inspector-protocol/network/cross-origin-isolation/resources/page-with-coep-corp.php?corp=cross-origin" defer>
</script> <br/>
Script CORP same site <span id="script-corp-same-site">not loaded</span>
<script src="https://devtools.oopif.test:8443/inspector-protocol/network/cross-origin-isolation/resources/page-with-coep-corp.php?corp=same-site" defer>
</script><br/>
Script CORP same origin <span id="script-corp-same-origin">not loaded</span>
<script src="https://devtools.oopif.test:8443/inspector-protocol/network/cross-origin-isolation/resources/page-with-coep-corp.php?corp=same-origin" defer>
</script><br/>
Sandboxed COOP iframe<br/>
<iframe src="https://devtools.oopif.test:8443/inspector-protocol/network/cross-origin-isolation/resources/page-with-coep-corp.php&coop">
</iframe><br/>
</body>
</html>
<?php
if (isset($_GET['corp'])) {
header("Cross-Origin-Resource-Policy: " . $_GET['corp']);
}
if (isset($_GET['coop'])) {
header("Cross-Origin-Opener-Policy: same-origin");
}
if (isset($_GET['coep'])) {
header("Cross-Origin-Embedder-Policy: require-corp");
}
echo "This is some content";
?>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment