dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / dom / tests_leaves_1.lucb
#==============================================================================================
#
# tests_leaves_1 - tests of QualifiedName, the character data nodes, Attr, NamedNodeMap,
# DOMTokenList and the id / anchor-name maps (region r18)
#
# DESCRIPTION:
# Ladybird has no unit tests for these files (its DOM is tested through Tests/LibWeb/Text,
# which needs scripting), so these pin the C++ behaviour: QualifiedName's interning, its
# derived strings and the hash of its Impl (values from a local driver over the reference
# build's AK), the mutation type names, nodes made in a realm (Text, Comment,
# CDATASection, ProcessingInstruction, DocumentType, DocumentFragment, Attr), CharacterData
# substrings, wholeText and text directionality, valid doctype names, the NamedNodeMap
# lookups, DOMTokenList's ordered sets and validation, ElementByIdMap and AnchorNameMap,
# and AbstractElement's traits.
#
# Nodes are made in a test realm (r14's web_test_create_realm) with a hand-built node
# document (r15's test_document, given the realm): Document's own constructor is region
# r17's. What reaches the document (mutation records need its page, HTMLCollection its DOM
# tree version) waits for r17; docs/regions/r18.md lists those scenarios.
#
#==============================================================================================
# mark: Helpers =================================================================================
## A hand-built Document (r15's test_document) belonging to `realm`, so nodes made in the realm
## can take it as their node document.
func test_realm_document(realm: Realm*) -> DomDocument*:
let document = test_document()
document.bind_platform_object().m_realm = realm
return document
## An Element of class `info` made in `realm` through Node's constructor (r19's test_realm_node),
## with a qualified name and Element's mixin tables.
func test_realm_element(realm: Realm*, document: DomDocument*, local_name: str, namespace_: ak.FlyString? = none) -> DomElement*:
let element = (DomElement*)test_realm_node(realm, &dom_element_class, DomNodeType.element_node, document)
dom_qualified_name_construct(&element.m_qualified_name, ak.fly_string_from_str(local_name), none, namespace_)
element.slottable_mixin.vtable = &dom_element_slottable_mixin_vtable
element.aria_mixin.vtable = &dom_element_aria_mixin_vtable
element.animatable.vtable = &dom_element_animatable_vtable
return element
## A Text node made in `realm`.
func test_text(realm: Realm*, document: DomDocument*, data: str) -> DomText*:
return realm_create_dom_text_utf16_string(realm, document, ak.utf16_string_from_str(data))
## Whether a Utf16String holds `text`.
func test_utf16_is(string: ak.Utf16String, text: str) -> bool:
return ak.utf16_string_base_eq_string_view(&string.utf16_string_base, ak.sv(text))
## Whether a FlyString holds `text`.
func test_fly_is(string: ak.FlyString, text: str) -> bool:
return ak.fly_string_eq_string_view(&string, ak.sv(text))
## Whether a String holds `text`.
func test_string_is(string: ak.String, text: str) -> bool:
return ak.string_eq_string_view(&string, ak.sv(text))
# mark: QualifiedName ===========================================================================
test "QualifiedName: equal triples share one Impl, with the lowercased name and the prefixed string":
web_initialize_strings()
var div: DomQualifiedName = ---
dom_qualified_name_construct(&div, ak.fly_string_from_str("DIV"), none, namespace_html)
var same: DomQualifiedName = ---
dom_qualified_name_construct(&same, ak.fly_string_from_str("DIV"), none, namespace_html)
var other_namespace: DomQualifiedName = ---
dom_qualified_name_construct(&other_namespace, ak.fly_string_from_str("DIV"), none, namespace_svg)
assert(div.m_impl == same.m_impl)
assert(div.m_impl != other_namespace.m_impl)
assert(test_fly_is(dom_qualified_name_local_name(&div), "DIV"))
assert(test_fly_is(dom_qualified_name_lowercased_local_name(&div), "div"))
assert(test_fly_is(dom_qualified_name_as_string(&div), "DIV"))
assert(dom_qualified_name_prefix(&div) == none)
var href: DomQualifiedName = ---
dom_qualified_name_construct(&href, ak.fly_string_from_str("href"), ak.fly_string_from_str("xlink"), namespace_x_link)
assert(test_fly_is(dom_qualified_name_as_string(&href), "xlink:href"))
assert(dom_node_optional_fly_string_is(dom_qualified_name_namespace(&href), namespace_x_link))
test "QualifiedName: the Impl hash is the reference build's hash_impl":
web_initialize_strings()
assert(dom_hash_impl(ak.fly_string_from_str("div"), none, none) == 403277409)
assert(dom_hash_impl(ak.fly_string_from_str("div"), none, namespace_html) == 94087268)
assert(dom_hash_impl(ak.fly_string_from_str("href"), ak.fly_string_from_str("xlink"), namespace_x_link) == 33809017)
var div: DomQualifiedName = ---
dom_qualified_name_construct(&div, ak.fly_string_from_str("div"), none, none)
assert(dom_impl_traits_hash(div.m_impl) == 403277409)
assert(dom_impl_traits_equals(div.m_impl, div.m_impl))
test "QualifiedName::set_prefix changes the shared Impl, but not its string (as in C++)":
var first: DomQualifiedName = ---
dom_qualified_name_construct(&first, ak.fly_string_from_str("r18-shared-prefix"), none, none)
var second: DomQualifiedName = ---
dom_qualified_name_construct(&second, ak.fly_string_from_str("r18-shared-prefix"), none, none)
dom_qualified_name_set_prefix(&first, ak.fly_string_from_str("p"))
assert(test_fly_is(dom_qualified_name_prefix(&second) else trap("no prefix"), "p"))
assert(test_fly_is(dom_qualified_name_as_string(&second), "r18-shared-prefix"))
test "the mutation record types are interned":
web_initialize_strings()
assert(test_fly_is(dom_mutation_type_attributes, "attributes"))
assert(test_fly_is(dom_mutation_type_character_data, "characterData"))
assert(test_fly_is(dom_mutation_type_child_list, "childList"))
# mark: Character data nodes ====================================================================
test "nodes made in a realm: Text, Comment, CDATASection, ProcessingInstruction and their names":
let vm = web_test_create_vm()
defer web_test_destroy_vm(vm)
let realm = web_test_create_realm(vm)
let document = test_realm_document(realm)
let text = test_text(realm, document, "hello")
assert(dom_node_type(text.dom_node()) == DomNodeType.text_node)
assert(text.slottable_mixin.vtable == &dom_text_slottable_mixin_vtable)
assert(test_fly_is(dom_node_node_name(text.dom_node()), "#text"))
assert(dom_character_data_length_in_utf16_code_units(text.dom_character_data()) == 5)
assert(dom_text_slottable_as_node_impl(&text.slottable_mixin) == text.dom_node())
let comment = realm_create_dom_comment(realm, document, ak.utf16_string_from_str("c"))
assert(test_fly_is(dom_node_node_name(comment.dom_node()), "#comment"))
assert(dom_node_type(comment.dom_node()) == DomNodeType.comment_node)
let cdata = realm_create_dom_cdata_section(realm, document, ak.utf16_string_from_str("x"))
assert(test_fly_is(dom_node_node_name(cdata.dom_node()), "#cdata-section"))
assert(dom_node_type(cdata.dom_node()) == DomNodeType.cdata_section_node)
assert(cdata.text.slottable_mixin.vtable == &dom_cdata_section_slottable_mixin_vtable)
let pi = realm_create_dom_processing_instruction(realm, document, ak.utf16_string_from_str("d"), ak.string_from_str("xml-stylesheet"))
assert(test_fly_is(dom_node_node_name(pi.dom_node()), "xml-stylesheet"))
assert(test_string_is(dom_processing_instruction_target(pi), "xml-stylesheet"))
test "CharacterData::substring_data: IndexSizeError past the length, clamped counts":
let vm = web_test_create_vm()
defer web_test_destroy_vm(vm)
let realm = web_test_create_realm(vm)
let text = test_text(realm, test_realm_document(realm), "abcdef")
let data = text.dom_character_data()
assert(test_utf16_is(dom_character_data_substring_data(data, 1, 3) else trap("threw"), "bcd"))
assert(test_utf16_is(dom_character_data_substring_data(data, 4, 100) else trap("threw"), "ef"))
assert(test_utf16_is(dom_character_data_substring_data(data, 6, 1) else trap("threw"), ""))
_ = dom_character_data_substring_data(data, 7, 0) catch failure:
assert(failure.code == webidl_exception)
let message = test_take_dom_exception_string()
assert(test_string_is(message, "[IndexSizeError]: Substring offset out of range."))
recover ak.utf16_string_new()
test "Text::whole_text joins the contiguous Text and CDATA siblings in tree order":
let vm = web_test_create_vm()
defer web_test_destroy_vm(vm)
let realm = web_test_create_realm(vm)
let document = test_realm_document(realm)
let parent = test_realm_element(realm, document, "p")
let first = test_text(realm, document, "a")
let cdata = realm_create_dom_cdata_section(realm, document, ak.utf16_string_from_str("b"))
let middle = test_text(realm, document, "c")
let comment = realm_create_dom_comment(realm, document, ak.utf16_string_from_str("x"))
let last = test_text(realm, document, "d")
tree_node_append_child(parent.dom_node(), first.dom_node())
tree_node_append_child(parent.dom_node(), cdata.dom_node())
tree_node_append_child(parent.dom_node(), middle.dom_node())
tree_node_append_child(parent.dom_node(), comment.dom_node())
tree_node_append_child(parent.dom_node(), last.dom_node())
assert(test_utf16_is(dom_text_whole_text(middle), "abc"))
assert(test_utf16_is(dom_text_whole_text(first), "abc"))
assert(test_utf16_is(dom_text_whole_text(last), "d"))
test "Text::directionality: the first strong character decides; none without one":
let vm = web_test_create_vm()
defer web_test_destroy_vm(vm)
let realm = web_test_create_realm(vm)
let document = test_realm_document(realm)
assert(dom_text_directionality(test_text(realm, document, "123 abc")) == DomElementDirectionality.ltr)
assert(dom_text_directionality(test_text(realm, document, "12 \u{5d0}b")) == DomElementDirectionality.rtl)
assert(dom_text_directionality(test_text(realm, document, "\u{627} x")) == DomElementDirectionality.rtl)
assert(dom_text_directionality(test_text(realm, document, "1 2 3 !")) == none)
# mark: DocumentType, DocumentFragment and Attr =================================================
test "DocumentType: names, ids and valid doctype names":
let vm = web_test_create_vm()
defer web_test_destroy_vm(vm)
let realm = web_test_create_realm(vm)
let document = test_realm_document(realm)
let doctype = dom_document_type_create(document)
dom_document_type_set_name(doctype, ak.string_from_str("html"))
dom_document_type_set_public_id(doctype, ak.string_from_str("pub"))
assert(test_fly_is(dom_node_node_name(doctype.dom_node()), "html"))
assert(test_string_is(dom_document_type_public_id(doctype), "pub"))
assert(test_string_is(dom_document_type_system_id(doctype), ""))
assert(dom_is_valid_doctype_name(ak.string_from_str("html")))
assert(dom_is_valid_doctype_name(ak.string_from_str("")))
assert(dom_is_valid_doctype_name(ak.string_from_str("a<b")))
assert(not dom_is_valid_doctype_name(ak.string_from_str("a b")))
assert(not dom_is_valid_doctype_name(ak.string_from_str("a>b")))
assert(not dom_is_valid_doctype_name(ak.string_from_str("a\tb")))
assert(not dom_is_valid_doctype_name(ak.string_from_str("a\u{c}b")))
assert(not dom_is_valid_doctype_name(ak.string_from_str("a\0b")))
test "DOMImplementation::create_document_type rejects invalid names with InvalidCharacterError":
let vm = web_test_create_vm()
defer web_test_destroy_vm(vm)
let realm = web_test_create_realm(vm)
let document = test_realm_document(realm)
let implementation = dom_implementation_create(document)
assert(dom_implementation_has_feature(implementation))
let doctype = dom_implementation_create_document_type(implementation, ak.string_from_str("svg"), ak.string_from_str("p"), ak.string_from_str("s")) else trap("threw")
assert(test_string_is(dom_document_type_name(doctype), "svg") and test_string_is(dom_document_type_system_id(doctype), "s"))
assert(dom_node_document(doctype.dom_node()) == document)
_ = dom_implementation_create_document_type(implementation, ak.string_from_str("a b"), ak.string_new(), ak.string_new()) catch:
assert(test_string_is(test_take_dom_exception_string(), "[InvalidCharacterError]: Invalid doctype name"))
recover doctype
test "DocumentFragment: its name and host":
let vm = web_test_create_vm()
defer web_test_destroy_vm(vm)
let realm = web_test_create_realm(vm)
let document = test_realm_document(realm)
let fragment = realm_create_dom_document_fragment(realm, document)
assert(test_fly_is(dom_node_node_name(fragment.dom_node()), "#document-fragment"))
assert(dom_document_fragment_host(fragment) == none)
let host = test_realm_element(realm, document, "div")
dom_document_fragment_set_host(fragment, host)
assert(dom_document_fragment_host(fragment) == host)
test "Attr: names from the qualified name, value, clone, and setting a value without an element":
web_initialize_strings()
let vm = web_test_create_vm()
defer web_test_destroy_vm(vm)
let realm = web_test_create_realm(vm)
let document = test_realm_document(realm)
var name: DomQualifiedName = ---
dom_qualified_name_construct(&name, ak.fly_string_from_str("href"), ak.fly_string_from_str("xlink"), namespace_x_link)
let attr = dom_attr_create_dom_qualified_name(document, name, ak.string_from_str("#a"))
assert(test_fly_is(dom_attr_name(attr), "xlink:href") and test_fly_is(dom_attr_local_name(attr), "href"))
assert(test_fly_is(dom_node_node_name(attr.dom_node()), "xlink:href"))
assert(test_fly_is(dom_attr_prefix(attr) else trap("no prefix"), "xlink"))
assert(dom_node_type(attr.dom_node()) == DomNodeType.attribute_node)
assert(dom_attr_specified(attr) and dom_attr_owner_element(attr) == none)
dom_attr_set_value(attr, ak.string_from_str("#b")) else trap("threw")
assert(test_string_is(dom_attr_value(attr), "#b"))
let clone = dom_attr_clone(attr, document)
assert(clone != attr and clone.m_qualified_name.m_impl == attr.m_qualified_name.m_impl)
assert(test_string_is(dom_attr_value(clone), "#b") and dom_attr_owner_element(clone) == none)
let plain = dom_attr_create_fly_string(document, ak.fly_string_from_str("id"), ak.string_from_str("x"))
assert(dom_attr_prefix(plain) == none and dom_attr_namespace_uri(plain) == none)
# mark: NamedNodeMap ============================================================================
test "NamedNodeMap: item and the lookups by name and by namespace (non-HTML element)":
web_initialize_strings()
let vm = web_test_create_vm()
defer web_test_destroy_vm(vm)
let realm = web_test_create_realm(vm)
let document = test_realm_document(realm)
let element = test_realm_element(realm, document, "svg", namespace_svg)
let map = dom_named_node_map_create(element)
assert(dom_named_node_map_is_empty(map))
var xlink_href: DomQualifiedName = ---
dom_qualified_name_construct(&xlink_href, ak.fly_string_from_str("href"), ak.fly_string_from_str("xlink"), namespace_x_link)
let first = dom_attr_create_fly_string(document, ak.fly_string_from_str("Width"), ak.string_from_str("10"), element)
let second = dom_attr_create_dom_qualified_name(document, xlink_href, ak.string_from_str("#x"), element)
let third = dom_attr_create_fly_string(document, ak.fly_string_from_str("Width"), ak.string_from_str("20"), element)
ak.vector_append_t(&map.m_attributes, first)
ak.vector_append_t(&map.m_attributes, second)
ak.vector_append_t(&map.m_attributes, third)
assert(dom_named_node_map_length(map) == 3)
assert(dom_named_node_map_item(map, 1) == second and dom_named_node_map_item(map, 3) == none)
# By qualified name: the first match; outside the HTML namespace the name is not lowercased.
var index: usize = 99
assert(dom_named_node_map_get_attribute(map, ak.fly_string_from_str("Width"), &index) == first and index == 0)
assert(dom_named_node_map_get_attribute(map, ak.fly_string_from_str("width"), &index) == none and index == 3)
assert(dom_named_node_map_get_named_item(map, ak.fly_string_from_str("xlink:href")) == second)
# By namespace and local name; the empty namespace is null.
assert(dom_named_node_map_get_attribute_ns(map, namespace_x_link, ak.fly_string_from_str("href"), &index) == second and index == 1)
assert(dom_named_node_map_get_named_item_ns(map, ak.fly_string_new(), ak.fly_string_from_str("Width")) == first)
assert(dom_named_node_map_get_attribute_ns(map, none, ak.fly_string_from_str("href")) == none)
# Duplicate names appear once in the supported property names.
let names = dom_named_node_map_supported_property_names_impl(map.bind_platform_object())
assert(ak.vector_size(&names) == 2)
assert(test_fly_is(*ak.vector_at_const(&names, 0), "Width") and test_fly_is(*ak.vector_at_const(&names, 1), "xlink:href"))
test "NamedNodeMap: removeNamedItem of a missing name throws NotFoundError with C++'s message":
web_initialize_strings()
let vm = web_test_create_vm()
defer web_test_destroy_vm(vm)
let realm = web_test_create_realm(vm)
let element = test_realm_element(realm, test_realm_document(realm), "svg", namespace_svg)
let map = dom_named_node_map_create(element)
_ = dom_named_node_map_remove_named_item(map, ak.fly_string_from_str("nope")) catch:
assert(test_string_is(test_take_dom_exception_string(), "[NotFoundError]: Attribute with name 'nope' not found"))
recover none
_ = dom_named_node_map_remove_named_item_ns(map, none, ak.fly_string_from_str("nope")) catch:
assert(test_string_is(test_take_dom_exception_string(), "[NotFoundError]: Attribute with namespace 'None' and local name 'nope' not found"))
recover none
# mark: DOMTokenList ============================================================================
test "DOMTokenList: the ordered set parser, serializer and set helpers":
let vm = web_test_create_vm()
defer web_test_destroy_vm(vm)
let realm = web_test_create_realm(vm)
let element = test_realm_element(realm, test_realm_document(realm), "span")
let list = dom_token_list_create(element, ak.fly_string_from_str("class"))
assert(dom_token_list_length(list) == 0)
dom_token_list_associated_attribute_changed(list, ak.sv(" a\tb a\nc "))
assert(dom_token_list_length(list) == 3)
assert(test_string_is(dom_token_list_item(list, 0) else trap("none"), "a") and test_string_is(dom_token_list_item(list, 2) else trap("none"), "c"))
assert(dom_token_list_item(list, 3) == none)
assert(dom_token_list_contains(list, ak.string_from_str("b")) and not dom_token_list_contains(list, ak.string_from_str("d")))
assert(test_string_is(dom_token_list_serialize_ordered_set(list), "a b c"))
# Infra's set replace keeps the earlier position and removes the later one.
replace_in_ordered_set(&list.m_token_set, ak.string_from_str("c"), ak.string_from_str("a"))
assert(test_string_is(dom_token_list_serialize_ordered_set(list), "a b"))
replace_in_ordered_set(&list.m_token_set, ak.string_from_str("a"), ak.string_from_str("z"))
assert(test_string_is(dom_token_list_serialize_ordered_set(list), "z b"))
append_to_ordered_set(&list.m_token_set, ak.string_from_str("b"))
remove_from_ordered_set(&list.m_token_set, ak.sv("z"))
assert(test_string_is(dom_token_list_serialize_ordered_set(list), "b"))
dom_token_list_associated_attribute_changed(list, ak.sv(""))
assert(dom_token_list_length(list) == 0)
test "DOMTokenList: token validation errors and the supported tokens of rel and sandbox":
let vm = web_test_create_vm()
defer web_test_destroy_vm(vm)
let realm = web_test_create_realm(vm)
let document = test_realm_document(realm)
let span = test_realm_element(realm, document, "span")
let list = dom_token_list_create(span, ak.fly_string_from_str("class"))
dom_token_list_validate_token(list, ak.sv("")) catch:
assert(test_string_is(test_take_dom_exception_string(), "[SyntaxError]: Non-empty DOM tokens are not allowed"))
recover ()
dom_token_list_validate_token(list, ak.sv("a b")) catch:
assert(test_string_is(test_take_dom_exception_string(), "[InvalidCharacterError]: DOM tokens containing ASCII whitespace are not allowed"))
recover ()
_ = dom_token_list_supports(list, ak.sv("x")) catch failure:
assert(failure.code == webidl_exception)
match idl_take_pending_exception():
.idl_simple_exception(exception):
let message = idl_simple_exception_message(&exception)
assert(exception.type_ == IdlSimpleExceptionType.type_error)
assert(test_string_is(message, "Attribute class does not define any supported tokens"))
_: trap("expected a TypeError")
recover false
let link = test_realm_element(realm, document, "link")
let rel = dom_token_list_create(link, ak.fly_string_from_str("rel"))
assert(dom_token_list_supports(rel, ak.sv("StyleSheet")) else trap("threw"))
assert(not (dom_token_list_supports(rel, ak.sv("noopener")) else trap("threw")))
let anchor_rel = dom_token_list_create(test_realm_element(realm, document, "a"), ak.fly_string_from_str("rel"))
assert(dom_token_list_supports(anchor_rel, ak.sv("NOOPENER")) else trap("threw"))
let sandbox = dom_token_list_create(test_realm_element(realm, document, "iframe"), ak.fly_string_from_str("sandbox"))
assert(dom_token_list_supports(sandbox, ak.sv("allow-top-navigation-to-custom-protocols")) else trap("threw"))
# mark: Id and anchor-name maps =================================================================
test "ElementByIdMap: add once per element, a cached first element, removal":
let vm = web_test_create_vm()
defer web_test_destroy_vm(vm)
let realm = web_test_create_realm(vm)
let document = test_realm_document(realm)
let root = test_realm_element(realm, document, "div")
let first = test_realm_element(realm, document, "p")
let second = test_realm_element(realm, document, "p")
tree_node_append_child(root.dom_node(), first.dom_node())
tree_node_append_child(root.dom_node(), second.dom_node())
let id = ak.fly_string_from_str("x")
first.m_id = id
second.m_id = id
var map: DomElementByIdMap
dom_element_by_id_map_add(&map, id, second)
dom_element_by_id_map_add(&map, id, second)
assert(dom_element_by_id_map_get(&map, id, root.dom_node()) == second)
dom_element_by_id_map_add(&map, id, first)
# Two elements: the cache is dropped and the first in tree order is found and cached.
assert(gc.weak_ptr(&(ak.hash_map_get_k(&map.m_map, id) else trap("no entry")).cached_first_element) == none)
assert(dom_element_by_id_map_get(&map, id, root.dom_node()) == first)
assert(gc.weak_ptr(&(ak.hash_map_get_k(&map.m_map, id) else trap("no entry")).cached_first_element) == first)
assert(dom_element_by_id_map_get(&map, ak.fly_string_from_str("y"), root.dom_node()) == none)
dom_element_by_id_map_remove(&map, id, first)
assert(ak.vector_size(&(ak.hash_map_get_k(&map.m_map, id) else trap("no entry")).elements) == 1)
dom_element_by_id_map_remove(&map, id, second)
assert(ak.hash_map_get_k(&map.m_map, id) == none)
test "AnchorNameMap: elements kept in tree order; the last one is the element by name":
let vm = web_test_create_vm()
defer web_test_destroy_vm(vm)
let realm = web_test_create_realm(vm)
let document = test_realm_document(realm)
let root = test_realm_element(realm, document, "div")
let first = test_realm_element(realm, document, "p")
let second = test_realm_element(realm, document, "p")
tree_node_append_child(root.dom_node(), first.dom_node())
tree_node_append_child(root.dom_node(), second.dom_node())
let name = ak.fly_string_from_str("--anchor")
var map: DomAnchorNameMap
dom_anchor_name_map_register_name(&map, name, second)
dom_anchor_name_map_register_name(&map, name, first)
dom_anchor_name_map_register_name(&map, name, first)
let elements = ak.hash_map_get_k(&map.m_map, name) else trap("no entry")
assert(ak.vector_size(elements) == 2 and *ak.vector_at(elements, 0) == first)
assert(dom_anchor_name_map_element_by_name(&map, name) == second)
dom_anchor_name_map_unregister_name(&map, name, second)
assert(dom_anchor_name_map_element_by_name(&map, name) == first)
dom_anchor_name_map_unregister_name(&map, name, first)
assert(dom_anchor_name_map_element_by_name(&map, name) == none and ak.hash_map_is_empty(&map.m_map))
# mark: AbstractElement =========================================================================
test "AbstractElement: traits, equality and the tree-counting context":
let vm = web_test_create_vm()
defer web_test_destroy_vm(vm)
let realm = web_test_create_realm(vm)
let document = test_realm_document(realm)
let parent = test_realm_element(realm, document, "ul")
let first = test_realm_element(realm, document, "li")
let second = test_realm_element(realm, document, "li")
tree_node_append_child(parent.dom_node(), first.dom_node())
tree_node_append_child(parent.dom_node(), test_text(realm, document, "x").dom_node())
tree_node_append_child(parent.dom_node(), second.dom_node())
let element = dom_abstract_element_make(second)
let before = dom_abstract_element_make(second, css_data.PseudoElement.before)
assert(dom_abstract_element_traits_equals(&element, &element) and not dom_abstract_element_traits_equals(&element, &before))
assert(dom_abstract_element_traits_hash(&element) == ak.pair_int_hash(ak.ptr_hash_void(second), 0xffffffff))
assert(dom_abstract_element_traits_hash(&before) == ak.pair_int_hash(ak.ptr_hash_void(second), (u32)css_data.PseudoElement.before))
assert(dom_abstract_element_parent_element(&before) == second)
assert(dom_abstract_element_parent_element(&element) == parent)
let context = dom_abstract_element_tree_counting_function_resolution_context(&element)
assert(context.sibling_count == 2 and context.sibling_index == 2)
let parent_element = dom_abstract_element_make(parent)
let root_context = dom_abstract_element_tree_counting_function_resolution_context(&parent_element)
assert(root_context.sibling_count == 1 and root_context.sibling_index == 1)