Skip to content

armgit / moli

Public Imported from GitHub
0

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

3.0 KB
Raw Blame
<!doctype html>
<meta charset="utf-8">
<p id="p1">The quick brown fox</p>
<p id="p2">jumps over the lazy dog</p>
<script src="/wpt/resources/testharness.js"></script>
<script src="/wpt/resources/testharnessreport.js"></script>
<script src="/wpt/resources/moli-wpt-adapter.js"></script>
<script src="/wpt/resources/WebIDLParser.js"></script>
<script src="/wpt/resources/idlharness.js"></script>
<script>
idl_test([`
interface Selection {
  readonly attribute Node? anchorNode;
  readonly attribute unsigned long anchorOffset;
  readonly attribute Node? focusNode;
  readonly attribute unsigned long focusOffset;
  readonly attribute boolean isCollapsed;
  readonly attribute unsigned long rangeCount;
  readonly attribute DOMString type;
  readonly attribute DOMString direction;
  Range getRangeAt(unsigned long index);
  undefined addRange(Range range);
  undefined removeRange(Range range);
  undefined removeAllRanges();
  undefined empty();
  undefined collapse(Node? node, optional unsigned long offset = 0);
  undefined setPosition(Node? node, optional unsigned long offset = 0);
  undefined collapseToStart();
  undefined collapseToEnd();
  undefined extend(Node node, optional unsigned long offset = 0);
  undefined setBaseAndExtent(Node? baseNode, unsigned long baseOffset, Node? extentNode, unsigned long extentOffset);
  undefined selectAllChildren(Node node);
  undefined deleteFromDocument();
  boolean containsNode(Node node, optional boolean allowPartialContainment = false);
  undefined modify(optional DOMString alter = "", optional DOMString direction = "", optional DOMString granularity = "");
};
`], [], function (idlArray) {
  idlArray.enable_function_length_assertions();
  idlArray.enable_interface_descriptor_assertions();
  idlArray.enable_operation_descriptor_assertions();
  idlArray.enable_attribute_descriptor_assertions();
  idlArray.enable_object_brand_assertions();
  idlArray.add_objects({
    Selection: ["window.getSelection()"]
  });
});

test(function () {
  const selection = window.getSelection();
  const p1 = document.getElementById("p1");
  selection.removeAllRanges();
  selection.collapse(p1.firstChild, 4);
  assert_equals(selection.rangeCount, 1);
  assert_true(selection.isCollapsed);
  assert_false(selection.hasOwnProperty("anchorNode"));
  assert_false(selection.hasOwnProperty("anchorOffset"));
  assert_false(selection.hasOwnProperty("focusNode"));
  assert_false(selection.hasOwnProperty("focusOffset"));
  assert_false(selection.hasOwnProperty("isCollapsed"));
  assert_false(selection.hasOwnProperty("rangeCount"));
  assert_false(selection.hasOwnProperty("type"));
  assert_false(selection.hasOwnProperty("direction"));
  assert_equals(selection.anchorOffset, 4);
  selection.setPosition(p1.firstChild);
  assert_equals(selection.anchorOffset, 0);
  selection.selectAllChildren(p1);
  assert_true(selection.containsNode(p1.firstChild));
  selection.removeAllRanges();
  assert_equals(selection.rangeCount, 0);
}, "Selection idlharness sample operations work on window.getSelection()");
</script>