Skip to content

armgit / moli

Public Imported from GitHub
0

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

2.2 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("section");
  const grandchild = document.createTextNode("leaf");
  const sibling = document.createElement("aside");

  child.appendChild(grandchild);
  parent.appendChild(child);
  parent.appendChild(sibling);

  assert_false(parent.contains(null));
  assert_true(parent.contains(parent));
  assert_true(parent.contains(child));
  assert_true(parent.contains(grandchild));
  assert_true(parent.contains(sibling));
  assert_false(child.contains(parent));
  assert_false(child.contains(sibling));
}, "Node.contains reports inclusive descendants and rejects null");

test(function () {
  const fragment = document.createDocumentFragment();
  const child = document.createElement("span");
  const grandchild = document.createTextNode("leaf");

  child.appendChild(grandchild);
  fragment.appendChild(child);

  assert_true(fragment.contains(fragment));
  assert_true(fragment.contains(child));
  assert_true(fragment.contains(grandchild));
  assert_false(child.contains(fragment));
}, "Node.contains works for DocumentFragment subtrees");

test(function () {
  const parent = document.createElement("div");
  const child = document.createElement("span");
  const grandchild = document.createElement("b");

  child.appendChild(grandchild);
  parent.appendChild(child);
  assert_true(parent.contains(grandchild));

  child.remove();
  assert_false(parent.contains(child));
  assert_false(parent.contains(grandchild));
  assert_true(child.contains(grandchild));
}, "Node.contains updates after a subtree is removed");

test(function () {
  const left = document.createElement("div");
  const right = document.createElement("div");
  const rightChild = document.createElement("span");
  right.appendChild(rightChild);

  assert_false(left.contains(right));
  assert_false(left.contains(rightChild));
  assert_true(right.contains(rightChild));
}, "Node.contains returns false across disconnected subtrees");
</script>