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">
<body></body>
<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 parent = document.createElement("div");
  const child = document.createElement("test");
  parent.appendChild(child);

  child.before();
  assert_equals(parent.innerHTML, "<test></test>");

  child.before(null, undefined, "", "text");
  assert_equals(parent.innerHTML, "nullundefinedtext<test></test>");
  assert_equals(parent.childNodes[2].data, "");
}, "ChildNode.before converts non-node arguments to Text before the child");

test(function () {
  const parent = document.createElement("div");
  const child = document.createElement("test");
  const x = document.createElement("x");
  parent.appendChild(child);

  child.before(x, "text");
  assert_equals(parent.innerHTML, "<x></x>text<test></test>");
}, "ChildNode.before inserts element and text arguments before the child");

test(function () {
  const parent = document.createElement("div");
  const child = document.createElement("test");
  parent.appendChild(child);

  child.before("text", child);
  assert_equals(parent.innerHTML, "text<test></test>");
}, "ChildNode.before handles the context object as an argument");

test(function () {
  const parent = document.createElement("div");
  const child = document.createElement("test");
  const x = document.createElement("x");
  const y = document.createElement("y");
  const z = document.createElement("z");

  parent.appendChild(y);
  parent.appendChild(child);
  parent.appendChild(x);

  child.before(x, y, z);
  assert_equals(parent.innerHTML, "<x></x><y></y><z></z><test></test>");
}, "ChildNode.before moves existing siblings before the child in argument order");

test(function () {
  const orphan = document.createElement("x");
  const y = document.createElement("y");

  orphan.before(y);
  assert_equals(orphan.previousSibling, null);
  assert_equals(y.parentNode, null);
}, "ChildNode.before on a child without any parent is a no-op");
</script>