dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / src / web / dom / tests_document.lucb
#==============================================================================================
#
# tests_document - tests of DOM::Document, DocumentLoading and the execCommand methods
# (region r17)
#
# DESCRIPTION:
# Ladybird has no unit tests for these files (Document is tested through
# Tests/LibWeb/Text, which needs scripting), so these pin the C++ behaviour of what runs
# in phase 1: a document's defaults, its document element, head, body and title, the
# title setter, readyState, an event's parent, quirks mode and compatMode, the node factories and
# their errors, Document::is_valid_name, the to_string of the layout and invalidation
# reasons, the value overrides of execCommand and the MIME types a navigation can load.
#
# These tests build their document outside the heap (as r15 and r18 do), given by hand the
# steps of Document's constructor, with a heap Page and test PageClient (page/tests_page).
# New tests use page/tests_page's web_test_create_document (Document::create, in the heap).
#
#==============================================================================================
# mark: Helpers =================================================================================
## A zeroed cell of `size` bytes outside any heap with `vtable` and `class_id`.
func test_document_off_heap_cell(size: usize, vtable: const void*, class_id: u16) -> gc.Cell*:
let bytes = memory.allocate(size, 16) else trap("out of memory")
memory.set(bytes, 0)
let cell = (gc.Cell*)bytes.data
cell.vtable = (const gc.CellVTable*)vtable
cell.class_id = class_id
return cell
## A Page for the documents made outside the heap: page/tests_page's heap Page with a test
## PageClient, kept alive for the VM's life (memory outside the heap is not scanned, DESIGN.md
## ยง3.3 rule 4).
func test_document_page() -> Page*:
let vm = vm_the()
let page = web_test_create_page(vm)
vm_keep_alive(vm, page)
return page
## A Document of `type_` in `realm`, made outside the heap (r18's test_realm_document) and given the
## steps of Document::Document that stay inside phase 1: the default member initializers, the
## URL, an opaque origin, the legacy platform object flags and the page.
func test_document_in_realm(realm: Realm*, type_: DocumentDomDocumentType = DocumentDomDocumentType.html) -> DomDocument*:
let document = test_realm_document(realm)
document.global_event_handlers.vtable = &dom_document_global_event_handlers_vtable
document.global_event_handlers.class_id = document.cell().class_id
dom_document_init_fields(document)
document.m_content_type = ak.string_from_str("application/xml")
document.m_origin = web_url.origin_create_opaque()
document.m_default_single_line_container_name = html_tag_names_div
document.m_page = test_document_page()
document.m_url = web_url.about_blank()
document.bind_platform_object().m_legacy_platform_object_flags = BindPlatformObjectLegacyPlatformObjectFlags(supports_named_properties = 1, has_legacy_override_built_ins_interface_extended_attribute = 1)
dom_document_set_document_type(document, type_)
return document
## An HTML element of class `info` (an HTMLElement subclass) in `realm`.
func test_document_html_element(realm: Realm*, document: DomDocument*, info: const ak.ClassInfo*, local_name: str) -> DomElement*:
let element = (DomElement*)test_realm_node(realm, info, DomNodeType.element_node, document)
dom_qualified_name_construct(&element.m_qualified_name, ak.fly_string_from_str(local_name), none, namespace_html)
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
## Whether a StringView holds `text`.
func test_sv_is(view: ak.StringView, text: str) -> bool:
return ak.string_view_equals(&view, text)
## `child` appended to `parent` by TreeNode::append_child: Node::append_child's insertion steps
## invalidate style, which is region r42's.
func test_document_append(parent: DomNode*, child: DomNode*):
tree_node_append_child(parent, child)
# mark: Defaults ================================================================================
test "a new document: content type, readiness, quirks mode, type and URL":
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_document_in_realm(realm, DocumentDomDocumentType.xml)
assert(test_string_is(dom_document_content_type(document), "application/xml"))
assert(test_sv_is(dom_document_ready_state(document), "complete"))
assert(not dom_document_in_quirks_mode(document))
assert(test_string_is(dom_document_compat_mode(document), "CSS1Compat"))
assert(not dom_document_is_html_document(document))
assert(test_string_is(dom_document_url_string(document), "about:blank"))
assert(dom_document_document_element(document) == none)
assert(dom_document_head(document) == none)
assert(dom_document_body(document) == none)
assert(dom_document_doctype(document) == none)
# mark: The document element, head, body and title ===========================================
test "html, head, title and body found through the tree; title strips and collapses whitespace":
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_document_in_realm(realm)
let html = test_document_html_element(realm, document, &html_html_element_class, "html")
let head = test_document_html_element(realm, document, &html_head_element_class, "head")
let title = test_document_html_element(realm, document, &html_title_element_class, "title")
let body = test_document_html_element(realm, document, &html_body_element_class, "body")
test_document_append(document.dom_node(), html.dom_node())
test_document_append(html.dom_node(), head.dom_node())
test_document_append(head.dom_node(), title.dom_node())
test_document_append(title.dom_node(), test_text(realm, document, " Hello \n world ").dom_node())
test_document_append(html.dom_node(), body.dom_node())
assert(dom_document_document_element(document) == html)
assert((DomElement*?)dom_document_html_element(document) == html)
assert((DomElement*?)dom_document_head(document) == head)
assert((DomElement*?)dom_document_title_element(document) == title)
assert((DomElement*?)dom_document_body(document) == body)
assert(test_utf16_is(dom_document_title(document), "Hello world"))
test "without a document element, title is empty and setting it does nothing":
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_document_in_realm(realm)
assert(test_utf16_is(dom_document_title(document), ""))
_ = dom_document_set_title(document, ak.utf16_string_from_str("ignored")) catch: trap("set_title threw")
assert(dom_document_document_element(document) == none)
assert(test_utf16_is(dom_document_title(document), ""))
assert(test_document_client_log.titles_changed == 0)
test "an element that is not html is the document element, but not the html element; head and body need it":
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_document_in_realm(realm)
let root = test_realm_element(realm, document, "root")
test_document_append(document.dom_node(), root.dom_node())
test_document_append(root.dom_node(), test_document_html_element(realm, document, &html_head_element_class, "head").dom_node())
test_document_append(root.dom_node(), test_document_html_element(realm, document, &html_body_element_class, "body").dom_node())
assert(dom_document_document_element(document) == root)
assert(dom_document_html_element(document) == none)
assert(dom_document_head(document) == none)
assert(dom_document_body(document) == none)
assert(dom_document_title_element(document) == none)
test "the body is the first body or frameset child of the 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_document_in_realm(realm)
let html = test_document_html_element(realm, document, &html_html_element_class, "html")
test_document_append(document.dom_node(), html.dom_node())
let frameset = test_document_html_element(realm, document, &html_frame_set_element_class, "frameset")
test_document_append(html.dom_node(), test_realm_element(realm, document, "div", namespace_html).dom_node())
test_document_append(html.dom_node(), frameset.dom_node())
test_document_append(html.dom_node(), test_document_html_element(realm, document, &html_body_element_class, "body").dom_node())
assert((DomElement*?)dom_document_body(document) == frameset)
# mark: getElementById, the id map and collections ===========================================
test "getElementById: a tree walk in a disconnected document, the id map in a connected one":
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_document_in_realm(realm)
let html = test_document_html_element(realm, document, &html_html_element_class, "html")
let first = test_realm_element(realm, document, "div", namespace_html)
let second = test_realm_element(realm, document, "span", namespace_html)
test_document_append(document.dom_node(), html.dom_node())
test_document_append(html.dom_node(), first.dom_node())
test_document_append(first.dom_node(), second.dom_node())
# Element::attribute_changed sets m_id (its style invalidation is region r42's), so the ids are set directly.
first.m_id = ak.fly_string_from_str("a")
second.m_id = ak.fly_string_from_str("b")
let id_a = ak.fly_string_from_str("a")
let id_b = ak.fly_string_from_str("b")
assert(not dom_node_is_connected(document.dom_node()))
assert(dom_parent_node_get_element_by_id(document.dom_parent_node(), id_b) == second)
assert(dom_parent_node_get_element_by_id(document.dom_parent_node(), ak.fly_string_from_str("c")) == none)
# A connected document answers from Document::element_by_id(), which insertion keeps.
dom_node_set_is_connected(document.dom_node(), true)
assert(dom_parent_node_get_element_by_id(document.dom_parent_node(), id_a) == none)
dom_element_by_id_map_add(dom_document_element_by_id(document), id_a, first)
assert(dom_parent_node_get_element_by_id(document.dom_parent_node(), id_a) == first)
dom_element_by_id_map_remove(dom_document_element_by_id(document), id_a, first)
assert(dom_parent_node_get_element_by_id(document.dom_parent_node(), id_a) == none)
dom_node_set_is_connected(document.dom_node(), false)
test "document.embeds is one live collection of the embed elements, shared by plugins; getElementsByName":
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_document_in_realm(realm)
let html = test_document_html_element(realm, document, &html_html_element_class, "html")
test_document_append(document.dom_node(), html.dom_node())
let embeds = dom_document_embeds(document)
assert(dom_document_embeds(document) == embeds)
assert(dom_document_plugins(document) == embeds)
assert(dom_html_collection_length(embeds) == 0)
let embed = test_document_html_element(realm, document, &html_embed_element_class, "embed")
embed.m_name = ak.fly_string_from_str("logo")
test_document_append(html.dom_node(), test_realm_element(realm, document, "p", namespace_html).dom_node())
test_document_append(html.dom_node(), embed.dom_node())
# TreeNode::append_child does not bump the DOM tree version as Node::insert does.
document.m_dom_tree_version += 1
assert(dom_html_collection_length(embeds) == 1)
assert(dom_html_collection_item(embeds, 0) == embed)
let named = dom_document_get_elements_by_name(document, ak.fly_string_from_str("logo"))
assert(dom_node_list_length(named) == 1)
# mark: Readiness, quirks mode and events =======================================================
test "readyState names the readiness; update_readiness to the current readiness does nothing":
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_document_in_realm(realm)
# The readiness starts as "complete"; setting it again returns before firing readystatechange (whose
# Event constructor reads the relevant global object, region r29's) or requesting a frame.
dom_document_update_readiness(document, HtmlDocumentReadyState.complete)
assert(test_sv_is(dom_document_ready_state(document), "complete"))
assert(test_document_client_log.frames_requested == 0)
assert(not document.m_needs_to_call_page_did_load)
document.m_readiness = HtmlDocumentReadyState.loading
assert(test_sv_is(dom_document_ready_state(document), "loading"))
dom_document_update_readiness(document, HtmlDocumentReadyState.loading)
document.m_readiness = HtmlDocumentReadyState.interactive
assert(test_sv_is(dom_document_ready_state(document), "interactive"))
test "quirks mode: compatMode is BackCompat only in quirks mode":
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_document_in_realm(realm)
dom_document_set_quirks_mode(document, DomQuirksMode.yes)
assert(dom_document_in_quirks_mode(document) and not dom_document_in_limited_quirks_mode(document))
assert(test_string_is(dom_document_compat_mode(document), "BackCompat"))
dom_document_set_quirks_mode(document, DomQuirksMode.limited)
assert(dom_document_in_limited_quirks_mode(document) and not dom_document_in_quirks_mode(document))
assert(test_string_is(dom_document_compat_mode(document), "CSS1Compat"))
dom_document_set_quirks_mode(document, DomQuirksMode.no)
assert(test_string_is(dom_document_compat_mode(document), "CSS1Compat"))
test "an event's parent from a document is its window, except for load events":
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_document_in_realm(realm)
# A document without a window has no parent.
let event = test_event(realm, "click")
assert(dom_document_get_parent_impl(document.dom_event_target(), event) == none)
let window = (HtmlWindow*)test_document_off_heap_cell(memory.size_of(HtmlWindow), html_window_class.vtable, html_window_class.first_id)
document.m_window = window
assert(dom_document_get_parent_impl(document.dom_event_target(), event) == window.dom_event_target())
# HTML::EventNames are interned by region r22; until then the test interns "load" itself.
html_event_names_load = ak.fly_string_from_str("load")
let load = test_event(realm, "load")
assert(dom_document_get_parent_impl(document.dom_event_target(), load) == none)
document.m_window = none
# mark: Node factories ==========================================================================
test "createTextNode, createComment and createDocumentFragment make nodes of the document":
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_document_in_realm(realm)
let text = dom_document_create_text_node(document, ak.utf16_string_from_str("words"))
assert(dom_node_type(text.dom_node()) == DomNodeType.text_node)
assert(dom_node_document(text.dom_node()) == document)
assert(test_utf16_is(dom_character_data_data(text.dom_character_data()), "words"))
let comment = dom_document_create_comment(document, ak.utf16_string_from_str("note"))
assert(dom_node_type(comment.dom_node()) == DomNodeType.comment_node)
assert(dom_node_document(comment.dom_node()) == document)
let fragment = dom_document_create_document_fragment(document)
assert(dom_node_type(fragment.dom_node()) == DomNodeType.document_fragment_node)
assert(dom_node_document(fragment.dom_node()) == document)
test "createCDATASection: NotSupportedError in HTML documents, InvalidCharacterError for ]]>":
web_initialize_strings()
let vm = web_test_create_vm()
defer web_test_destroy_vm(vm)
let realm = web_test_create_realm(vm)
let html_document = test_document_in_realm(realm)
let thrown_1: DomCdataSection*? = dom_document_create_cdata_section(html_document, ak.utf16_string_from_str("x")) catch failure:
assert(failure.code == webidl_exception)
assert(test_string_is(test_take_dom_exception_string(), "[NotSupportedError]: This operation is not supported for HTML documents"))
recover none
assert(thrown_1 == none)
let xml_document = test_document_in_realm(realm, DocumentDomDocumentType.xml)
let thrown_2: DomCdataSection*? = dom_document_create_cdata_section(xml_document, ak.utf16_string_from_str("a]]>b")) catch failure:
assert(failure.code == webidl_exception)
assert(test_string_is(test_take_dom_exception_string(), "[InvalidCharacterError]: String may not contain ']]>'"))
recover none
assert(thrown_2 == none)
let cdata = dom_document_create_cdata_section(xml_document, ak.utf16_string_from_str("a]]b")) else trap("createCDATASection threw")
assert(dom_node_is_cdata_section(cdata.dom_node()))
assert(dom_node_document(cdata.dom_node()) == xml_document)
test "createProcessingInstruction checks the target's Name production and ?> in the data":
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_document_in_realm(realm, DocumentDomDocumentType.xml)
let thrown_1: DomProcessingInstruction*? = dom_document_create_processing_instruction(document, ak.string_from_str("1x"), ak.utf16_string_from_str("d")) catch failure:
assert(failure.code == webidl_exception)
assert(test_string_is(test_take_dom_exception_string(), "[InvalidCharacterError]: Invalid character in target name."))
recover none
assert(thrown_1 == none)
let thrown_2: DomProcessingInstruction*? = dom_document_create_processing_instruction(document, ak.string_from_str("x"), ak.utf16_string_from_str("a?>")) catch failure:
assert(failure.code == webidl_exception)
assert(test_string_is(test_take_dom_exception_string(), "[InvalidCharacterError]: String may not contain '?>'"))
recover none
assert(thrown_2 == none)
let pi = dom_document_create_processing_instruction(document, ak.string_from_str("xml-stylesheet"), ak.utf16_string_from_str("href=a")) else trap("createProcessingInstruction threw")
assert(test_string_is(pi.m_target, "xml-stylesheet"))
assert(dom_node_document(pi.dom_node()) == document)
test "createElement rejects an invalid local name; createAttribute lowercases in HTML documents":
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_document_in_realm(realm)
let thrown_1: DomElement*? = dom_document_create_element(document, ak.string_from_str("a b"), .string(ak.String())) catch failure:
assert(failure.code == webidl_exception)
assert(test_string_is(test_take_dom_exception_string(), "[InvalidCharacterError]: Invalid character in tag name."))
recover none
assert(thrown_1 == none)
let thrown_2: DomAttr*? = dom_document_create_attribute(document, ak.string_from_str("a=b")) catch failure:
assert(failure.code == webidl_exception)
assert(test_string_is(test_take_dom_exception_string(), "[InvalidCharacterError]: Invalid character in attribute name."))
recover none
assert(thrown_2 == none)
let attribute = dom_document_create_attribute(document, ak.string_from_str("DATA-X")) else trap("createAttribute threw")
assert(test_fly_is(dom_attr_local_name(attribute), "data-x"))
assert(dom_node_document(attribute.dom_node()) == document)
let xml_document = test_document_in_realm(realm, DocumentDomDocumentType.xml)
let xml_attribute = dom_document_create_attribute(xml_document, ak.string_from_str("DATA-X")) else trap("createAttribute threw")
assert(test_fly_is(dom_attr_local_name(xml_attribute), "DATA-X"))
test "is_valid_name follows the XML Name production":
assert(dom_document_is_valid_name(ak.string_from_str("foo")))
assert(dom_document_is_valid_name(ak.string_from_str(":a")))
assert(dom_document_is_valid_name(ak.string_from_str("_a-b.c9")))
assert(dom_document_is_valid_name(ak.string_from_str("\u{e9}t\u{e9}")))
assert(not dom_document_is_valid_name(ak.string_from_str("")))
assert(not dom_document_is_valid_name(ak.string_from_str("1foo")))
assert(not dom_document_is_valid_name(ak.string_from_str("-a")))
assert(not dom_document_is_valid_name(ak.string_from_str("a b")))
assert(not dom_document_is_valid_name(ak.string_from_str("\u{d7}")))
# mark: CSS environment variables and custom properties =========================================
test "environment variables: text scale 1, safe areas 0px, viewport segments invalid":
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_document_in_realm(realm)
var one_index: i32[1] = [0]
let no_indices = one_index[0..<0]
var scale = dom_document_environment_variable_value(document, css_data.EnvironmentVariable.preferred_text_scale, no_indices) else trap("no value")
assert(ak.vector_size(&scale) == 1)
let scale_token = css_syntax.component_value_token(ak.vector_at(&scale, 0))
assert(css_syntax.token_is(&scale_token, css_syntax.TokenType.number))
assert(css_syntax.token_number_value(&scale_token) == 1.0)
var inset = dom_document_environment_variable_value(document, css_data.EnvironmentVariable.safe_area_inset_top, no_indices) else trap("no value")
let inset_token = css_syntax.component_value_token(ak.vector_at(&inset, 0))
assert(css_syntax.token_is(&inset_token, css_syntax.TokenType.dimension))
assert(css_syntax.token_dimension_value(&inset_token) == 0.0)
assert(test_fly_is(css_syntax.token_dimension_unit(&inset_token), "px"))
var indexed = dom_document_environment_variable_value(document, css_data.EnvironmentVariable.safe_area_max_inset_left, one_index[0..<1]) else trap("no value")
assert(css_syntax.component_value_is_guaranteed_invalid(ak.vector_at(&indexed, 0)))
var segment = dom_document_environment_variable_value(document, css_data.EnvironmentVariable.viewport_segment_width, no_indices) else trap("no value")
assert(ak.vector_size(&segment) == 1)
assert(css_syntax.component_value_is_guaranteed_invalid(ak.vector_at(&segment, 0)))
test "custom properties: registrations come from the registered set, then the @property cache":
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_document_in_realm(realm)
let name = ak.fly_string_from_str("--size")
assert(dom_document_get_registered_custom_property(document, name) == none)
let from_rules = CssCustomPropertyRegistration(property_name = name, syntax = ak.string_from_str("<length>"), inherit = false, initial_value = none)
_ = ak.hash_map_set(&document.m_cached_registered_properties_from_css_property_rules, name, from_rules)
let cached = dom_document_get_registered_custom_property(document, name) else trap("no registration")
assert(test_string_is(cached.syntax, "<length>"))
let registered = CssCustomPropertyRegistration(property_name = name, syntax = ak.string_from_str("*"), inherit = true, initial_value = none)
_ = ak.hash_map_set(dom_document_registered_property_set(document), name, registered)
let found = dom_document_get_registered_custom_property(document, name) else trap("no registration")
assert(test_string_is(found.syntax, "*") and found.inherit)
# mark: to_string, MIME types and execCommand ===================================================
test "to_string of the layout reasons":
assert(test_sv_is(dom_to_string_dom_update_layout_reason(DomUpdateLayoutReason.auto_scroll_selection), "AutoScrollSelection"))
assert(test_sv_is(dom_to_string_dom_update_layout_reason(DomUpdateLayoutReason.dump_display_list), "DumpDisplayList"))
assert(test_sv_is(dom_to_string_dom_set_needs_layout_reason(DomSetNeedsLayoutReason.keyframe_effect), "KeyframeEffect"))
assert(test_sv_is(dom_to_string_dom_invalidate_layout_tree_rea(DomInvalidateLayoutTreeReason.document_pending_top_layer_removals_processed), "DocumentPendingTopLayerRemovalsProcessed"))
assert(test_sv_is(dom_to_string_dom_set_needs_layout_tree_upda(DomSetNeedsLayoutTreeUpdateReason.none_), "None"))
## The MIME type `text` parses to.
func test_document_mime(text: str) -> MimeType:
return mime_type_parse(ak.sv(text)) else trap("not a MIME type")
test "can_load_document_with_type: the types load_document handles":
web_initialize_strings()
let loadable: str[13] = ["text/html", "application/xhtml+xml", "image/svg+xml", "text/xml", "text/javascript", "application/json", "text/css", "text/plain", "text/vtt", "multipart/x-mixed-replace", "image/png", "application/pdf", "text/markdown"]
for text in loadable:
let type_ = test_document_mime(text)
assert(can_load_document_with_type(&type_))
let unloadable: str[3] = ["application/octet-stream", "application/zip", "font/woff2"]
for text in unloadable:
let type_ = test_document_mime(text)
assert(not can_load_document_with_type(&type_))
test "execCommand and the queryCommand methods throw InvalidStateError outside HTML documents":
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_document_in_realm(realm, DocumentDomDocumentType.xml)
let bold = ak.fly_string_from_str("bold")
_ = dom_document_exec_command(document, bold, false, ak.utf16_string_new()) catch failure:
assert(failure.code == webidl_exception)
assert(test_string_is(test_take_dom_exception_string(), "[InvalidStateError]: execCommand is only supported on HTML documents"))
recover false
_ = dom_document_query_command_supported(document, bold) catch failure:
assert(test_string_is(test_take_dom_exception_string(), "[InvalidStateError]: queryCommandSupported is only supported on HTML documents"))
recover false
_ = dom_document_query_command_value(document, bold) catch failure:
assert(test_string_is(test_take_dom_exception_string(), "[InvalidStateError]: queryCommandValue is only supported on HTML documents"))
recover ak.String()
# A recursive execCommand returns false before anything else.
let html_document = test_document_in_realm(realm)
html_document.m_inside_exec_command = true
let result = dom_document_exec_command(html_document, bold, false, ak.utf16_string_new()) else trap("execCommand threw")
assert(not result)
assert(html_document.m_inside_exec_command)
test "the backColor and hiliteColor value overrides are set and cleared together":
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_document_in_realm(realm)
let back_color = ak.fly_string_from_str("backColor")
let hilite_color = ak.fly_string_from_str("hiliteColor")
let bold = ak.fly_string_from_str("bold")
dom_document_set_command_value_override(document, back_color, ak.utf16_string_from_str("red"))
assert(test_utf16_is(*(dom_document_command_value_override(document, hilite_color) else trap("no override")), "red"))
dom_document_set_command_value_override(document, hilite_color, ak.utf16_string_from_str("blue"))
assert(test_utf16_is(*(dom_document_command_value_override(document, back_color) else trap("no override")), "blue"))
dom_document_set_command_value_override(document, bold, ak.utf16_string_from_str("x"))
dom_document_clear_command_value_override(document, hilite_color)
assert(dom_document_command_value_override(document, back_color) == none)
assert(dom_document_command_value_override(document, hilite_color) == none)
assert(dom_document_command_value_override(document, bold) != none)