Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

2.0 KB
Raw Blame
<!doctype html>
<meta charset="utf-8">
<script src="/wpt/resources/testharness.js"></script>
<script src="/wpt/resources/testharnessreport.js"></script>
<script src="/wpt/resources/moli-wpt-adapter.js"></script>
<body>
<script>
test(function () {
  const initialHref = location.href;
  const initialProtocol = location.protocol;
  const initialLength = history.length;

  for (const invalid of ["", "1invalid:", "!bad", "http bad"]) {
    assert_throws_dom(
      "SyntaxError",
      () => { location.protocol = invalid; },
      `invalid scheme ${JSON.stringify(invalid)} should throw`
    );
  }

  assert_equals(location.href, initialHref, "invalid syntax must preserve the URL");
  assert_equals(location.protocol, initialProtocol, "invalid syntax must preserve the protocol");
  assert_equals(history.length, initialLength, "invalid syntax must not grow history");
}, "location.protocol rejects invalid schemes without navigation");

for (const scheme of ["data", "custom", "file"]) {
  promise_test(async t => {
    const iframe = document.createElement("iframe");
    t.add_cleanup(() => iframe.remove());
    iframe.src = "resources/location-protocol-target.html";
    const loaded = new Promise(resolve => { iframe.onload = resolve; });
    document.body.appendChild(iframe);
    await loaded;

    const originalDocument = iframe.contentDocument;
    const originalHref = iframe.contentWindow.location.href;
    if (scheme === "file") {
      assert_not_equals(new URL(originalHref).port, "", "fixture uses a non-default port");
    }
    const reloaded = new Promise(resolve => { iframe.onload = resolve; });
    iframe.contentWindow.location.protocol = scheme;
    await reloaded;

    assert_equals(iframe.contentWindow.location.href, originalHref, "scheme replacement preserves the URL");
    assert_not_equals(iframe.contentDocument, originalDocument, "unchanged HTTP URL still navigates to a new Document");
  }, `location.protocol = ${scheme} reloads an HTTP URL when scheme replacement is rejected`);
}
</script>