<!DOCTYPE html>
<title>Warnings when setting document.domain without Origin-Agent-Cluster header</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<iframe src="https://{{domains[www]}}:{{location[port]}}/wpt_internal/origin-agent-cluster-default-warning/resources/frame.html"></iframe>
<script>
// These tests ensure that deprecation warnings are issued when document.domain
// is set, and when a cross-origin access based on that document.domain setting
// is made. This requires the OriginAgentClusterDefaultWarning flag.
//
// The ReportingObserver infrastructure seems to coalescs deprecation warnings,
// so that multiple waring events only result in a single warning. To accomodate
// this, we'll move each test into a single file, despite this making the test
// suite somewhat harder to follow.
// Wait for onload event, since that guarantees the iframe has loaded.
const onload = new Promise((resolve, reject) => {
window.onload = _ => { resolve(); };
});
// Wait for a message from (any of) our frame(s).
function onmessage() {
return new Promise((resolve, reject) => {
window.addEventListener("message", msg => { resolve(msg); },
{ once: true });
});
}
// Test that setting document.domain (without an Origin-Agent-Cluster header)
// will issue a deprecation warning (with id
// kDocumentDomainSettingWithoutOriginAgentClusterHeader).
promise_test(async t => {
await onload;
frames[0].postMessage("relax", "*");
var msg = await onmessage();
assert_equals(msg.data.type, "relaxed");
assert_equals(msg.data.body, "{{host}}");
msg = await onmessage();
assert_equals(msg.data.type, "deprecation");
assert_equals(msg.data.id, "DocumentDomainSettingWithoutOriginAgentClusterHeader");
}, "Deprecation warning for setting document.domain");
</script>