Skip to content

armgit / moli

Public Imported from GitHub
0

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

2.1 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 assert_throws_name(expectedName, callback) {
  try {
    callback();
  } catch (error) {
    assert_equals(error.name, expectedName);
    return;
  }
  throw new Error("Expected " + expectedName);
}

function assert_created_event(alias, constructor) {
  test(function () {
    const event = document.createEvent(alias);

    assert_true(event instanceof constructor, "constructor identity");
    assert_equals(Object.getPrototypeOf(event), constructor.prototype, "prototype");
    assert_equals(event.type, "", "type");
    assert_equals(event.target, null, "target");
    assert_equals(event.currentTarget, null, "currentTarget");
    assert_equals(event.eventPhase, Event.NONE, "eventPhase");
    assert_equals(event.bubbles, false, "bubbles");
    assert_equals(event.cancelable, false, "cancelable");
    assert_equals(event.defaultPrevented, false, "defaultPrevented");
    assert_equals(event.isTrusted, false, "isTrusted");
  }, "createEvent(" + JSON.stringify(alias) + ") creates " + constructor.name);
}

[
  ["Event", Event],
  ["Events", Event],
  ["HTMLEvents", Event],
  ["SVGEvents", Event],
  ["CustomEvent", CustomEvent],
  ["UIEvent", UIEvent],
  ["UIEvents", UIEvent],
  ["MouseEvent", MouseEvent],
  ["MouseEvents", MouseEvent],
  ["KeyboardEvent", KeyboardEvent],
  ["MessageEvent", MessageEvent],
].forEach(function ([alias, constructor]) {
  assert_created_event(alias, constructor);
  assert_created_event(alias.toLowerCase(), constructor);
  assert_created_event(alias.toUpperCase(), constructor);
});

test(function () {
  [
    "foo",
    "CustomEvents",
    "KeyboardEvents",
    "MessageEvents",
    "WheelEvent",
    "PointerEvent",
    "ErrorEvent",
    "MutationEvent",
    "U\u0130Event",
    "U\u0131Event",
  ].forEach(function (alias) {
    assert_throws_name("NotSupportedError", function () {
      document.createEvent(alias);
    });
  });
}, "createEvent() rejects unsupported and non-legacy event names");
</script>