Skip to content

armgit / moli

Public Imported from GitHub
0

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

1.8 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>
test(function () {
  const initialHref = location.href;
  const initialLength = history.length;
  const pushedUrl = new URL("child/push?x=1", initialHref);
  const replacedUrl = new URL("../replace?y=2#frag", pushedUrl.href);

  history.pushState({ step: 1 }, "", "child/push?x=1");
  assert_equals(location.href, pushedUrl.href, "pushState should resolve relative URLs");
  assert_equals(
    location.pathname + location.search,
    pushedUrl.pathname + pushedUrl.search,
    "pushState should update location path and query",
  );
  assert_equals(location.hash, "", "pushState should not introduce a fragment here");
  assert_equals(history.length, initialLength + 1, "pushState should extend session history");
  assert_equals(JSON.stringify(history.state), "{\"step\":1}", "pushState should update history.state");

  history.replaceState({ step: 2 }, "", "../replace?y=2#frag");
  assert_equals(
    location.href,
    replacedUrl.href,
    "replaceState should resolve relative URLs against the current entry URL",
  );
  assert_equals(
    location.pathname + location.search + location.hash,
    replacedUrl.pathname + replacedUrl.search + replacedUrl.hash,
    "replaceState should update path, query, and fragment",
  );
  assert_equals(
    history.length,
    initialLength + 1,
    "replaceState should keep the current session history length",
  );
  assert_equals(
    JSON.stringify(history.state),
    "{\"step\":2}",
    "replaceState should replace history.state",
  );
}, "History relative URLs resolve against the current entry and update location");
</script>