Skip to content

armgit / moli

Public Imported from GitHub
0

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

1.9 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>
<script>
function query_param(name) {
  return new URL(location.href).searchParams.get(name);
}

const STORAGE_PREFIX = "__lm_wpt_location_href_basic__";
const stage = query_param("stage");

if (stage !== "final") {
  sessionStorage.setItem(STORAGE_PREFIX + "initialHref", location.href);
  sessionStorage.setItem(STORAGE_PREFIX + "initialLength", String(history.length));
  location.href = location.pathname + "?stage=final&marker=href";
} else {
  test(function () {
    const initialHref = sessionStorage.getItem(STORAGE_PREFIX + "initialHref");
    const initialLength = Number(sessionStorage.getItem(STORAGE_PREFIX + "initialLength"));

    assert_true(initialHref !== null, "source stage should store the initial href");
    assert_true(initialHref !== location.href, "href assignment should commit a new destination URL");
    assert_equals(query_param("marker"), "href", "final URL should include the href marker");
    assert_true(
      location.href.indexOf("stage=final") !== -1,
      "href assignment should reach the final-stage destination",
    );
    assert_true(
      history.length >= initialLength,
      "href assignment should leave the session history surface in a valid state after navigation",
    );
    assert_true(document.location === window.location, "document.location should alias window.location");
    assert_equals(typeof location.assign, "function", "location.assign should stay callable");
    assert_equals(typeof location.replace, "function", "location.replace should stay callable");
    assert_equals(typeof location.reload, "function", "location.reload should stay callable");
  }, "location.href assignment navigates to the destination during page load");
}
</script>