diff options
Diffstat (limited to 'testing/web-platform/tests/editing/include/editor-test-utils.js')
-rw-r--r-- | testing/web-platform/tests/editing/include/editor-test-utils.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/testing/web-platform/tests/editing/include/editor-test-utils.js b/testing/web-platform/tests/editing/include/editor-test-utils.js index d0d50d22a6..b180f3343f 100644 --- a/testing/web-platform/tests/editing/include/editor-test-utils.js +++ b/testing/web-platform/tests/editing/include/editor-test-utils.js @@ -424,4 +424,79 @@ class EditorTestUtils { ); } } + + static getRangeArrayDescription(arrayOfRanges) { + if (arrayOfRanges === null) { + return "null"; + } + if (arrayOfRanges === undefined) { + return "undefined"; + } + if (!Array.isArray(arrayOfRanges)) { + return "Unknown Object"; + } + if (arrayOfRanges.length === 0) { + return "[]"; + } + let result = ""; + for (let range of arrayOfRanges) { + if (result === "") { + result = "["; + } else { + result += ","; + } + result += `{${EditorTestUtils.getRangeDescription(range)}}`; + } + result += "]"; + return result; + } + + static getNodeDescription(node) { + if (!node) { + return "null"; + } + switch (node.nodeType) { + case Node.TEXT_NODE: + case Node.COMMENT_NODE: + case Node.CDATA_SECTION_NODE: + return `${node.nodeName} "${node.data.replaceAll("\n", "\\\\n")}"`; + case Node.ELEMENT_NODE: + return `<${node.nodeName.toLowerCase()}${ + node.hasAttribute("id") ? ` id="${node.getAttribute("id")}"` : "" + }${ + node.hasAttribute("class") ? ` class="${node.getAttribute("class")}"` : "" + }${ + node.hasAttribute("contenteditable") + ? ` contenteditable="${node.getAttribute("contenteditable")}"` + : "" + }${ + node.inert ? ` inert` : "" + }${ + node.hidden ? ` hidden` : "" + }${ + node.readonly ? ` readonly` : "" + }${ + node.disabled ? ` disabled` : "" + }>`; + default: + return `${node.nodeName}`; + } + } + + static getRangeDescription(range) { + if (range === null) { + return "null"; + } + if (range === undefined) { + return "undefined"; + } + return range.startContainer == range.endContainer && + range.startOffset == range.endOffset + ? `(${EditorTestUtils.getNodeDescription(range.startContainer)}, ${range.startOffset})` + : `(${EditorTestUtils.getNodeDescription(range.startContainer)}, ${ + range.startOffset + }) - (${EditorTestUtils.getNodeDescription(range.endContainer)}, ${range.endOffset})`; + } + + } |