@@ -631,262 +631,7 @@ pub const Node = struct {
631631};
632632
633633const testing = @import ("../../testing.zig" );
634- test "Browser.DOM.node" {
635- var runner = try testing .jsRunner (testing .tracking_allocator , .{});
636- defer runner .deinit ();
637-
638- {
639- var err_out : ? []const u8 = null ;
640- try runner .exec (
641- \\ function trimAndReplace(str) {
642- \\ str = str.replace(/(\r\n|\n|\r)/gm,'');
643- \\ str = str.replace(/\s+/g, ' ');
644- \\ str = str.trim();
645- \\ return str;
646- \\ }
647- , "trimAndReplace" , & err_out );
648- }
649-
650- try runner .testCases (&.{
651- .{ "document.body.compareDocumentPosition(document.firstChild); " , "10" },
652- .{ "document.getElementById(\" para-empty\" ).compareDocumentPosition(document.getElementById(\" content\" ));" , "10" },
653- .{ "document.getElementById(\" content\" ).compareDocumentPosition(document.getElementById(\" para-empty\" ));" , "20" },
654- .{ "document.getElementById(\" link\" ).compareDocumentPosition(document.getElementById(\" link\" ));" , "0" },
655- .{ "document.getElementById(\" para-empty\" ).compareDocumentPosition(document.getElementById(\" link\" ));" , "2" },
656- .{ "document.getElementById(\" link\" ).compareDocumentPosition(document.getElementById(\" para-empty\" ));" , "4" },
657- }, .{});
658-
659- try runner .testCases (&.{
660- .{ "document.getElementById('content').getRootNode().__proto__.constructor.name" , "HTMLDocument" },
661- }, .{});
662-
663- try runner .testCases (&.{
664- // for next test cases
665- .{ "let content = document.getElementById('content')" , "undefined" },
666- .{ "let link = document.getElementById('link')" , "undefined" },
667- .{ "let first_child = content.firstChild.nextSibling" , "undefined" }, // nextSibling because of line return \n
668-
669- .{ "let body_first_child = document.body.firstChild" , "undefined" },
670- .{ "body_first_child.localName" , "div" },
671- .{ "body_first_child.__proto__.constructor.name" , "HTMLDivElement" },
672- .{ "document.getElementById('para-empty').firstChild.firstChild" , "null" },
673- }, .{});
674-
675- try runner .testCases (&.{
676- .{ "let last_child = content.lastChild.previousSibling" , "undefined" }, // previousSibling because of line return \n
677- .{ "last_child.__proto__.constructor.name" , "Comment" },
678- }, .{});
679-
680- try runner .testCases (&.{
681- .{ "let next_sibling = link.nextSibling.nextSibling" , "undefined" },
682- .{ "next_sibling.localName" , "p" },
683- .{ "next_sibling.__proto__.constructor.name" , "HTMLParagraphElement" },
684- .{ "content.nextSibling.nextSibling" , "null" },
685- }, .{});
686-
687- try runner .testCases (&.{
688- .{ "let prev_sibling = document.getElementById('para-empty').previousSibling.previousSibling" , "undefined" },
689- .{ "prev_sibling.localName" , "a" },
690- .{ "prev_sibling.__proto__.constructor.name" , "HTMLAnchorElement" },
691- .{ "content.previousSibling" , "null" },
692- }, .{});
693-
694- try runner .testCases (&.{
695- .{ "let parent = document.getElementById('para').parentElement" , "undefined" },
696- .{ "parent.localName" , "div" },
697- .{ "parent.__proto__.constructor.name" , "HTMLDivElement" },
698- .{ "let h = content.parentElement.parentElement" , "undefined" },
699- .{ "h.parentElement" , "null" },
700- .{ "h.parentNode.__proto__.constructor.name" , "HTMLDocument" },
701- }, .{});
702-
703- try runner .testCases (&.{
704- .{ "first_child.nodeName === 'A'" , "true" },
705- .{ "link.firstChild.nodeName === '#text'" , "true" },
706- .{ "last_child.nodeName === '#comment'" , "true" },
707- .{ "document.nodeName === '#document'" , "true" },
708- }, .{});
709-
710- try runner .testCases (&.{
711- .{ "first_child.nodeType === 1" , "true" },
712- .{ "link.firstChild.nodeType === 3" , "true" },
713- .{ "last_child.nodeType === 8" , "true" },
714- .{ "document.nodeType === 9" , "true" },
715- }, .{});
716-
717- try runner .testCases (&.{
718- .{ "let owner = content.ownerDocument" , "undefined" },
719- .{ "owner.__proto__.constructor.name" , "HTMLDocument" },
720- .{ "document.ownerDocument" , "null" },
721- .{ "let owner2 = document.createElement('div').ownerDocument" , "undefined" },
722- .{ "owner2.__proto__.constructor.name" , "HTMLDocument" },
723- }, .{});
724-
725- try runner .testCases (&.{
726- .{ "content.isConnected" , "true" },
727- .{ "document.isConnected" , "true" },
728- .{ "const connDiv = document.createElement('div')" , null },
729- .{ "connDiv.isConnected" , "false" },
730- .{ "const connParentDiv = document.createElement('div')" , null },
731- .{ "connParentDiv.appendChild(connDiv)" , null },
732- .{ "connDiv.isConnected" , "false" },
733- .{ "content.appendChild(connParentDiv)" , null },
734- .{ "connDiv.isConnected" , "true" },
735- }, .{});
736-
737- try runner .testCases (&.{
738- .{ "last_child.nodeValue === 'comment'" , "true" },
739- .{ "link.nodeValue === null" , "true" },
740- .{ "let text = link.firstChild" , "undefined" },
741- .{ "text.nodeValue === 'OK'" , "true" },
742- .{ "text.nodeValue = 'OK modified'" , "OK modified" },
743- .{ "text.nodeValue === 'OK modified'" , "true" },
744- .{ "link.nodeValue = 'nothing'" , "nothing" },
745- }, .{});
746-
747- try runner .testCases (&.{
748- .{ "text.textContent === 'OK modified'" , "true" },
749- .{ "trimAndReplace(content.textContent) === 'OK modified And'" , "true" },
750- .{ "text.textContent = 'OK'" , "OK" },
751- .{ "text.textContent" , "OK" },
752- .{ "trimAndReplace(document.getElementById('para-empty').textContent)" , "" },
753- .{ "document.getElementById('para-empty').textContent = 'OK'" , "OK" },
754- .{ "document.getElementById('para-empty').firstChild.nodeName === '#text'" , "true" },
755- }, .{});
756-
757- try runner .testCases (&.{
758- .{ "let append = document.createElement('h1')" , "undefined" },
759- .{ "content.appendChild(append).toString()" , "[object HTMLHeadingElement]" },
760- .{ "content.lastChild.__proto__.constructor.name" , "HTMLHeadingElement" },
761- .{ "content.appendChild(link).toString()" , "[object HTMLAnchorElement]" },
762- }, .{});
763-
764- try runner .testCases (&.{
765- .{ "let clone = link.cloneNode()" , "undefined" },
766- .{ "clone.toString()" , "[object HTMLAnchorElement]" },
767- .{ "clone.parentNode === null" , "true" },
768- .{ "clone.firstChild === null" , "true" },
769- .{ "let clone_deep = link.cloneNode(true)" , "undefined" },
770- .{ "clone_deep.firstChild.nodeName === '#text'" , "true" },
771- }, .{});
772-
773- try runner .testCases (&.{
774- .{ "link.contains(text)" , "true" },
775- .{ "text.contains(link)" , "false" },
776- }, .{});
777-
778- try runner .testCases (&.{
779- .{ "link.hasChildNodes()" , "true" },
780- .{ "text.hasChildNodes()" , "false" },
781- }, .{});
782-
783- try runner .testCases (&.{
784- .{ "link.childNodes.length" , "1" },
785- .{ "text.childNodes.length" , "0" },
786- }, .{});
787-
788- try runner .testCases (&.{
789- .{ "let insertBefore = document.createElement('a')" , "undefined" },
790- .{ "link.insertBefore(insertBefore, text) !== undefined" , "true" },
791- .{ "link.firstChild.localName === 'a'" , "true" },
792-
793- .{ "let insertBefore2 = document.createElement('b')" , null },
794- .{ "link.insertBefore(insertBefore2, null).localName" , "b" },
795- .{ "link.childNodes[link.childNodes.length - 1].localName" , "b" },
796- }, .{});
797-
798- try runner .testCases (&.{
799- // TODO: does not seems to work
800- // .{ "link.isDefaultNamespace('')", "true" },
801- .{ "link.isDefaultNamespace('false')" , "false" },
802- }, .{});
803-
804- try runner .testCases (&.{
805- .{ "let equal1 = document.createElement('a')" , "undefined" },
806- .{ "let equal2 = document.createElement('a')" , "undefined" },
807- .{ "equal1.textContent = 'is equal'" , "is equal" },
808- .{ "equal2.textContent = 'is equal'" , "is equal" },
809- // TODO: does not seems to work
810- // .{ "equal1.isEqualNode(equal2)", "true" },
811- }, .{});
812-
813- try runner .testCases (&.{
814- .{ "document.body.isSameNode(document.body)" , "true" },
815- }, .{});
816-
817- try runner .testCases (&.{
818- // TODO: no test
819- .{ "link.normalize()" , "undefined" },
820- }, .{});
821-
822- try runner .testCases (&.{
823- .{ "link.baseURI" , "https://lightpanda.io/opensource-browser/" },
824- }, .{});
825-
826- try runner .testCases (&.{
827- .{ "content.removeChild(append) !== undefined" , "true" },
828- .{ "last_child.__proto__.constructor.name !== 'HTMLHeadingElement'" , "true" },
829- }, .{});
830-
831- try runner .testCases (&.{
832- .{ "let replace = document.createElement('div')" , "undefined" },
833- .{ "link.replaceChild(replace, insertBefore) !== undefined" , "true" },
834- }, .{});
835-
836- try runner .testCases (&.{
837- .{ "Node.ELEMENT_NODE" , "1" },
838- .{ "Node.ATTRIBUTE_NODE" , "2" },
839- .{ "Node.TEXT_NODE" , "3" },
840- .{ "Node.CDATA_SECTION_NODE" , "4" },
841- .{ "Node.PROCESSING_INSTRUCTION_NODE" , "7" },
842- .{ "Node.COMMENT_NODE" , "8" },
843- .{ "Node.DOCUMENT_NODE" , "9" },
844- .{ "Node.DOCUMENT_TYPE_NODE" , "10" },
845- .{ "Node.DOCUMENT_FRAGMENT_NODE" , "11" },
846- .{ "Node.ENTITY_REFERENCE_NODE" , "5" },
847- .{ "Node.ENTITY_NODE" , "6" },
848- .{ "Node.NOTATION_NODE" , "12" },
849- }, .{});
850- }
851-
852- test "Browser.DOM.node.owner" {
853- var runner = try testing .jsRunner (testing .tracking_allocator , .{ .html =
854- \\ <div id="target-container">
855- \\ <p id="reference-node">
856- \\ I am the original reference node.
857- \\ </p>
858- \\ </div>"
859- });
860-
861- defer runner .deinit ();
862-
863- try runner .testCases (&.{
864- .{
865- \\ const parser = new DOMParser();
866- \\ const newDoc = parser.parseFromString('<div id="new-node"><p>Hey</p><span>Marked</span></div>', 'text/html');
867- \\ const newNode = newDoc.getElementById('new-node');
868- \\ const parent = document.getElementById('target-container');
869- \\ const referenceNode = document.getElementById('reference-node');
870- \\ parent.insertBefore(newNode, referenceNode);
871- \\ const k = document.getElementById('new-node');
872- \\ const ptag = k.querySelector('p');
873- \\ const spanTag = k.querySelector('span');
874- \\ const anotherDoc = parser.parseFromString('<div id="another-new-node"></div>', 'text/html');
875- \\ const anotherNewNode = anotherDoc.getElementById('another-new-node');
876- \\
877- \\ parent.appendChild(anotherNewNode)
878- ,
879- "[object HTMLDivElement]" ,
880- },
881-
882- .{ "parent.ownerDocument === newNode.ownerDocument" , "true" },
883- .{ "parent.ownerDocument === anotherNewNode.ownerDocument" , "true" },
884- .{ "newNode.firstChild.nodeName" , "P" },
885- .{ "ptag.ownerDocument === parent.ownerDocument" , "true" },
886- .{ "spanTag.ownerDocument === parent.ownerDocument" , "true" },
887- .{ "parent.contains(newNode)" , "true" },
888- .{ "parent.contains(anotherNewNode)" , "true" },
889- .{ "anotherDoc.contains(anotherNewNode)" , "false" },
890- .{ "newDoc.contains(newNode)" , "false" },
891- }, .{});
634+ test "Browser: DOM.Node" {
635+ try testing .htmlRunner ("dom/node.html" );
636+ try testing .htmlRunner ("dom/node_owner.html" );
892637}
0 commit comments