зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1621559 [wpt PR 22183] - [COEP] Create reporter for initial empty document, a=testonly
Automatic update from web-platform-tests
[COEP] Create reporter for initial empty document
Initial empty documents have a special navigation path, which leads to
missing reports for cross-origin embedder policy violations. Fix the
issue by creating a CrossOriginEmbedderPolicyReporter in the special
navigation path.
Bug: 1052764
Change-Id: I5825eb2946dc00f9e042b55e602fd786dc2d1adc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2097800
Commit-Queue: Yutaka Hirano <yhirano@chromium.org>
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#768780}
--
wpt-commits: f597fd3b0f531feeab70f697025bc242361aa444
wpt-pr: 22183
This commit is contained in:
Родитель
9bc3fe0cfc
Коммит
3e3810fb7c
|
@ -0,0 +1,77 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<body>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/get-host-info.sub.js"></script>
|
||||
<script>
|
||||
const {ORIGIN, REMOTE_ORIGIN} = get_host_info();
|
||||
const COEP =
|
||||
'|header(cross-origin-embedder-policy,require-corp)' +
|
||||
'|header(cross-origin-embedder-policy-report-only,require-corp)';
|
||||
const FRAME_URL = `${ORIGIN}/common/blank.html?pipe=`;
|
||||
const REMOTE_FRAME_URL = `${REMOTE_ORIGIN}/common/blank.html?pipe=`;
|
||||
|
||||
function checkCorpReport(report, contextUrl, blockedUrl) {
|
||||
assert_equals(report.type, 'coep');
|
||||
assert_equals(report.url, contextUrl);
|
||||
assert_equals(report.body.type, 'corp');
|
||||
assert_equals(report.body['blocked-url'], blockedUrl);
|
||||
}
|
||||
|
||||
function loadFrame(document, url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const frame = document.createElement('iframe');
|
||||
frame.src = url;
|
||||
frame.onload = () => resolve(frame);
|
||||
frame.onerror = reject;
|
||||
document.body.appendChild(frame);
|
||||
});
|
||||
}
|
||||
|
||||
function observeReportsUpTo(global, upto) {
|
||||
const reports = [];
|
||||
return new Promise(resolve => {
|
||||
const observer = new global.ReportingObserver((rs) => {
|
||||
for (const r of rs) {
|
||||
reports.push(r.toJSON());
|
||||
if (reports.length == upto) {
|
||||
observer.disconnect();
|
||||
resolve(reports);
|
||||
}
|
||||
}
|
||||
});
|
||||
observer.observe();
|
||||
});
|
||||
}
|
||||
|
||||
promise_test(async (t) => {
|
||||
const parent = await loadFrame(document, FRAME_URL + COEP);
|
||||
t.add_cleanup(() => parent.remove());
|
||||
loadFrame(parent.contentDocument, REMOTE_FRAME_URL + COEP);
|
||||
|
||||
// One for COEP, one for COEP-RO.
|
||||
const reports = await observeReportsUpTo(parent.contentWindow, 2);
|
||||
|
||||
assert_equals(reports.length, 2);
|
||||
checkCorpReport(reports[0], parent.src, REMOTE_FRAME_URL + COEP);
|
||||
checkCorpReport(reports[1], parent.src, REMOTE_FRAME_URL + COEP);
|
||||
}, 'Navigation CORP');
|
||||
|
||||
promise_test(async (t) => {
|
||||
const grandParent = await loadFrame(document, FRAME_URL + COEP);
|
||||
t.add_cleanup(() => grandParent.remove());
|
||||
const parent = grandParent.contentDocument.createElement('iframe');
|
||||
grandParent.contentDocument.body.appendChild(parent);
|
||||
loadFrame(parent.contentDocument, REMOTE_FRAME_URL + COEP);
|
||||
|
||||
// One for COEP, one for COEP-RO.
|
||||
const reports = await observeReportsUpTo(parent.contentWindow, 2);
|
||||
|
||||
assert_equals(reports.length, 2);
|
||||
checkCorpReport(reports[0], 'about:blank', REMOTE_FRAME_URL + COEP);
|
||||
checkCorpReport(reports[1], 'about:blank', REMOTE_FRAME_URL + COEP);
|
||||
}, 'Navigation CORP and about:blank');
|
||||
|
||||
</script>
|
||||
</body></html>
|
Загрузка…
Ссылка в новой задаче