chromium/third_party/blink/web_tests/wpt_internal/origin-agent-cluster-default-warning/document-domain-access-navigate.https.sub.html

<!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="about:blank"></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 onload event for a given frame.
function onframeload(frame) {
  return new Promise((resolve, reject) => {
    frame.addEventListener("load", _ => { resolve(); }, { once: true });
  });
}

// 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 });
  });
}

// Wait for a ReportingObserver report.
const onreport = new Promise((resolve, reject) => {
    new ReportingObserver((reports, observer) => {
      resolve(reports[reports.length - 1]);
      observer.takeRecords();
    }, {buffered: true}).observe();
  });

// Same as the previous test, but first navigate the target frame.
promise_test(async t => {
  await onload;

  // Navigate the frame from about:blink to its final location to ensure that
  // that code path is covered, too.
  frames[0].location = "https://{{domains[www1]}}:{{location[port]}}/wpt_internal/origin-agent-cluster-default-warning/resources/frame.html"
  await onframeload(document.getElementsByTagName("iframe")[0]);

  // Now proceed as above: Tell the frame to relax its same-origin restriction
  // and then reach into the frame.

  frames[0].postMessage("relax", "*");
  var msg = await onmessage();
  assert_equals(msg.data.type, "relaxed");
  assert_equals(msg.data.body, "{{host}}");

  document.domain = document.domain;
  frames[0].document.bodyi
  var report = await onreport;
  assert_equals(report.type, "deprecation");
  assert_equals(report.body.id, "CrossOriginAccessBasedOnDocumentDomain");
}, "Deprecation warning for document-domain mediated cross-origin access, " +
   "after first navigation the target frame.");
</script>