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>
<script>
promise_test(async function () {
  const initialHref = location.href;
  let count = 0;
  let currentUrl = "null";
  let fromUrl = "null";
  let navigationType = "null";
  let eventBubbles = "unset";
  let eventCancelable = "unset";
  let eventComposed = "unset";
  let eventTrusted = "unset";

  const eventPromise = new Promise((resolve) => {
    navigation.addEventListener("currententrychange", (event) => {
      count += 1;
      currentUrl = navigation.currentEntry ? navigation.currentEntry.url : "null";
      fromUrl = event.from ? event.from.url : "null";
      navigationType = String(event.navigationType);
      eventBubbles = String(event.bubbles);
      eventCancelable = String(event.cancelable);
      eventComposed = String(event.composed);
      eventTrusted = String(event.isTrusted);
      resolve(event);
    }, { once: true });
  });

  location.href = initialHref + "#1";

  await eventPromise;

  assert_equals(count, 1, "hash navigation should dispatch one currententrychange event");
  assert_equals(location.href, initialHref + "#1", "hash navigation should update location.href");
  assert_equals(currentUrl, initialHref + "#1", "currentEntry URL should include the new fragment");
  assert_equals(fromUrl, initialHref, "event.from URL should point at the previous entry");
  assert_equals(navigationType, "replace", "early same-document hash navigation should surface navigationType=replace");
  assert_equals(eventBubbles, "false", "hash currententrychange should not bubble");
  assert_equals(eventCancelable, "false", "hash currententrychange should not be cancelable");
  assert_equals(eventComposed, "false", "hash currententrychange should not be composed");
  assert_equals(eventTrusted, "true", "hash currententrychange should be trusted");
}, "navigation.currententrychange fires on same-document hash navigation");
</script>